diff options
author | Florian Weimer <fweimer@redhat.com> | 2020-01-02 10:18:10 +0100 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2020-01-02 10:18:10 +0100 |
commit | 4cf0d223052dabb9caed29e1e91e1d61933e14fb (patch) | |
tree | 67679008431b6bc21bb6f7a5efd5f2071f9a76f1 /sysdeps/unix/sysv/linux/tst-glibcsyscalls.py | |
parent | 5f72f9800b250410cad3abfeeb09469ef12b2438 (diff) | |
download | glibc-4cf0d223052dabb9caed29e1e91e1d61933e14fb.tar glibc-4cf0d223052dabb9caed29e1e91e1d61933e14fb.tar.gz glibc-4cf0d223052dabb9caed29e1e91e1d61933e14fb.tar.bz2 glibc-4cf0d223052dabb9caed29e1e91e1d61933e14fb.zip |
Linux: Add tables with system call numbers
The new tables are currently only used for consistency checks
with the installed kernel headers and the architecture-independent
system call names table. They are based on Linux 5.4.
The goal is to use these architecture-specific tables to ensure
that system call wrappers are available irrespective of the version
of the installed kernel headers.
The tables are formatted in the form of C header files so that they
can be used directly in an #include directive, without external
preprocessing. (External preprocessing of a plain table file
would introduce cross-subdirectory dependency issues.) However,
the intent is that they can still be treated as tables and can be
processed by simple tools.
The irregular system call names on 32-bit arm add a complication.
The <fixup-asm-unistd.h> header is introduced to work around that,
and the system calls are listed under regular names in the
<arch-syscall.h> file.
A make target, update-syscalls-list, is added to patch the glibc
sources with data from the current kernel headers.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Diffstat (limited to 'sysdeps/unix/sysv/linux/tst-glibcsyscalls.py')
-rw-r--r-- | sysdeps/unix/sysv/linux/tst-glibcsyscalls.py | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/sysdeps/unix/sysv/linux/tst-glibcsyscalls.py b/sysdeps/unix/sysv/linux/tst-glibcsyscalls.py new file mode 100644 index 0000000000..b5b03cebc1 --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-glibcsyscalls.py @@ -0,0 +1,88 @@ +#!/usr/bin/python3 +# Consistency checks for glibc system call lists. +# Copyright (C) 2020 Free Software Foundation, Inc. +# This file is part of the GNU C Library. +# +# The GNU C Library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# The GNU C Library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with the GNU C Library; if not, see +# <http://www.gnu.org/licenses/>. + +import argparse +import sys + +import glibcextract +import glibcsyscalls + +def main(): + """The main entry point.""" + parser = argparse.ArgumentParser( + description="System call list consistency checks") + parser.add_argument('--cc', metavar='CC', required=True, + help='C compiler (including options) to use') + parser.add_argument('syscall_numbers_list', metavar='PATH', + help='Path to the list of system call numbers') + parser.add_argument('syscall_names_list', metavar='PATH', + help='Path to the list of system call names') + + args = parser.parse_args() + + glibc_constants = glibcsyscalls.load_arch_syscall_header( + args.syscall_numbers_list) + with open(args.syscall_names_list) as inp: + glibc_names = glibcsyscalls.SyscallNamesList(inp) + kernel_constants = glibcsyscalls.kernel_constants(args.cc) + kernel_version = glibcsyscalls.linux_kernel_version(args.cc) + + errors = 0 + warnings = False + for name in glibc_constants.keys() & kernel_constants.keys(): + if glibc_constants[name] != kernel_constants[name]: + print("error: syscall {!r} number mismatch: glibc={!r} kernel={!r}" + .format(name, glibc_constants[name], kernel_constants[name])) + errors = 1 + + # The architecture-specific list in the glibc tree must be a + # subset of the global list of system call names. + for name in glibc_constants.keys() - set(glibc_names.syscalls): + print("error: architecture syscall {!r} missing from global names list" + .format(name)) + errors = 1 + + for name in glibc_constants.keys() - kernel_constants.keys(): + print("info: glibc syscall {!r} not known to kernel".format(name)) + warnings = True + + # If the glibc-recorded kernel version is not older than the + # installed kernel headers, the glibc system call set must be a + # superset of the kernel system call set. + if glibc_names.kernel_version >= kernel_version: + for name in kernel_constants.keys() - glibc_constants.keys(): + print("error: kernel syscall {!r} ({}) not known to glibc" + .format(name, kernel_constants[name])) + errors = 1 + else: + for name in kernel_constants.keys() - glibc_constants.keys(): + print("warning: kernel syscall {!r} ({}) not known to glibc" + .format(name, kernel_constants[name])) + warnings = True + + if errors > 0 or warnings: + print("info: glibc tables are based on kernel version {}".format( + ".".join(map(str, glibc_names.kernel_version)))) + print("info: installed kernel headers are version {}".format( + ".".join(map(str, kernel_version)))) + + sys.exit(errors) + +if __name__ == '__main__': + main() |