syscall_32.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __ASM_SH_SYSCALL_32_H
  3. #define __ASM_SH_SYSCALL_32_H
  4. #include <uapi/linux/audit.h>
  5. #include <linux/kernel.h>
  6. #include <linux/sched.h>
  7. #include <linux/err.h>
  8. #include <asm/ptrace.h>
  9. /* The system call number is given by the user in R3 */
  10. static inline long syscall_get_nr(struct task_struct *task,
  11. struct pt_regs *regs)
  12. {
  13. return (regs->tra >= 0) ? regs->regs[3] : -1L;
  14. }
  15. static inline void syscall_rollback(struct task_struct *task,
  16. struct pt_regs *regs)
  17. {
  18. /*
  19. * XXX: This needs some thought. On SH we don't
  20. * save away the original r0 value anywhere.
  21. */
  22. }
  23. static inline long syscall_get_error(struct task_struct *task,
  24. struct pt_regs *regs)
  25. {
  26. return IS_ERR_VALUE(regs->regs[0]) ? regs->regs[0] : 0;
  27. }
  28. static inline long syscall_get_return_value(struct task_struct *task,
  29. struct pt_regs *regs)
  30. {
  31. return regs->regs[0];
  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. if (error)
  38. regs->regs[0] = -error;
  39. else
  40. regs->regs[0] = val;
  41. }
  42. static inline void syscall_get_arguments(struct task_struct *task,
  43. struct pt_regs *regs,
  44. unsigned int i, unsigned int n,
  45. unsigned long *args)
  46. {
  47. /*
  48. * Do this simply for now. If we need to start supporting
  49. * fetching arguments from arbitrary indices, this will need some
  50. * extra logic. Presently there are no in-tree users that depend
  51. * on this behaviour.
  52. */
  53. BUG_ON(i);
  54. /* Argument pattern is: R4, R5, R6, R7, R0, R1 */
  55. switch (n) {
  56. case 6: args[5] = regs->regs[1];
  57. case 5: args[4] = regs->regs[0];
  58. case 4: args[3] = regs->regs[7];
  59. case 3: args[2] = regs->regs[6];
  60. case 2: args[1] = regs->regs[5];
  61. case 1: args[0] = regs->regs[4];
  62. case 0:
  63. break;
  64. default:
  65. BUG();
  66. }
  67. }
  68. static inline void syscall_set_arguments(struct task_struct *task,
  69. struct pt_regs *regs,
  70. unsigned int i, unsigned int n,
  71. const unsigned long *args)
  72. {
  73. /* Same note as above applies */
  74. BUG_ON(i);
  75. switch (n) {
  76. case 6: regs->regs[1] = args[5];
  77. case 5: regs->regs[0] = args[4];
  78. case 4: regs->regs[7] = args[3];
  79. case 3: regs->regs[6] = args[2];
  80. case 2: regs->regs[5] = args[1];
  81. case 1: regs->regs[4] = args[0];
  82. break;
  83. default:
  84. BUG();
  85. }
  86. }
  87. static inline int syscall_get_arch(void)
  88. {
  89. int arch = AUDIT_ARCH_SH;
  90. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  91. arch |= __AUDIT_ARCH_LE;
  92. #endif
  93. return arch;
  94. }
  95. #endif /* __ASM_SH_SYSCALL_32_H */