syscall.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. * asm-ARCH/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_rollback - roll back registers after an aborted system call
  38. * @task: task of interest, must be in system call exit tracing
  39. * @regs: task_pt_regs() of @task
  40. *
  41. * It's only valid to call this when @task is stopped for system
  42. * call exit tracing (due to %SYSCALL_WORK_SYSCALL_TRACE or
  43. * %SYSCALL_WORK_SYSCALL_AUDIT), after ptrace_report_syscall_entry()
  44. * returned nonzero to prevent the system call from taking place.
  45. *
  46. * This rolls back the register state in @regs so it's as if the
  47. * system call instruction was a no-op. The registers containing
  48. * the system call number and arguments are as they were before the
  49. * system call instruction. This may not be the same as what the
  50. * register state looked like at system call entry tracing.
  51. */
  52. void syscall_rollback(struct task_struct *task, struct pt_regs *regs);
  53. /**
  54. * syscall_get_error - check result of traced system call
  55. * @task: task of interest, must be blocked
  56. * @regs: task_pt_regs() of @task
  57. *
  58. * Returns 0 if the system call succeeded, or -ERRORCODE if it failed.
  59. *
  60. * It's only valid to call this when @task is stopped for tracing on exit
  61. * from a system call, due to %SYSCALL_WORK_SYSCALL_TRACE or
  62. * %SYSCALL_WORK_SYSCALL_AUDIT.
  63. */
  64. long syscall_get_error(struct task_struct *task, struct pt_regs *regs);
  65. /**
  66. * syscall_get_return_value - get the return value of a traced system call
  67. * @task: task of interest, must be blocked
  68. * @regs: task_pt_regs() of @task
  69. *
  70. * Returns the return value of the successful system call.
  71. * This value is meaningless if syscall_get_error() returned nonzero.
  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_return_value(struct task_struct *task, struct pt_regs *regs);
  78. /**
  79. * syscall_set_return_value - change the return value of a traced system call
  80. * @task: task of interest, must be blocked
  81. * @regs: task_pt_regs() of @task
  82. * @error: negative error code, or zero to indicate success
  83. * @val: user return value if @error is zero
  84. *
  85. * This changes the results of the system call that user mode will see.
  86. * If @error is zero, the user sees a successful system call with a
  87. * return value of @val. If @error is nonzero, it's a negated errno
  88. * code; the user sees a failed system call with this errno code.
  89. *
  90. * It's only valid to call this when @task is stopped for tracing on exit
  91. * from a system call, due to %SYSCALL_WORK_SYSCALL_TRACE or
  92. * %SYSCALL_WORK_SYSCALL_AUDIT.
  93. */
  94. void syscall_set_return_value(struct task_struct *task, struct pt_regs *regs,
  95. int error, long val);
  96. /**
  97. * syscall_get_arguments - extract system call parameter values
  98. * @task: task of interest, must be blocked
  99. * @regs: task_pt_regs() of @task
  100. * @args: array filled with argument values
  101. *
  102. * Fetches 6 arguments to the system call. First argument is stored in
  103. * @args[0], and so on.
  104. *
  105. * It's only valid to call this when @task is stopped for tracing on
  106. * entry to a system call, due to %SYSCALL_WORK_SYSCALL_TRACE or
  107. * %SYSCALL_WORK_SYSCALL_AUDIT.
  108. */
  109. void syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
  110. unsigned long *args);
  111. /**
  112. * syscall_get_arch - return the AUDIT_ARCH for the current system call
  113. * @task: task of interest, must be blocked
  114. *
  115. * Returns the AUDIT_ARCH_* based on the system call convention in use.
  116. *
  117. * It's only valid to call this when @task is stopped on entry to a system
  118. * call, due to %SYSCALL_WORK_SYSCALL_TRACE, %SYSCALL_WORK_SYSCALL_AUDIT, or
  119. * %SYSCALL_WORK_SECCOMP.
  120. *
  121. * Architectures which permit CONFIG_HAVE_ARCH_SECCOMP_FILTER must
  122. * provide an implementation of this.
  123. */
  124. int syscall_get_arch(struct task_struct *task);
  125. #endif /* _ASM_SYSCALL_H */