syscall.h 2.2 KB

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