summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmmar Faizi <ammar.faizi@students.amikom.ac.id>2021-10-03 22:34:26 +0700
committerJens Axboe <axboe@kernel.dk>2021-10-03 09:58:39 -0600
commit1c591c368215a39fae2f9612cc456c7d1203ad0e (patch)
tree063c634267a198237aa40162e419bb49a269c765
parentf5b052a4f57d740258690cf77f99ea08225e12c4 (diff)
downloadliburing-1c591c368215a39fae2f9612cc456c7d1203ad0e.tar.gz
liburing-1c591c368215a39fae2f9612cc456c7d1203ad0e.tar.bz2
src/syscall: Wrap `errno` for `__sys_io_uring_{register,setup,enter{2,}}`
Make it possible to remove the dependency of `errno` variable (which comes from 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. Don't touch them all, 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 `static inline` in `src/syscall.h`. They are just a wrapper to make sure liburing internal sources do not touch `errno` variable from C files directly. We need to make C files not to touch the `errno` variable to support build without libc. Link: https://github.com/axboe/liburing/issues/443#issuecomment-927873932 Cc: Bedirhan KURT <windowz414@gnuweeb.org> Suggested-by: Louvian Lyndal <louvianlyndal@gmail.com> Signed-off-by: Ammar Faizi <ammar.faizi@students.amikom.ac.id> Link: https://lore.kernel.org/r/20211003153428.369258-2-ammar.faizi@students.amikom.ac.id Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--src/syscall.c43
-rw-r--r--src/syscall.h81
2 files changed, 85 insertions, 39 deletions
diff --git a/src/syscall.c b/src/syscall.c
index 69027e5..5923fbb 100644
--- a/src/syscall.c
+++ b/src/syscall.c
@@ -11,41 +11,6 @@
#include "liburing/io_uring.h"
#include "syscall.h"
-#ifdef __alpha__
-/*
- * alpha and mips are exception, other architectures have
- * common numbers for new system calls.
- */
-# ifndef __NR_io_uring_setup
-# define __NR_io_uring_setup 535
-# endif
-# ifndef __NR_io_uring_enter
-# define __NR_io_uring_enter 536
-# endif
-# ifndef __NR_io_uring_register
-# define __NR_io_uring_register 537
-# endif
-#elif defined __mips__
-# ifndef __NR_io_uring_setup
-# define __NR_io_uring_setup (__NR_Linux + 425)
-# endif
-# ifndef __NR_io_uring_enter
-# define __NR_io_uring_enter (__NR_Linux + 426)
-# endif
-# ifndef __NR_io_uring_register
-# define __NR_io_uring_register (__NR_Linux + 427)
-# endif
-#else /* !__alpha__ and !__mips__ */
-# ifndef __NR_io_uring_setup
-# define __NR_io_uring_setup 425
-# endif
-# ifndef __NR_io_uring_enter
-# define __NR_io_uring_enter 426
-# endif
-# ifndef __NR_io_uring_register
-# define __NR_io_uring_register 427
-# endif
-#endif
int __sys_io_uring_register(int fd, unsigned opcode, const void *arg,
unsigned nr_args)
@@ -59,15 +24,15 @@ int __sys_io_uring_setup(unsigned entries, struct io_uring_params *p)
}
int __sys_io_uring_enter2(int fd, unsigned to_submit, unsigned min_complete,
- unsigned flags, sigset_t *sig, int sz)
+ unsigned flags, sigset_t *sig, int sz)
{
- return syscall(__NR_io_uring_enter, fd, to_submit, min_complete,
- flags, sig, sz);
+ return syscall(__NR_io_uring_enter, fd, to_submit, min_complete, flags,
+ sig, sz);
}
int __sys_io_uring_enter(int fd, unsigned to_submit, unsigned min_complete,
unsigned flags, sigset_t *sig)
{
return __sys_io_uring_enter2(fd, to_submit, min_complete, flags, sig,
- _NSIG / 8);
+ _NSIG / 8);
}
diff --git a/src/syscall.h b/src/syscall.h
index 2368f83..f7f63aa 100644
--- a/src/syscall.h
+++ b/src/syscall.h
@@ -2,7 +2,49 @@
#ifndef LIBURING_SYSCALL_H
#define LIBURING_SYSCALL_H
+#include <errno.h>
#include <signal.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/syscall.h>
+#include <sys/resource.h>
+
+#ifdef __alpha__
+/*
+ * alpha and mips are exception, other architectures have
+ * common numbers for new system calls.
+ */
+# ifndef __NR_io_uring_setup
+# define __NR_io_uring_setup 535
+# endif
+# ifndef __NR_io_uring_enter
+# define __NR_io_uring_enter 536
+# endif
+# ifndef __NR_io_uring_register
+# define __NR_io_uring_register 537
+# endif
+#elif defined __mips__
+# ifndef __NR_io_uring_setup
+# define __NR_io_uring_setup (__NR_Linux + 425)
+# endif
+# ifndef __NR_io_uring_enter
+# define __NR_io_uring_enter (__NR_Linux + 426)
+# endif
+# ifndef __NR_io_uring_register
+# define __NR_io_uring_register (__NR_Linux + 427)
+# endif
+#else /* !__alpha__ and !__mips__ */
+# ifndef __NR_io_uring_setup
+# define __NR_io_uring_setup 425
+# endif
+# ifndef __NR_io_uring_enter
+# define __NR_io_uring_enter 426
+# endif
+# ifndef __NR_io_uring_register
+# define __NR_io_uring_register 427
+# endif
+#endif
+
struct io_uring_params;
@@ -17,4 +59,43 @@ int __sys_io_uring_enter2(int fd, unsigned to_submit, unsigned min_complete,
int __sys_io_uring_register(int fd, unsigned int opcode, const void *arg,
unsigned int nr_args);
+
+
+static inline int ____sys_io_uring_register(int fd, unsigned opcode,
+ const void *arg, unsigned nr_args)
+{
+ int ret;
+
+ ret = syscall(__NR_io_uring_register, fd, opcode, arg, nr_args);
+ return (ret < 0) ? -errno : ret;
+}
+
+static inline int ____sys_io_uring_setup(unsigned entries,
+ struct io_uring_params *p)
+{
+ int ret;
+
+ ret = syscall(__NR_io_uring_setup, entries, p);
+ return (ret < 0) ? -errno : ret;
+}
+
+static inline int ____sys_io_uring_enter2(int fd, unsigned to_submit,
+ unsigned min_complete, unsigned flags,
+ sigset_t *sig, int sz)
+{
+ int ret;
+
+ ret = syscall(__NR_io_uring_enter, fd, to_submit, min_complete, flags,
+ sig, sz);
+ return (ret < 0) ? -errno : ret;
+}
+
+static inline int ____sys_io_uring_enter(int fd, unsigned to_submit,
+ unsigned min_complete, unsigned flags,
+ sigset_t *sig)
+{
+ return ____sys_io_uring_enter2(fd, to_submit, min_complete, flags, sig,
+ _NSIG / 8);
+}
+
#endif