syscall.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Access to user system call parameters and results
  4. *
  5. * See asm-generic/syscall.h for descriptions of what we must do here.
  6. */
  7. #ifndef _ASM_ARM_SYSCALL_H
  8. #define _ASM_ARM_SYSCALL_H
  9. #include <uapi/linux/audit.h> /* for AUDIT_ARCH_* */
  10. #include <linux/elf.h> /* for ELF_EM */
  11. #include <linux/err.h>
  12. #include <linux/sched.h>
  13. #include <asm/unistd.h>
  14. #define NR_syscalls (__NR_syscalls)
  15. extern const unsigned long sys_call_table[];
  16. static inline int syscall_get_nr(struct task_struct *task,
  17. struct pt_regs *regs)
  18. {
  19. return task_thread_info(task)->syscall;
  20. }
  21. static inline void syscall_rollback(struct task_struct *task,
  22. struct pt_regs *regs)
  23. {
  24. regs->ARM_r0 = regs->ARM_ORIG_r0;
  25. }
  26. static inline long syscall_get_error(struct task_struct *task,
  27. struct pt_regs *regs)
  28. {
  29. unsigned long error = regs->ARM_r0;
  30. return IS_ERR_VALUE(error) ? error : 0;
  31. }
  32. static inline long syscall_get_return_value(struct task_struct *task,
  33. struct pt_regs *regs)
  34. {
  35. return regs->ARM_r0;
  36. }
  37. static inline void syscall_set_return_value(struct task_struct *task,
  38. struct pt_regs *regs,
  39. int error, long val)
  40. {
  41. regs->ARM_r0 = (long) error ? error : val;
  42. }
  43. #define SYSCALL_MAX_ARGS 7
  44. static inline void syscall_get_arguments(struct task_struct *task,
  45. struct pt_regs *regs,
  46. unsigned int i, unsigned int n,
  47. unsigned long *args)
  48. {
  49. if (n == 0)
  50. return;
  51. if (i + n > SYSCALL_MAX_ARGS) {
  52. unsigned long *args_bad = args + SYSCALL_MAX_ARGS - i;
  53. unsigned int n_bad = n + i - SYSCALL_MAX_ARGS;
  54. pr_warn("%s called with max args %d, handling only %d\n",
  55. __func__, i + n, SYSCALL_MAX_ARGS);
  56. memset(args_bad, 0, n_bad * sizeof(args[0]));
  57. n = SYSCALL_MAX_ARGS - i;
  58. }
  59. if (i == 0) {
  60. args[0] = regs->ARM_ORIG_r0;
  61. args++;
  62. i++;
  63. n--;
  64. }
  65. memcpy(args, &regs->ARM_r0 + i, n * sizeof(args[0]));
  66. }
  67. static inline void syscall_set_arguments(struct task_struct *task,
  68. struct pt_regs *regs,
  69. unsigned int i, unsigned int n,
  70. const unsigned long *args)
  71. {
  72. if (n == 0)
  73. return;
  74. if (i + n > SYSCALL_MAX_ARGS) {
  75. pr_warn("%s called with max args %d, handling only %d\n",
  76. __func__, i + n, SYSCALL_MAX_ARGS);
  77. n = SYSCALL_MAX_ARGS - i;
  78. }
  79. if (i == 0) {
  80. regs->ARM_ORIG_r0 = args[0];
  81. args++;
  82. i++;
  83. n--;
  84. }
  85. memcpy(&regs->ARM_r0 + i, args, n * sizeof(args[0]));
  86. }
  87. static inline int syscall_get_arch(void)
  88. {
  89. /* ARM tasks don't change audit architectures on the fly. */
  90. return AUDIT_ARCH_ARM;
  91. }
  92. #endif /* _ASM_ARM_SYSCALL_H */