syscall.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __ASM_SYSCALL_H
  3. #define __ASM_SYSCALL_H
  4. #include <linux/sched.h>
  5. #include <linux/err.h>
  6. #include <abi/regdef.h>
  7. static inline int
  8. syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
  9. {
  10. return regs_syscallid(regs);
  11. }
  12. static inline void
  13. syscall_rollback(struct task_struct *task, struct pt_regs *regs)
  14. {
  15. regs->a0 = regs->orig_a0;
  16. }
  17. static inline long
  18. syscall_get_error(struct task_struct *task, struct pt_regs *regs)
  19. {
  20. unsigned long error = regs->a0;
  21. return IS_ERR_VALUE(error) ? error : 0;
  22. }
  23. static inline long
  24. syscall_get_return_value(struct task_struct *task, struct pt_regs *regs)
  25. {
  26. return regs->a0;
  27. }
  28. static inline void
  29. syscall_set_return_value(struct task_struct *task, struct pt_regs *regs,
  30. int error, long val)
  31. {
  32. regs->a0 = (long) error ?: val;
  33. }
  34. static inline void
  35. syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
  36. unsigned int i, unsigned int n, unsigned long *args)
  37. {
  38. BUG_ON(i + n > 6);
  39. if (i == 0) {
  40. args[0] = regs->orig_a0;
  41. args++;
  42. i++;
  43. n--;
  44. }
  45. memcpy(args, &regs->a1 + i * sizeof(regs->a1), n * sizeof(args[0]));
  46. }
  47. static inline void
  48. syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
  49. unsigned int i, unsigned int n, const unsigned long *args)
  50. {
  51. BUG_ON(i + n > 6);
  52. if (i == 0) {
  53. regs->orig_a0 = args[0];
  54. args++;
  55. i++;
  56. n--;
  57. }
  58. memcpy(&regs->a1 + i * sizeof(regs->a1), args, n * sizeof(regs->a0));
  59. }
  60. #endif /* __ASM_SYSCALL_H */