diff options
| author | Al Viro <viro@zeniv.linux.org.uk> | 2013-01-21 15:03:44 -0500 |
|---|---|---|
| committer | Al Viro <viro@zeniv.linux.org.uk> | 2013-03-03 22:46:21 -0500 |
| commit | 07fe6e00f6cca6fef85a14a1dc3ed4f2e35d3f0b (patch) | |
| tree | a3e4f9e97b298fd778f9bbab188322407d822473 | |
| parent | 6dbe51c251a327e012439c4772097a13df43c5b8 (diff) | |
get rid of duplicate logics in __SC_....[1-6] definitions
All those guys have the same form - "take a list of type/name pairs,
apply some macro to each of them". Abstract that part away, convert
all __SC_FOO##x(__VA_ARGS__) to __MAP(x,__SC_FOO,__VA_ARGS__).
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
| -rw-r--r-- | include/linux/compat.h | 18 | ||||
| -rw-r--r-- | include/linux/syscalls.h | 82 |
2 files changed, 38 insertions, 62 deletions
diff --git a/include/linux/compat.h b/include/linux/compat.h index 76a87fb57ac2..8c1dfc8d830d 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h | |||
| @@ -27,12 +27,6 @@ | |||
| 27 | #define __SC_DELOUSE(t,v) ((t)(unsigned long)(v)) | 27 | #define __SC_DELOUSE(t,v) ((t)(unsigned long)(v)) |
| 28 | #endif | 28 | #endif |
| 29 | 29 | ||
| 30 | #define __SC_CCAST1(t1, a1) __SC_DELOUSE(t1,a1) | ||
| 31 | #define __SC_CCAST2(t2, a2, ...) __SC_DELOUSE(t2,a2), __SC_CCAST1(__VA_ARGS__) | ||
| 32 | #define __SC_CCAST3(t3, a3, ...) __SC_DELOUSE(t3,a3), __SC_CCAST2(__VA_ARGS__) | ||
| 33 | #define __SC_CCAST4(t4, a4, ...) __SC_DELOUSE(t4,a4), __SC_CCAST3(__VA_ARGS__) | ||
| 34 | #define __SC_CCAST5(t5, a5, ...) __SC_DELOUSE(t5,a5), __SC_CCAST4(__VA_ARGS__) | ||
| 35 | #define __SC_CCAST6(t6, a6, ...) __SC_DELOUSE(t6,a6), __SC_CCAST5(__VA_ARGS__) | ||
| 36 | #define COMPAT_SYSCALL_DEFINE1(name, ...) \ | 30 | #define COMPAT_SYSCALL_DEFINE1(name, ...) \ |
| 37 | COMPAT_SYSCALL_DEFINEx(1, _##name, __VA_ARGS__) | 31 | COMPAT_SYSCALL_DEFINEx(1, _##name, __VA_ARGS__) |
| 38 | #define COMPAT_SYSCALL_DEFINE2(name, ...) \ | 32 | #define COMPAT_SYSCALL_DEFINE2(name, ...) \ |
| @@ -49,19 +43,19 @@ | |||
| 49 | #ifdef CONFIG_HAVE_SYSCALL_WRAPPERS | 43 | #ifdef CONFIG_HAVE_SYSCALL_WRAPPERS |
| 50 | 44 | ||
| 51 | #define COMPAT_SYSCALL_DEFINEx(x, name, ...) \ | 45 | #define COMPAT_SYSCALL_DEFINEx(x, name, ...) \ |
| 52 | asmlinkage long compat_sys##name(__SC_DECL##x(__VA_ARGS__)); \ | 46 | asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));\ |
| 53 | static inline long C_SYSC##name(__SC_DECL##x(__VA_ARGS__)); \ | 47 | static inline long C_SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__));\ |
| 54 | asmlinkage long compat_SyS##name(__SC_LONG##x(__VA_ARGS__)) \ | 48 | asmlinkage long compat_SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__))\ |
| 55 | { \ | 49 | { \ |
| 56 | return (long) C_SYSC##name(__SC_CCAST##x(__VA_ARGS__)); \ | 50 | return C_SYSC##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__)); \ |
| 57 | } \ | 51 | } \ |
| 58 | SYSCALL_ALIAS(compat_sys##name, compat_SyS##name); \ | 52 | SYSCALL_ALIAS(compat_sys##name, compat_SyS##name); \ |
| 59 | static inline long C_SYSC##name(__SC_DECL##x(__VA_ARGS__)) | 53 | static inline long C_SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__)) |
| 60 | 54 | ||
| 61 | #else /* CONFIG_HAVE_SYSCALL_WRAPPERS */ | 55 | #else /* CONFIG_HAVE_SYSCALL_WRAPPERS */ |
| 62 | 56 | ||
| 63 | #define COMPAT_SYSCALL_DEFINEx(x, name, ...) \ | 57 | #define COMPAT_SYSCALL_DEFINEx(x, name, ...) \ |
| 64 | asmlinkage long compat_sys##name(__SC_DECL##x(__VA_ARGS__)) | 58 | asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) |
| 65 | 59 | ||
| 66 | #endif /* CONFIG_HAVE_SYSCALL_WRAPPERS */ | 60 | #endif /* CONFIG_HAVE_SYSCALL_WRAPPERS */ |
| 67 | 61 | ||
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index 313a8e0a6553..f9411f0c1c80 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h | |||
| @@ -78,49 +78,31 @@ struct sigaltstack; | |||
| 78 | #include <linux/key.h> | 78 | #include <linux/key.h> |
| 79 | #include <trace/syscall.h> | 79 | #include <trace/syscall.h> |
| 80 | 80 | ||
| 81 | #define __SC_DECL1(t1, a1) t1 a1 | 81 | /* |
| 82 | #define __SC_DECL2(t2, a2, ...) t2 a2, __SC_DECL1(__VA_ARGS__) | 82 | * __MAP - apply a macro to syscall arguments |
| 83 | #define __SC_DECL3(t3, a3, ...) t3 a3, __SC_DECL2(__VA_ARGS__) | 83 | * __MAP(n, m, t1, a1, t2, a2, ..., tn, an) will expand to |
| 84 | #define __SC_DECL4(t4, a4, ...) t4 a4, __SC_DECL3(__VA_ARGS__) | 84 | * m(t1, a1), m(t2, a2), ..., m(tn, an) |
| 85 | #define __SC_DECL5(t5, a5, ...) t5 a5, __SC_DECL4(__VA_ARGS__) | 85 | * The first argument must be equal to the amount of type/name |
| 86 | #define __SC_DECL6(t6, a6, ...) t6 a6, __SC_DECL5(__VA_ARGS__) | 86 | * pairs given. Note that this list of pairs (i.e. the arguments |
| 87 | 87 | * of __MAP starting at the third one) is in the same format as | |
| 88 | #define __SC_LONG1(t1, a1) long a1 | 88 | * for SYSCALL_DEFINE<n>/COMPAT_SYSCALL_DEFINE<n> |
| 89 | #define __SC_LONG2(t2, a2, ...) long a2, __SC_LONG1(__VA_ARGS__) | 89 | */ |
| 90 | #define __SC_LONG3(t3, a3, ...) long a3, __SC_LONG2(__VA_ARGS__) | 90 | #define __MAP1(m,t,a) m(t,a) |
| 91 | #define __SC_LONG4(t4, a4, ...) long a4, __SC_LONG3(__VA_ARGS__) | 91 | #define __MAP2(m,t,a,...) m(t,a), __MAP1(m,__VA_ARGS__) |
| 92 | #define __SC_LONG5(t5, a5, ...) long a5, __SC_LONG4(__VA_ARGS__) | 92 | #define __MAP3(m,t,a,...) m(t,a), __MAP2(m,__VA_ARGS__) |
| 93 | #define __SC_LONG6(t6, a6, ...) long a6, __SC_LONG5(__VA_ARGS__) | 93 | #define __MAP4(m,t,a,...) m(t,a), __MAP3(m,__VA_ARGS__) |
| 94 | 94 | #define __MAP5(m,t,a,...) m(t,a), __MAP4(m,__VA_ARGS__) | |
| 95 | #define __SC_CAST1(t1, a1) (t1) a1 | 95 | #define __MAP6(m,t,a,...) m(t,a), __MAP5(m,__VA_ARGS__) |
| 96 | #define __SC_CAST2(t2, a2, ...) (t2) a2, __SC_CAST1(__VA_ARGS__) | 96 | #define __MAP(n,...) __MAP##n(__VA_ARGS__) |
| 97 | #define __SC_CAST3(t3, a3, ...) (t3) a3, __SC_CAST2(__VA_ARGS__) | 97 | |
| 98 | #define __SC_CAST4(t4, a4, ...) (t4) a4, __SC_CAST3(__VA_ARGS__) | 98 | #define __SC_DECL(t, a) t a |
| 99 | #define __SC_CAST5(t5, a5, ...) (t5) a5, __SC_CAST4(__VA_ARGS__) | 99 | #define __SC_LONG(t, a) long a |
| 100 | #define __SC_CAST6(t6, a6, ...) (t6) a6, __SC_CAST5(__VA_ARGS__) | 100 | #define __SC_CAST(t, a) (t) a |
| 101 | 101 | #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(sizeof(type) > sizeof(long)) | |
| 102 | #define __SC_TEST(type) BUILD_BUG_ON(sizeof(type) > sizeof(long)) | ||
| 103 | #define __SC_TEST1(t1, a1) __SC_TEST(t1) | ||
| 104 | #define __SC_TEST2(t2, a2, ...) __SC_TEST(t2); __SC_TEST1(__VA_ARGS__) | ||
| 105 | #define __SC_TEST3(t3, a3, ...) __SC_TEST(t3); __SC_TEST2(__VA_ARGS__) | ||
| 106 | #define __SC_TEST4(t4, a4, ...) __SC_TEST(t4); __SC_TEST3(__VA_ARGS__) | ||
| 107 | #define __SC_TEST5(t5, a5, ...) __SC_TEST(t5); __SC_TEST4(__VA_ARGS__) | ||
| 108 | #define __SC_TEST6(t6, a6, ...) __SC_TEST(t6); __SC_TEST5(__VA_ARGS__) | ||
| 109 | 102 | ||
| 110 | #ifdef CONFIG_FTRACE_SYSCALLS | 103 | #ifdef CONFIG_FTRACE_SYSCALLS |
| 111 | #define __SC_STR_ADECL1(t, a) #a | 104 | #define __SC_STR_ADECL(t, a) #a |
| 112 | #define __SC_STR_ADECL2(t, a, ...) #a, __SC_STR_ADECL1(__VA_ARGS__) | 105 | #define __SC_STR_TDECL(t, a) #t |
| 113 | #define __SC_STR_ADECL3(t, a, ...) #a, __SC_STR_ADECL2(__VA_ARGS__) | ||
| 114 | #define __SC_STR_ADECL4(t, a, ...) #a, __SC_STR_ADECL3(__VA_ARGS__) | ||
| 115 | #define __SC_STR_ADECL5(t, a, ...) #a, __SC_STR_ADECL4(__VA_ARGS__) | ||
| 116 | #define __SC_STR_ADECL6(t, a, ...) #a, __SC_STR_ADECL5(__VA_ARGS__) | ||
| 117 | |||
| 118 | #define __SC_STR_TDECL1(t, a) #t | ||
| 119 | #define __SC_STR_TDECL2(t, a, ...) #t, __SC_STR_TDECL1(__VA_ARGS__) | ||
| 120 | #define __SC_STR_TDECL3(t, a, ...) #t, __SC_STR_TDECL2(__VA_ARGS__) | ||
| 121 | #define __SC_STR_TDECL4(t, a, ...) #t, __SC_STR_TDECL3(__VA_ARGS__) | ||
| 122 | #define __SC_STR_TDECL5(t, a, ...) #t, __SC_STR_TDECL4(__VA_ARGS__) | ||
| 123 | #define __SC_STR_TDECL6(t, a, ...) #t, __SC_STR_TDECL5(__VA_ARGS__) | ||
| 124 | 106 | ||
| 125 | extern struct ftrace_event_class event_class_syscall_enter; | 107 | extern struct ftrace_event_class event_class_syscall_enter; |
| 126 | extern struct ftrace_event_class event_class_syscall_exit; | 108 | extern struct ftrace_event_class event_class_syscall_exit; |
| @@ -217,10 +199,10 @@ extern struct trace_event_functions exit_syscall_print_funcs; | |||
| 217 | #ifdef CONFIG_FTRACE_SYSCALLS | 199 | #ifdef CONFIG_FTRACE_SYSCALLS |
| 218 | #define SYSCALL_DEFINEx(x, sname, ...) \ | 200 | #define SYSCALL_DEFINEx(x, sname, ...) \ |
| 219 | static const char *types_##sname[] = { \ | 201 | static const char *types_##sname[] = { \ |
| 220 | __SC_STR_TDECL##x(__VA_ARGS__) \ | 202 | __MAP(x,__SC_STR_TDECL,__VA_ARGS__) \ |
| 221 | }; \ | 203 | }; \ |
| 222 | static const char *args_##sname[] = { \ | 204 | static const char *args_##sname[] = { \ |
| 223 | __SC_STR_ADECL##x(__VA_ARGS__) \ | 205 | __MAP(x,__SC_STR_ADECL,__VA_ARGS__) \ |
| 224 | }; \ | 206 | }; \ |
| 225 | SYSCALL_METADATA(sname, x); \ | 207 | SYSCALL_METADATA(sname, x); \ |
| 226 | __SYSCALL_DEFINEx(x, sname, __VA_ARGS__) | 208 | __SYSCALL_DEFINEx(x, sname, __VA_ARGS__) |
| @@ -234,21 +216,21 @@ extern struct trace_event_functions exit_syscall_print_funcs; | |||
| 234 | #define SYSCALL_DEFINE(name) static inline long SYSC_##name | 216 | #define SYSCALL_DEFINE(name) static inline long SYSC_##name |
| 235 | 217 | ||
| 236 | #define __SYSCALL_DEFINEx(x, name, ...) \ | 218 | #define __SYSCALL_DEFINEx(x, name, ...) \ |
| 237 | asmlinkage long sys##name(__SC_DECL##x(__VA_ARGS__)); \ | 219 | asmlinkage long sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)); \ |
| 238 | static inline long SYSC##name(__SC_DECL##x(__VA_ARGS__)); \ | 220 | static inline long SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__)); \ |
| 239 | asmlinkage long SyS##name(__SC_LONG##x(__VA_ARGS__)) \ | 221 | asmlinkage long SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \ |
| 240 | { \ | 222 | { \ |
| 241 | __SC_TEST##x(__VA_ARGS__); \ | 223 | __MAP(x,__SC_TEST,__VA_ARGS__); \ |
| 242 | return (long) SYSC##name(__SC_CAST##x(__VA_ARGS__)); \ | 224 | return SYSC##name(__MAP(x,__SC_CAST,__VA_ARGS__)); \ |
| 243 | } \ | 225 | } \ |
| 244 | SYSCALL_ALIAS(sys##name, SyS##name); \ | 226 | SYSCALL_ALIAS(sys##name, SyS##name); \ |
| 245 | static inline long SYSC##name(__SC_DECL##x(__VA_ARGS__)) | 227 | static inline long SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__)) |
| 246 | 228 | ||
| 247 | #else /* CONFIG_HAVE_SYSCALL_WRAPPERS */ | 229 | #else /* CONFIG_HAVE_SYSCALL_WRAPPERS */ |
| 248 | 230 | ||
| 249 | #define SYSCALL_DEFINE(name) asmlinkage long sys_##name | 231 | #define SYSCALL_DEFINE(name) asmlinkage long sys_##name |
| 250 | #define __SYSCALL_DEFINEx(x, name, ...) \ | 232 | #define __SYSCALL_DEFINEx(x, name, ...) \ |
| 251 | asmlinkage long sys##name(__SC_DECL##x(__VA_ARGS__)) | 233 | asmlinkage long sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) |
| 252 | 234 | ||
| 253 | #endif /* CONFIG_HAVE_SYSCALL_WRAPPERS */ | 235 | #endif /* CONFIG_HAVE_SYSCALL_WRAPPERS */ |
| 254 | 236 | ||
