]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/missing_syscalls.py
add ipv6 range element creation test cases
[thirdparty/systemd.git] / src / basic / missing_syscalls.py
1 #!/usr/bin/env python3
2 import sys
3 import functools
4
5 # We only generate numbers for a dozen or so syscalls
6 SYSCALLS = [
7 'bpf',
8 'close_range',
9 'copy_file_range',
10 'getrandom',
11 'memfd_create',
12 'name_to_handle_at',
13 'pidfd_open',
14 'pidfd_send_signal',
15 'pkey_mprotect',
16 'renameat2',
17 'setns',
18 'statx']
19
20 def dictify(f):
21 def wrap(*args, **kwargs):
22 return dict(f(*args, **kwargs))
23 return functools.update_wrapper(wrap, f)
24
25 @dictify
26 def parse_syscall_table(filename):
27 print(f'Reading {filename}…')
28 for line in open(filename):
29 items = line.split()
30 if len(items) >= 2:
31 yield items[0], int(items[1])
32
33 def parse_syscall_tables(filenames):
34 return {filename.split('-')[-1]: parse_syscall_table(filename)
35 for filename in filenames}
36
37 DEF_TEMPLATE = '''\
38 #ifndef __IGNORE_{syscall}
39 # if defined(__aarch64__)
40 # define systemd_NR_{syscall} {nr_arm64}
41 # elif defined(__alpha__)
42 # define systemd_NR_{syscall} {nr_alpha}
43 # elif defined(__arc__) || defined(__tilegx__)
44 # define systemd_NR_{syscall} {nr_arc}
45 # elif defined(__arm__)
46 # define systemd_NR_{syscall} {nr_arm}
47 # elif defined(__i386__)
48 # define systemd_NR_{syscall} {nr_i386}
49 # elif defined(__ia64__)
50 # define systemd_NR_{syscall} {nr_ia64}
51 # elif defined(__m68k__)
52 # define systemd_NR_{syscall} {nr_m68k}
53 # elif defined(_MIPS_SIM)
54 # if _MIPS_SIM == _MIPS_SIM_ABI32
55 # define systemd_NR_{syscall} {nr_mipso32}
56 # elif _MIPS_SIM == _MIPS_SIM_NABI32
57 # define systemd_NR_{syscall} {nr_mips64n32}
58 # elif _MIPS_SIM == _MIPS_SIM_ABI64
59 # define systemd_NR_{syscall} {nr_mips64}
60 # else
61 # error "Unknown MIPS ABI"
62 # endif
63 # elif defined(__powerpc__)
64 # define systemd_NR_{syscall} {nr_powerpc}
65 # elif defined(__s390__)
66 # define systemd_NR_{syscall} {nr_s390}
67 # elif defined(__sparc__)
68 # define systemd_NR_{syscall} {nr_sparc}
69 # elif defined(__x86_64__)
70 # if defined(__ILP32__)
71 # define systemd_NR_{syscall} ({nr_x86_64} | /* __X32_SYSCALL_BIT */ 0x40000000)
72 # else
73 # define systemd_NR_{syscall} {nr_x86_64}
74 # endif
75 # else
76 # warning "{syscall}() syscall number is unknown for your architecture"
77 # endif
78
79 /* may be (invalid) negative number due to libseccomp, see PR 13319 */
80 # if defined __NR_{syscall} && __NR_{syscall} >= 0
81 # if defined systemd_NR_{syscall}
82 assert_cc(__NR_{syscall} == systemd_NR_{syscall});
83 # endif
84 # else
85 # if defined __NR_{syscall}
86 # undef __NR_{syscall}
87 # endif
88 # if defined systemd_NR_{syscall} && systemd_NR_{syscall} >= 0
89 # define __NR_{syscall} systemd_NR_{syscall}
90 # endif
91 # endif
92 #endif
93 '''
94
95 def print_syscall_def(syscall, tables, out):
96 mappings = {f'nr_{arch}':t.get(syscall, -1)
97 for arch, t in tables.items()}
98 print(DEF_TEMPLATE.format(syscall=syscall, **mappings),
99 file=out)
100
101 def print_syscall_defs(syscalls, tables, out):
102 print('/* This file is generated. Do not edit! */\n', file=out)
103 for syscall in syscalls:
104 print_syscall_def(syscall, tables, out)
105
106 if __name__ == '__main__':
107 output_file = sys.argv[1]
108 arch_files = sys.argv[2:]
109 out = open(output_file, 'wt')
110
111 tables = parse_syscall_tables(arch_files)
112 print_syscall_defs(SYSCALLS, tables, out)
113
114 print(f'Wrote {output_file}')