Merge pull request #18263 from keszybz/syscalls-auto

Generate missing syscalls headers programatically
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2021-01-16 17:21:34 +01:00
committed by GitHub
29 changed files with 10395 additions and 544 deletions

View File

@@ -1626,6 +1626,16 @@ includes = include_directories('src/basic',
add_project_arguments('-include', 'config.h', language : 'c')
generate_gperfs = find_program('tools/generate-gperfs.py')
autosuspend_update_sh = find_program('tools/autosuspend-update.sh')
hwdb_update_sh = find_program('tools/hwdb-update.sh')
make_autosuspend_rules_py = find_program('tools/make-autosuspend-rules.py')
make_directive_index_py = find_program('tools/make-directive-index.py')
make_man_index_py = find_program('tools/make-man-index.py')
syscall_table_update_sh = find_program('tools/syscall-table-update.sh')
xml_helper_py = find_program('tools/xml_helper.py')
update_dbus_docs_py = find_program('tools/update-dbus-docs.py')
############################################################
subdir('po')
subdir('catalog')
@@ -1694,17 +1704,6 @@ install_libsystemd_static = static_library(
############################################################
autosuspend_update_sh = find_program('tools/autosuspend-update.sh')
hwdb_update_sh = find_program('tools/hwdb-update.sh')
make_autosuspend_rules_py = find_program('tools/make-autosuspend-rules.py')
make_directive_index_py = find_program('tools/make-directive-index.py')
make_man_index_py = find_program('tools/make-man-index.py')
syscall_names_update_sh = find_program('tools/syscall-names-update.sh')
xml_helper_py = find_program('tools/xml_helper.py')
update_dbus_docs_py = find_program('tools/update-dbus-docs.py')
############################################################
# binaries that have --help and are intended for use by humans,
# usually, but not always, installed in /bin.
public_programs = []

View File

@@ -4,9 +4,9 @@ set -eu
for i in *.h */*.h; do
if [[ $i == 'loadavg.h' ]]; then
curl https://raw.githubusercontent.com/torvalds/linux/master/include/linux/sched/$i -o $i
curl --fail https://raw.githubusercontent.com/torvalds/linux/master/include/linux/sched/$i -o $i
else
curl https://raw.githubusercontent.com/torvalds/linux/master/include/uapi/linux/$i -o $i
curl --fail https://raw.githubusercontent.com/torvalds/linux/master/include/uapi/linux/$i -o $i
fi
sed -i -e 's/__user //g' -e '/^#include <linux\/compiler.h>/ d' $i

View File

@@ -262,6 +262,9 @@ missing_audit_h = files('missing_audit.h')
missing_capability_h = files('missing_capability.h')
missing_socket_h = files('missing_socket.h')
missing_syscall_def_h = files('missing_syscall_def.h')
basic_sources += missing_syscall_def_h
generate_af_list = find_program('generate-af-list.sh')
af_list_txt = custom_target(
'af-list.txt',
@@ -330,9 +333,47 @@ foreach item : [['af', af_list_txt, 'af', ''],
endforeach
basic_sources += generated_gperf_headers
basic_gcrypt_sources = files(
'gcrypt-util.c',
'gcrypt-util.h')
############################################################
arch_list = [
'alpha',
'arc',
'arm',
'arm64',
'i386',
'ia64',
'm68k',
'mips64',
'mips64n32',
'mipso32',
'powerpc',
'powerpc64',
's390',
's390x',
'sparc',
'x86_64']
run_target(
'update-syscall-tables',
command : [syscall_table_update_sh, meson.current_source_dir()] + arch_list)
syscall_names_text = files('syscall-names.text')
syscall_lists = []
foreach arch: arch_list
syscall_lists += files('syscalls-@0@'.format(arch))
endforeach
missing_syscalls_py = find_program('missing_syscalls.py')
run_target(
'update-syscall-header',
command : [missing_syscalls_py,
missing_syscall_def_h,
syscall_lists])
############################################################
libbasic = static_library(
'basic',
@@ -348,6 +389,12 @@ libbasic = static_library(
c_args : ['-fvisibility=default'],
install : false)
############################################################
basic_gcrypt_sources = files(
'gcrypt-util.c',
'gcrypt-util.h')
# A convenience library that is separate from libbasic to avoid
# unnecessary linking to libgcrypt.
libbasic_gcrypt = static_library(

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,115 @@
#!/usr/bin/env python3
import sys
import os
import functools
# We only generate numbers for a dozen or so syscalls
SYSCALLS = [
'bpf',
'close_range',
'copy_file_range',
'getrandom',
'memfd_create',
'name_to_handle_at',
'pidfd_open',
'pidfd_send_signal',
'pkey_mprotect',
'renameat2',
'setns',
'statx']
def dictify(f):
def wrap(*args, **kwargs):
return dict(f(*args, **kwargs))
return functools.update_wrapper(wrap, f)
@dictify
def parse_syscall_table(filename):
print(f'Reading {filename}')
for line in open(filename):
items = line.split()
if len(items) >= 2:
yield items[0], int(items[1])
def parse_syscall_tables(filenames):
return {filename.split('-')[-1]: parse_syscall_table(filename)
for filename in filenames}
DEF_TEMPLATE = '''\
#ifndef __IGNORE_{syscall}
# if defined(__aarch64__)
# define systemd_NR_{syscall} {nr_arm64}
# elif defined(__alpha__)
# define systemd_NR_{syscall} {nr_alpha}
# elif defined(__arc__) || defined(__tilegx__)
# define systemd_NR_{syscall} {nr_arc}
# elif defined(__arm__)
# define systemd_NR_{syscall} {nr_arm}
# elif defined(__i386__)
# define systemd_NR_{syscall} {nr_i386}
# elif defined(__ia64__)
# define systemd_NR_{syscall} {nr_ia64}
# elif defined(__m68k__)
# define systemd_NR_{syscall} {nr_m68k}
# elif defined(_MIPS_SIM)
# if _MIPS_SIM == _MIPS_SIM_ABI32
# define systemd_NR_{syscall} {nr_mipso32}
# elif _MIPS_SIM == _MIPS_SIM_NABI32
# define systemd_NR_{syscall} {nr_mips64n32}
# elif _MIPS_SIM == _MIPS_SIM_ABI64
# define systemd_NR_{syscall} {nr_mips64}
# else
# error "Unknown MIPS ABI"
# endif
# elif defined(__powerpc__)
# define systemd_NR_{syscall} {nr_powerpc}
# elif defined(__s390__)
# define systemd_NR_{syscall} {nr_s390}
# elif defined(__sparc__)
# define systemd_NR_{syscall} {nr_sparc}
# elif defined(__x86_64__)
# if defined(__ILP32__)
# define systemd_NR_{syscall} ({nr_x86_64} | /* __X32_SYSCALL_BIT */ 0x40000000)
# else
# define systemd_NR_{syscall} {nr_x86_64}
# endif
# else
# warning "{syscall}() syscall number is unknown for your architecture"
# endif
/* may be (invalid) negative number due to libseccomp, see PR 13319 */
# if defined __NR_{syscall} && __NR_{syscall} >= 0
# if defined systemd_NR_{syscall}
assert_cc(__NR_{syscall} == systemd_NR_{syscall});
# endif
# else
# if defined __NR_{syscall}
# undef __NR_{syscall}
# endif
# if defined systemd_NR_{syscall} && systemd_NR_{syscall} >= 0
# define __NR_{syscall} systemd_NR_{syscall}
# endif
# endif
#endif
'''
def print_syscall_def(syscall, tables, out):
mappings = {f'nr_{arch}':t.get(syscall, -1)
for arch, t in tables.items()}
print(DEF_TEMPLATE.format(syscall=syscall, **mappings),
file=out)
def print_syscall_defs(syscalls, tables, out):
print('/* This file is generated. Do not edit! */\n', file=out)
for syscall in syscalls:
print_syscall_def(syscall, tables, out)
if __name__ == '__main__':
output_file = sys.argv[1]
arch_files = sys.argv[2:]
out = open(output_file, 'wt')
tables = parse_syscall_tables(arch_files)
print_syscall_defs(SYSCALLS, tables, out)
print(f'Wrote {output_file}')

View File

@@ -13,7 +13,6 @@ arc_settls
arc_usr_cmpxchg
arch_prctl
arm_fadvise64_64
arm_sync_file_range
atomic_barrier
atomic_cmpxchg_32
bdflush
@@ -60,6 +59,7 @@ epoll_create1
epoll_ctl
epoll_ctl_old
epoll_pwait
epoll_pwait2
epoll_wait
epoll_wait_old
eventfd
@@ -241,7 +241,6 @@ name_to_handle_at
nanosleep
newfstatat
nfsservctl
ni_syscall
nice
old_adjtimex
old_getpagesize
@@ -568,7 +567,6 @@ times
tkill
truncate
truncate64
udftrap
ugetrlimit
umask
umount
@@ -584,7 +582,6 @@ utime
utimensat
utimensat_time64
utimes
utimesat
utrap_install
vfork
vhangup

595
src/basic/syscalls-alpha Normal file

File diff suppressed because it is too large Load Diff

595
src/basic/syscalls-arc Normal file

File diff suppressed because it is too large Load Diff

595
src/basic/syscalls-arm Normal file

File diff suppressed because it is too large Load Diff

595
src/basic/syscalls-arm64 Normal file

File diff suppressed because it is too large Load Diff

595
src/basic/syscalls-i386 Normal file

File diff suppressed because it is too large Load Diff

595
src/basic/syscalls-ia64 Normal file

File diff suppressed because it is too large Load Diff

595
src/basic/syscalls-m68k Normal file

File diff suppressed because it is too large Load Diff

595
src/basic/syscalls-mips64 Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

595
src/basic/syscalls-mipso32 Normal file

File diff suppressed because it is too large Load Diff

595
src/basic/syscalls-powerpc Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

595
src/basic/syscalls-s390 Normal file

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More