Skip to contentSkip to conversation

tools/nolibc: introduce poll.h

PATCH In review Thomas Weißschuh 2 participants 4 messages Apr 30, 2025 – May 11, 2025 Nolibc header file

lore
Share & tools
lore
#0 lore raw

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]>
#1 lore raw

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
index 41ef18872a7e9435a5efec9c0b32b9e29fcd4ce8..3ad6ac3fde0aed8eac12ed944c06015bbccde6f1 100644
@@ -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
index d1b949e094eeb7cc0fe875deeafa4c972ecf35b2..05a4bd5fba8bab9b6f896e617f73c49e30a1242e 100644
@@ -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
index 68e60e6742114a5422c8afef56a67415ed652c2f..5733fe54911dca44c7423951ff85fb166d95c06f 100644
@@ -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
#2 lore raw

PATCH 2/2 tools/nolibc: use poll-related definitions from UAPI headers

In reply to Thomas Weißschuh

The 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
index be6e44fe022d9e8f196821c6c5eb6d0a56e8aacb..1765acb17ea01ff53cbad0b4750e4938446b6a45 100644
@@ -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
index fe97953d16572db3e4c18cdc8921c6a991d64f94..70f20519ebf908b90c242b5ff71d05364fa89f2f 100644
@@ -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
maintainer Acked-by on the v1 series
#3 lore raw
In reply to Thomas Weißschuh

Hi Thomas,

sorry for the delay!

Quoted 3 lines · Thomas Weißschuh

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")

This one will be pretty useful for a number of small programs which try to be a bit interactive, that's nice.

Thanks!
Willy