syscall.h 2.1 KB

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