From 01cf24ec66c663e3f40be1d5c703aa9666effc85 Mon Sep 17 00:00:00 2001 From: Kacper Date: Mon, 15 Dec 2025 18:44:07 +0100 Subject: Add inotify and reorganize eventfd and io_uring syscalls --- lib/libc/sys/Kbuild | 12 ++--- lib/libc/sys/eventfd.c | 6 --- lib/libc/sys/eventfd/Kbuild | 3 ++ lib/libc/sys/eventfd/eventfd.c | 6 +++ lib/libc/sys/eventfd/eventfd_read.c | 8 +++ lib/libc/sys/eventfd/eventfd_write.c | 8 +++ lib/libc/sys/eventfd_read.c | 8 --- lib/libc/sys/eventfd_write.c | 8 --- lib/libc/sys/inotify/Kbuild | 1 + lib/libc/sys/inotify/inotify_add_watch.c | 7 +++ lib/libc/sys/inotify/inotify_init.c | 7 +++ lib/libc/sys/inotify/inotify_rm_watch.c | 7 +++ lib/libc/sys/io_uring/Kbuild | 3 ++ lib/libc/sys/io_uring/io_uring_enter.c | 10 ++++ lib/libc/sys/io_uring/io_uring_register.c | 7 +++ lib/libc/sys/io_uring/io_uring_setup.c | 81 +++++++++++++++++++++++++++++++ lib/libc/sys/io_uring_enter.c | 10 ---- lib/libc/sys/io_uring_register.c | 7 --- lib/libc/sys/io_uring_setup.c | 81 ------------------------------- 19 files changed, 153 insertions(+), 127 deletions(-) delete mode 100644 lib/libc/sys/eventfd.c create mode 100644 lib/libc/sys/eventfd/Kbuild create mode 100644 lib/libc/sys/eventfd/eventfd.c create mode 100644 lib/libc/sys/eventfd/eventfd_read.c create mode 100644 lib/libc/sys/eventfd/eventfd_write.c delete mode 100644 lib/libc/sys/eventfd_read.c delete mode 100644 lib/libc/sys/eventfd_write.c create mode 100644 lib/libc/sys/inotify/Kbuild create mode 100644 lib/libc/sys/inotify/inotify_add_watch.c create mode 100644 lib/libc/sys/inotify/inotify_init.c create mode 100644 lib/libc/sys/inotify/inotify_rm_watch.c create mode 100644 lib/libc/sys/io_uring/Kbuild create mode 100644 lib/libc/sys/io_uring/io_uring_enter.c create mode 100644 lib/libc/sys/io_uring/io_uring_register.c create mode 100644 lib/libc/sys/io_uring/io_uring_setup.c delete mode 100644 lib/libc/sys/io_uring_enter.c delete mode 100644 lib/libc/sys/io_uring_register.c delete mode 100644 lib/libc/sys/io_uring_setup.c (limited to 'lib/libc/sys') diff --git a/lib/libc/sys/Kbuild b/lib/libc/sys/Kbuild index caaf922a..a2928e14 100644 --- a/lib/libc/sys/Kbuild +++ b/lib/libc/sys/Kbuild @@ -1,14 +1,12 @@ -obj-y += eventfd.o -obj-y += eventfd_read.o -obj-y += eventfd_write.o +obj-y += eventfd/ +obj-y += inotify/ +obj-y += io_uring/ + +obj-y += flock.o obj-y += getauxval.o -obj-y += io_uring_enter.o -obj-y += io_uring_register.o -obj-y += io_uring_setup.o obj-y += ioctl.o obj-y += mount.o obj-y += reboot.o obj-y += sysinfo.o obj-y += umount.o obj-y += umount2.o -obj-y += flock.o diff --git a/lib/libc/sys/eventfd.c b/lib/libc/sys/eventfd.c deleted file mode 100644 index b0fb5d86..00000000 --- a/lib/libc/sys/eventfd.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int eventfd(unsigned int initval, int flags) -{ - return syscall(eventfd2, initval, flags); -} diff --git a/lib/libc/sys/eventfd/Kbuild b/lib/libc/sys/eventfd/Kbuild new file mode 100644 index 00000000..ad7a3422 --- /dev/null +++ b/lib/libc/sys/eventfd/Kbuild @@ -0,0 +1,3 @@ +obj-y += eventfd.o +obj-y += eventfd_read.o +obj-y += eventfd_write.o diff --git a/lib/libc/sys/eventfd/eventfd.c b/lib/libc/sys/eventfd/eventfd.c new file mode 100644 index 00000000..b0fb5d86 --- /dev/null +++ b/lib/libc/sys/eventfd/eventfd.c @@ -0,0 +1,6 @@ +#include + +int eventfd(unsigned int initval, int flags) +{ + return syscall(eventfd2, initval, flags); +} diff --git a/lib/libc/sys/eventfd/eventfd_read.c b/lib/libc/sys/eventfd/eventfd_read.c new file mode 100644 index 00000000..78d73623 --- /dev/null +++ b/lib/libc/sys/eventfd/eventfd_read.c @@ -0,0 +1,8 @@ +#include +#include +#include + +int eventfd_read(int fildes, eventfd_t *value) +{ + return (sizeof(*value) == read(fildes, value, sizeof(*value))) ? 0 : -1; +} diff --git a/lib/libc/sys/eventfd/eventfd_write.c b/lib/libc/sys/eventfd/eventfd_write.c new file mode 100644 index 00000000..9c89b388 --- /dev/null +++ b/lib/libc/sys/eventfd/eventfd_write.c @@ -0,0 +1,8 @@ +#include +#include +#include + +int eventfd_write(int fildes, eventfd_t value) +{ + return (sizeof(value) == write(fildes, &value, sizeof(value))) ? 0 : -1; +} diff --git a/lib/libc/sys/eventfd_read.c b/lib/libc/sys/eventfd_read.c deleted file mode 100644 index 78d73623..00000000 --- a/lib/libc/sys/eventfd_read.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include -#include - -int eventfd_read(int fildes, eventfd_t *value) -{ - return (sizeof(*value) == read(fildes, value, sizeof(*value))) ? 0 : -1; -} diff --git a/lib/libc/sys/eventfd_write.c b/lib/libc/sys/eventfd_write.c deleted file mode 100644 index 9c89b388..00000000 --- a/lib/libc/sys/eventfd_write.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include -#include - -int eventfd_write(int fildes, eventfd_t value) -{ - return (sizeof(value) == write(fildes, &value, sizeof(value))) ? 0 : -1; -} diff --git a/lib/libc/sys/inotify/Kbuild b/lib/libc/sys/inotify/Kbuild new file mode 100644 index 00000000..339bef40 --- /dev/null +++ b/lib/libc/sys/inotify/Kbuild @@ -0,0 +1 @@ +obj-y += inotify_init.o diff --git a/lib/libc/sys/inotify/inotify_add_watch.c b/lib/libc/sys/inotify/inotify_add_watch.c new file mode 100644 index 00000000..22ffd7b1 --- /dev/null +++ b/lib/libc/sys/inotify/inotify_add_watch.c @@ -0,0 +1,7 @@ +#include +#include + +int inotify_add_watch(int fildes, const char *name, uint32_t mask) +{ + return syscall(inotify_add_watch, fildes, name, mask); +} diff --git a/lib/libc/sys/inotify/inotify_init.c b/lib/libc/sys/inotify/inotify_init.c new file mode 100644 index 00000000..5baa9589 --- /dev/null +++ b/lib/libc/sys/inotify/inotify_init.c @@ -0,0 +1,7 @@ +#include +#include + +int inotify_init(void) +{ + return syscall(inotify_init); +} diff --git a/lib/libc/sys/inotify/inotify_rm_watch.c b/lib/libc/sys/inotify/inotify_rm_watch.c new file mode 100644 index 00000000..e2729cd0 --- /dev/null +++ b/lib/libc/sys/inotify/inotify_rm_watch.c @@ -0,0 +1,7 @@ +#include +#include + +int inotify_rm_watch(int fildes, int wd) +{ + return syscall(inotify_rm_watch, fildes, wd); +} diff --git a/lib/libc/sys/io_uring/Kbuild b/lib/libc/sys/io_uring/Kbuild new file mode 100644 index 00000000..7a25a4b1 --- /dev/null +++ b/lib/libc/sys/io_uring/Kbuild @@ -0,0 +1,3 @@ +obj-y += io_uring_enter.o +obj-y += io_uring_register.o +obj-y += io_uring_setup.o diff --git a/lib/libc/sys/io_uring/io_uring_enter.c b/lib/libc/sys/io_uring/io_uring_enter.c new file mode 100644 index 00000000..5fe0773d --- /dev/null +++ b/lib/libc/sys/io_uring/io_uring_enter.c @@ -0,0 +1,10 @@ +#include +#include + +int io_uring_enter(unsigned int fd, unsigned int to_submit, + unsigned int min_complete, unsigned int flags, sigset_t *sig, + size_t sz) +{ + return syscall(io_uring_enter, fd, to_submit, min_complete, flags, sig, + sz); +} diff --git a/lib/libc/sys/io_uring/io_uring_register.c b/lib/libc/sys/io_uring/io_uring_register.c new file mode 100644 index 00000000..bee2355f --- /dev/null +++ b/lib/libc/sys/io_uring/io_uring_register.c @@ -0,0 +1,7 @@ +#include + +int io_uring_register(unsigned int fd, unsigned int opcode, void *arg, + unsigned int nr_args) +{ + return syscall(io_uring_register, fd, opcode, arg, nr_args); +} diff --git a/lib/libc/sys/io_uring/io_uring_setup.c b/lib/libc/sys/io_uring/io_uring_setup.c new file mode 100644 index 00000000..0a368a81 --- /dev/null +++ b/lib/libc/sys/io_uring/io_uring_setup.c @@ -0,0 +1,81 @@ +#include +#include +#include +#include +#include + +struct io_uring __io_uring; + +int io_uring_setup(unsigned int entries, struct io_uring_params *params) +{ + return syscall(io_uring_setup, entries, params); +} + +int __io_uring_setup(void) +{ + struct io_uring_params p; + memset(&p, 0, sizeof(p)); + + __io_uring.fd = io_uring_setup(IO_URING_ENTRIES, &p); + + if (__io_uring.fd < 0) + return -1; + + __io_uring.sq.ring_size = + p.sq_off.array + p.sq_entries * sizeof(unsigned int); + __io_uring.sq.ring = mmap(NULL, __io_uring.sq.ring_size, + PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_POPULATE, __io_uring.fd, + IORING_OFF_SQ_RING); + + if (__io_uring.sq.ring == MAP_FAILED) + return -1; + + __io_uring.sq.head = __io_uring.sq.ring + p.sq_off.head; + __io_uring.sq.tail = __io_uring.sq.ring + p.sq_off.tail; + __io_uring.sq.ring_mask = __io_uring.sq.ring + p.sq_off.ring_mask; + __io_uring.sq.ring_entries = __io_uring.sq.ring + p.sq_off.ring_entries; + __io_uring.sq.flags = __io_uring.sq.ring + p.sq_off.flags; + __io_uring.sq.dropped = __io_uring.sq.ring + p.sq_off.dropped; + __io_uring.sq.array = __io_uring.sq.ring + p.sq_off.array; + __io_uring.sq.sqes = + mmap(NULL, p.sq_entries * sizeof(struct io_uring_sqe), + PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, + __io_uring.fd, IORING_OFF_SQES); + + if (__io_uring.sq.sqes == MAP_FAILED) { + munmap(__io_uring.sq.ring, __io_uring.sq.ring_size); + return -1; + } + + __io_uring.cq.ring_size = + p.cq_off.cqes + p.cq_entries * sizeof(struct io_uring_cqe); + __io_uring.cq.ring = mmap(NULL, __io_uring.cq.ring_size, + PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_POPULATE, __io_uring.fd, + IORING_OFF_CQ_RING); + + if (__io_uring.cq.ring == MAP_FAILED) { + munmap(__io_uring.sq.ring, __io_uring.sq.ring_size); + munmap(__io_uring.sq.sqes, + p.sq_entries * sizeof(struct io_uring_sqe)); + return -1; + } + + __io_uring.eventfd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); + if (__io_uring.eventfd < 0) + return -1; + + io_uring_register(__io_uring.fd, IORING_REGISTER_EVENTFD, + &__io_uring.eventfd, 1); + + __io_uring.cq.head = __io_uring.cq.ring + p.cq_off.head; + __io_uring.cq.tail = __io_uring.cq.ring + p.cq_off.tail; + __io_uring.cq.ring_mask = __io_uring.cq.ring + p.cq_off.ring_mask; + __io_uring.cq.ring_entries = __io_uring.cq.ring + p.cq_off.ring_entries; + __io_uring.cq.overflow = __io_uring.cq.ring + p.cq_off.overflow; + __io_uring.cq.cqes = __io_uring.cq.ring + p.cq_off.cqes; + __io_uring.cq.flags = __io_uring.cq.ring + p.cq_off.flags; + + return 0; +} diff --git a/lib/libc/sys/io_uring_enter.c b/lib/libc/sys/io_uring_enter.c deleted file mode 100644 index 5fe0773d..00000000 --- a/lib/libc/sys/io_uring_enter.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -int io_uring_enter(unsigned int fd, unsigned int to_submit, - unsigned int min_complete, unsigned int flags, sigset_t *sig, - size_t sz) -{ - return syscall(io_uring_enter, fd, to_submit, min_complete, flags, sig, - sz); -} diff --git a/lib/libc/sys/io_uring_register.c b/lib/libc/sys/io_uring_register.c deleted file mode 100644 index bee2355f..00000000 --- a/lib/libc/sys/io_uring_register.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int io_uring_register(unsigned int fd, unsigned int opcode, void *arg, - unsigned int nr_args) -{ - return syscall(io_uring_register, fd, opcode, arg, nr_args); -} diff --git a/lib/libc/sys/io_uring_setup.c b/lib/libc/sys/io_uring_setup.c deleted file mode 100644 index 0a368a81..00000000 --- a/lib/libc/sys/io_uring_setup.c +++ /dev/null @@ -1,81 +0,0 @@ -#include -#include -#include -#include -#include - -struct io_uring __io_uring; - -int io_uring_setup(unsigned int entries, struct io_uring_params *params) -{ - return syscall(io_uring_setup, entries, params); -} - -int __io_uring_setup(void) -{ - struct io_uring_params p; - memset(&p, 0, sizeof(p)); - - __io_uring.fd = io_uring_setup(IO_URING_ENTRIES, &p); - - if (__io_uring.fd < 0) - return -1; - - __io_uring.sq.ring_size = - p.sq_off.array + p.sq_entries * sizeof(unsigned int); - __io_uring.sq.ring = mmap(NULL, __io_uring.sq.ring_size, - PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_POPULATE, __io_uring.fd, - IORING_OFF_SQ_RING); - - if (__io_uring.sq.ring == MAP_FAILED) - return -1; - - __io_uring.sq.head = __io_uring.sq.ring + p.sq_off.head; - __io_uring.sq.tail = __io_uring.sq.ring + p.sq_off.tail; - __io_uring.sq.ring_mask = __io_uring.sq.ring + p.sq_off.ring_mask; - __io_uring.sq.ring_entries = __io_uring.sq.ring + p.sq_off.ring_entries; - __io_uring.sq.flags = __io_uring.sq.ring + p.sq_off.flags; - __io_uring.sq.dropped = __io_uring.sq.ring + p.sq_off.dropped; - __io_uring.sq.array = __io_uring.sq.ring + p.sq_off.array; - __io_uring.sq.sqes = - mmap(NULL, p.sq_entries * sizeof(struct io_uring_sqe), - PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, - __io_uring.fd, IORING_OFF_SQES); - - if (__io_uring.sq.sqes == MAP_FAILED) { - munmap(__io_uring.sq.ring, __io_uring.sq.ring_size); - return -1; - } - - __io_uring.cq.ring_size = - p.cq_off.cqes + p.cq_entries * sizeof(struct io_uring_cqe); - __io_uring.cq.ring = mmap(NULL, __io_uring.cq.ring_size, - PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_POPULATE, __io_uring.fd, - IORING_OFF_CQ_RING); - - if (__io_uring.cq.ring == MAP_FAILED) { - munmap(__io_uring.sq.ring, __io_uring.sq.ring_size); - munmap(__io_uring.sq.sqes, - p.sq_entries * sizeof(struct io_uring_sqe)); - return -1; - } - - __io_uring.eventfd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); - if (__io_uring.eventfd < 0) - return -1; - - io_uring_register(__io_uring.fd, IORING_REGISTER_EVENTFD, - &__io_uring.eventfd, 1); - - __io_uring.cq.head = __io_uring.cq.ring + p.cq_off.head; - __io_uring.cq.tail = __io_uring.cq.ring + p.cq_off.tail; - __io_uring.cq.ring_mask = __io_uring.cq.ring + p.cq_off.ring_mask; - __io_uring.cq.ring_entries = __io_uring.cq.ring + p.cq_off.ring_entries; - __io_uring.cq.overflow = __io_uring.cq.ring + p.cq_off.overflow; - __io_uring.cq.cqes = __io_uring.cq.ring + p.cq_off.cqes; - __io_uring.cq.flags = __io_uring.cq.ring + p.cq_off.flags; - - return 0; -} -- cgit v1.2.3