syscall.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/ptrace.h>
  7. #include <linux/seccomp.h>
  8. #include <kern_util.h>
  9. #include <sysdep/ptrace.h>
  10. #include <sysdep/ptrace_user.h>
  11. #include <sysdep/syscalls.h>
  12. #include <linux/time-internal.h>
  13. #include <asm/unistd.h>
  14. #include <asm/delay.h>
  15. void handle_syscall(struct uml_pt_regs *r)
  16. {
  17. struct pt_regs *regs = container_of(r, struct pt_regs, regs);
  18. int syscall;
  19. /* Initialize the syscall number and default return value. */
  20. UPT_SYSCALL_NR(r) = PT_SYSCALL_NR(r->gp);
  21. PT_REGS_SET_SYSCALL_RETURN(regs, -ENOSYS);
  22. if (syscall_trace_enter(regs))
  23. goto out;
  24. /* Do the seccomp check after ptrace; failures should be fast. */
  25. if (secure_computing() == -1)
  26. goto out;
  27. syscall = UPT_SYSCALL_NR(r);
  28. if (syscall >= 0 && syscall < __NR_syscalls) {
  29. unsigned long ret = EXECUTE_SYSCALL(syscall, regs);
  30. PT_REGS_SET_SYSCALL_RETURN(regs, ret);
  31. /*
  32. * An error value here can be some form of -ERESTARTSYS
  33. * and then we'd just loop. Make any error syscalls take
  34. * some time, so that it won't just loop if something is
  35. * not ready, and hopefully other things will make some
  36. * progress.
  37. */
  38. if (IS_ERR_VALUE(ret) &&
  39. (time_travel_mode == TT_MODE_INFCPU ||
  40. time_travel_mode == TT_MODE_EXTERNAL)) {
  41. um_udelay(1);
  42. schedule();
  43. }
  44. }
  45. out:
  46. syscall_trace_leave(regs);
  47. }