| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | |
| 3 | # NOTE: changes to the arch_syscall_table struct in syscalls.h will affect |
| 4 | # this script/gperf - BEWARE! |
| 5 | |
| 6 | ### |
| 7 | # helper functions |
| 8 | |
| 9 | function exit_usagescip-shell shell libseccomp 2.6.0-2 exit_usage().() { |
| 10 | echoscip-shell system . . echo. "usage: $0 <syscall_csv_file> <gperf_template>" |
| 11 | exit 1 |
| 12 | } |
| 13 | |
| 14 | ### |
| 15 | # main |
| 16 | |
| 17 | # sanity check |
| 18 | [[ ! -r "$1" || ! -r "$2" ]] && exit_usagescip-shell shell libseccomp 2.6.0-2 exit_usage(). |
| 19 | sys_csv=$1 |
| 20 | gperf_tmpl=$2 |
| 21 | |
| 22 | sys_csv_tmp=$(mktempscip-shell system . . mktemp. -t generate_syscalls_XXXXXX) |
| 23 | |
| 24 | # filter and prepare the syscall csv file |
| 25 | catscip-shell system . . cat. $sys_csv | grepscip-shell system . . grep. -v '^#' | nlscip-shell system . . nl. -ba -s, -v0 | \ |
| 26 | sed -e '{s|^[[:space:]]\+\([0-9]\+\),\([^,]\+\),\(.*\)|\2,\1,\3|;};' \ |
| 27 | -e '{:r1; {s|\([^,]\+\)\(.*\)[^_]PNR|\1\2,__PNR_\1|g;}; t r1;};' \ |
| 28 | -e '{s|,KV_|,SCMP_KV_|g;};' \ |
| 29 | > $sys_csv_tmp |
| 30 | [[ $? -ne 0 ]] && exit 1 |
| 31 | |
| 32 | # create the gperf file |
| 33 | sedscip-shell system . . sed. -e "/@@SYSCALLS_TABLE@@/r $sys_csv_tmp" \ |
| 34 | -e '/@@SYSCALLS_TABLE@@/dscip-shell filesystem . . `/@@SYSCALLS_TABLE@@/d`.' \ |
| 35 | $gperf_tmpl > syscalls.perf |
| 36 | [[ $? -ne 0 ]] && exit 1 |
| 37 | |
| 38 | # cleanup |
| 39 | rmscip-shell system . . rm. -f $sys_csv_tmp |
| 40 | |
| 41 | exit 0 |