1 /* 2 * Common syscall type defines 3 * 4 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. 5 */ 6 7 #ifndef _SYSCALLS_COMMON_H 8 #define _SYSCALLS_COMMON_H 1 9 10 #ifndef _SYSCALL_H 11 # error "Never use <bits/syscalls-common.h> directly; include <sys/syscall.h> instead." 12 #endif 13 14 #ifndef SYS_ify 15 # define SYS_ify(syscall_name) (__NR_##syscall_name) 16 #endif 17 18 #ifndef __ASSEMBLER__ 19 20 #include <errno.h> 21 22 #ifndef INTERNAL_SYSCALL_DECL 23 # define INTERNAL_SYSCALL_DECL(err) do { } while (0) 24 #endif 25 #ifndef INTERNAL_SYSCALL_ERROR_P 26 # define INTERNAL_SYSCALL_ERROR_P(val, err) ((unsigned long)val >= (unsigned long)(-4095)) 27 #endif 28 #ifndef INTERNAL_SYSCALL_ERRNO 29 # define INTERNAL_SYSCALL_ERRNO(val, err) (-(val)) 30 #endif 31 32 /* Define a macro which expands into the inline wrapper code for a system call */ 33 #ifndef INLINE_SYSCALL 34 # define INLINE_SYSCALL(name, nr, args...) INLINE_SYSCALL_NCS(__NR_##name, nr, args) 35 #endif 36 #ifndef INLINE_SYSCALL_NOERR 37 # define INLINE_SYSCALL_NOERR(name, nr, args...) INLINE_SYSCALL_NOERR_NCS(__NR_##name, nr, args) 38 #endif 39 40 /* Just like INLINE_SYSCALL(), but take a non-constant syscall (NCS) argument */ 41 #ifndef INLINE_SYSCALL_NCS 42 # define INLINE_SYSCALL_NCS(num, nr, args...) \ 43 (__extension__ \ 44 ({ \ 45 long __res; \ 46 INTERNAL_SYSCALL_DECL(__err); \ 47 (__extension__ \ 48 ({ \ 49 __res = INTERNAL_SYSCALL_NCS(num, __err, nr, args); \ 50 if (unlikely(INTERNAL_SYSCALL_ERROR_P(__res, __err))) { \ 51 __set_errno(INTERNAL_SYSCALL_ERRNO(__res, __err)); \ 52 __res = -1L; \ 53 } \ 54 __res; \ 55 }) \ 56 ); \ 57 }) \ 58 ) 59 #endif 60 #ifndef INLINE_SYSCALL_NOERR_NCS 61 # define INLINE_SYSCALL_NOERR_NCS(num, nr, args...) \ 62 ({ \ 63 long __res; \ 64 INTERNAL_SYSCALL_DECL(__err); \ 65 __res = INTERNAL_SYSCALL_NCS(num, __err, nr, args); \ 66 __res; \ 67 }) 68 #endif 69 70 /* No point in forcing people to implement both when they only need one */ 71 #ifndef INTERNAL_SYSCALL 72 # define INTERNAL_SYSCALL(name, err, nr, args...) INTERNAL_SYSCALL_NCS(__NR_##name, err, nr, args) 73 #endif 74 75 #ifndef INTERNAL_SYSCALL_NCS 76 # error your port needs to define INTERNAL_SYSCALL_NCS in bits/syscalls.h 77 #endif 78 79 #ifndef _syscall0 80 81 #define C_DECL_ARGS_0() void 82 #define C_DECL_ARGS_1(t, v) t v 83 #define C_DECL_ARGS_2(t, v, args...) t v, C_DECL_ARGS_1(args) 84 #define C_DECL_ARGS_3(t, v, args...) t v, C_DECL_ARGS_2(args) 85 #define C_DECL_ARGS_4(t, v, args...) t v, C_DECL_ARGS_3(args) 86 #define C_DECL_ARGS_5(t, v, args...) t v, C_DECL_ARGS_4(args) 87 #define C_DECL_ARGS_6(t, v, args...) t v, C_DECL_ARGS_5(args) 88 89 #define C_ARGS_0() 90 #define C_ARGS_1(t, v) v 91 #define C_ARGS_2(t, v, args...) v, C_ARGS_1(args) 92 #define C_ARGS_3(t, v, args...) v, C_ARGS_2(args) 93 #define C_ARGS_4(t, v, args...) v, C_ARGS_3(args) 94 #define C_ARGS_5(t, v, args...) v, C_ARGS_4(args) 95 #define C_ARGS_6(t, v, args...) v, C_ARGS_5(args) 96 97 #define SYSCALL_FUNC(nargs, type, name, args...) \ 98 type name(C_DECL_ARGS_##nargs(args)) { \ 99 return (type)INLINE_SYSCALL(name, nargs, C_ARGS_##nargs(args)); \ 100 } 101 102 #define SYSCALL_FUNC_TIME64(nargs, type, name, args...) \ 103 type name(C_DECL_ARGS_##nargs(args)) { \ 104 return (type)INLINE_SYSCALL(name##_time64, nargs, C_ARGS_##nargs(args)); \ 105 } 106 107 #define SYSCALL_FUNC_64(nargs, type, name, args...) \ 108 type name(C_DECL_ARGS_##nargs(args)) { \ 109 return (type)INLINE_SYSCALL(name##64, nargs, C_ARGS_##nargs(args)); \ 110 } 111 112 113 #define SYSCALL_NOERR_FUNC(nargs, type, name, args...) \ 114 type name(C_DECL_ARGS_##nargs(args)) { \ 115 return (type)INLINE_SYSCALL_NOERR(name, nargs, C_ARGS_##nargs(args)); \ 116 } 117 118 #define SYSCALL_NOERR_FUNC_TIME64(nargs, type, name, args...) \ 119 type name(C_DECL_ARGS_##nargs(args)) { \ 120 return (type)INLINE_SYSCALL_NOERR(name##_time64, nargs, C_ARGS_##nargs(args)); \ 121 } 122 123 #define SYSCALL_NOERR_FUNC_64(nargs, type, name, args...) \ 124 type name(C_DECL_ARGS_##nargs(args)) { \ 125 return (type)INLINE_SYSCALL_NOERR(name##64, nargs, C_ARGS_##nargs(args)); \ 126 } 127 128 #define SYSCALL_FUNC_BODY(nargs, type, name, args...) \ 129 return (type)INLINE_SYSCALL(name, nargs, C_ARGS_##nargs(args)); 130 131 #define SYSCALL_FUNC_BODY_TIME64(nargs, type, name, args...) \ 132 return (type)INLINE_SYSCALL(name##_time64, nargs, C_ARGS_##nargs(args)); 133 134 #define SYSCALL_FUNC_BODY_64(nargs, type, name, args...) \ 135 return (type)INLINE_SYSCALL(name##64, nargs, C_ARGS_##nargs(args)); 136 137 #define _syscall0(args...) SYSCALL_FUNC(0, args) 138 #define _syscall_noerr0(args...) SYSCALL_NOERR_FUNC(0, args) 139 #define _syscall1(args...) SYSCALL_FUNC(1, args) 140 #define _syscall_noerr1(args...) SYSCALL_NOERR_FUNC(1, args) 141 #define _syscall2(args...) SYSCALL_FUNC(2, args) 142 #define _syscall2_body(args...) SYSCALL_FUNC_BODY(2, args) 143 #define _syscall3(args...) SYSCALL_FUNC(3, args) 144 #define _syscall4(args...) SYSCALL_FUNC(4, args) 145 #define _syscall5(args...) SYSCALL_FUNC(5, args) 146 #define _syscall6(args...) SYSCALL_FUNC(6, args) 147 148 #define _syscall0_time64(args...) SYSCALL_FUNC_TIME64(0, args) 149 #define _syscall_noerr0_time64(args...) SYSCALL_NOERR_FUNC_TIME64(0, args) 150 #define _syscall1_time64(args...) SYSCALL_FUNC_TIME64(1, args) 151 #define _syscall_noerr1_time64(args...) SYSCALL_NOERR_FUNC_TIME64(1, args) 152 #define _syscall2_time64(args...) SYSCALL_FUNC_TIME64(2, args) 153 #define _syscall2_body_time64(args...) SYSCALL_FUNC_BODY_TIME64(2, args) 154 #define _syscall3_time64(args...) SYSCALL_FUNC_TIME64(3, args) 155 #define _syscall4_time64(args...) SYSCALL_FUNC_TIME64(4, args) 156 #define _syscall5_time64(args...) SYSCALL_FUNC_TIME64(5, args) 157 #define _syscall6_time64(args...) SYSCALL_FUNC_TIME64(6, args) 158 159 #define _syscall0_64(args...) SYSCALL_FUNC_64(0, args) 160 #define _syscall_noerr0_64(args...) SYSCALL_NOERR_FUNC_64(0, args) 161 #define _syscall1_64(args...) SYSCALL_FUNC_64(1, args) 162 #define _syscall_noerr1_64(args...) SYSCALL_NOERR_FUNC_64(1, args) 163 #define _syscall2_64(args...) SYSCALL_FUNC_64(2, args) 164 #define _syscall2_body_64(args...) SYSCALL_FUNC_BODY_64(2, args) 165 #define _syscall3_64(args...) SYSCALL_FUNC_64(3, args) 166 #define _syscall4_64(args...) SYSCALL_FUNC_64(4, args) 167 #define _syscall5_64(args...) SYSCALL_FUNC_64(5, args) 168 #define _syscall6_64(args...) SYSCALL_FUNC_64(6, args) 169 170 171 #endif /* _syscall0 */ 172 173 #endif /* __ASSEMBLER__ */ 174 175 #endif 176