syscall.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Access to user system call parameters and results
  4. *
  5. * Copyright (C) 2008 Red Hat, Inc. All rights reserved.
  6. *
  7. * See asm-generic/syscall.h for descriptions of what we must do here.
  8. */
  9. #ifndef _ASM_SYSCALL_H
  10. #define _ASM_SYSCALL_H 1
  11. #include <uapi/linux/audit.h>
  12. #include <linux/sched.h>
  13. #include <linux/thread_info.h>
  14. #ifdef CONFIG_ARCH_HAS_SYSCALL_WRAPPER
  15. typedef long (*syscall_fn)(const struct pt_regs *);
  16. #else
  17. typedef long (*syscall_fn)(unsigned long, unsigned long, unsigned long,
  18. unsigned long, unsigned long, unsigned long);
  19. #endif
  20. /* ftrace syscalls requires exporting the sys_call_table */
  21. extern const syscall_fn sys_call_table[];
  22. extern const syscall_fn compat_sys_call_table[];
  23. static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
  24. {
  25. /*
  26. * Note that we are returning an int here. That means 0xffffffff, ie.
  27. * 32-bit negative 1, will be interpreted as -1 on a 64-bit kernel.
  28. * This is important for seccomp so that compat tasks can set r0 = -1
  29. * to reject the syscall.
  30. */
  31. if (trap_is_syscall(regs))
  32. return regs->gpr[0];
  33. else
  34. return -1;
  35. }
  36. static inline void syscall_rollback(struct task_struct *task,
  37. struct pt_regs *regs)
  38. {
  39. regs->gpr[3] = regs->orig_gpr3;
  40. }
  41. static inline long syscall_get_error(struct task_struct *task,
  42. struct pt_regs *regs)
  43. {
  44. if (trap_is_scv(regs)) {
  45. unsigned long error = regs->gpr[3];
  46. return IS_ERR_VALUE(error) ? error : 0;
  47. } else {
  48. /*
  49. * If the system call failed,
  50. * regs->gpr[3] contains a positive ERRORCODE.
  51. */
  52. return (regs->ccr & 0x10000000UL) ? -regs->gpr[3] : 0;
  53. }
  54. }
  55. static inline long syscall_get_return_value(struct task_struct *task,
  56. struct pt_regs *regs)
  57. {
  58. return regs->gpr[3];
  59. }
  60. static inline void syscall_set_return_value(struct task_struct *task,
  61. struct pt_regs *regs,
  62. int error, long val)
  63. {
  64. if (trap_is_scv(regs)) {
  65. regs->gpr[3] = (long) error ?: val;
  66. } else {
  67. /*
  68. * In the general case it's not obvious that we must deal with
  69. * CCR here, as the syscall exit path will also do that for us.
  70. * However there are some places, eg. the signal code, which
  71. * check ccr to decide if the value in r3 is actually an error.
  72. */
  73. if (error) {
  74. regs->ccr |= 0x10000000L;
  75. regs->gpr[3] = error;
  76. } else {
  77. regs->ccr &= ~0x10000000L;
  78. regs->gpr[3] = val;
  79. }
  80. }
  81. }
  82. static inline void syscall_get_arguments(struct task_struct *task,
  83. struct pt_regs *regs,
  84. unsigned long *args)
  85. {
  86. unsigned long val, mask = -1UL;
  87. unsigned int n = 6;
  88. if (is_tsk_32bit_task(task))
  89. mask = 0xffffffff;
  90. while (n--) {
  91. if (n == 0)
  92. val = regs->orig_gpr3;
  93. else
  94. val = regs->gpr[3 + n];
  95. args[n] = val & mask;
  96. }
  97. }
  98. static inline int syscall_get_arch(struct task_struct *task)
  99. {
  100. if (is_tsk_32bit_task(task))
  101. return AUDIT_ARCH_PPC;
  102. else if (IS_ENABLED(CONFIG_CPU_LITTLE_ENDIAN))
  103. return AUDIT_ARCH_PPC64LE;
  104. else
  105. return AUDIT_ARCH_PPC64;
  106. }
  107. #endif /* _ASM_SYSCALL_H */