syscall.h 2.1 KB

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