aboutgitcodelistschat:MatrixIRC
path: root/scripts/nr_syscalls.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/nr_syscalls.sh')
-rwxr-xr-xscripts/nr_syscalls.sh63
1 files changed, 63 insertions, 0 deletions
diff --git a/scripts/nr_syscalls.sh b/scripts/nr_syscalls.sh
new file mode 100755
index 0000000..380d6f1
--- /dev/null
+++ b/scripts/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="common/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}"