]> mj.ucw.cz Git - moe.git/commitdiff
Generate a table of all known syscalls and use it to show syscall
authorMartin Mares <mj@ucw.cz>
Fri, 18 Jan 2008 22:48:21 +0000 (23:48 +0100)
committerMartin Mares <mj@ucw.cz>
Fri, 18 Jan 2008 22:48:21 +0000 (23:48 +0100)
names instead of numbers.

Makefile
src/box.c
src/mk-syscall-table [new file with mode: 0755]

index 79846d94515009c268b603e5ebe95a26310c8a27..8c13b71d2fe976fc9836bf1126403f55de715653 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ VERSION=1.0.1
 #DEBUG=-ggdb
 CFLAGS=-O2 -Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -Wundef -Wredundant-decls -Winline $(DEBUG) -std=gnu99
 
-CC=gcc-4.1.1
+#CC=gcc-4.1.1
 
 # Comment out if you are using a recent gcc
 CFLAGS+=-Wno-pointer-sign -Wdisabled-optimization -Wno-missing-field-initializers
@@ -26,10 +26,16 @@ bin/iwrapper: src/iwrapper.o
 bin/md5crypt: src/md5crypt.o src/md5.o
 bin/pedant: src/pedant.o
 
+src/box.o: src/box.c src/syscall-table.h
+
+src/syscall-table.h:
+       src/mk-syscall-table
+
 submit:
 
 clean::
        rm -f `find . -name "*~" -or -name "*.[oa]" -or -name "\#*\#" -or -name TAGS -or -name core`
+       rm -f src/syscall-table.h
        rm -f bin/box bin/iwrapper bin/md5crypt bin/pedant
 
 distclean: clean
index 126452adbe176f9f511e38a47bef1e7f32cc1124..fe1c22f83a7e81bd068a0a0dcab63666666671c2 100644 (file)
--- a/src/box.c
+++ b/src/box.c
@@ -91,6 +91,39 @@ msg(char *msg, ...)
   va_end(args);
 }
 
+struct syscall {
+  const char *name;
+  int override;
+};
+
+static struct syscall syscall_tab[] = {
+#include "syscall-table.h"
+};
+#define NUM_SYSCALLS (sizeof(syscall_tab)/sizeof(syscall_tab[0]))
+
+static const char *
+syscall_name(unsigned int id, char *buf)
+{
+  if (id < NUM_SYSCALLS && syscall_tab[id].name)
+    return syscall_tab[id].name;
+  else
+    {
+      sprintf(buf, "#%d", id);
+      return buf;
+    }
+}
+
+#if 0
+static struct syscall *
+syscall_by_name(char *name)
+{
+  for (unsigned int i=0; i<sizeof(syscall_tab)/sizeof(syscall_tab[0]); i++)
+    if (!strcmp(syscall_tab[i].name, name))
+      return &syscall_tab[i];
+  return NULL;
+}
+#endif
+
 static void
 valid_filename(unsigned long addr)
 {
@@ -420,7 +453,8 @@ boxkeeper(void)
                msg(">> Traceme request caught\n");
              else if (stop_count & 1)          /* Syscall entry */
                {
-                 msg(">> Syscall %3ld (%08lx,%08lx,%08lx) ", u.regs.orig_eax, u.regs.ebx, u.regs.ecx, u.regs.edx);
+                 char namebuf[32];
+                 msg(">> Syscall %-12s (%08lx,%08lx,%08lx) ", syscall_name(u.regs.orig_eax, namebuf), u.regs.ebx, u.regs.ecx, u.regs.edx);
                  if (!exec_seen)
                    {
                      msg("[master] ");
@@ -440,7 +474,7 @@ boxkeeper(void)
                      u.regs.orig_eax = 0xffffffff;
                      if (ptrace(PTRACE_SETREGS, box_pid, NULL, &u) < 0)
                        die("ptrace(PTRACE_SETREGS): %m");
-                     die("Forbidden syscall %d", sys);
+                     die("Forbidden syscall %s", syscall_name(sys, namebuf));
                    }
                }
              else                                      /* Syscall return */
diff --git a/src/mk-syscall-table b/src/mk-syscall-table
new file mode 100755 (executable)
index 0000000..e90334d
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/sh
+set -e
+(
+echo '/* Syscall table automatically generated by mk-syscall-table */'
+echo
+echo '#include <asm/unistd.h>' |
+       gcc -E -dM - |
+       sed 's/^#define __NR_\([^       ]\+\).*/[ __NR_\1 ] = { "\1", 0 },/;t;d'
+) >src/syscall-table.h