syscall.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. return IS_ERR_VALUE(regs->gprs[2]) ? regs->gprs[2] : 0;
  36. }
  37. static inline long syscall_get_return_value(struct task_struct *task,
  38. struct pt_regs *regs)
  39. {
  40. return regs->gprs[2];
  41. }
  42. static inline void syscall_set_return_value(struct task_struct *task,
  43. struct pt_regs *regs,
  44. int error, long val)
  45. {
  46. regs->gprs[2] = error ? error : val;
  47. }
  48. static inline void syscall_get_arguments(struct task_struct *task,
  49. struct pt_regs *regs,
  50. unsigned int i, unsigned int n,
  51. unsigned long *args)
  52. {
  53. unsigned long mask = -1UL;
  54. /*
  55. * No arguments for this syscall, there's nothing to do.
  56. */
  57. if (!n)
  58. return;
  59. BUG_ON(i + n > 6);
  60. #ifdef CONFIG_COMPAT
  61. if (test_tsk_thread_flag(task, TIF_31BIT))
  62. mask = 0xffffffff;
  63. #endif
  64. while (n-- > 0)
  65. if (i + n > 0)
  66. args[n] = regs->gprs[2 + i + n] & mask;
  67. if (i == 0)
  68. args[0] = regs->orig_gpr2 & mask;
  69. }
  70. static inline void syscall_set_arguments(struct task_struct *task,
  71. struct pt_regs *regs,
  72. unsigned int i, unsigned int n,
  73. const unsigned long *args)
  74. {
  75. BUG_ON(i + n > 6);
  76. while (n-- > 0)
  77. if (i + n > 0)
  78. regs->gprs[2 + i + n] = args[n];
  79. if (i == 0)
  80. regs->orig_gpr2 = args[0];
  81. }
  82. static inline int syscall_get_arch(void)
  83. {
  84. #ifdef CONFIG_COMPAT
  85. if (test_tsk_thread_flag(current, TIF_31BIT))
  86. return AUDIT_ARCH_S390;
  87. #endif
  88. return AUDIT_ARCH_S390X;
  89. }
  90. #endif /* _ASM_SYSCALL_H */