Hi everyone, This is the v2 of RFC to implement the kernel style return value for liburing. The main purpose of these changes is to make it possible to remove the dependency of `errno` variable. If we can land this on liburing, we will start working on no libc support with raw system call written in Assembly (no libc). These changes should not affect the user, only affect liburing internal sources. We do not plan to drop the libc dependency, we just want to make it possible to build liburing without the libc. Currently, we expose these functions to userland: 1) `__sys_io_uring_register` 2) `__sys_io_uring_setup` 3) `__sys_io_uring_enter2` 4) `__sys_io_uring_enter` The tests in `test/io_uring_{enter,register,setup}.c` are the examples of it. Since the userland needs to check the `errno` value to use them properly, this means those functions always depend on libc. So we cannot change their behavior. This ensures the changes only affect liburing internal and no visible functionality changes for the users. Then we introduce new functions with the same name (with extra underscore as prefix, 4 underscores): 1) `____sys_io_uring_register` 2) `____sys_io_uring_setup` 3) `____sys_io_uring_enter2` 4) `____sys_io_uring_enter` These functions do not use `errno` variable *on the caller*, they use the kernel style return value (return a negative value of error code when errors). These functions are defined as `inline static` in `src/syscall.h`. They are just a wrapper to make sure liburing internal sources do not touch `errno` variable from C files directly. After that, we need to deal with other syscalls. Currently we have 5 wrapper functions for all syscalls used in liburing. They are: 1) `liburing_mmap` 2) `liburing_munmap` 3) `liburing_madvise` 4) `liburing_getrlimit` 5) `liburing_setrlimit` Also add kernel error header `src/kernel_err.h`, this is taken from the Linux kernel source `include/linux/err.h` with a bit modification. The purpose of `src/kernel_err.h` file is to use `PTR_ERR()`, `ERR_PTR()`, etc. to implement the kernel style return value for pointer return value. Currently only `liburing_mmap()` that depends on this kernel error header file. If you want a git repository, you can take a look at: git://github.com/ammarfaizi2/liburing.git kernel-style-retval Please review. ---------------------------------------------------------------- Changes since v1: - Make all wrapper functions be `static inline`, so they don't pollute the global scope. - Reduce the number of patches. Now we only have 4 patches (it was 6). Link: https://github.com/axboe/liburing/issues/443 Link: [v1] https://lore.kernel.org/io-uring/20210929101606.62822-1-ammar.faizi@xxxxxxxxxxxxxxxxxxxxx/ ---------------------------------------------------------------- Ammar Faizi (4): src/syscall: Implement the kernel style return value src/{queue,register,setup}: Don't use `__sys_io_uring*` Wrap all syscalls in a kernel style return value src/{queue,register,setup}: Remove `#include <errno.h>` src/kernel_err.h | 75 ++++++++++++++++++ src/queue.c | 28 +++---- src/register.c | 190 ++++++++++++++------------------------------- src/setup.c | 61 ++++++++------- src/syscall.c | 42 +--------- src/syscall.h | 130 +++++++++++++++++++++++++++++++ 6 files changed, 310 insertions(+), 216 deletions(-) create mode 100644 src/kernel_err.h -- Ammar Faizi