From 9f8c543dc81f0c4239acae6713f5414eb7dc681d Mon Sep 17 00:00:00 2001 From: sin Date: Fri, 13 Mar 2015 11:00:46 +0000 Subject: 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. --- include/poll.h | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'include/poll.h') 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 @@ #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 #ifndef __cplusplus +#undef poll -static inline __attribute__ ((always_inline)) -int -__fortify_poll(struct pollfd *fds, nfds_t nfds, int timeout) +extern int __poll_orig(struct pollfd *, nfds_t, int) + __asm__(__USER_LABEL_PREFIX__ "poll"); +extern __inline __attribute__((__always_inline__,__gnu_inline__)) +int poll(struct pollfd *fds, nfds_t nfds, int timeout) { __typeof__(sizeof 0) bos = __builtin_object_size(fds, 0); if (nfds > bos / sizeof(struct pollfd)) __builtin_trap(); - return poll(fds, nfds, timeout); + return __poll_orig(fds, nfds, timeout); } #ifdef _GNU_SOURCE -static inline __attribute__ ((always_inline)) -int -__fortify_ppoll(struct pollfd *fds, nfds_t nfds, - const struct timespec *timeout, const sigset_t *mask) +#undef ppoll +extern int __ppoll_orig(struct pollfd *, nfds_t, const struct timespec *, const sigset_t *) + __asm__(__USER_LABEL_PREFIX__ "ppoll"); +extern __inline __attribute__((__always_inline__,__gnu_inline__)) +int ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout, const sigset_t *mask) { __typeof__(sizeof 0) bos = __builtin_object_size(fds, 0); if (nfds > bos / sizeof(struct pollfd)) __builtin_trap(); - return ppoll(fds, nfds, timeout, mask); + return __ppoll_orig(fds, nfds, timeout, mask); } #endif -#undef poll -#define poll(fds, nfds, timeout) __fortify_poll(fds, nfds, timeout) - -#ifdef _GNU_SOURCE -#undef ppoll -#define ppoll(fds, nfds, timeout, mask) __fortify_ppoll(fds, nfds, timeout, mask) -#endif - #endif #endif -- cgit v1.3