Skip to content

Commit 0872098

Browse files
Brian GerstKAGA-KOKO
authored andcommitted
x86/entry: Move max syscall number calculation to syscallhdr.sh
Instead of using an array in asm-offsets to calculate the max syscall number, calculate it when writing out the syscall headers. Signed-off-by: Brian Gerst <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 2e487c3 commit 0872098

File tree

12 files changed

+24
-72
lines changed

12 files changed

+24
-72
lines changed

arch/x86/entry/syscall_32.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <linux/linkage.h>
55
#include <linux/sys.h>
66
#include <linux/cache.h>
7-
#include <asm/asm-offsets.h>
7+
#include <asm/unistd.h>
88
#include <asm/syscall.h>
99

1010
#ifdef CONFIG_IA32_EMULATION
@@ -22,11 +22,11 @@ extern asmlinkage long sys_ni_syscall(unsigned long, unsigned long, unsigned lon
2222

2323
#define __SYSCALL_I386(nr, sym, qual) [nr] = sym,
2424

25-
__visible const sys_call_ptr_t ia32_sys_call_table[__NR_syscall_compat_max+1] = {
25+
__visible const sys_call_ptr_t ia32_sys_call_table[__NR_ia32_syscall_max+1] = {
2626
/*
2727
* Smells like a compiler bug -- it doesn't work
2828
* when the & below is removed.
2929
*/
30-
[0 ... __NR_syscall_compat_max] = &__sys_ni_syscall,
30+
[0 ... __NR_ia32_syscall_max] = &__sys_ni_syscall,
3131
#include <asm/syscalls_32.h>
3232
};

arch/x86/entry/syscall_64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <linux/sys.h>
66
#include <linux/cache.h>
77
#include <linux/syscalls.h>
8-
#include <asm/asm-offsets.h>
8+
#include <asm/unistd.h>
99
#include <asm/syscall.h>
1010

1111
#define __SYSCALL_X32(nr, sym, qual)

arch/x86/entry/syscall_x32.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <linux/sys.h>
66
#include <linux/cache.h>
77
#include <linux/syscalls.h>
8-
#include <asm/asm-offsets.h>
8+
#include <asm/unistd.h>
99
#include <asm/syscall.h>
1010

1111
#define __SYSCALL_64(nr, sym, qual)
@@ -16,11 +16,11 @@
1616

1717
#define __SYSCALL_X32(nr, sym, qual) [nr] = sym,
1818

19-
asmlinkage const sys_call_ptr_t x32_sys_call_table[__NR_syscall_x32_max+1] = {
19+
asmlinkage const sys_call_ptr_t x32_sys_call_table[__NR_x32_syscall_max+1] = {
2020
/*
2121
* Smells like a compiler bug -- it doesn't work
2222
* when the & below is removed.
2323
*/
24-
[0 ... __NR_syscall_x32_max] = &__x64_sys_ni_syscall,
24+
[0 ... __NR_x32_syscall_max] = &__x64_sys_ni_syscall,
2525
#include <asm/syscalls_64.h>
2626
};

arch/x86/entry/syscalls/syscallhdr.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,21 @@ grep -E "^[0-9A-Fa-fXx]+[[:space:]]+${my_abis}" "$in" | sort -n | (
1515
echo "#define ${fileguard} 1"
1616
echo ""
1717

18+
max=0
1819
while read nr abi name entry ; do
1920
if [ -z "$offset" ]; then
2021
echo "#define __NR_${prefix}${name} $nr"
2122
else
2223
echo "#define __NR_${prefix}${name} ($offset + $nr)"
2324
fi
25+
26+
max=$nr
2427
done
2528

29+
echo ""
30+
echo "#ifdef __KERNEL__"
31+
echo "#define __NR_${prefix}syscall_max $max"
32+
echo "#endif"
2633
echo ""
2734
echo "#endif /* ${fileguard} */"
2835
) > "$out"

arch/x86/entry/vdso/vdso32/vclock_gettime.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414
#undef CONFIG_64BIT
1515
#undef CONFIG_X86_64
16+
#undef CONFIG_COMPAT
1617
#undef CONFIG_PGTABLE_LEVELS
1718
#undef CONFIG_ILLEGAL_POINTER_VALUE
1819
#undef CONFIG_SPARSEMEM_VMEMMAP

arch/x86/include/asm/syscall.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <uapi/linux/audit.h>
1414
#include <linux/sched.h>
1515
#include <linux/err.h>
16-
#include <asm/asm-offsets.h> /* For NR_syscalls */
1716
#include <asm/thread_info.h> /* for TS_COMPAT */
1817
#include <asm/unistd.h>
1918

@@ -28,8 +27,6 @@ extern const sys_call_ptr_t sys_call_table[];
2827

2928
#if defined(CONFIG_X86_32)
3029
#define ia32_sys_call_table sys_call_table
31-
#define __NR_syscall_compat_max __NR_syscall_max
32-
#define IA32_NR_syscalls NR_syscalls
3330
#endif
3431

3532
#if defined(CONFIG_IA32_EMULATION)

arch/x86/include/asm/unistd.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313
# define __ARCH_WANT_SYS_OLD_MMAP
1414
# define __ARCH_WANT_SYS_OLD_SELECT
1515

16+
# define __NR_ia32_syscall_max __NR_syscall_max
17+
1618
# else
1719

1820
# include <asm/unistd_64.h>
1921
# include <asm/unistd_64_x32.h>
22+
# include <asm/unistd_32_ia32.h>
2023
# define __ARCH_WANT_SYS_TIME
2124
# define __ARCH_WANT_SYS_UTIME
2225
# define __ARCH_WANT_COMPAT_SYS_PREADV64
@@ -26,6 +29,10 @@
2629

2730
# endif
2831

32+
# define NR_syscalls (__NR_syscall_max + 1)
33+
# define X32_NR_syscalls (__NR_x32_syscall_max + 1)
34+
# define IA32_NR_syscalls (__NR_ia32_syscall_max + 1)
35+
2936
# define __ARCH_WANT_NEW_STAT
3037
# define __ARCH_WANT_OLD_READDIR
3138
# define __ARCH_WANT_OLD_STAT

arch/x86/kernel/asm-offsets_32.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55

66
#include <asm/ucontext.h>
77

8-
#define __SYSCALL_I386(nr, sym, qual) [nr] = 1,
9-
static char syscalls[] = {
10-
#include <asm/syscalls_32.h>
11-
};
12-
138
/* workaround for a warning with -Wmissing-prototypes */
149
void foo(void);
1510

@@ -60,8 +55,4 @@ void foo(void)
6055
BLANK();
6156
OFFSET(stack_canary_offset, stack_canary, canary);
6257
#endif
63-
64-
BLANK();
65-
DEFINE(__NR_syscall_max, sizeof(syscalls) - 1);
66-
DEFINE(NR_syscalls, sizeof(syscalls));
6758
}

arch/x86/kernel/asm-offsets_64.c

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,6 @@
55

66
#include <asm/ia32.h>
77

8-
#define __SYSCALL_64(nr, sym, qual) [nr] = 1,
9-
#define __SYSCALL_X32(nr, sym, qual)
10-
static char syscalls_64[] = {
11-
#include <asm/syscalls_64.h>
12-
};
13-
#undef __SYSCALL_64
14-
#undef __SYSCALL_X32
15-
16-
#ifdef CONFIG_X86_X32_ABI
17-
#define __SYSCALL_64(nr, sym, qual)
18-
#define __SYSCALL_X32(nr, sym, qual) [nr] = 1,
19-
static char syscalls_x32[] = {
20-
#include <asm/syscalls_64.h>
21-
};
22-
#undef __SYSCALL_64
23-
#undef __SYSCALL_X32
24-
#endif
25-
26-
#define __SYSCALL_I386(nr, sym, qual) [nr] = 1,
27-
static char syscalls_ia32[] = {
28-
#include <asm/syscalls_32.h>
29-
};
30-
#undef __SYSCALL_I386
31-
328
#if defined(CONFIG_KVM_GUEST) && defined(CONFIG_PARAVIRT_SPINLOCKS)
339
#include <asm/kvm_para.h>
3410
#endif
@@ -90,17 +66,5 @@ int main(void)
9066
DEFINE(stack_canary_offset, offsetof(struct fixed_percpu_data, stack_canary));
9167
BLANK();
9268
#endif
93-
94-
DEFINE(__NR_syscall_max, sizeof(syscalls_64) - 1);
95-
DEFINE(NR_syscalls, sizeof(syscalls_64));
96-
97-
#ifdef CONFIG_X86_X32_ABI
98-
DEFINE(__NR_syscall_x32_max, sizeof(syscalls_x32) - 1);
99-
DEFINE(X32_NR_syscalls, sizeof(syscalls_x32));
100-
#endif
101-
102-
DEFINE(__NR_syscall_compat_max, sizeof(syscalls_ia32) - 1);
103-
DEFINE(IA32_NR_syscalls, sizeof(syscalls_ia32));
104-
10569
return 0;
10670
}

arch/x86/um/sys_call_table_32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <linux/linkage.h>
88
#include <linux/sys.h>
99
#include <linux/cache.h>
10-
#include <generated/user_constants.h>
10+
#include <asm/unistd.h>
1111
#include <asm/syscall.h>
1212

1313
#define __NO_STUBS

0 commit comments

Comments
 (0)