syscall.h 3.2 KB

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