syscall.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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/err.h>
  9. #include <linux/sched.h>
  10. #include <asm/unistd.h>
  11. #define NR_syscalls (__NR_syscalls)
  12. extern const unsigned long sys_call_table[];
  13. static inline int syscall_get_nr(struct task_struct *task,
  14. struct pt_regs *regs)
  15. {
  16. return task_thread_info(task)->syscall;
  17. }
  18. static inline void syscall_rollback(struct task_struct *task,
  19. struct pt_regs *regs)
  20. {
  21. regs->ARM_r0 = regs->ARM_ORIG_r0;
  22. }
  23. static inline long syscall_get_error(struct task_struct *task,
  24. struct pt_regs *regs)
  25. {
  26. unsigned long error = regs->ARM_r0;
  27. return IS_ERR_VALUE(error) ? error : 0;
  28. }
  29. static inline long syscall_get_return_value(struct task_struct *task,
  30. struct pt_regs *regs)
  31. {
  32. return regs->ARM_r0;
  33. }
  34. static inline void syscall_set_return_value(struct task_struct *task,
  35. struct pt_regs *regs,
  36. int error, long val)
  37. {
  38. regs->ARM_r0 = (long) error ? error : val;
  39. }
  40. #define SYSCALL_MAX_ARGS 7
  41. static inline void syscall_get_arguments(struct task_struct *task,
  42. struct pt_regs *regs,
  43. unsigned int i, unsigned int n,
  44. unsigned long *args)
  45. {
  46. if (i + n > SYSCALL_MAX_ARGS) {
  47. unsigned long *args_bad = args + SYSCALL_MAX_ARGS - i;
  48. unsigned int n_bad = n + i - SYSCALL_MAX_ARGS;
  49. pr_warning("%s called with max args %d, handling only %d\n",
  50. __func__, i + n, SYSCALL_MAX_ARGS);
  51. memset(args_bad, 0, n_bad * sizeof(args[0]));
  52. n = SYSCALL_MAX_ARGS - i;
  53. }
  54. if (i == 0) {
  55. args[0] = regs->ARM_ORIG_r0;
  56. args++;
  57. i++;
  58. n--;
  59. }
  60. memcpy(args, &regs->ARM_r0 + i, n * sizeof(args[0]));
  61. }
  62. static inline void syscall_set_arguments(struct task_struct *task,
  63. struct pt_regs *regs,
  64. unsigned int i, unsigned int n,
  65. const unsigned long *args)
  66. {
  67. if (i + n > SYSCALL_MAX_ARGS) {
  68. pr_warning("%s called with max args %d, handling only %d\n",
  69. __func__, i + n, SYSCALL_MAX_ARGS);
  70. n = SYSCALL_MAX_ARGS - i;
  71. }
  72. if (i == 0) {
  73. regs->ARM_ORIG_r0 = args[0];
  74. args++;
  75. i++;
  76. n--;
  77. }
  78. memcpy(&regs->ARM_r0 + i, args, n * sizeof(args[0]));
  79. }
  80. #endif /* _ASM_ARM_SYSCALL_H */