syscall.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 <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 (i + n > SYSCALL_MAX_ARGS) {
  49. unsigned long *args_bad = args + SYSCALL_MAX_ARGS - i;
  50. unsigned int n_bad = n + i - SYSCALL_MAX_ARGS;
  51. pr_warning("%s called with max args %d, handling only %d\n",
  52. __func__, i + n, SYSCALL_MAX_ARGS);
  53. memset(args_bad, 0, n_bad * sizeof(args[0]));
  54. n = SYSCALL_MAX_ARGS - i;
  55. }
  56. if (i == 0) {
  57. args[0] = regs->ARM_ORIG_r0;
  58. args++;
  59. i++;
  60. n--;
  61. }
  62. memcpy(args, &regs->ARM_r0 + i, n * sizeof(args[0]));
  63. }
  64. static inline void syscall_set_arguments(struct task_struct *task,
  65. struct pt_regs *regs,
  66. unsigned int i, unsigned int n,
  67. const unsigned long *args)
  68. {
  69. if (i + n > SYSCALL_MAX_ARGS) {
  70. pr_warning("%s called with max args %d, handling only %d\n",
  71. __func__, i + n, SYSCALL_MAX_ARGS);
  72. n = SYSCALL_MAX_ARGS - i;
  73. }
  74. if (i == 0) {
  75. regs->ARM_ORIG_r0 = args[0];
  76. args++;
  77. i++;
  78. n--;
  79. }
  80. memcpy(&regs->ARM_r0 + i, args, n * sizeof(args[0]));
  81. }
  82. static inline int syscall_get_arch(struct task_struct *task,
  83. struct pt_regs *regs)
  84. {
  85. /* ARM tasks don't change audit architectures on the fly. */
  86. return AUDIT_ARCH_ARM;
  87. }
  88. #endif /* _ASM_ARM_SYSCALL_H */