[PATCH] arch: unify handling of syscall.tbl in arch-syscall-validate
authorWANG Xuerui <git@xen0n.name>
Tue, 20 Aug 2024 04:05:46 +0000 (12:05 +0800)
committerFelix Geyer <fgeyer@debian.org>
Sun, 24 Nov 2024 20:54:16 +0000 (21:54 +0100)
Apart from de-duplication of logic, this refactor is also going to help
syncing to the Linux 6.11+ definitions, where all architectures are
converted to source their syscall definitions from syscall.tbl files.

The change is tested on Linux 6.2 sources to not affect the generated
syscalls.csv apart from timestamp changes.

Signed-off-by: WANG Xuerui <git@xen0n.name>
Signed-off-by: Paul Moore <paul@paul-moore.com>
Gbp-Pq: Name arch_unify_handling_of_syscall.tbl_in_arch-syscall-validate.patch

src/arch-syscall-validate

index efbf2216644578965328b3478ff9515da43c58e2..d9ee6f9e355f945d41fa0dfe43ad6bb0d874d43c 100755 (executable)
@@ -161,6 +161,31 @@ function mangle_lib_syscall() {
        sed $sed_filter | sed '/,-[0-9]\+$/d'
 }
 
+#
+# Dump syscalls matching specified tags from the given syscall.tbl file
+#
+# Arguments:
+#     1        path to the syscall.tbl file to dump
+#     (rest)   tags to match (except "common" which is always included)
+#
+#  Dump the matched syscall table entries to stdout.
+#
+function dump_from_syscall_tbl() {
+       local file="$1"
+       shift
+
+       local tag
+       local tag_regexp='^(common'
+       for tag in "$@"; do
+               tag_regexp="${tag_regexp}|${tag}"
+       done
+       tag_regexp="${tag_regexp}) "
+
+       cat "$file" | grep -v '^#\|^$' | awk '{ print $2,$3,$1 }' | \
+               grep -E "$tag_regexp" | awk '{ print $2","$3 }' | sort | \
+               grep -Ev '^(reserved|unused)[0-9]+,'
+}
+
 #
 # Dump the x86 system syscall table
 #
