syscall_32.h 2.4 KB

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