syscall.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Access to user system call parameters and results
  4. *
  5. * Copyright (C) 2008-2009 Red Hat, Inc. All rights reserved.
  6. *
  7. * This file is a stub providing documentation for what functions
  8. * arch/ARCH/include/asm/syscall.h files need to define. Most arch definitions
  9. * will be simple inlines.
  10. *
  11. * All of these functions expect to be called with no locks,
  12. * and only when the caller is sure that the task of interest
  13. * cannot return to user mode while we are looking at it.
  14. */
  15. #ifndef _ASM_SYSCALL_H
  16. #define _ASM_SYSCALL_H 1
  17. struct task_struct;
  18. struct pt_regs;
  19. /**
  20. * syscall_get_nr - find what system call a task is executing
  21. * @task: task of interest, must be blocked
  22. * @regs: task_pt_regs() of @task
  23. *
  24. * If @task is executing a system call or is at system call
  25. * tracing about to attempt one, returns the system call number.
  26. * If @task is not executing a system call, i.e. it's blocked
  27. * inside the kernel for a fault or signal, returns -1.
  28. *
  29. * Note this returns int even on 64-bit machines. Only 32 bits of
  30. * system call number can be meaningful. If the actual arch value
  31. * is 64 bits, this truncates to 32 bits so 0xffffffff means -1.
  32. *
  33. * It's only valid to call this when @task is known to be blocked.
  34. */
  35. int syscall_get_nr(struct task_struct *task, struct pt_regs *regs);
  36. /**
  37. * syscall_set_nr - change the system call a task is executing
  38. * @task: task of interest, must be blocked
  39. * @regs: task_pt_regs() of @task
  40. * @nr: system call number
  41. *
  42. * Changes the system call number @task is about to execute.
  43. *
  44. * It's only valid to call this when @task is stopped for tracing on
  45. * entry to a system call, due to %SYSCALL_WORK_SYSCALL_TRACE or
  46. * %SYSCALL_WORK_SYSCALL_AUDIT.
  47. */
  48. void syscall_set_nr(struct task_struct *task, struct pt_regs *regs, int nr);
  49. /**
  50. * syscall_rollback - roll back registers after an aborted system call
  51. * @task: task of interest, must be in system call exit tracing
  52. * @regs: task_pt_regs() of @task
  53. *
  54. * It's only valid to call this when @task is stopped for system
  55. * call exit tracing (due to %SYSCALL_WORK_SYSCALL_TRACE or
  56. * %SYSCALL_WORK_SYSCALL_AUDIT), after ptrace_report_syscall_entry()
  57. * returned nonzero to prevent the system call from taking place.
  58. *
  59. * This rolls back the register state in @regs so it's as if the
  60. * system call instruction was a no-op. The registers containing
  61. * the system call number and arguments are as they were before the
  62. * system call instruction. This may not be the same as what the
  63. * register state looked like at system call entry tracing.
  64. */
  65. void syscall_rollback(struct task_struct *task, struct pt_regs *regs);
  66. /**
  67. * syscall_get_error - check result of traced system call
  68. * @task: task of interest, must be blocked
  69. * @regs: task_pt_regs() of @task
  70. *
  71. * Returns 0 if the system call succeeded, or -ERRORCODE if it failed.
  72. *
  73. * It's only valid to call this when @task is stopped for tracing on exit
  74. * from a system call, due to %SYSCALL_WORK_SYSCALL_TRACE or
  75. * %SYSCALL_WORK_SYSCALL_AUDIT.
  76. */
  77. long syscall_get_error(struct task_struct *task, struct pt_regs *regs);
  78. /**
  79. * syscall_get_return_value - get the return value of a traced system call
  80. * @task: task of interest, must be blocked
  81. * @regs: task_pt_regs() of @task
  82. *
  83. * Returns the return value of the successful system call.
  84. * This value is meaningless if syscall_get_error() returned nonzero.
  85. *
  86. * It's only valid to call this when @task is stopped for tracing on exit
  87. * from a system call, due to %SYSCALL_WORK_SYSCALL_TRACE or
  88. * %SYSCALL_WORK_SYSCALL_AUDIT.
  89. */
  90. long syscall_get_return_value(struct task_struct *task, struct pt_regs *regs);
  91. /**
  92. * syscall_set_return_value - change the return value of a traced system call
  93. * @task: task of interest, must be blocked
  94. * @regs: task_pt_regs() of @task
  95. * @error: negative error code, or zero to indicate success
  96. * @val: user return value if @error is zero
  97. *
  98. * This changes the results of the system call that user mode will see.
  99. * If @error is zero, the user sees a successful system call with a
  100. * return value of @val. If @error is nonzero, it's a negated errno
  101. * code; the user sees a failed system call with this errno code.
  102. *
  103. * It's only valid to call this when @task is stopped for tracing on exit
  104. * from a system call, due to %SYSCALL_WORK_SYSCALL_TRACE or
  105. * %SYSCALL_WORK_SYSCALL_AUDIT.
  106. */
  107. void syscall_set_return_value(struct task_struct *task, struct pt_regs *regs,
  108. int error, long val);
  109. /**
  110. * syscall_get_arguments - extract system call parameter values
  111. * @task: task of interest, must be blocked
  112. * @regs: task_pt_regs() of @task
  113. * @args: array filled with argument values
  114. *
  115. * Fetches 6 arguments to the system call. First argument is stored in
  116. * @args[0], and so on.
  117. *
  118. * It's only valid to call this when @task is stopped for tracing on
  119. * entry to a system call, due to %SYSCALL_WORK_SYSCALL_TRACE or
  120. * %SYSCALL_WORK_SYSCALL_AUDIT.
  121. */
  122. void syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
  123. unsigned long *args);
  124. /**
  125. * syscall_set_arguments - change system call parameter value
  126. * @task: task of interest, must be in system call entry tracing
  127. * @regs: task_pt_regs() of @task
  128. * @args: array of argument values to store
  129. *
  130. * Changes 6 arguments to the system call.
  131. * The first argument gets value @args[0], and so on.
  132. *
  133. * It's only valid to call this when @task is stopped for tracing on
  134. * entry to a system call, due to %SYSCALL_WORK_SYSCALL_TRACE or
  135. * %SYSCALL_WORK_SYSCALL_AUDIT.
  136. */
  137. void syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
  138. const unsigned long *args);
  139. /**
  140. * syscall_get_arch - return the AUDIT_ARCH for the current system call
  141. * @task: task of interest, must be blocked
  142. *
  143. * Returns the AUDIT_ARCH_* based on the system call convention in use.
  144. *
  145. * It's only valid to call this when @task is stopped on entry to a system
  146. * call, due to %SYSCALL_WORK_SYSCALL_TRACE, %SYSCALL_WORK_SYSCALL_AUDIT, or
  147. * %SYSCALL_WORK_SECCOMP.
  148. *
  149. * Architectures which permit CONFIG_HAVE_ARCH_SECCOMP_FILTER must
  150. * provide an implementation of this.
  151. */
  152. int syscall_get_arch(struct task_struct *task);
  153. #endif /* _ASM_SYSCALL_H */