syscall.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
  3. * Licensed under the GPL
  4. */
  5. #include "linux/sys.h"
  6. #include "linux/ptrace.h"
  7. #include "asm/errno.h"
  8. #include "asm/unistd.h"
  9. #include "asm/ptrace.h"
  10. #include "asm/current.h"
  11. #include "sysdep/syscalls.h"
  12. #include "kern_util.h"
  13. #include "syscall.h"
  14. void handle_syscall(union uml_pt_regs *r)
  15. {
  16. struct pt_regs *regs = container_of(r, struct pt_regs, regs);
  17. long result;
  18. int syscall;
  19. #ifdef UML_CONFIG_SYSCALL_DEBUG
  20. int index;
  21. index = record_syscall_start(UPT_SYSCALL_NR(r));
  22. #endif
  23. syscall_trace(r, 0);
  24. current->thread.nsyscalls++;
  25. nsyscalls++;
  26. /* This should go in the declaration of syscall, but when I do that,
  27. * strace -f -c bash -c 'ls ; ls' breaks, sometimes not tracing
  28. * children at all, sometimes hanging when bash doesn't see the first
  29. * ls exit.
  30. * The assembly looks functionally the same to me. This is
  31. * gcc version 4.0.1 20050727 (Red Hat 4.0.1-5)
  32. * in case it's a compiler bug.
  33. */
  34. syscall = UPT_SYSCALL_NR(r);
  35. if((syscall >= NR_syscalls) || (syscall < 0))
  36. result = -ENOSYS;
  37. else result = EXECUTE_SYSCALL(syscall, regs);
  38. REGS_SET_SYSCALL_RETURN(r->skas.regs, result);
  39. syscall_trace(r, 1);
  40. #ifdef UML_CONFIG_SYSCALL_DEBUG
  41. record_syscall_end(index, result);
  42. #endif
  43. }