syscall.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 <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. static inline long syscall_get_nr(struct task_struct *task,
  22. struct pt_regs *regs)
  23. {
  24. return regs->regs[2];
  25. }
  26. static inline unsigned long mips_get_syscall_arg(unsigned long *arg,
  27. struct task_struct *task, struct pt_regs *regs, unsigned int n)
  28. {
  29. unsigned long usp __maybe_unused = regs->regs[29];
  30. switch (n) {
  31. case 0: case 1: case 2: case 3:
  32. *arg = regs->regs[4 + n];
  33. return 0;
  34. #ifdef CONFIG_32BIT
  35. case 4: case 5: case 6: case 7:
  36. return get_user(*arg, (int *)usp + 4 * n);
  37. #endif
  38. #ifdef CONFIG_64BIT
  39. case 4: case 5: case 6: case 7:
  40. #ifdef CONFIG_MIPS32_O32
  41. if (test_thread_flag(TIF_32BIT_REGS))
  42. return get_user(*arg, (int *)usp + 4 * n);
  43. else
  44. #endif
  45. *arg = regs->regs[4 + n];
  46. return 0;
  47. #endif
  48. default:
  49. BUG();
  50. }
  51. unreachable();
  52. }
  53. static inline long syscall_get_return_value(struct task_struct *task,
  54. struct pt_regs *regs)
  55. {
  56. return regs->regs[2];
  57. }
  58. static inline void syscall_set_return_value(struct task_struct *task,
  59. struct pt_regs *regs,
  60. int error, long val)
  61. {
  62. if (error) {
  63. regs->regs[2] = -error;
  64. regs->regs[7] = -1;
  65. } else {
  66. regs->regs[2] = val;
  67. regs->regs[7] = 0;
  68. }
  69. }
  70. static inline void syscall_get_arguments(struct task_struct *task,
  71. struct pt_regs *regs,
  72. unsigned int i, unsigned int n,
  73. unsigned long *args)
  74. {
  75. int ret;
  76. while (n--)
  77. ret |= mips_get_syscall_arg(args++, task, regs, i++);
  78. /*
  79. * No way to communicate an error because this is a void function.
  80. */
  81. #if 0
  82. return ret;
  83. #endif
  84. }
  85. extern const unsigned long sys_call_table[];
  86. extern const unsigned long sys32_call_table[];
  87. extern const unsigned long sysn32_call_table[];
  88. static inline int __syscall_get_arch(void)
  89. {
  90. int arch = EM_MIPS;
  91. #ifdef CONFIG_64BIT
  92. arch |= __AUDIT_ARCH_64BIT;
  93. #endif
  94. #if defined(__LITTLE_ENDIAN)
  95. arch |= __AUDIT_ARCH_LE;
  96. #endif
  97. return arch;
  98. }
  99. #endif /* __ASM_MIPS_SYSCALL_H */