syscall.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 long syscall_get_nr(struct task_struct *task,
  26. struct pt_regs *regs)
  27. {
  28. return current_thread_info()->syscall;
  29. }
  30. static inline unsigned long mips_get_syscall_arg(unsigned long *arg,
  31. struct task_struct *task, struct pt_regs *regs, unsigned int n)
  32. {
  33. unsigned long usp __maybe_unused = regs->regs[29];
  34. switch (n) {
  35. case 0: case 1: case 2: case 3:
  36. *arg = regs->regs[4 + n];
  37. return 0;
  38. #ifdef CONFIG_32BIT
  39. case 4: case 5: case 6: case 7:
  40. return get_user(*arg, (int *)usp + n);
  41. #endif
  42. #ifdef CONFIG_64BIT
  43. case 4: case 5: case 6: case 7:
  44. #ifdef CONFIG_MIPS32_O32
  45. if (test_thread_flag(TIF_32BIT_REGS))
  46. return get_user(*arg, (int *)usp + n);
  47. else
  48. #endif
  49. *arg = regs->regs[4 + n];
  50. return 0;
  51. #endif
  52. default:
  53. BUG();
  54. }
  55. unreachable();
  56. }
  57. static inline long syscall_get_return_value(struct task_struct *task,
  58. struct pt_regs *regs)
  59. {
  60. return regs->regs[2];
  61. }
  62. static inline void syscall_rollback(struct task_struct *task,
  63. struct pt_regs *regs)
  64. {
  65. /* Do nothing */
  66. }
  67. static inline void syscall_set_return_value(struct task_struct *task,
  68. struct pt_regs *regs,
  69. int error, long val)
  70. {
  71. if (error) {
  72. regs->regs[2] = -error;
  73. regs->regs[7] = -1;
  74. } else {
  75. regs->regs[2] = val;
  76. regs->regs[7] = 0;
  77. }
  78. }
  79. static inline void syscall_get_arguments(struct task_struct *task,
  80. struct pt_regs *regs,
  81. unsigned int i, unsigned int n,
  82. unsigned long *args)
  83. {
  84. int ret;
  85. /* O32 ABI syscall() - Either 64-bit with O32 or 32-bit */
  86. if ((IS_ENABLED(CONFIG_32BIT) ||
  87. test_tsk_thread_flag(task, TIF_32BIT_REGS)) &&
  88. (regs->regs[2] == __NR_syscall))
  89. i++;
  90. while (n--)
  91. ret |= mips_get_syscall_arg(args++, task, regs, i++);
  92. /*
  93. * No way to communicate an error because this is a void function.
  94. */
  95. #if 0
  96. return ret;
  97. #endif
  98. }
  99. extern const unsigned long sys_call_table[];
  100. extern const unsigned long sys32_call_table[];
  101. extern const unsigned long sysn32_call_table[];
  102. static inline int syscall_get_arch(void)
  103. {
  104. int arch = AUDIT_ARCH_MIPS;
  105. #ifdef CONFIG_64BIT
  106. if (!test_thread_flag(TIF_32BIT_REGS)) {
  107. arch |= __AUDIT_ARCH_64BIT;
  108. /* N32 sets only TIF_32BIT_ADDR */
  109. if (test_thread_flag(TIF_32BIT_ADDR))
  110. arch |= __AUDIT_ARCH_CONVENTION_MIPS64_N32;
  111. }
  112. #endif
  113. #if defined(__LITTLE_ENDIAN)
  114. arch |= __AUDIT_ARCH_LE;
  115. #endif
  116. return arch;
  117. }
  118. #endif /* __ASM_MIPS_SYSCALL_H */