Skip to content

Commit cfce7b0

Browse files
xen0npcmoore
authored andcommitted
arch: unify handling of syscall.tbl in arch-syscall-validate
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]> Signed-off-by: Paul Moore <[email protected]>
1 parent 9c4eb5e commit cfce7b0

File tree

1 file changed

+47
-66
lines changed

1 file changed

+47
-66
lines changed

src/arch-syscall-validate

Lines changed: 47 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,31 @@ function mangle_lib_syscall() {
162162
sed $sed_filter | sed '/,-[0-9]\+$/d'
163163
}
164164

165+
#
166+
# Dump syscalls matching specified tags from the given syscall.tbl file
167+
#
168+
# Arguments:
169+
# 1 path to the syscall.tbl file to dump
170+
# (rest) tags to match (except "common" which is always included)
171+
#
172+
# Dump the matched syscall table entries to stdout.
173+
#
174+
function dump_from_syscall_tbl() {
175+
local file="$1"
176+
shift
177+
178+
local tag
179+
local tag_regexp='^(common'
180+
for tag in "$@"; do
181+
tag_regexp="${tag_regexp}|${tag}"
182+
done
183+
tag_regexp="${tag_regexp}) "
184+
185+
cat "$file" | grep -v '^#\|^$' | awk '{ print $2,$3,$1 }' | \
186+
grep -E "$tag_regexp" | awk '{ print $2","$3 }' | sort | \
187+
grep -Ev '^(reserved|unused)[0-9]+,'
188+
}
189+
165190
#
166191
# Dump the x86 system syscall table
167192
#
@@ -171,9 +196,7 @@ function mangle_lib_syscall() {
171196
# Dump the architecture's syscall table to stdout.
172197
#
173198
function dump_sys_x86() {
174-
cat $1/arch/x86/entry/syscalls/syscall_32.tbl | \
175-
grep -v "^#" | awk '{ print $3","$1 }' | \
176-
sort
199+
dump_from_syscall_tbl "$1/arch/x86/entry/syscalls/syscall_32.tbl" i386
177200
}
178201

179202
#
@@ -194,9 +217,7 @@ function dump_lib_x86() {
194217
# Dump the architecture's syscall table to stdout.
195218
#
196219
function dump_sys_x86_64() {
197-
cat $1/arch/x86/entry/syscalls/syscall_64.tbl | \
198-
grep -v "^#" | sed '/^$/d' | awk '{ print $2,$3,$1 }' | \
199-
sed '/^x32/d' | awk '{ print $2","$3 }' | sort
220+
dump_from_syscall_tbl "$1/arch/x86/entry/syscalls/syscall_64.tbl" 64
200221
}
201222

202223
#
@@ -217,9 +238,7 @@ function dump_lib_x86_64() {
217238
# Dump the architecture's syscall table to stdout.
218239
#
219240
function dump_sys_x32() {
220-
cat $1/arch/x86/entry/syscalls/syscall_64.tbl | \
221-
grep -v "^#" | sed '/^$/d' | awk '{ print $2,$3,$1 }' | \
222-
sed '/^64/d' | awk '{ print $2","$3 }' | sort
241+
dump_from_syscall_tbl "$1/arch/x86/entry/syscalls/syscall_64.tbl" x32
223242
}
224243

225244
#
@@ -240,14 +259,12 @@ function dump_lib_x32() {
240259
# Dump the architecture's syscall table to stdout.
241260
#
242261
function dump_sys_arm() {
243-
cat $1/arch/arm/tools/syscall.tbl | grep -v "^#" | \
244-
sed -n "/[0-9]\+[ \t]\+\(common\|eabi\)/p" | \
245-
awk '{ print $3","$1 }' | sort | (cat -; \
246-
(cat $1/arch/arm/include/uapi/asm/unistd.h | \
247-
grep "^#define __ARM_NR_" | \
248-
grep -v "^#define __ARM_NR_BASE" | \
249-
sed 's/#define __ARM_NR_\([a-z0-9_]*\)[ \t]\+(__ARM_NR_BASE+\(.*\))/\1 983040 + \2/' | \
250-
awk '{ print $1","$2+$4 }')) | sort
262+
dump_from_syscall_tbl "$1/arch/arm/tools/syscall.tbl" eabi | (cat -; \
263+
(cat $1/arch/arm/include/uapi/asm/unistd.h | \
264+
grep "^#define __ARM_NR_" | \
265+
grep -v "^#define __ARM_NR_BASE" | \
266+
sed 's/#define __ARM_NR_\([a-z0-9_]*\)[ \t]\+(__ARM_NR_BASE+\(.*\))/\1 983040 + \2/' | \
267+
awk '{ print $1","$2+$4 }')) | sort
251268
}
252269

253270
#
@@ -356,11 +373,7 @@ function dump_lib_loongarch64() {
356373
# Dump the architecture's syscall table to stdout.
357374
#
358375
function dump_sys_m68k() {
359-
cat $1/arch/m68k/kernel/syscalls/syscall.tbl | \
360-
grep -v "^#" | \
361-
sed -n "/[0-9]\+[ \t]\+\(common\)/p" | \
362-
awk '{ print $3","$1 }' | \
363-
sort
376+
dump_from_syscall_tbl "$1/arch/m68k/kernel/syscalls/syscall.tbl"
364377
}
365378

366379
#
@@ -381,11 +394,7 @@ function dump_lib_m68k() {
381394
# Dump the architecture's syscall table to stdout.
382395
#
383396
function dump_sys_mips() {
384-
cat $1/arch/mips/kernel/syscalls/syscall_o32.tbl | \
385-
grep -v "^#" | \
386-
sed -e '/[ \t]\+reserved[0-9]\+[ \t]\+/d;' | \
387-
sed -e '/[ \t]\+unused[0-9]\+[ \t]\+/d;' | \
388-
awk '{ print $3","$1 }' | sort
397+
dump_from_syscall_tbl "$1/arch/mips/kernel/syscalls/syscall_o32.tbl" o32
389398
}
390399

391400
#
@@ -406,11 +415,7 @@ function dump_lib_mips() {
406415
# Dump the architecture's syscall table to stdout.
407416
#
408417
function dump_sys_mips64() {
409-
cat $1/arch/mips/kernel/syscalls/syscall_n64.tbl | \
410-
grep -v "^#" | \
411-
sed -e '/[ \t]\+reserved[0-9]\+[ \t]\+/d;' | \
412-
sed -e '/[ \t]\+unused[0-9]\+[ \t]\+/d;' | \
413-
awk '{ print $3","$1 }' | sort
418+
dump_from_syscall_tbl "$1/arch/mips/kernel/syscalls/syscall_n64.tbl" n64
414419
}
415420

416421
#
@@ -431,11 +436,7 @@ function dump_lib_mips64() {
431436
# Dump the architecture's syscall table to stdout.
432437
#
433438
function dump_sys_mips64n32() {
434-
cat $1/arch/mips/kernel/syscalls/syscall_n32.tbl | \
435-
grep -v "^#" | \
436-
sed -e '/[ \t]\+reserved[0-9]\+[ \t]\+/d;' | \
437-
sed -e '/[ \t]\+unused[0-9]\+[ \t]\+/d;' | \
438-
awk '{ print $3","$1 }' | sort
439+
dump_from_syscall_tbl "$1/arch/mips/kernel/syscalls/syscall_n32.tbl" n32
439440
}
440441

441442
#
@@ -456,11 +457,7 @@ function dump_lib_mips64n32() {
456457
# Dump the architecture's syscall table to stdout.
457458
#
458459
function dump_sys_parisc() {
459-
cat $1/arch/parisc/kernel/syscalls/syscall.tbl | \
460-
grep -v "^#" | \
461-
sed -n "/[0-9]\+[ \t]\+\(common\|32\)/p" | \
462-
awk '{ print $3","$1 }' | \
463-
sort
460+
dump_from_syscall_tbl "$1/arch/parisc/kernel/syscalls/syscall.tbl" 32
464461
}
465462

466463
#
@@ -481,11 +478,7 @@ function dump_lib_parisc() {
481478
# Dump the architecture's syscall table to stdout.
482479
#
483480
function dump_sys_parisc64() {
484-
cat $1/arch/parisc/kernel/syscalls/syscall.tbl | \
485-
grep -v "^#" | \
486-
sed -n "/[0-9]\+[ \t]\+\(common\|64\)/p" | \
487-
awk '{ print $3","$1 }' | \
488-
sort
481+
dump_from_syscall_tbl "$1/arch/parisc/kernel/syscalls/syscall.tbl" 64
489482
}
490483

491484
#
@@ -506,9 +499,8 @@ function dump_lib_parisc64() {
506499
# Dump the architecture's syscall table to stdout.
507500
#
508501
function dump_sys_ppc() {
509-
cat $1/arch/powerpc/kernel/syscalls/syscall.tbl | grep -v "^#" | \
510-
sed -ne "/[0-9]\+[ \t]\+\(common\|nospu\|32\)/p" | \
511-
awk '{ print $3","$1 }' | sort
502+
dump_from_syscall_tbl "$1/arch/powerpc/kernel/syscalls/syscall.tbl" \
503+
nospu 32
512504
}
513505

514506
#
@@ -529,9 +521,8 @@ function dump_lib_ppc() {
529521
# Dump the architecture's syscall table to stdout.
530522
#
531523
function dump_sys_ppc64() {
532-
cat $1/arch/powerpc/kernel/syscalls/syscall.tbl | grep -v "^#" | \
533-
sed -ne "/[0-9]\+[ \t]\+\(common\|nospu\|64\)/p" | \
534-
awk '{ print $3","$1 }' | sort
524+
dump_from_syscall_tbl "$1/arch/powerpc/kernel/syscalls/syscall.tbl" \
525+
nospu 64
535526
}
536527

537528
#
@@ -595,10 +586,7 @@ function dump_lib_riscv64() {
595586
# Dump the architecture's syscall table to stdout.
596587
#
597588
function dump_sys_s390() {
598-
cat $1/arch/s390/kernel/syscalls/syscall.tbl | grep -v "^#" | \
599-
sed -ne "/[0-9]\+[ \t]\+\(common\|32\)/p" | \
600-
awk '{ print $3","$1 }' | \
601-
sort
589+
dump_from_syscall_tbl "$1/arch/s390/kernel/syscalls/syscall.tbl" 32
602590
}
603591

604592
#
@@ -619,10 +607,7 @@ function dump_lib_s390() {
619607
# Dump the architecture's syscall table to stdout.
620608
#
621609
function dump_sys_s390x() {
622-
cat $1/arch/s390/kernel/syscalls/syscall.tbl | grep -v "^#" | \
623-
sed -ne "/[0-9]\+[ \t]\+\(common\|64\)/p" | \
624-
awk '{ print $3","$1 }' | \
625-
sort
610+
dump_from_syscall_tbl "$1/arch/s390/kernel/syscalls/syscall.tbl" 64
626611
}
627612

628613
#
@@ -643,11 +628,7 @@ function dump_lib_s390x() {
643628
# Dump the architecture's syscall table to stdout.
644629
#
645630
function dump_sys_sh() {
646-
cat $1/arch/sh/kernel/syscalls/syscall.tbl | \
647-
grep -v "^#" | \
648-
sed -n "/[0-9]\+[ \t]\+\(common\)/p" | \
649-
awk '{ print $3","$1 }' | \
650-
sort
631+
dump_from_syscall_tbl "$1/arch/sh/kernel/syscalls/syscall.tbl"
651632
}
652633

653634
#

0 commit comments

Comments
 (0)