syscall.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  3. * Licensed under the GPL
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/ptrace.h>
  7. #include <kern_util.h>
  8. #include <sysdep/ptrace.h>
  9. #include <sysdep/syscalls.h>
  10. extern int syscall_table_size;
  11. #define NR_SYSCALLS (syscall_table_size / sizeof(void *))
  12. void handle_syscall(struct uml_pt_regs *r)
  13. {
  14. struct pt_regs *regs = container_of(r, struct pt_regs, regs);
  15. long result;
  16. int syscall;
  17. if (syscall_trace_enter(regs)) {
  18. result = -ENOSYS;
  19. goto out;
  20. }
  21. /*
  22. * This should go in the declaration of syscall, but when I do that,
  23. * strace -f -c bash -c 'ls ; ls' breaks, sometimes not tracing
  24. * children at all, sometimes hanging when bash doesn't see the first
  25. * ls exit.
  26. * The assembly looks functionally the same to me. This is
  27. * gcc version 4.0.1 20050727 (Red Hat 4.0.1-5)
  28. * in case it's a compiler bug.
  29. */
  30. syscall = UPT_SYSCALL_NR(r);
  31. if ((syscall >= NR_SYSCALLS) || (syscall < 0))
  32. result = -ENOSYS;
  33. else result = EXECUTE_SYSCALL(syscall, regs);
  34. out:
  35. PT_REGS_SET_SYSCALL_RETURN(regs, result);
  36. syscall_trace_leave(regs);
  37. }