diff options
author | Dominik Brodowski <linux@dominikbrodowski.net> | 2018-04-05 05:53:01 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2018-04-05 10:59:25 -0400 |
commit | 1bd21c6c21e848996339508d3ffb106d505256a8 (patch) | |
tree | 34cb9bbb4d695798b192a08f45cbf6aeda984e8b | |
parent | dfe64506c01e57159a4c550fe537c13a317ff01b (diff) |
syscalls/core: Introduce CONFIG_ARCH_HAS_SYSCALL_WRAPPER=y
It may be useful for an architecture to override the definitions of the
SYSCALL_DEFINE0() and __SYSCALL_DEFINEx() macros in <linux/syscalls.h>,
in particular to use a different calling convention for syscalls.
This patch provides a mechanism to do so: It introduces
CONFIG_ARCH_HAS_SYSCALL_WRAPPER. If it is enabled, <asm/sycall_wrapper.h>
is included in <linux/syscalls.h> and may be used to define the macros
mentioned above. Moreover, as the syscall calling convention may be
different if CONFIG_ARCH_HAS_SYSCALL_WRAPPER is set, the syscall function
prototypes in <linux/syscalls.h> are #ifndef'd out in that case.
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/20180405095307.3730-3-linux@dominikbrodowski.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r-- | include/linux/syscalls.h | 23 | ||||
-rw-r--r-- | init/Kconfig | 7 |
2 files changed, 30 insertions, 0 deletions
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index b961184f597a..503ab245d4ce 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h | |||
@@ -81,6 +81,17 @@ union bpf_attr; | |||
81 | #include <linux/key.h> | 81 | #include <linux/key.h> |
82 | #include <trace/syscall.h> | 82 | #include <trace/syscall.h> |
83 | 83 | ||
84 | #ifdef CONFIG_ARCH_HAS_SYSCALL_WRAPPER | ||
85 | /* | ||
86 | * It may be useful for an architecture to override the definitions of the | ||
87 | * SYSCALL_DEFINE0() and __SYSCALL_DEFINEx() macros, in particular to use a | ||
88 | * different calling convention for syscalls. To allow for that, the prototypes | ||
89 | * for the sys_*() functions below will *not* be included if | ||
90 | * CONFIG_ARCH_HAS_SYSCALL_WRAPPER is enabled. | ||
91 | */ | ||
92 | #include <asm/syscall_wrapper.h> | ||
93 | #endif /* CONFIG_ARCH_HAS_SYSCALL_WRAPPER */ | ||
94 | |||
84 | /* | 95 | /* |
85 | * __MAP - apply a macro to syscall arguments | 96 | * __MAP - apply a macro to syscall arguments |
86 | * __MAP(n, m, t1, a1, t2, a2, ..., tn, an) will expand to | 97 | * __MAP(n, m, t1, a1, t2, a2, ..., tn, an) will expand to |
@@ -189,11 +200,13 @@ static inline int is_syscall_trace_event(struct trace_event_call *tp_event) | |||
189 | } | 200 | } |
190 | #endif | 201 | #endif |
191 | 202 | ||
203 | #ifndef SYSCALL_DEFINE0 | ||
192 | #define SYSCALL_DEFINE0(sname) \ | 204 | #define SYSCALL_DEFINE0(sname) \ |
193 | SYSCALL_METADATA(_##sname, 0); \ | 205 | SYSCALL_METADATA(_##sname, 0); \ |
194 | asmlinkage long sys_##sname(void); \ | 206 | asmlinkage long sys_##sname(void); \ |
195 | ALLOW_ERROR_INJECTION(sys_##sname, ERRNO); \ | 207 | ALLOW_ERROR_INJECTION(sys_##sname, ERRNO); \ |
196 | asmlinkage long sys_##sname(void) | 208 | asmlinkage long sys_##sname(void) |
209 | #endif /* SYSCALL_DEFINE0 */ | ||
197 | 210 | ||
198 | #define SYSCALL_DEFINE1(name, ...) SYSCALL_DEFINEx(1, _##name, __VA_ARGS__) | 211 | #define SYSCALL_DEFINE1(name, ...) SYSCALL_DEFINEx(1, _##name, __VA_ARGS__) |
199 | #define SYSCALL_DEFINE2(name, ...) SYSCALL_DEFINEx(2, _##name, __VA_ARGS__) | 212 | #define SYSCALL_DEFINE2(name, ...) SYSCALL_DEFINEx(2, _##name, __VA_ARGS__) |
@@ -209,6 +222,8 @@ static inline int is_syscall_trace_event(struct trace_event_call *tp_event) | |||
209 | __SYSCALL_DEFINEx(x, sname, __VA_ARGS__) | 222 | __SYSCALL_DEFINEx(x, sname, __VA_ARGS__) |
210 | 223 | ||
211 | #define __PROTECT(...) asmlinkage_protect(__VA_ARGS__) | 224 | #define __PROTECT(...) asmlinkage_protect(__VA_ARGS__) |
225 | |||
226 | #ifndef __SYSCALL_DEFINEx | ||
212 | #define __SYSCALL_DEFINEx(x, name, ...) \ | 227 | #define __SYSCALL_DEFINEx(x, name, ...) \ |
213 | asmlinkage long sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) \ | 228 | asmlinkage long sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) \ |
214 | __attribute__((alias(__stringify(SyS##name)))); \ | 229 | __attribute__((alias(__stringify(SyS##name)))); \ |
@@ -223,6 +238,7 @@ static inline int is_syscall_trace_event(struct trace_event_call *tp_event) | |||
223 | return ret; \ | 238 | return ret; \ |
224 | } \ | 239 | } \ |
225 | static inline long SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__)) | 240 | static inline long SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__)) |
241 | #endif /* __SYSCALL_DEFINEx */ | ||
226 | 242 | ||
227 | /* | 243 | /* |
228 | * Called before coming back to user-mode. Returning to user-mode with an | 244 | * Called before coming back to user-mode. Returning to user-mode with an |
@@ -252,7 +268,12 @@ static inline void addr_limit_user_check(void) | |||
252 | * Please note that these prototypes here are only provided for information | 268 | * Please note that these prototypes here are only provided for information |
253 | * purposes, for static analysis, and for linking from the syscall table. | 269 | * purposes, for static analysis, and for linking from the syscall table. |
254 | * These functions should not be called elsewhere from kernel code. | 270 | * These functions should not be called elsewhere from kernel code. |
271 | * | ||
272 | * As the syscall calling convention may be different from the default | ||
273 | * for architectures overriding the syscall calling convention, do not | ||
274 | * include the prototypes if CONFIG_ARCH_HAS_SYSCALL_WRAPPER is enabled. | ||
255 | */ | 275 | */ |
276 | #ifndef CONFIG_ARCH_HAS_SYSCALL_WRAPPER | ||
256 | asmlinkage long sys_io_setup(unsigned nr_reqs, aio_context_t __user *ctx); | 277 | asmlinkage long sys_io_setup(unsigned nr_reqs, aio_context_t __user *ctx); |
257 | asmlinkage long sys_io_destroy(aio_context_t ctx); | 278 | asmlinkage long sys_io_destroy(aio_context_t ctx); |
258 | asmlinkage long sys_io_submit(aio_context_t, long, | 279 | asmlinkage long sys_io_submit(aio_context_t, long, |
@@ -1076,6 +1097,8 @@ asmlinkage long sys_old_mmap(struct mmap_arg_struct __user *arg); | |||
1076 | */ | 1097 | */ |
1077 | asmlinkage long sys_ni_syscall(void); | 1098 | asmlinkage long sys_ni_syscall(void); |
1078 | 1099 | ||
1100 | #endif /* CONFIG_ARCH_HAS_SYSCALL_WRAPPER */ | ||
1101 | |||
1079 | 1102 | ||
1080 | /* | 1103 | /* |
1081 | * Kernel code should not call syscalls (i.e., sys_xyzyyz()) directly. | 1104 | * Kernel code should not call syscalls (i.e., sys_xyzyyz()) directly. |
diff --git a/init/Kconfig b/init/Kconfig index 2852692d7c9c..068eb6c3bbf7 100644 --- a/init/Kconfig +++ b/init/Kconfig | |||
@@ -1923,3 +1923,10 @@ source "kernel/Kconfig.locks" | |||
1923 | 1923 | ||
1924 | config ARCH_HAS_SYNC_CORE_BEFORE_USERMODE | 1924 | config ARCH_HAS_SYNC_CORE_BEFORE_USERMODE |
1925 | bool | 1925 | bool |
1926 | |||
1927 | # It may be useful for an architecture to override the definitions of the | ||
1928 | # SYSCALL_DEFINE() and __SYSCALL_DEFINEx() macros in <linux/syscalls.h>, | ||
1929 | # in particular to use a different calling convention for syscalls. | ||
1930 | config ARCH_HAS_SYSCALL_WRAPPER | ||
1931 | def_bool n | ||
1932 | depends on !COMPAT | ||