poll.h revision b97049c0390cb1a11b9cb0b14391972e69398ce5
1/* 2 * Copyright (C) 2017 The Android Open Source Project 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in 12 * the documentation and/or other materials provided with the 13 * distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29#ifndef _POLL_H_ 30#error "Never include this file directly; instead, include <poll.h>" 31#endif 32 33int __poll_chk(struct pollfd*, nfds_t, int, size_t) __INTRODUCED_IN(23); 34int __ppoll_chk(struct pollfd*, nfds_t, const struct timespec*, const sigset_t*, size_t) 35 __INTRODUCED_IN(23); 36 37#if defined(__BIONIC_FORTIFY) 38#if __ANDROID_API__ >= __ANDROID_API_M__ 39#if defined(__clang__) 40__BIONIC_ERROR_FUNCTION_VISIBILITY 41int poll(struct pollfd* fds, nfds_t fd_count, int timeout) __overloadable 42 __enable_if(__bos(fds) != __BIONIC_FORTIFY_UNKNOWN_SIZE && 43 __bos(fds) < sizeof(*fds) * fd_count, 44 "selected when there aren't fd_count fds") 45 __errorattr("too many fds specified"); 46 47__BIONIC_FORTIFY_INLINE 48int poll(struct pollfd* const fds __pass_object_size, nfds_t fd_count, 49 int timeout) __overloadable { 50 size_t bos_fds = __bos(fds); 51 52 if (bos_fds == __BIONIC_FORTIFY_UNKNOWN_SIZE) { 53 return __call_bypassing_fortify(poll)(fds, fd_count, timeout); 54 } 55 56 return __poll_chk(fds, fd_count, timeout, bos_fds); 57} 58 59__BIONIC_ERROR_FUNCTION_VISIBILITY 60int ppoll(struct pollfd* fds, nfds_t fd_count, const struct timespec* timeout, 61 const sigset_t* mask) __overloadable 62 __enable_if(__bos(fds) != __BIONIC_FORTIFY_UNKNOWN_SIZE && 63 __bos(fds) < sizeof(*fds) * fd_count, 64 "selected when there aren't fd_count fds") 65 __errorattr("too many fds specified"); 66 67__BIONIC_FORTIFY_INLINE 68int ppoll(struct pollfd* const fds __pass_object_size, nfds_t fd_count, 69 const struct timespec* timeout, const sigset_t* mask) __overloadable { 70 size_t bos_fds = __bos(fds); 71 72 if (bos_fds == __BIONIC_FORTIFY_UNKNOWN_SIZE) { 73 return __call_bypassing_fortify(ppoll)(fds, fd_count, timeout, mask); 74 } 75 76 return __ppoll_chk(fds, fd_count, timeout, mask, bos_fds); 77} 78#else /* defined(__clang__) */ 79int __poll_real(struct pollfd*, nfds_t, int) __RENAME(poll); 80__errordecl(__poll_too_small_error, "poll: pollfd array smaller than fd count"); 81 82int __ppoll_real(struct pollfd*, nfds_t, const struct timespec*, const sigset_t*) __RENAME(ppoll) 83 __INTRODUCED_IN(21); 84__errordecl(__ppoll_too_small_error, "ppoll: pollfd array smaller than fd count"); 85 86__BIONIC_FORTIFY_INLINE 87int poll(struct pollfd* fds, nfds_t fd_count, int timeout) { 88 if (__bos(fds) != __BIONIC_FORTIFY_UNKNOWN_SIZE) { 89 if (!__builtin_constant_p(fd_count)) { 90 return __poll_chk(fds, fd_count, timeout, __bos(fds)); 91 } else if (__bos(fds) / sizeof(*fds) < fd_count) { 92 __poll_too_small_error(); 93 } 94 } 95 return __poll_real(fds, fd_count, timeout); 96} 97 98__BIONIC_FORTIFY_INLINE 99int ppoll(struct pollfd* fds, nfds_t fd_count, const struct timespec* timeout, 100 const sigset_t* mask) { 101 if (__bos(fds) != __BIONIC_FORTIFY_UNKNOWN_SIZE) { 102 if (!__builtin_constant_p(fd_count)) { 103 return __ppoll_chk(fds, fd_count, timeout, mask, __bos(fds)); 104 } else if (__bos(fds) / sizeof(*fds) < fd_count) { 105 __ppoll_too_small_error(); 106 } 107 } 108 return __ppoll_real(fds, fd_count, timeout, mask); 109} 110 111#endif /* defined(__clang__) */ 112#endif /* __ANDROID_API__ >= __ANDROID_API_M__ */ 113#endif /* defined(__BIONIC_FORTIFY) */ 114