syscall.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Access to user system call parameters and results
  4. *
  5. * Copyright IBM Corp. 2008
  6. * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
  7. */
  8. #ifndef _ASM_SYSCALL_H
  9. #define _ASM_SYSCALL_H 1
  10. #include <uapi/linux/audit.h>
  11. #include <linux/sched.h>
  12. #include <linux/err.h>
  13. #include <asm/ptrace.h>
  14. /*
  15. * The syscall table always contains 32 bit pointers since we know that the
  16. * address of the function to be called is (way) below 4GB. So the "int"
  17. * type here is what we want [need] for both 32 bit and 64 bit systems.
  18. */
  19. extern const unsigned int sys_call_table[];
  20. extern const unsigned int sys_call_table_emu[];
  21. static inline long syscall_get_nr(struct task_struct *task,
  22. struct pt_regs *regs)
  23. {
  24. return test_pt_regs_flag(regs, PIF_SYSCALL) ?
  25. (regs->int_code & 0xffff) : -1;
  26. }
  27. static inline void syscall_rollback(struct task_struct *task,
  28. struct pt_regs *regs)
  29. {
  30. regs->gprs[2] = regs->orig_gpr2;
  31. }
  32. static inline long syscall_get_error(struct task_struct *task,
  33. struct pt_regs *regs)
  34. {
  35. unsigned long error = regs->gprs[2];
  36. #ifdef CONFIG_COMPAT
  37. if (test_tsk_thread_flag(task, TIF_31BIT)) {
  38. /*
  39. * Sign-extend the value so (int)-EFOO becomes (long)-EFOO
  40. * and will match correctly in comparisons.
  41. */
  42. error = (long)(int)error;
  43. }
  44. #endif
  45. return IS_ERR_VALUE(error) ? error : 0;
  46. }
  47. static inline long syscall_get_return_value(struct task_struct *task,
  48. struct pt_regs *regs)
  49. {
  50. return regs->gprs[2];
  51. }
  52. static inline void syscall_set_return_value(struct task_struct *task,
  53. struct pt_regs *regs,
  54. int error, long val)
  55. {
  56. regs->gprs[2] = error ? error : val;
  57. }
  58. static inline void syscall_get_arguments(struct task_struct *task,
  59. struct pt_regs *regs,
  60. unsigned int i, unsigned int n,
  61. unsigned long *args)
  62. {
  63. unsigned long mask = -1UL;
  64. /*
  65. * No arguments for this syscall, there's nothing to do.
  66. */
  67. if (!n)
  68. return;
  69. BUG_ON(i + n > 6);
  70. #ifdef CONFIG_COMPAT
  71. if (test_tsk_thread_flag(task, TIF_31BIT))
  72. mask = 0xffffffff;
  73. #endif
  74. while (n-- > 0)
  75. if (i + n > 0)
  76. args[n] = regs->gprs[2 + i + n] & mask;
  77. if (i == 0)
  78. args[0] = regs->orig_gpr2 & mask;
  79. }
  80. static inline void syscall_set_arguments(struct task_struct *task,
  81. struct pt_regs *regs,
  82. unsigned int i, unsigned int n,
  83. const unsigned long *args)
  84. {
  85. BUG_ON(i + n > 6);
  86. while (n-- > 0)
  87. if (i + n > 0)
  88. regs->gprs[2 + i + n] = args[n];
  89. if (i == 0)
  90. regs->orig_gpr2 = args[0];
  91. }
  92. static inline int syscall_get_arch(void)
  93. {
  94. #ifdef CONFIG_COMPAT
  95. if (test_tsk_thread_flag(current, TIF_31BIT))
  96. return AUDIT_ARCH_S390;
  97. #endif
  98. return AUDIT_ARCH_S390X;
  99. }
  100. #endif /* _ASM_SYSCALL_H */