1 /* SPDX-License-Identifier: MIT */
2 #ifndef LIBURING_SYSCALL_H
3 #define LIBURING_SYSCALL_H
4
5 #include <errno.h>
6 #include <signal.h>
7 #include <stdint.h>
8 #include <unistd.h>
9 #include <stdbool.h>
10 #include <sys/mman.h>
11 #include <sys/syscall.h>
12 #include <sys/resource.h>
13
14 #include <liburing.h>
15
16 #ifdef __alpha__
17 /*
18 * alpha and mips are exception, other architectures have
19 * common numbers for new system calls.
20 */
21 #ifndef __NR_io_uring_setup
22 #define __NR_io_uring_setup 535
23 #endif
24 #ifndef __NR_io_uring_enter
25 #define __NR_io_uring_enter 536
26 #endif
27 #ifndef __NR_io_uring_register
28 #define __NR_io_uring_register 537
29 #endif
30 #elif defined __mips__
31 #ifndef __NR_io_uring_setup
32 #define __NR_io_uring_setup (__NR_Linux + 425)
33 #endif
34 #ifndef __NR_io_uring_enter
35 #define __NR_io_uring_enter (__NR_Linux + 426)
36 #endif
37 #ifndef __NR_io_uring_register
38 #define __NR_io_uring_register (__NR_Linux + 427)
39 #endif
40 #else /* !__alpha__ and !__mips__ */
41 #ifndef __NR_io_uring_setup
42 #define __NR_io_uring_setup 425
43 #endif
44 #ifndef __NR_io_uring_enter
45 #define __NR_io_uring_enter 426
46 #endif
47 #ifndef __NR_io_uring_register
48 #define __NR_io_uring_register 427
49 #endif
50 #endif
51
52 /*
53 * Don't put this below the #include "arch/$arch/syscall.h", that
54 * file may need it.
55 */
56 struct io_uring_params;
57
ERR_PTR(intptr_t n)58 static inline void *ERR_PTR(intptr_t n)
59 {
60 return (void *) n;
61 }
62
PTR_ERR(const void * ptr)63 static inline intptr_t PTR_ERR(const void *ptr)
64 {
65 return (intptr_t) ptr;
66 }
67
IS_ERR(const void * ptr)68 static inline bool IS_ERR(const void *ptr)
69 {
70 return uring_unlikely((uintptr_t) ptr >= (uintptr_t) -4095UL);
71 }
72
73 #define __INTERNAL__LIBURING_SYSCALL_H
74 #if defined(__x86_64__) || defined(__i386__)
75 #include "arch/x86/syscall.h"
76 #elif defined(__aarch64__)
77 #include "arch/aarch64/syscall.h"
78 #else
79 /*
80 * We don't have native syscall wrappers
81 * for this arch. Must use libc!
82 */
83 #ifdef CONFIG_NOLIBC
84 #error "This arch doesn't support building liburing without libc"
85 #endif
86 /* libc syscall wrappers. */
87 #include "arch/generic/syscall.h"
88 #endif
89 #undef __INTERNAL__LIBURING_SYSCALL_H
90
91 /*
92 * For backward compatibility.
93 * (these __sys* functions always use libc, see syscall.c)
94 */
95 int __sys_io_uring_setup(unsigned entries, struct io_uring_params *p);
96 int __sys_io_uring_enter(int fd, unsigned to_submit, unsigned min_complete,
97 unsigned flags, sigset_t *sig);
98 int __sys_io_uring_enter2(int fd, unsigned to_submit, unsigned min_complete,
99 unsigned flags, sigset_t *sig, int sz);
100 int __sys_io_uring_register(int fd, unsigned int opcode, const void *arg,
101 unsigned int nr_args);
102
103 #endif
104