syscall.h 2.4 KB

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