2 * Common syscall type defines
4 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
7 #ifndef _SYSCALLS_COMMON_H
8 #define _SYSCALLS_COMMON_H 1
11 # error "Never use <bits/syscalls-common.h> directly; include <sys/syscall.h> instead."
15 # define SYS_ify(syscall_name) (__NR_##syscall_name)
22 #ifndef INTERNAL_SYSCALL_DECL
23 # define INTERNAL_SYSCALL_DECL(err) do { } while (0)
25 #ifndef INTERNAL_SYSCALL_ERROR_P
26 # define INTERNAL_SYSCALL_ERROR_P(val, err) ((unsigned long)val >= (unsigned long)(-4095))
28 #ifndef INTERNAL_SYSCALL_ERRNO
29 # define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
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)
37 /* Just like INLINE_SYSCALL(), but take a non-constant syscall (NCS) argument */
38 #ifndef INLINE_SYSCALL_NCS
39 # define INLINE_SYSCALL_NCS(name, nr, args...) \
41 INTERNAL_SYSCALL_DECL(err); \
42 long res = INTERNAL_SYSCALL_NCS(name, err, nr, args); \
43 if (unlikely(INTERNAL_SYSCALL_ERROR_P(res, err))) { \
44 __set_errno(INTERNAL_SYSCALL_ERRNO(res, err)); \
51 /* No point in forcing people to implement both when they only need one */
52 #ifndef INTERNAL_SYSCALL
53 # define INTERNAL_SYSCALL(name, err, nr, args...) INTERNAL_SYSCALL_NCS(__NR_##name, err, nr, args)
56 #ifndef INTERNAL_SYSCALL_NCS
57 # error your port needs to define INTERNAL_SYSCALL_NCS in bits/syscalls.h
62 #define C_DECL_ARGS_0() void
63 #define C_DECL_ARGS_1(t, v) t v
64 #define C_DECL_ARGS_2(t, v, args...) t v, C_DECL_ARGS_1(args)
65 #define C_DECL_ARGS_3(t, v, args...) t v, C_DECL_ARGS_2(args)
66 #define C_DECL_ARGS_4(t, v, args...) t v, C_DECL_ARGS_3(args)
67 #define C_DECL_ARGS_5(t, v, args...) t v, C_DECL_ARGS_4(args)
68 #define C_DECL_ARGS_6(t, v, args...) t v, C_DECL_ARGS_5(args)
71 #define C_ARGS_1(t, v) v
72 #define C_ARGS_2(t, v, args...) v, C_ARGS_1(args)
73 #define C_ARGS_3(t, v, args...) v, C_ARGS_2(args)
74 #define C_ARGS_4(t, v, args...) v, C_ARGS_3(args)
75 #define C_ARGS_5(t, v, args...) v, C_ARGS_4(args)
76 #define C_ARGS_6(t, v, args...) v, C_ARGS_5(args)
78 #define SYSCALL_FUNC(nargs, type, name, args...) \
79 type name(C_DECL_ARGS_##nargs(args)) { \
80 return (type)INLINE_SYSCALL(name, nargs, C_ARGS_##nargs(args)); \
83 #define _syscall0(args...) SYSCALL_FUNC(0, args)
84 #define _syscall1(args...) SYSCALL_FUNC(1, args)
85 #define _syscall2(args...) SYSCALL_FUNC(2, args)
86 #define _syscall3(args...) SYSCALL_FUNC(3, args)
87 #define _syscall4(args...) SYSCALL_FUNC(4, args)
88 #define _syscall5(args...) SYSCALL_FUNC(5, args)
89 #define _syscall6(args...) SYSCALL_FUNC(6, args)
91 #endif /* _syscall0 */
93 #endif /* __ASSEMBLER__ */