diff options
| author | sin | 2015-03-13 11:00:46 +0000 |
|---|---|---|
| committer | sin | 2015-03-13 11:00:46 +0000 |
| commit | 9f8c543dc81f0c4239acae6713f5414eb7dc681d (patch) | |
| tree | 0c8dad17e27c510cc3c98502841aa1a75dfa3d1e /include/poll.h | |
| parent | b211796d68c4a6b56f999534627791f3576b6135 (diff) | |
Rework fortify implementation to use extern inline
Overriding functions with macros is legal in C but a lot of software
is not prepared for it. Use the extern inline method to achieve the
same result.
Diffstat (limited to 'include/poll.h')
| -rw-r--r-- | include/poll.h | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/include/poll.h b/include/poll.h index 5490b94..93976dd 100644 --- a/include/poll.h +++ b/include/poll.h | |||
| @@ -6,40 +6,35 @@ | |||
| 6 | #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 | 6 | #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 |
| 7 | 7 | ||
| 8 | #ifndef __cplusplus | 8 | #ifndef __cplusplus |
| 9 | #undef poll | ||
| 9 | 10 | ||
| 10 | static inline __attribute__ ((always_inline)) | 11 | extern int __poll_orig(struct pollfd *, nfds_t, int) |
| 11 | int | 12 | __asm__(__USER_LABEL_PREFIX__ "poll"); |
| 12 | __fortify_poll(struct pollfd *fds, nfds_t nfds, int timeout) | 13 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 14 | int poll(struct pollfd *fds, nfds_t nfds, int timeout) | ||
| 13 | { | 15 | { |
| 14 | __typeof__(sizeof 0) bos = __builtin_object_size(fds, 0); | 16 | __typeof__(sizeof 0) bos = __builtin_object_size(fds, 0); |
| 15 | 17 | ||
| 16 | if (nfds > bos / sizeof(struct pollfd)) | 18 | if (nfds > bos / sizeof(struct pollfd)) |
| 17 | __builtin_trap(); | 19 | __builtin_trap(); |
| 18 | return poll(fds, nfds, timeout); | 20 | return __poll_orig(fds, nfds, timeout); |
| 19 | } | 21 | } |
| 20 | 22 | ||
| 21 | #ifdef _GNU_SOURCE | 23 | #ifdef _GNU_SOURCE |
| 22 | static inline __attribute__ ((always_inline)) | 24 | #undef ppoll |
| 23 | int | 25 | extern int __ppoll_orig(struct pollfd *, nfds_t, const struct timespec *, const sigset_t *) |
| 24 | __fortify_ppoll(struct pollfd *fds, nfds_t nfds, | 26 | __asm__(__USER_LABEL_PREFIX__ "ppoll"); |
| 25 | const struct timespec *timeout, const sigset_t *mask) | 27 | extern __inline __attribute__((__always_inline__,__gnu_inline__)) |
| 28 | int ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout, const sigset_t *mask) | ||
| 26 | { | 29 | { |
| 27 | __typeof__(sizeof 0) bos = __builtin_object_size(fds, 0); | 30 | __typeof__(sizeof 0) bos = __builtin_object_size(fds, 0); |
| 28 | 31 | ||
| 29 | if (nfds > bos / sizeof(struct pollfd)) | 32 | if (nfds > bos / sizeof(struct pollfd)) |
| 30 | __builtin_trap(); | 33 | __builtin_trap(); |
| 31 | return ppoll(fds, nfds, timeout, mask); | 34 | return __ppoll_orig(fds, nfds, timeout, mask); |
| 32 | } | 35 | } |
| 33 | #endif | 36 | #endif |
| 34 | 37 | ||
| 35 | #undef poll | ||
| 36 | #define poll(fds, nfds, timeout) __fortify_poll(fds, nfds, timeout) | ||
| 37 | |||
| 38 | #ifdef _GNU_SOURCE | ||
| 39 | #undef ppoll | ||
| 40 | #define ppoll(fds, nfds, timeout, mask) __fortify_ppoll(fds, nfds, timeout, mask) | ||
| 41 | #endif | ||
| 42 | |||
| 43 | #endif | 38 | #endif |
| 44 | 39 | ||
| 45 | #endif | 40 | #endif |
