From 69e542bd2d750b9ffa007767b2ea3b1c88028df5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20Wei=C3=9Fschuh?= Date: Fri, 5 May 2023 00:39:40 +0200 Subject: [PATCH] enosys: find syscalls at build time MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Weißschuh --- .github/workflows/cibuild-setup-ubuntu.sh | 1 + meson.build | 8 +++++++- misc-utils/Makemodule.am | 9 +++++++++ misc-utils/enosys.c | 8 ++++---- tools/Makemodule.am | 4 +++- tools/all_syscalls | 15 +++++++++++++++ 6 files changed, 39 insertions(+), 6 deletions(-) create mode 100755 tools/all_syscalls diff --git a/.github/workflows/cibuild-setup-ubuntu.sh b/.github/workflows/cibuild-setup-ubuntu.sh index 3ffa9fcb37..de9f8a85c5 100755 --- a/.github/workflows/cibuild-setup-ubuntu.sh +++ b/.github/workflows/cibuild-setup-ubuntu.sh @@ -27,6 +27,7 @@ PACKAGES=( iproute2 dmsetup python3-dev + gawk ) PACKAGES_OPTIONAL=( diff --git a/meson.build b/meson.build index 9449501e18..e1099cf547 100644 --- a/meson.build +++ b/meson.build @@ -2856,9 +2856,15 @@ if not is_disabler(exe) bashcompletions += ['waitpid'] endif +syscalls_h = custom_target('syscalls.h', + input : 'tools/all_syscalls', + output : 'syscalls.h', + command : ['bash', '@INPUT@', cc.cmd_array()], +) + exe = executable( 'enosys', - 'misc-utils/enosys.c', + 'misc-utils/enosys.c', syscalls_h, include_directories : includes, link_with : [lib_common], install_dir : usrbin_exec_dir, diff --git a/misc-utils/Makemodule.am b/misc-utils/Makemodule.am index 9c558994db..76fa9014ab 100644 --- a/misc-utils/Makemodule.am +++ b/misc-utils/Makemodule.am @@ -299,6 +299,15 @@ waitpid_CFLAGS = $(AM_CFLAGS) endif if BUILD_ENOSYS + +misc-utils/enosys.c: syscalls.h + +syscalls.h: $(top_srcdir)/tools/all_syscalls + $(top_srcdir)/tools/all_syscalls $(CC) $(CFLAGS) + +-include syscalls.h.deps +CLEANFILES += syscalls.h syscalls.h.deps + usrbin_exec_PROGRAMS += enosys MANPAGES += misc-utils/enosys.1 dist_noinst_DATA += misc-utils/enosys.1.adoc diff --git a/misc-utils/enosys.c b/misc-utils/enosys.c index 79f57b2553..6ea176a599 100644 --- a/misc-utils/enosys.c +++ b/misc-utils/enosys.c @@ -69,11 +69,11 @@ struct syscall { }; static const struct syscall syscalls[] = { - { "move_mount", __NR_move_mount }, - { "open_tree", __NR_open_tree }, - { "fsopen", __NR_fsopen }, - { "fallocate", __NR_fallocate }, +#define UL_SYSCALL(name, nr) { name, nr }, +#include "syscalls.h" +#undef UL_SYSCALL }; +static_assert(sizeof(syscalls) > 0, "no syscalls found"); static void __attribute__((__noreturn__)) usage(void) { diff --git a/tools/Makemodule.am b/tools/Makemodule.am index dbda625872..ebee6c334f 100644 --- a/tools/Makemodule.am +++ b/tools/Makemodule.am @@ -56,4 +56,6 @@ EXTRA_DIST += \ tools/config-gen.d/non-libmount.conf \ \ tools/asciidoctor-includetracker.rb \ - tools/asciidoctor-unicodeconverter.rb + tools/asciidoctor-unicodeconverter.rb \ + \ + tools/all_syscalls diff --git a/tools/all_syscalls b/tools/all_syscalls new file mode 100755 index 0000000000..9c147786cf --- /dev/null +++ b/tools/all_syscalls @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +OUTPUT=syscalls.h +SYSCALL_INCLUDES=" +#include +" + +trap 'rm $OUTPUT $OUTPUT.deps' ERR + +"$@" -MD -MF "$OUTPUT.deps" <<< "$SYSCALL_INCLUDES" -dM -E - \ + | gawk 'match($0, /^#define __NR_([^ ]+)/, res) { print "UL_SYSCALL(\"" res[1] "\", __NR_" res[1] ")" }' \ + | sort \ + > "$OUTPUT" -- 2.47.3