tools/nolibc: introduce poll.h
cover tools/nolibc: introduce poll.h
Move poll() to the standard poll.h and drop the custom related definitions. This also allows to drop an iffy workaround from the nolibc next branch:e1896bb9e079 ("selftests: harness: Guard includes on nolibc")
---
Thomas Weißschuh (2):
tools/nolibc: move poll() to poll.h
tools/nolibc: use poll-related definitions from UAPI headers
tools/include/nolibc/Makefile | 1 + tools/include/nolibc/nolibc.h | 1 + tools/include/nolibc/poll.h | 55 +++++++++++++++++++++++++++++++++++++++++++ tools/include/nolibc/sys.h | 37 ----------------------------- tools/include/nolibc/types.h | 14 ----------- 5 files changed, 57 insertions(+), 51 deletions(-)
---
base-commit: e1896bb9e07948b4825883cbc3ca37cf59e17578
change-id: 20250430-poll-75dc16e95639
Best regards,
Signature · 1 line
Thomas Weißschuh <[email protected]>
PATCH 1/2 tools/nolibc: move poll() to poll.h
This is the location regular userspace expects the definition.
--- tools/include/nolibc/Makefile | 1 + tools/include/nolibc/nolibc.h | 1 + tools/include/nolibc/poll.h | 55 +++++++++++++++++++++++++++++++++++++++++++ tools/include/nolibc/sys.h | 37 ----------------------------- 4 files changed, 57 insertions(+), 37 deletions(-)
tools/include/nolibc/Makefile +1 -0
@@ -36,6 +36,7 @@ all_files := \ getopt.h \ limits.h \ nolibc.h \ + poll.h \ signal.h \ stackprotector.h \ std.h \
tools/include/nolibc/nolibc.h +1 -0
@@ -114,6 +114,7 @@#include "dirent.h" #include "fcntl.h" #include "getopt.h" +#include "poll.h" /* Used by programs to avoid std includes */ #define NOLIBC
tools/include/nolibc/poll.h new file +55 -0
55 lines not on this page · raw message
tools/include/nolibc/sys.h +0 -37
@@ -766,43 +766,6 @@ int pivot_root(const char *new, const char *old) } -/* -* int poll(struct pollfd *fds, int nfds, int timeout); -*/ - -static __attribute__((unused)) -int sys_poll (struct pollfd *fds,int nfds,int timeout) -{ -#if defined(__NR_ppoll) -struct timespec t; - -if (timeout >=0 ) { - t.tv_sec = timeout /1000 ; - t.tv_nsec = (timeout %1000 ) *1000000 ; - } -return my_syscall5 (__NR_ppoll, fds, nfds, (timeout >=0 ) ? &t :NULL ,NULL ,0 ); -#elif defined(__NR_ppoll_time64) -struct __kernel_timespec t; - -if (timeout >=0 ) { - t.tv_sec = timeout /1000 ; - t.tv_nsec = (timeout %1000 ) *1000000 ; - } -return my_syscall5 (__NR_ppoll_time64, fds, nfds, (timeout >=0 ) ? &t :NULL ,NULL ,0 ); -#elif defined(__NR_poll) -return my_syscall3 (__NR_poll, fds, nfds, timeout); -#else -return __nolibc_enosys (__func__, fds, nfds, timeout); -#endif -} - -static __attribute__((unused)) -int poll (struct pollfd *fds,int nfds,int timeout) -{ -return __sysret (sys_poll (fds, nfds, timeout)); -} - -/* * ssize_t read(int fd, void *buf, size_t count); */
Signature · 1 line
2.49.0
PATCH 2/2 tools/nolibc: use poll-related definitions from UAPI headers
In reply to Thomas WeißschuhThe UAPI headers already provide definitions for these symbols. Using them makes the code shorter, more robust and compatible with applications using linux/poll.h directly.
--- tools/include/nolibc/poll.h | 2 +- tools/include/nolibc/types.h | 14 -------------- 2 files changed, 1 insertion(+), 15 deletions(-)
tools/include/nolibc/poll.h +1 -1
@@ -11,9 +11,9 @@#define _NOLIBC_POLL_H#include "arch.h" -#include "types.h" #include "sys.h" +#include <linux/poll.h> #include <linux/time.h> /*
tools/include/nolibc/types.h +0 -14
@@ -159,20 +159,6 @@ typedef struct { __set->fds[__idx] =0 ; \ }while (0 ) -/* for poll() */ -#define POLLIN 0x0001 -#define POLLPRI 0x0002 -#define POLLOUT 0x0004 -#define POLLERR 0x0008 -#define POLLHUP 0x0010 -#define POLLNVAL 0x0020 - -struct pollfd { -int fd; -short int events; -short int revents; -}; -/* for getdents64() */ struct linux_dirent64 {uint64_t d_ino;
Signature · 1 line
2.49.0
Hi Thomas,
sorry for the delay!
Quoted 3 lines · Thomas Weißschuh
Move
poll()to the standardpoll.hand drop the custom related definitions. This also allows to drop an iffy workaround from the nolibc next branch:e1896bb9e079("selftests: harness: Guard includes on nolibc")
This one will be pretty useful for a number of small programs which try to be a bit interactive, that's nice.
Thanks!
Willy