poll.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (C) 2015 Dimitris Papastamos <sin@2f30.org>
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted.
  6. *
  7. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  10. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  12. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  13. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. */
  15. #ifndef _FORTIFY_POLL_H
  16. #define _FORTIFY_POLL_H
  17. __extension__
  18. #include_next <poll.h>
  19. #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0
  20. #include "fortify-headers.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. #undef poll
  25. _FORTIFY_FN(poll) int poll(struct pollfd *__f, nfds_t __n, int __s)
  26. {
  27. __typeof__(sizeof 0) __b = __builtin_object_size(__f, 0);
  28. if (__n > __b / sizeof(struct pollfd))
  29. __builtin_trap();
  30. return __orig_poll(__f, __n, __s);
  31. }
  32. #ifdef _GNU_SOURCE
  33. #undef ppoll
  34. _FORTIFY_FN(ppoll) int ppoll(struct pollfd *__f, nfds_t __n, const struct timespec *__s,
  35. const sigset_t *__m)
  36. {
  37. __typeof__(sizeof 0) __b = __builtin_object_size(__f, 0);
  38. if (__n > __b / sizeof(struct pollfd))
  39. __builtin_trap();
  40. return __orig_ppoll(__f, __n, __s, __m);
  41. }
  42. #endif
  43. #ifdef __cplusplus
  44. }
  45. #endif
  46. #endif
  47. #endif