summaryrefslogtreecommitdiff
path: root/include/poll.h
blob: ac79695387ea877aa2d53d2d51dfd56450266c98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef FORTIFY_POLL_H_
#define FORTIFY_POLL_H_

#include_next <poll.h>

#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0

#ifdef __cplusplus
extern "C" {
#endif

static inline __attribute__ ((always_inline))
int
__fortify_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);
}

#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)
{
	__typeof__(sizeof 0) bos = __builtin_object_size(fds, 0);

	if (nfds > bos / sizeof(struct pollfd))
		__builtin_trap();
	return ppoll(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

#ifdef __cplusplus
}
#endif

#endif

#endif