1 #!/bin/sh 2 # syscall reporting example for seccomp 3 # 4 # Copyright (c) 2012 The Chromium OS Authors <chromium-os-dev@chromium.org> 5 # Authors: 6 # Kees Cook <keescook@chromium.org> 7 # 8 # Use of this source code is governed by a BSD-style license that can be 9 # found in the LICENSE file. 10 11 CC=$1 12 [ -n "$TARGET_CC_NOCACHE" ] && CC=$TARGET_CC_NOCACHE 13 14 echo "#include <asm/unistd.h>" 15 16 # for loongarch __NR3264_* macros 17 echo "#include <sys/syscall.h>" | ${CC} -E -dM - | grep '^#define __NR3264_[a-z0-9_]\+[ \t].*[0-9].*$' 18 19 echo "static const char *__syscall_names[] = {" 20 echo "#include <sys/syscall.h>" | ${CC} -E -dM - | grep '^#define __NR_[a-z0-9_]\+[ \t].*[0-9].*$' | \ 21 LC_ALL=C sed -r -n -e 's/^\#define[ \t]+__NR_([a-z0-9_]+)[ \t]+([ ()+0-9a-zNR_LSYCABE]+)(.*)/ [\2] = "\1",/p' 22 echo "};" 23 24 extra_syscalls="$(echo "#include <sys/syscall.h>" | ${CC} -E -dM - | sed -r -n -e 's/^#define __ARM_NR_([a-z0-9_]+)/\1/p')" 25 26 cat <<EOF 27 static inline const char *syscall_name(unsigned i) { 28 if (i < ARRAY_SIZE(__syscall_names)) 29 return __syscall_names[i]; 30 switch (i) { 31 EOF 32 echo "$extra_syscalls" | \ 33 LC_ALL=C sed -r -n -e 's/^([a-z0-9_]+)[ \t]+([ ()+0-9a-zNR_LAMBSE]+)(.*)/ case \2: return "\1";/p' 34 cat <<EOF 35 default: return (void*)0; 36 } 37 } 38 EOF 39 40 cat <<EOF 41 static inline int syscall_index(unsigned i) { 42 if (i < ARRAY_SIZE(__syscall_names)) 43 return i; 44 switch (i) { 45 EOF 46 echo "$extra_syscalls" | \ 47 LC_ALL=C perl -ne 'print " case $2: return ARRAY_SIZE(__syscall_names) + ", $. - 1, ";\n" if /^([a-z0-9_]+)[ \t]+([ ()+0-9a-zNR_LAMBSE]+)(.*)/;' 48 cat <<EOF 49 default: return -1; 50 } 51 } 52 EOF 53 54 cat <<EOF 55 static inline int syscall_index_to_number(unsigned i) { 56 if (i < ARRAY_SIZE(__syscall_names)) 57 return i; 58 switch (i) { 59 EOF 60 echo "$extra_syscalls" | \ 61 LC_ALL=C perl -ne 'print " case ARRAY_SIZE(__syscall_names) + ", $. - 1, ": return $2;\n" if /^([a-z0-9_]+)[ \t]+([ ()+0-9a-zNR_LAMBSE]+)(.*)/;' 62 cat <<EOF 63 default: return -1; 64 } 65 } 66 EOF 67 68 echo "#define SYSCALL_COUNT (ARRAY_SIZE(__syscall_names) + $({ test -n "$extra_syscalls" && echo "$extra_syscalls"; } | wc -l))"
This page was automatically generated by LXR 0.3.1. • OpenWrt