syscall-generic.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Access to user system call parameters and results
  4. *
  5. * See asm-generic/syscall.h for function descriptions.
  6. *
  7. * Copyright (C) 2015 Mickaël Salaün <mic@digikod.net>
  8. */
  9. #ifndef __UM_SYSCALL_GENERIC_H
  10. #define __UM_SYSCALL_GENERIC_H
  11. #include <asm/ptrace.h>
  12. #include <linux/err.h>
  13. #include <linux/sched.h>
  14. #include <sysdep/ptrace.h>
  15. static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
  16. {
  17. return PT_REGS_SYSCALL_NR(regs);
  18. }
  19. static inline void syscall_set_nr(struct task_struct *task, struct pt_regs *regs, int nr)
  20. {
  21. PT_REGS_SYSCALL_NR(regs) = nr;
  22. }
  23. static inline void syscall_rollback(struct task_struct *task,
  24. struct pt_regs *regs)
  25. {
  26. /* do nothing */
  27. }
  28. static inline long syscall_get_error(struct task_struct *task,
  29. struct pt_regs *regs)
  30. {
  31. const long error = regs_return_value(regs);
  32. return IS_ERR_VALUE(error) ? error : 0;
  33. }
  34. static inline long syscall_get_return_value(struct task_struct *task,
  35. struct pt_regs *regs)
  36. {
  37. return regs_return_value(regs);
  38. }
  39. static inline void syscall_set_return_value(struct task_struct *task,
  40. struct pt_regs *regs,
  41. int error, long val)
  42. {
  43. PT_REGS_SET_SYSCALL_RETURN(regs, (long) error ?: val);
  44. }
  45. static inline void syscall_get_arguments(struct task_struct *task,
  46. struct pt_regs *regs,
  47. unsigned long *args)
  48. {
  49. const struct uml_pt_regs *r = &regs->regs;
  50. *args++ = UPT_SYSCALL_ARG1(r);
  51. *args++ = UPT_SYSCALL_ARG2(r);
  52. *args++ = UPT_SYSCALL_ARG3(r);
  53. *args++ = UPT_SYSCALL_ARG4(r);
  54. *args++ = UPT_SYSCALL_ARG5(r);
  55. *args = UPT_SYSCALL_ARG6(r);
  56. }
  57. static inline void syscall_set_arguments(struct task_struct *task,
  58. struct pt_regs *regs,
  59. const unsigned long *args)
  60. {
  61. struct uml_pt_regs *r = &regs->regs;
  62. UPT_SYSCALL_ARG1(r) = *args++;
  63. UPT_SYSCALL_ARG2(r) = *args++;
  64. UPT_SYSCALL_ARG3(r) = *args++;
  65. UPT_SYSCALL_ARG4(r) = *args++;
  66. UPT_SYSCALL_ARG5(r) = *args++;
  67. UPT_SYSCALL_ARG6(r) = *args;
  68. }
  69. /* See arch/x86/um/asm/syscall.h for syscall_get_arch() definition. */
  70. #endif /* __UM_SYSCALL_GENERIC_H */