syscall.h 2.4 KB

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