Skip to content

Commit

Permalink
arch: unify handling of syscall.tbl in arch-syscall-validate
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
xen0n committed Aug 20, 2024
1 parent c92d618 commit af3e1c9
Showing 1 changed file with 47 additions and 66 deletions.
113 changes: 47 additions & 66 deletions src/arch-syscall-validate
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,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
#
Expand All @@ -171,9 +196,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
}

#
Expand All @@ -194,9 +217,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
}

#
Expand All @@ -217,9 +238,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
}

#
Expand All @@ -240,14 +259,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
}

#
Expand Down Expand Up @@ -356,11 +373,7 @@ function dump_lib_loongarch64() {
# Dump the architecture's syscall table to stdout.
#
function dump_sys_m68k() {
cat $1/arch/m68k/kernel/syscalls/syscall.tbl | \
grep -v "^#" | \
sed -n "/[0-9]\+[ \t]\+\(common\)/p" | \
awk '{ print $3","$1 }' | \
sort
dump_from_syscall_tbl "$1/arch/m68k/kernel/syscalls/syscall.tbl"
}

#
Expand All @@ -381,11 +394,7 @@ function dump_lib_m68k() {
# 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
}

#
Expand All @@ -406,11 +415,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
}

#
Expand All @@ -431,11 +436,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
}

#
Expand All @@ -456,11 +457,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
}

#
Expand All @@ -481,11 +478,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
}

#
Expand All @@ -506,9 +499,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
}

#
Expand All @@ -529,9 +521,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
}

#
Expand Down Expand Up @@ -595,10 +586,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
}

#
Expand All @@ -619,10 +607,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
}

#
Expand All @@ -643,11 +628,7 @@ function dump_lib_s390x() {
# Dump the architecture's syscall table to stdout.
#
function dump_sys_sh() {
cat $1/arch/sh/kernel/syscalls/syscall.tbl | \
grep -v "^#" | \
sed -n "/[0-9]\+[ \t]\+\(common\)/p" | \
awk '{ print $3","$1 }' | \
sort
dump_from_syscall_tbl "$1/arch/sh/kernel/syscalls/syscall.tbl"
}

#
Expand Down

0 comments on commit af3e1c9

Please sign in to comment.