@@ -170,9 +195,7 @@ function mangle_lib_syscall() {
 #  Dump the architecture's syscall table to stdout.
 #
 function dump_sys_x86() {
-       cat $1/arch/x86/entry/syscalls/syscall_32.tbl | \
-               grep -v "^#" | awk '{ print $3","$1 }' | \
-               sort
+       dump_from_syscall_tbl "$1/arch/x86/entry/syscalls/syscall_32.tbl" i386
 }
 
 #
@@ -193,9 +216,7 @@ function dump_lib_x86() {
 #  Dump the architecture's syscall table to stdout.
 #
 function dump_sys_x86_64() {
-       cat $1/arch/x86/entry/syscalls/syscall_64.tbl | \
-               grep -v "^#" | sed '/^$/d' | awk '{ print $2,$3,$1 }' | \
-               sed '/^x32/d' | awk '{ print $2","$3 }' | sort
+       dump_from_syscall_tbl "$1/arch/x86/entry/syscalls/syscall_64.tbl" 64
 }
 
 #
@@ -216,9 +237,7 @@ function dump_lib_x86_64() {
 #  Dump the architecture's syscall table to stdout.
 #
 function dump_sys_x32() {
-       cat $1/arch/x86/entry/syscalls/syscall_64.tbl | \
-               grep -v "^#" | sed '/^$/d' | awk '{ print $2,$3,$1 }' | \
-               sed '/^64/d' | awk '{ print $2","$3 }' | sort
+       dump_from_syscall_tbl "$1/arch/x86/entry/syscalls/syscall_64.tbl" x32
 }
 
 #
@@ -239,14 +258,12 @@ function dump_lib_x32() {
 #  Dump the architecture's syscall table to stdout.
 #
 function dump_sys_arm() {
-       cat $1/arch/arm/tools/syscall.tbl | grep -v "^#" | \
-               sed -n "/[0-9]\+[ \t]\+\(common\|eabi\)/p" | \
-               awk '{ print $3","$1 }' | sort | (cat -; \
-                       (cat $1/arch/arm/include/uapi/asm/unistd.h | \
-                       grep "^#define __ARM_NR_" | \
-                       grep -v "^#define __ARM_NR_BASE" | \
-                       sed 's/#define __ARM_NR_\([a-z0-9_]*\)[ \t]\+(__ARM_NR_BASE+\(.*\))/\1 983040 + \2/' | \
-                       awk '{ print $1","$2+$4 }')) | sort
+       dump_from_syscall_tbl "$1/arch/arm/tools/syscall.tbl" eabi | (cat -; \
+               (cat $1/arch/arm/include/uapi/asm/unistd.h | \
+               grep "^#define __ARM_NR_" | \
+               grep -v "^#define __ARM_NR_BASE" | \
+               sed 's/#define __ARM_NR_\([a-z0-9_]*\)[ \t]\+(__ARM_NR_BASE+\(.*\))/\1 983040 + \2/' | \
+               awk '{ print $1","$2+$4 }')) | sort
 }
 
 #
@@ -356,11 +373,7 @@ function dump_lib_loongarch64() {
 #  Dump the architecture's syscall table to stdout.
 #
 function dump_sys_mips() {
-       cat $1/arch/mips/kernel/syscalls/syscall_o32.tbl | \
-               grep -v "^#" | \
-               sed -e '/[ \t]\+reserved[0-9]\+[ \t]\+/d;' | \
-               sed -e '/[ \t]\+unused[0-9]\+[ \t]\+/d;' | \
-               awk '{ print $3","$1 }' | sort
+       dump_from_syscall_tbl "$1/arch/mips/kernel/syscalls/syscall_o32.tbl" o32
 }
 
 #
@@ -381,11 +394,7 @@ function dump_lib_mips() {
 #  Dump the architecture's syscall table to stdout.
 #
 function dump_sys_mips64() {
-       cat $1/arch/mips/kernel/syscalls/syscall_n64.tbl | \
-               grep -v "^#" | \
-               sed -e '/[ \t]\+reserved[0-9]\+[ \t]\+/d;' | \
-               sed -e '/[ \t]\+unused[0-9]\+[ \t]\+/d;' | \
-               awk '{ print $3","$1 }' | sort
+       dump_from_syscall_tbl "$1/arch/mips/kernel/syscalls/syscall_n64.tbl" n64
 }
 
 #
@@ -406,11 +415,7 @@ function dump_lib_mips64() {
 #  Dump the architecture's syscall table to stdout.
 #
 function dump_sys_mips64n32() {
-       cat $1/arch/mips/kernel/syscalls/syscall_n32.tbl | \
-               grep -v "^#" | \
-               sed -e '/[ \t]\+reserved[0-9]\+[ \t]\+/d;' | \
-               sed -e '/[ \t]\+unused[0-9]\+[ \t]\+/d;' | \
-               awk '{ print $3","$1 }' | sort
+       dump_from_syscall_tbl "$1/arch/mips/kernel/syscalls/syscall_n32.tbl" n32
 }
 
 #
@@ -431,11 +436,7 @@ function dump_lib_mips64n32() {
 #  Dump the architecture's syscall table to stdout.
 #
 function dump_sys_parisc() {
-       cat $1/arch/parisc/kernel/syscalls/syscall.tbl | \
-               grep -v "^#" | \
-               sed -n "/[0-9]\+[ \t]\+\(common\|32\)/p" | \
-               awk '{ print $3","$1 }' | \
-               sort
+       dump_from_syscall_tbl "$1/arch/parisc/kernel/syscalls/syscall.tbl" 32
 }
 
 #
@@ -456,11 +457,7 @@ function dump_lib_parisc() {
 #  Dump the architecture's syscall table to stdout.
 #
 function dump_sys_parisc64() {
-       cat $1/arch/parisc/kernel/syscalls/syscall.tbl | \
-               grep -v "^#" | \
-               sed -n "/[0-9]\+[ \t]\+\(common\|64\)/p" | \
-               awk '{ print $3","$1 }' | \
-               sort
+       dump_from_syscall_tbl "$1/arch/parisc/kernel/syscalls/syscall.tbl" 64
 }
 
 #
@@ -481,9 +478,8 @@ function dump_lib_parisc64() {
 #  Dump the architecture's syscall table to stdout.
 #
 function dump_sys_ppc() {
-       cat $1/arch/powerpc/kernel/syscalls/syscall.tbl | grep -v "^#" | \
-               sed -ne "/[0-9]\+[ \t]\+\(common\|nospu\|32\)/p" | \
-               awk '{ print $3","$1 }' | sort
+       dump_from_syscall_tbl "$1/arch/powerpc/kernel/syscalls/syscall.tbl" \
+               nospu 32
 }
 
 #
@@ -504,9 +500,8 @@ function dump_lib_ppc() {
 #  Dump the architecture's syscall table to stdout.
 #
 function dump_sys_ppc64() {
-       cat $1/arch/powerpc/kernel/syscalls/syscall.tbl | grep -v "^#" | \
-               sed -ne "/[0-9]\+[ \t]\+\(common\|nospu\|64\)/p" | \
-               awk '{ print $3","$1 }' | sort
+       dump_from_syscall_tbl "$1/arch/powerpc/kernel/syscalls/syscall.tbl" \
+               nospu 64
 }
 
 #
@@ -570,10 +565,7 @@ function dump_lib_riscv64() {
 #  Dump the architecture's syscall table to stdout.
 #
 function dump_sys_s390() {
-       cat $1/arch/s390/kernel/syscalls/syscall.tbl | grep -v "^#" | \
-               sed -ne "/[0-9]\+[ \t]\+\(common\|32\)/p" | \
-               awk '{ print $3","$1 }' | \
-               sort
+       dump_from_syscall_tbl "$1/arch/s390/kernel/syscalls/syscall.tbl" 32
 }
 
 #
@@ -594,10 +586,7 @@ function dump_lib_s390() {
 #  Dump the architecture's syscall table to stdout.
 #
 function dump_sys_s390x() {
-       cat $1/arch/s390/kernel/syscalls/syscall.tbl | grep -v "^#" | \
-               sed -ne "/[0-9]\+[ \t]\+\(common\|64\)/p" | \
-               awk '{ print $3","$1 }' | \
-               sort
+       dump_from_syscall_tbl "$1/arch/s390/kernel/syscalls/syscall.tbl" 64
 }
 
 #