syscall.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Access to user system call parameters and results
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * See asm-generic/syscall.h for descriptions of what we must do here.
  9. *
  10. * Copyright (C) 2012 Ralf Baechle <[email protected]>
  11. */
  12. #ifndef __ASM_MIPS_SYSCALL_H
  13. #define __ASM_MIPS_SYSCALL_H
  14. #include <linux/compiler.h>
  15. #include <uapi/linux/audit.h>
  16. #include <linux/elf-em.h>
  17. #include <linux/kernel.h>
  18. #include <linux/sched.h>
  19. #include <linux/uaccess.h>
  20. #include <asm/ptrace.h>
  21. #include <asm/unistd.h>
  22. #ifndef __NR_syscall /* Only defined if _MIPS_SIM == _MIPS_SIM_ABI32 */
  23. #define __NR_syscall 4000
  24. #endif
  25. static inline bool mips_syscall_is_indirect(struct task_struct *task,
  26. struct pt_regs *regs)
  27. {
  28. /* O32 ABI syscall() - Either 64-bit with O32 or 32-bit */
  29. return (IS_ENABLED(CONFIG_32BIT) ||
  30. test_tsk_thread_flag(task, TIF_32BIT_REGS)) &&
  31. (regs->regs[2] == __NR_syscall);
  32. }
  33. static inline long syscall_get_nr(struct task_struct *task,
  34. struct pt_regs *regs)
  35. {
  36. return task_thread_info(task)->syscall;
  37. }
  38. static inline void mips_syscall_update_nr(struct task_struct *task,
  39. struct pt_regs *regs)
  40. {
  41. /*
  42. * v0 is the system call number, except for O32 ABI syscall(), where it
  43. * ends up in a0.
  44. */
  45. if (mips_syscall_is_indirect(task, regs))
  46. task_thread_info(task)->syscall = regs->regs[4];
  47. else
  48. task_thread_info(task)->syscall = regs->regs[2];
  49. }
  50. static inline void mips_get_syscall_arg(unsigned long *arg,
  51. struct task_struct *task, struct pt_regs *regs, unsigned int n)
  52. {
  53. unsigned long usp __maybe_unused = regs->regs[29];
  54. switch (n) {
  55. case 0: case 1: case 2: case 3:
  56. *arg = regs->regs[4 + n];
  57. return;
  58. #ifdef CONFIG_32BIT
  59. case 4: case 5: case 6: case 7:
  60. get_user(*arg, (int *)usp + n);
  61. return;
  62. #endif
  63. #ifdef CONFIG_64BIT
  64. case 4: case 5: case 6: case 7:
  65. #ifdef CONFIG_MIPS32_O32
  66. if (test_tsk_thread_flag(task, TIF_32BIT_REGS))
  67. get_user(*arg, (int *)usp + n);
  68. else
  69. #endif
  70. *arg = regs->regs[4 + n];
  71. return;
  72. #endif
  73. default:
  74. BUG();
  75. }
  76. unreachable();
  77. }
  78. static inline long syscall_get_error(struct task_struct *task,
  79. struct pt_regs *regs)
  80. {
  81. return regs->regs[7] ? -regs->regs[2] : 0;
  82. }
  83. static inline long syscall_get_return_value(struct task_struct *task,
  84. struct pt_regs *regs)
  85. {
  86. return regs->regs[2];
  87. }
  88. static inline void syscall_rollback(struct task_struct *task,
  89. struct pt_regs *regs)
  90. {
  91. /* Do nothing */
  92. }
  93. static inline void syscall_set_return_value(struct task_struct *task,
  94. struct pt_regs *regs,
  95. int error, long val)
  96. {
  97. if (error) {
  98. regs->regs[2] = -error;
  99. regs->regs[7] = 1;
  100. } else {
  101. regs->regs[2] = val;
  102. regs->regs[7] = 0;
  103. }
  104. }
  105. static inline void syscall_get_arguments(struct task_struct *task,
  106. struct pt_regs *regs,
  107. unsigned long *args)
  108. {
  109. unsigned int i = 0;
  110. unsigned int n = 6;
  111. /* O32 ABI syscall() */
  112. if (mips_syscall_is_indirect(task, regs))
  113. i++;
  114. while (n--)
  115. mips_get_syscall_arg(args++, task, regs, i++);
  116. }
  117. extern const unsigned long sys_call_table[];
  118. extern const unsigned long sys32_call_table[];
  119. extern const unsigned long sysn32_call_table[];
  120. static inline int syscall_get_arch(struct task_struct *task)
  121. {
  122. int arch = AUDIT_ARCH_MIPS;
  123. #ifdef CONFIG_64BIT
  124. if (!test_tsk_thread_flag(task, TIF_32BIT_REGS)) {
  125. arch |= __AUDIT_ARCH_64BIT;
  126. /* N32 sets only TIF_32BIT_ADDR */
  127. if (test_tsk_thread_flag(task, TIF_32BIT_ADDR))
  128. arch |= __AUDIT_ARCH_CONVENTION_MIPS64_N32;
  129. }
  130. #endif
  131. #if defined(__LITTLE_ENDIAN)
  132. arch |= __AUDIT_ARCH_LE;
  133. #endif
  134. return arch;
  135. }
  136. #endif /* __ASM_MIPS_SYSCALL_H */