Imported Upstream version 0.3.113
[platform/upstream/libaio.git] / src / syscall.h
1 #include <sys/syscall.h>
2 #include <unistd.h>
3 #include <errno.h>
4
5 #define _SYMSTR(str)    #str
6 #define SYMSTR(str)     _SYMSTR(str)
7
8 #define SYMVER(compat_sym, orig_sym, ver_sym)   \
9         __asm__(".symver " SYMSTR(compat_sym) "," SYMSTR(orig_sym) "@LIBAIO_" SYMSTR(ver_sym));
10
11 #define DEFSYMVER(compat_sym, orig_sym, ver_sym)        \
12         __asm__(".symver " SYMSTR(compat_sym) "," SYMSTR(orig_sym) "@@LIBAIO_" SYMSTR(ver_sym));
13
14 #if defined(__i386__)
15 #include "syscall-i386.h"
16 #elif defined(__x86_64__)
17 #include "syscall-x86_64.h"
18 #elif defined(__ia64__)
19 #include "syscall-ia64.h"
20 #elif defined(__PPC__)
21 #include "syscall-ppc.h"
22 #elif defined(__s390__)
23 #include "syscall-s390.h"
24 #elif defined(__alpha__)
25 #include "syscall-alpha.h"
26 #elif defined(__arm__)
27 #include "syscall-arm.h"
28 #elif defined(__sparc__)
29 #include "syscall-sparc.h"
30 #elif defined(__aarch64__) || defined(__loongarch__) || defined(__riscv)
31 #include "syscall-generic.h"
32 #else
33 #warning "using system call numbers from sys/syscall.h"
34 #endif
35
36 #define _body_io_syscall(sname, args...)        \
37 {                                               \
38         int ret, saved_errno;                   \
39         saved_errno = errno;                    \
40         ret= syscall(__NR_##sname, ## args);    \
41         if (ret < 0) {                          \
42                 ret = -errno;                   \
43                 errno = saved_errno;            \
44         }                                       \
45         return ret;                             \
46 }
47
48 #define io_syscall1(type,fname,sname,type1,arg1) \
49 type fname(type1 arg1) \
50 _body_io_syscall(sname, (long)arg1)
51
52 #define io_syscall2(type,fname,sname,type1,arg1,type2,arg2) \
53 type fname(type1 arg1,type2 arg2) \
54 _body_io_syscall(sname, (long)arg1, (long)arg2)
55
56 #define io_syscall3(type,fname,sname,type1,arg1,type2,arg2,type3,arg3) \
57 type fname(type1 arg1,type2 arg2,type3 arg3) \
58 _body_io_syscall(sname, (long)arg1, (long)arg2, (long)arg3)
59
60 #define io_syscall4(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4) \
61 type fname (type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
62 _body_io_syscall(sname, (long)arg1, (long)arg2, (long)arg3, (long)arg4)
63
64 #define io_syscall5(type,fname,sname,type1,arg1,type2,arg2,type3,arg3,type4,arg4, type5,arg5) \
65 type fname (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5) \
66 _body_io_syscall(sname, (long)arg1, (long)arg2, (long)arg3, (long)arg4, (long)arg5)
67
68 #define io_syscall6(type,fname,sname,type1,arg1,type2,arg2,type3,arg3, \
69                 type4,arg4,type5,arg5,type6,arg6) \
70 type fname (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, \
71                 type6 arg6) \
72 _body_io_syscall(sname, (long)arg1, (long)arg2, (long)arg3, (long)arg4, \
73                (long)arg5, (long)arg6)