[PATCH v4 10/12] syscalls: Add an option for offsetting the common table
From: André Almeida
Date: Tue Aug 11 2026 - 23:38:37 EST
To better support architectures that doesn't share the same syscall
numbers, but have them in the same sequence, add an new option to offset
the common syscall table numbers by a value. This make it possible to reuse
the common syscall table for alpha.
Signed-off-by: André Almeida <andrealmeid@xxxxxxxxxx>
---
scripts/syscallhdr.sh | 21 ++++++++++++++-------
scripts/syscalltbl.sh | 17 ++++++++++++++---
2 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/scripts/syscallhdr.sh b/scripts/syscallhdr.sh
index 54e09d3e686c..0e095dac9db2 100755
--- a/scripts/syscallhdr.sh
+++ b/scripts/syscallhdr.sh
@@ -16,17 +16,18 @@
set -e
usage() {
- echo >&2 "usage: $0 [--abis ABIS] [--emit-nr] [--offset OFFSET] [--prefix PREFIX] [--common-tbl PATH] INFILE OUTFILE" >&2
+ echo >&2 "usage: $0 [--abis ABIS] [--emit-nr] [--offset OFFSET] [--prefix PREFIX] [--common-tbl PATH] [--common-offset OFFSET] INFILE OUTFILE" >&2
echo >&2
echo >&2 " INFILE input syscall table"
echo >&2 " OUTFILE output header file"
echo >&2
echo >&2 "options:"
- echo >&2 " --abis ABIS ABI(s) to handle (By default, all lines are handled)"
- echo >&2 " --emit-nr Emit the macro of the number of syscalls (__NR_syscalls)"
- echo >&2 " --offset OFFSET The offset of syscall numbers"
- echo >&2 " --prefix PREFIX The prefix to the macro like __NR_<PREFIX><NAME>"
- echo >&2 " --common-tbl PATH Use the common number table"
+ echo >&2 " --abis ABIS ABI(s) to handle (By default, all lines are handled)"
+ echo >&2 " --emit-nr Emit the macro of the number of syscalls (__NR_syscalls)"
+ echo >&2 " --offset OFFSET The offset of syscall numbers"
+ echo >&2 " --prefix PREFIX The prefix to the macro like __NR_<PREFIX><NAME>"
+ echo >&2 " --common-tbl PATH Use the common number table"
+ echo >&2 " --common-offset OFFSET Apply an offset for the numbers of the common table"
exit 1
}
@@ -34,6 +35,7 @@ usage() {
abis=
emit_nr=
offset=
+common_offset=
prefix=
common_tbl=
common_tbl_path=
@@ -57,6 +59,9 @@ do
common_tbl=1
common_tbl_path=$2
shift 2;;
+ --common-offset)
+ common_offset=$2
+ shift 2;;
-*)
echo "$1: unknown option" >&2
usage;;
@@ -107,7 +112,7 @@ gen_hdr() {
max=$nr
if [ -n "$offset" ]; then
- nr="($offset + $nr)"
+ nr=$((nr + offset))
fi
echo "#define __NR_$prefix$name $nr"
@@ -120,7 +125,9 @@ emit_start_guard > $outfile
gen_hdr $infile >> $outfile
if [ -n "$common_tbl" ]; then
+ offset=$common_offset
gen_hdr $common_tbl_path >> "$outfile"
+ unset offset
fi
if [ -n "$emit_nr" ]; then
diff --git a/scripts/syscalltbl.sh b/scripts/syscalltbl.sh
index 91c135143b22..c00f848b5b66 100755
--- a/scripts/syscalltbl.sh
+++ b/scripts/syscalltbl.sh
@@ -16,14 +16,15 @@
set -e
usage() {
- echo >&2 "usage: $0 [--abis ABIS] [--common-tbl PATH] INFILE OUTFILE" >&2
+ echo >&2 "usage: $0 [--abis ABIS] [--common-tbl PATH] [--common-offset OFFSET] INFILE OUTFILE" >&2
echo >&2
echo >&2 " INFILE input syscall table"
echo >&2 " OUTFILE output header file"
echo >&2
echo >&2 "options:"
- echo >&2 " --abis ABIS ABI(s) to handle (By default, all lines are handled)"
- echo >&2 " --common-tbl PATH Use the common syscall number table"
+ echo >&2 " --abis ABIS ABI(s) to handle (By default, all lines are handled)"
+ echo >&2 " --common-tbl PATH Use the common syscall number table"
+ echo >&2 " --common-offset OFFSET Apply an offset for the numbers of the common table"
exit 1
}
@@ -31,6 +32,7 @@ usage() {
abis=
common_tbl=
common_tbl_path=
+common_offset=
while [ $# -gt 0 ]
do
@@ -42,6 +44,9 @@ do
common_tbl=1
common_tbl_path=$2
shift 2;;
+ --common-offset)
+ common_offset=$2
+ shift 2;;
-*)
echo "$1: unknown option" >&2
usage;;
@@ -65,6 +70,10 @@ gen_tbl() {
while read nr abi name native compat noreturn; do
+ if [ -n "$offset" ]; then
+ nr=$((nr + offset))
+ fi
+
if [ $nxt -gt $nr ]; then
echo "error: $input: syscall table is not sorted or duplicates the same syscall number" >&2
exit 1
@@ -105,5 +114,7 @@ gen_tbl() {
gen_tbl $infile > "$outfile"
if [ -n "$common_tbl" ]; then
+ offset=$common_offset
gen_tbl $common_tbl_path >> "$outfile"
+ unset offset
fi
--
2.55.0