Skip to content

Commit 45db1c6

Browse files
author
H. Peter Anvin
committed
x86, um: Use the same style generated syscall tables as native
Now when the native kernel uses a single style of generated system call table, follow suite for UML and implement the same style, all in C. This requires __NR_syscall_max and NR_syscalls to be generated; on native this is done in asm-headers.h but that file is common to all UML architectures; therefore put it in user-headers.h instead which already have accommodations for architecture-specific values. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
1 parent 392f4b7 commit 45db1c6

File tree

5 files changed

+84
-46
lines changed

5 files changed

+84
-46
lines changed

arch/x86/um/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ subarch-$(CONFIG_MODULES) += ../kernel/module.o
3737
USER_OBJS := bugs_$(BITS).o ptrace_user.o fault.o
3838

3939
extra-y += user-offsets.s
40-
$(obj)/user-offsets.s: c_flags = -Wp,-MD,$(depfile) $(USER_CFLAGS)
40+
$(obj)/user-offsets.s: c_flags = -Wp,-MD,$(depfile) $(USER_CFLAGS) \
41+
-Iarch/x86/include/generated
4142

4243
UNPROFILE_OBJS := stub_segv.o
4344
CFLAGS_stub_segv.o := $(CFLAGS_NO_HARDENING)

arch/x86/um/sys_call_table_32.S

Lines changed: 0 additions & 26 deletions
This file was deleted.

arch/x86/um/sys_call_table_32.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* System call table for UML/i386, copied from arch/x86/kernel/syscall_*.c
3+
* with some changes for UML.
4+
*/
5+
6+
#include <linux/linkage.h>
7+
#include <linux/sys.h>
8+
#include <linux/cache.h>
9+
#include <generated/user_constants.h>
10+
11+
#define __NO_STUBS
12+
13+
/*
14+
* Below you can see, in terms of #define's, the differences between the x86-64
15+
* and the UML syscall table.
16+
*/
17+
18+
/* Not going to be implemented by UML, since we have no hardware. */
19+
#define stub_iopl sys_ni_syscall
20+
#define sys_ioperm sys_ni_syscall
21+
22+
#define sys_vm86old sys_ni_syscall
23+
#define sys_vm86 sys_ni_syscall
24+
25+
#define old_mmap sys_old_mmap
26+
27+
#define ptregs_fork sys_fork
28+
#define ptregs_execve sys_execve
29+
#define ptregs_iopl sys_iopl
30+
#define ptregs_vm86old sys_vm86old
31+
#define ptregs_clone sys_clone
32+
#define ptregs_vm86 sys_vm86
33+
#define ptregs_sigaltstack sys_sigaltstack
34+
#define ptregs_vfork sys_vfork
35+
36+
#define __SYSCALL_I386(nr, sym, compat) extern asmlinkage void sym(void) ;
37+
#include <asm/syscalls_32.h>
38+
39+
#undef __SYSCALL_I386
40+
#define __SYSCALL_I386(nr, sym, compat) [ nr ] = sym,
41+
42+
typedef void (*sys_call_ptr_t)(void);
43+
44+
extern void sys_ni_syscall(void);
45+
46+
sys_call_ptr_t sys_call_table[] __cacheline_aligned = {
47+
/*
48+
* Smells like a compiler bug -- it doesn't work
49+
* when the & below is removed.
50+
*/
51+
[0 ... __NR_syscall_max] = &sys_ni_syscall,
52+
#include <asm/syscalls_32.h>
53+
};
54+
55+
int syscall_table_size = sizeof(sys_call_table);

arch/x86/um/sys_call_table_64.c

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/*
2-
* System call table for UML/x86-64, copied from arch/x86_64/kernel/syscall.c
2+
* System call table for UML/x86-64, copied from arch/x86/kernel/syscall_*.c
33
* with some changes for UML.
44
*/
55

66
#include <linux/linkage.h>
77
#include <linux/sys.h>
88
#include <linux/cache.h>
9+
#include <generated/user_constants.h>
910

1011
#define __NO_STUBS
1112

@@ -34,31 +35,23 @@
3435
#define stub_sigaltstack sys_sigaltstack
3536
#define stub_rt_sigreturn sys_rt_sigreturn
3637

37-
#define __SYSCALL(nr, sym) extern asmlinkage void sym(void) ;
38-
#undef _ASM_X86_UNISTD_64_H
39-
#include "../../x86/include/asm/unistd_64.h"
38+
#define __SYSCALL_64(nr, sym, compat) extern asmlinkage void sym(void) ;
39+
#include <asm/syscalls_64.h>
4040

41-
#undef __SYSCALL
42-
#define __SYSCALL(nr, sym) [ nr ] = sym,
43-
#undef _ASM_X86_UNISTD_64_H
41+
#undef __SYSCALL_64
42+
#define __SYSCALL_64(nr, sym, compat) [ nr ] = sym,
4443

4544
typedef void (*sys_call_ptr_t)(void);
4645

4746
extern void sys_ni_syscall(void);
4847

49-
/*
50-
* We used to have a trick here which made sure that holes in the
51-
* x86_64 table were filled in with sys_ni_syscall, but a comment in
52-
* unistd_64.h says that holes aren't allowed, so the trick was
53-
* removed.
54-
* The trick looked like this
55-
* [0 ... UM_NR_syscall_max] = &sys_ni_syscall
56-
* before including unistd_64.h - the later initializations overwrote
57-
* the sys_ni_syscall filler.
58-
*/
59-
6048
sys_call_ptr_t sys_call_table[] __cacheline_aligned = {
61-
#include <asm/unistd_64.h>
49+
/*
50+
* Smells like a compiler bug -- it doesn't work
51+
* when the & below is removed.
52+
*/
53+
[0 ... __NR_syscall_max] = &sys_ni_syscall,
54+
#include <asm/syscalls_64.h>
6255
};
6356

6457
int syscall_table_size = sizeof(sys_call_table);

arch/x86/um/user-offsets.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@
88
#include <asm/ptrace.h>
99
#include <asm/types.h>
1010

11+
#ifdef __i386__
12+
#define __SYSCALL_I386(nr, sym, compat) [nr] = 1,
13+
static char syscalls[] = {
14+
#include <asm/syscalls_32.h>
15+
};
16+
#else
17+
#define __SYSCALL_64(nr, sym, compat) [nr] = 1,
18+
static char syscalls[] = {
19+
#include <asm/syscalls_64.h>
20+
};
21+
#endif
22+
1123
#define DEFINE(sym, val) \
1224
asm volatile("\n->" #sym " %0 " #val : : "i" (val))
1325

@@ -77,4 +89,7 @@ void foo(void)
7789
DEFINE(UM_PROT_READ, PROT_READ);
7890
DEFINE(UM_PROT_WRITE, PROT_WRITE);
7991
DEFINE(UM_PROT_EXEC, PROT_EXEC);
92+
93+
DEFINE(__NR_syscall_max, sizeof(syscalls) - 1);
94+
DEFINE(NR_syscalls, sizeof(syscalls));
8095
}

0 commit comments

Comments
 (0)