diff --git a/third_party/musl/ndk_musl_include/sys/select.h b/third_party/musl/ndk_musl_include/sys/select.h index d933d308c4c7d947b56f6e996b5c90f725c2e306..48f941038d7c606993238bb6f99222db9ca0500b 100644 --- a/third_party/musl/ndk_musl_include/sys/select.h +++ b/third_party/musl/ndk_musl_include/sys/select.h @@ -23,10 +23,19 @@ typedef struct { unsigned long fds_bits[FD_SETSIZE / 8 / sizeof(long)]; } fd_set; +/** +* @brief Check if fd passed to fd_set is valid (<1024). +* +* This method will check fd(0 <= fd < 1024) is valid for select, abort if not. +* +* @param fd: Specified fd. +*/ +void __fd_chk(int fd); + #define FD_ZERO(s) do { int __i; unsigned long *__b=(s)->fds_bits; for(__i=sizeof (fd_set)/sizeof (long); __i; __i--) *__b++=0; } while(0) -#define FD_SET(d, s) ((s)->fds_bits[(d)/(8*sizeof(long))] |= (1UL<<((d)%(8*sizeof(long))))) -#define FD_CLR(d, s) ((s)->fds_bits[(d)/(8*sizeof(long))] &= ~(1UL<<((d)%(8*sizeof(long))))) -#define FD_ISSET(d, s) !!((s)->fds_bits[(d)/(8*sizeof(long))] & (1UL<<((d)%(8*sizeof(long))))) +#define FD_SET(d, s) do { __fd_chk(d); ((s)->fds_bits[(d)/(8*sizeof(long))] |= (1UL<<((d)%(8*sizeof(long))))); } while(0) +#define FD_CLR(d, s) do { __fd_chk(d); ((s)->fds_bits[(d)/(8*sizeof(long))] &= ~(1UL<<((d)%(8*sizeof(long))))); } while(0) +#define FD_ISSET(d, s) ((d) >= 0 && (d) < FD_SETSIZE && (!!((s)->fds_bits[(d)/(8*sizeof(long))] & (1UL<<((d)%(8*sizeof(long))))))) int select (int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict, struct timeval *__restrict); int pselect (int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict, const struct timespec *__restrict, const sigset_t *__restrict); diff --git a/third_party/musl/ndk_script/adapter/libc.ndk.json b/third_party/musl/ndk_script/adapter/libc.ndk.json index 09454d9ff30b8613d63dd80980a205e7acbff74e..41070eecda4bb977a650b3b593d7d405d468a4ec 100644 --- a/third_party/musl/ndk_script/adapter/libc.ndk.json +++ b/third_party/musl/ndk_script/adapter/libc.ndk.json @@ -6,6 +6,7 @@ { "name": "__duplocale" }, { "name": "__errno_location" }, { "name": "__fbufsize" }, + { "name": "__fd_chk"}, { "name": "__flbf" }, { "name": "__flt_rounds" }, { "name": "__fpclassify" },