Skip to content

Commit 1bd21c6

Browse files
Dominik BrodowskiIngo Molnar
authored andcommitted
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>
1 parent dfe6450 commit 1bd21c6

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

include/linux/syscalls.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ union bpf_attr;
8181
#include <linux/key.h>
8282
#include <trace/syscall.h>
8383

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+
8495
/*
8596
* __MAP - apply a macro to syscall arguments
8697
* __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)
189200
}
190201
#endif
191202

203+
#ifndef SYSCALL_DEFINE0
192204
#define SYSCALL_DEFINE0(sname) \
193205
SYSCALL_METADATA(_##sname, 0); \
194206
asmlinkage long sys_##sname(void); \
195207
ALLOW_ERROR_INJECTION(sys_##sname, ERRNO); \
196208
asmlinkage long sys_##sname(void)
209+
#endif /* SYSCALL_DEFINE0 */
197210

198211
#define SYSCALL_DEFINE1(name, ...) SYSCALL_DEFINEx(1, _##name, __VA_ARGS__)
199212
#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)
209222
__SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
210223

211224
#define __PROTECT(...) asmlinkage_protect(__VA_ARGS__)
225+
226+
#ifndef __SYSCALL_DEFINEx
212227
#define __SYSCALL_DEFINEx(x, name, ...) \
213228
asmlinkage long sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) \
214229
__attribute__((alias(__stringify(SyS##name)))); \
@@ -223,6 +238,7 @@ static inline int is_syscall_trace_event(struct trace_event_call *tp_event)
223238
return ret; \
224239
} \
225240
static inline long SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__))
241+
#endif /* __SYSCALL_DEFINEx */
226242

227243
/*
228244
* 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)
252268
* Please note that these prototypes here are only provided for information
253269
* purposes, for static analysis, and for linking from the syscall table.
254270
* 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.
255275
*/
276+
#ifndef CONFIG_ARCH_HAS_SYSCALL_WRAPPER
256277
asmlinkage long sys_io_setup(unsigned nr_reqs, aio_context_t __user *ctx);
257278
asmlinkage long sys_io_destroy(aio_context_t ctx);
258279
asmlinkage long sys_io_submit(aio_context_t, long,
@@ -1076,6 +1097,8 @@ asmlinkage long sys_old_mmap(struct mmap_arg_struct __user *arg);
10761097
*/
10771098
asmlinkage long sys_ni_syscall(void);
10781099

1100+
#endif /* CONFIG_ARCH_HAS_SYSCALL_WRAPPER */
1101+
10791102

10801103
/*
10811104
* Kernel code should not call syscalls (i.e., sys_xyzyyz()) directly.

init/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,3 +1923,10 @@ source "kernel/Kconfig.locks"
19231923

19241924
config ARCH_HAS_SYNC_CORE_BEFORE_USERMODE
19251925
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

0 commit comments

Comments
 (0)