diff options
Diffstat (limited to 'libc/include/poll.h')
-rw-r--r-- | libc/include/poll.h | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/libc/include/poll.h b/libc/include/poll.h index 0199cab..7c16d81 100644 --- a/libc/include/poll.h +++ b/libc/include/poll.h @@ -38,8 +38,52 @@ __BEGIN_DECLS typedef unsigned int nfds_t; -extern int poll(struct pollfd*, nfds_t, int); -extern int ppoll(struct pollfd*, nfds_t, const struct timespec*, const sigset_t*); +int poll(struct pollfd*, nfds_t, int); +int ppoll(struct pollfd*, nfds_t, const struct timespec*, const sigset_t*); + +int __poll_chk(struct pollfd*, nfds_t, int, size_t); +int __poll_real(struct pollfd*, nfds_t, int) __RENAME(poll); +__errordecl(__poll_too_small_error, "poll: pollfd array smaller than fd count"); + +int __ppoll_chk(struct pollfd*, nfds_t, const struct timespec*, const sigset_t*, size_t); +int __ppoll_real(struct pollfd*, nfds_t, const struct timespec*, const sigset_t*) __RENAME(ppoll); +__errordecl(__ppoll_too_small_error, "ppoll: pollfd array smaller than fd count"); + +#if defined(__BIONIC_FORTIFY) + +__BIONIC_FORTIFY_INLINE +int poll(struct pollfd* fds, nfds_t fd_count, int timeout) { +#if defined(__clang__) + return __poll_chk(fds, fd_count, timeout, __bos(fds)); +#else + if (__bos(fds) != __BIONIC_FORTIFY_UNKNOWN_SIZE) { + if (!__builtin_constant_p(fd_count)) { + return __poll_chk(fds, fd_count, timeout, __bos(fds)); + } else if (__bos(fds) / sizeof(*fds) < fd_count) { + __poll_too_small_error(); + } + } + return __poll_real(fds, fd_count, timeout); +#endif +} + +__BIONIC_FORTIFY_INLINE +int ppoll(struct pollfd* fds, nfds_t fd_count, const struct timespec* timeout, const sigset_t* mask) { +#if defined(__clang__) + return __ppoll_chk(fds, fd_count, timeout, mask, __bos(fds)); +#else + if (__bos(fds) != __BIONIC_FORTIFY_UNKNOWN_SIZE) { + if (!__builtin_constant_p(fd_count)) { + return __ppoll_chk(fds, fd_count, timeout, mask, __bos(fds)); + } else if (__bos(fds) / sizeof(*fds) < fd_count) { + __ppoll_too_small_error(); + } + } + return __ppoll_real(fds, fd_count, timeout, mask); +#endif +} + +#endif __END_DECLS |