syscall.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 <ralf@linux-mips.org>
  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 current_thread_info()->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 unsigned long 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 0;
  58. #ifdef CONFIG_32BIT
  59. case 4: case 5: case 6: case 7:
  60. return get_user(*arg, (int *)usp + n);
  61. #endif
  62. #ifdef CONFIG_64BIT
  63. case 4: case 5: case 6: case 7:
  64. #ifdef CONFIG_MIPS32_O32
  65. if (test_tsk_thread_flag(task, TIF_32BIT_REGS))
  66. return get_user(*arg, (int *)usp + n);
  67. else
  68. #endif
  69. *arg = regs->regs[4 + n];
  70. return 0;
  71. #endif
  72. default:
  73. BUG();
  74. }
  75. unreachable();
  76. }
  77. static inline long syscall_get_return_value(struct task_struct *task,
  78. struct pt_regs *regs)
  79. {
  80. return regs->regs[2];
  81. }
  82. static inline void syscall_rollback(struct task_struct *task,
  83. struct pt_regs *regs)
  84. {
  85. /* Do nothing */
  86. }
  87. static inline void syscall_set_return_value(struct task_struct *task,
  88. struct pt_regs *regs,
  89. int error, long val)
  90. {
  91. if (error) {
  92. regs->regs[2] = -error;
  93. regs->regs[7] = 1;
  94. } else {
  95. regs->regs[2] = val;
  96. regs->regs[7] = 0;
  97. }
  98. }
  99. static inline void syscall_get_arguments(struct task_struct *task,
  100. struct pt_regs *regs,
  101. unsigned int i, unsigned int n,
  102. unsigned long *args)
  103. {
  104. int ret;
  105. /* O32 ABI syscall() */
  106. if (mips_syscall_is_indirect(task, regs))
  107. i++;
  108. while (n--)
  109. ret |= mips_get_syscall_arg(args++, task, regs, i++);
  110. /*
  111. * No way to communicate an error because this is a void function.
  112. */
  113. #if 0
  114. return ret;
  115. #endif
  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(void)
  121. {
  122. int arch = AUDIT_ARCH_MIPS;
  123. #ifdef CONFIG_64BIT
  124. if (!test_thread_flag(TIF_32BIT_REGS)) {
  125. arch |= __AUDIT_ARCH_64BIT;
  126. /* N32 sets only TIF_32BIT_ADDR */
  127. if (test_thread_flag(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 */