select.h (2410B)
1 /* 2 * Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org> 3 * Copyright (C) 2022 q66 <q66@chimera-linux.org> 4 * 5 * Permission to use, copy, modify, and/or distribute this software for any 6 * purpose with or without fee is hereby granted. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #ifndef _FORTIFY_SYS_SELECT_H 18 #define _FORTIFY_SYS_SELECT_H 19 20 #if !defined(__cplusplus) && !defined(__clang__) 21 __extension__ 22 #endif 23 #include_next <sys/select.h> 24 25 #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 26 #include "../fortify-headers.h" 27 28 #ifdef __cplusplus 29 extern "C" { 30 #endif 31 32 #define _STI static __inline__ \ 33 __attribute__((__always_inline__,__gnu_inline__,__artificial__)) 34 35 _STI void __fortify_FD_CLR(int __f, fd_set * _FORTIFY_POS0 __s) 36 { 37 __fh_size_t __b = __fh_bos(__s, 0); 38 39 if (__f < 0 || __f >= FD_SETSIZE || __b < sizeof(fd_set)) 40 __builtin_trap(); 41 FD_CLR(__f, __s); 42 } 43 44 _STI void __fortify_FD_SET(int __f, fd_set * _FORTIFY_POS0 __s) 45 { 46 __fh_size_t __b = __fh_bos(__s, 0); 47 48 if (__f < 0 || __f >= FD_SETSIZE || __b < sizeof(fd_set)) 49 __builtin_trap(); 50 FD_SET(__f, __s); 51 } 52 53 _STI int __fortify_FD_ISSET(int __f, const fd_set * _FORTIFY_POS0 __s) 54 { 55 __fh_size_t __b = __fh_bos(__s, 0); 56 57 if (__f < 0 || __f >= FD_SETSIZE || __b < sizeof(fd_set)) 58 __builtin_trap(); 59 return FD_ISSET(__f, __s); 60 } 61 62 #undef _STI 63 64 #undef FD_CLR 65 #define FD_CLR(fd, set) __fortify_FD_CLR(fd, set) 66 #undef FD_SET 67 #define FD_SET(fd, set) __fortify_FD_SET(fd, set) 68 #undef FD_ISSET 69 #define FD_ISSET(fd, set) __fortify_FD_ISSET(fd, set) 70 71 #ifndef __clang__ 72 #undef select 73 _FORTIFY_FN(select) int select(int nfds, fd_set* readfds, 74 fd_set* writefds, 75 fd_set* exceptfds, 76 struct timeval *timeout){ 77 if (nfds > FD_SETSIZE + 1) 78 __builtin_trap(); 79 return __orig_select(nfds, readfds, writefds, exceptfds, timeout); 80 } 81 #endif 82 83 #ifdef __cplusplus 84 } 85 #endif 86 87 #endif 88 89 #endif