aboutgitcodelistschat:MatrixIRC
path: root/nr_syscalls.sh
diff options
context:
space:
mode:
authorAlice Frosi <afrosi@redhat.com>2022-12-21 11:06:37 +0100
committerAlice Frosi <afrosi@redhat.com>2022-12-21 14:46:41 +0100
commit49d2d37856368fe6bae685bdbb13029ad4803762 (patch)
treedbace69cba0765f6304df2a66f7f338d1b8a9538 /nr_syscalls.sh
parentd2d05a79e959f54c98e901d08a7ab0ae37d09c23 (diff)
downloadseitan-49d2d37856368fe6bae685bdbb13029ad4803762.tar
seitan-49d2d37856368fe6bae685bdbb13029ad4803762.tar.gz
seitan-49d2d37856368fe6bae685bdbb13029ad4803762.tar.bz2
seitan-49d2d37856368fe6bae685bdbb13029ad4803762.tar.lz
seitan-49d2d37856368fe6bae685bdbb13029ad4803762.tar.xz
seitan-49d2d37856368fe6bae685bdbb13029ad4803762.tar.zst
seitan-49d2d37856368fe6bae685bdbb13029ad4803762.zip
Generate syscalls numbers with nr_syscalls.sh
Refactor filter.sh script by: * renaming the filter.sh to nr_syscalls.sh * removing the BPF filter generation * simplifying the syscall number and header generation Signed-off-by: Alice Frosi <afrosi@redhat.com>
Diffstat (limited to 'nr_syscalls.sh')
-rwxr-xr-xnr_syscalls.sh63
1 files changed, 63 insertions, 0 deletions
diff --git a/nr_syscalls.sh b/nr_syscalls.sh
new file mode 100755
index 0000000..9ad3d19
--- /dev/null
+++ b/nr_syscalls.sh
@@ -0,0 +1,63 @@
+#!/bin/sh -eu
+#
+# SPDX-License-Identifier: AGPL-3.0-or-later
+#
+# SEITAN - Syscall Expressive Interpreter, Transformer and Notifier
+#
+# filter.sh - Build binary-search tree BPF program with SECCOMP_RET_USER_NOTIF
+#
+# Copyright (c) 2022 Red Hat GmbH
+# Author: Stefano Brivio <sbrivio@redhat.com>
+
+IN="${@}"
+OUT_NUMBERS="numbers.h"
+
+HEADER_NUMBERS="/* This file was automatically generated by $(basename ${0}) */
+#ifndef NUMBERS_H_
+#define NUMBERS_H_
+
+struct syscall_numbers {
+ char name[1024];
+ long number;
+};
+
+struct syscall_numbers numbers[] = {"
+
+FOOTER_NUMBERS="};
+
+#endif"
+
+syscalls=(
+ "accept"
+ "bind"
+ "connect"
+ "getpeername"
+ "getsockname"
+ "getsockopt"
+ "listen"
+ "mount"
+ "openat"
+ "recvfrom"
+ "recvmmsg"
+ "recvmsg"
+ "sendmmsg"
+ "sendmsg"
+ "sendto"
+ "setsockopt"
+ "shutdown"
+ "socket"
+ "socketpair"
+)
+
+printf '%s\n' "${HEADER_NUMBERS}" > "${OUT_NUMBERS}"
+# syscall_nr - Get syscall number from compiler, also note in numbers.h
+__in="$(printf "#include <asm-generic/unistd.h>\n#include <sys/syscall.h>\n__NR_%s" ${syscalls[@]})"
+__out="$(echo "${__in}" |cc -E -xc - -o - |sed -n '/\#.*$/!p'| sed '/^$/d')"
+
+awk -v AS="${syscalls[*]}" -v BS="${__out[*]}" \
+'BEGIN { MAX=split(AS,a, / /); split(BS,b, / /);
+for (x = 1; x <= MAX; x++)
+ { printf "\t{\"%s\",\t%d},\n", a[x], b[x] }
+ }' >> "${OUT_NUMBERS}"
+
+printf '%s\n' "${FOOTER_NUMBERS}" >> "${OUT_NUMBERS}"