• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/procd/make_syscall_h.sh

  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 echo "static const char *__syscall_names[] = {"
 16 echo "#include <sys/syscall.h>" | ${CC} -E -dM - | grep '^#define __NR_[a-z0-9_]\+[ \t].*[0-9].*$' | \
 17         LC_ALL=C sed -r -n -e 's/^\#define[ \t]+__NR_([a-z0-9_]+)[ \t]+([ ()+0-9a-zNR_LSYCABE]+)(.*)/ [\2] = "\1",/p'
 18 echo "};"
 19 
 20 extra_syscalls="$(echo "#include <sys/syscall.h>" | ${CC} -E -dM - | sed -r -n -e 's/^#define __ARM_NR_([a-z0-9_]+)/\1/p')"
 21 
 22 cat <<EOF
 23 static inline const char *syscall_name(unsigned i) {
 24   if (i < ARRAY_SIZE(__syscall_names))
 25     return __syscall_names[i];
 26   switch (i) {
 27 EOF
 28 echo "$extra_syscalls" | \
 29     LC_ALL=C sed -r -n -e 's/^([a-z0-9_]+)[ \t]+([ ()+0-9a-zNR_LAMBSE]+)(.*)/    case \2: return "\1";/p'
 30 cat <<EOF
 31   default: return (void*)0;
 32   }
 33 }
 34 EOF
 35 
 36 cat <<EOF
 37 static inline int syscall_index(unsigned i) {
 38   if (i < ARRAY_SIZE(__syscall_names))
 39     return i;
 40   switch (i) {
 41 EOF
 42 echo "$extra_syscalls" | \
 43     LC_ALL=C perl -ne 'print "  case $2: return ARRAY_SIZE(__syscall_names) + ", $. - 1, ";\n" if /^([a-z0-9_]+)[ \t]+([ ()+0-9a-zNR_LAMBSE]+)(.*)/;'
 44 cat <<EOF
 45   default: return -1;
 46   }
 47 }
 48 EOF
 49 
 50 cat <<EOF
 51 static inline int syscall_index_to_number(unsigned i) {
 52   if (i < ARRAY_SIZE(__syscall_names))
 53     return i;
 54   switch (i) {
 55 EOF
 56 echo "$extra_syscalls" | \
 57     LC_ALL=C perl -ne 'print "  case ARRAY_SIZE(__syscall_names) + ", $. - 1, ": return $2;\n" if /^([a-z0-9_]+)[ \t]+([ ()+0-9a-zNR_LAMBSE]+)(.*)/;'
 58 cat <<EOF
 59   default: return -1;
 60   }
 61 }
 62 EOF
 63 
 64 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