syscall.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. syscall_trace(r, 0);
  18. /*
  19. * This should go in the declaration of syscall, but when I do that,
  20. * strace -f -c bash -c 'ls ; ls' breaks, sometimes not tracing
  21. * children at all, sometimes hanging when bash doesn't see the first
  22. * ls exit.
  23. * The assembly looks functionally the same to me. This is
  24. * gcc version 4.0.1 20050727 (Red Hat 4.0.1-5)
  25. * in case it's a compiler bug.
  26. */
  27. syscall = UPT_SYSCALL_NR(r);
  28. if ((syscall >= NR_syscalls) || (syscall < 0))
  29. result = -ENOSYS;
  30. else result = EXECUTE_SYSCALL(syscall, regs);
  31. REGS_SET_SYSCALL_RETURN(r->gp, result);
  32. syscall_trace(r, 1);
  33. }