Debian Codegraph @

src/arch-gperf-generate

raw
1 #!/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_usage() {
10 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_usage
19 sys_csv=$1
20 gperf_tmpl=$2
21
22 sys_csv_tmp=$(mktemp -t generate_syscalls_XXXXXX)
23
24 # filter and prepare the syscall csv file
25 cat $sys_csv | grep -v '^#' | 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 sed -e "/@@SYSCALLS_TABLE@@/r $sys_csv_tmp" \
34 -e '/@@SYSCALLS_TABLE@@/d' \
35 $gperf_tmpl > syscalls.perf
36 [[ $? -ne 0 ]] && exit 1
37
38 # cleanup
39 rm -f $sys_csv_tmp
40
41 exit 0