1 /* SPDX-License-Identifier: LGPL-2.1 OR MIT */ 2 /* 3 * poll definitions for NOLIBC 4 * Copyright (C) 2017-2021 Willy Tarreau <w@1wt.eu> 5 */ 6 7 /* make sure to include all global symbols */ 8 #include "nolibc.h" 9 10 #ifndef _NOLIBC_POLL_H 11 #define _NOLIBC_POLL_H 12 13 #include "arch.h" 14 #include "sys.h" 15 16 #include <linux/poll.h> 17 #include <linux/time.h> 18 19 /* 20 * int poll(struct pollfd *fds, int nfds, int timeout); 21 */ 22 23 static __attribute__((unused)) 24 int sys_poll(struct pollfd *fds, int nfds, int timeout) 25 { 26 #if defined(__NR_ppoll) 27 struct timespec t; 28 29 if (timeout >= 0) { 30 t.tv_sec = timeout / 1000; 31 t.tv_nsec = (timeout % 1000) * 1000000; 32 } 33 return my_syscall5(__NR_ppoll, fds, nfds, (timeout >= 0) ? &t : NULL, NULL, 0); 34 #elif defined(__NR_ppoll_time64) 35 struct __kernel_timespec t; 36 37 if (timeout >= 0) { 38 t.tv_sec = timeout / 1000; 39 t.tv_nsec = (timeout % 1000) * 1000000; 40 } 41 return my_syscall5(__NR_ppoll_time64, fds, nfds, (timeout >= 0) ? &t : NULL, NULL, 0); 42 #elif defined(__NR_poll) 43 return my_syscall3(__NR_poll, fds, nfds, timeout); 44 #else 45 return __nolibc_enosys(__func__, fds, nfds, timeout); 46 #endif 47 } 48 49 static __attribute__((unused)) 50 int poll(struct pollfd *fds, int nfds, int timeout) 51 { 52 return __sysret(sys_poll(fds, nfds, timeout)); 53 } 54 55 #endif /* _NOLIBC_POLL_H */ 56