aboutgitcodelistschat:MatrixIRC
path: root/scripts/nr_syscalls.sh
blob: c154afa115442e60d017682d40c873658b1f3f98 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12

             
                                           








                                                                              
                              















                                                                               




















                   


                                                                       
                                                                                                                       








                                                                            
#!/bin/sh -eu
#
# SPDX-License-Identifier: GPL-2.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="$(for c in ${syscalls}; do printf "#include <asm-generic/unistd.h>\n#include <sys/syscall.h>\n__NR_%s" $c; done)"
__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}"