syscall.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Access to user system call parameters and results
  3. *
  4. * Copyright (C) 2008-2009 Red Hat, Inc. All rights reserved.
  5. *
  6. * This copyrighted material is made available to anyone wishing to use,
  7. * modify, copy, or redistribute it subject to the terms and conditions
  8. * of the GNU General Public License v.2.
  9. *
  10. * This file is a stub providing documentation for what functions
  11. * asm-ARCH/syscall.h files need to define. Most arch definitions
  12. * will be simple inlines.
  13. *
  14. * All of these functions expect to be called with no locks,
  15. * and only when the caller is sure that the task of interest
  16. * cannot return to user mode while we are looking at it.
  17. */
  18. #ifndef _ASM_SYSCALL_H
  19. #define _ASM_SYSCALL_H 1
  20. struct task_struct;
  21. struct pt_regs;
  22. /**
  23. * syscall_get_nr - find what system call a task is executing
  24. * @task: task of interest, must be blocked
  25. * @regs: task_pt_regs() of @task
  26. *
  27. * If @task is executing a system call or is at system call
  28. * tracing about to attempt one, returns the system call number.
  29. * If @task is not executing a system call, i.e. it's blocked
  30. * inside the kernel for a fault or signal, returns -1.
  31. *
  32. * Note this returns int even on 64-bit machines. Only 32 bits of
  33. * system call number can be meaningful. If the actual arch value
  34. * is 64 bits, this truncates to 32 bits so 0xffffffff means -1.
  35. *
  36. * It's only valid to call this when @task is known to be blocked.
  37. */
  38. int syscall_get_nr(struct task_struct *task, struct pt_regs *regs);
  39. /**
  40. * syscall_rollback - roll back registers after an aborted system call
  41. * @task: task of interest, must be in system call exit tracing
  42. * @regs: task_pt_regs() of @task
  43. *
  44. * It's only valid to call this when @task is stopped for system
  45. * call exit tracing (due to TIF_SYSCALL_TRACE or TIF_SYSCALL_AUDIT),
  46. * after tracehook_report_syscall_entry() returned nonzero to prevent
  47. * the system call from taking place.
  48. *
  49. * This rolls back the register state in @regs so it's as if the
  50. * system call instruction was a no-op. The registers containing
  51. * the system call number and arguments are as they were before the
  52. * system call instruction. This may not be the same as what the
  53. * register state looked like at system call entry tracing.
  54. */
  55. void syscall_rollback(struct task_struct *task, struct pt_regs *regs);
  56. /**
  57. * syscall_get_error - check result of traced system call
  58. * @task: task of interest, must be blocked
  59. * @regs: task_pt_regs() of @task
  60. *
  61. * Returns 0 if the system call succeeded, or -ERRORCODE if it failed.
  62. *
  63. * It's only valid to call this when @task is stopped for tracing on exit
  64. * from a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
  65. */
  66. long syscall_get_error(struct task_struct *task, struct pt_regs *regs);
  67. /**
  68. * syscall_get_return_value - get the return value of a traced system call
  69. * @task: task of interest, must be blocked
  70. * @regs: task_pt_regs() of @task
  71. *
  72. * Returns the return value of the successful system call.
  73. * This value is meaningless if syscall_get_error() returned nonzero.
  74. *
  75. * It's only valid to call this when @task is stopped for tracing on exit
  76. * from a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
  77. */
  78. long syscall_get_return_value(struct task_struct *task, struct pt_regs *regs);
  79. /**
  80. * syscall_set_return_value - change the return value of a traced system call
  81. * @task: task of interest, must be blocked
  82. * @regs: task_pt_regs() of @task
  83. * @error: negative error code, or zero to indicate success
  84. * @val: user return value if @error is zero
  85. *
  86. * This changes the results of the system call that user mode will see.
  87. * If @error is zero, the user sees a successful system call with a
  88. * return value of @val. If @error is nonzero, it's a negated errno
  89. * code; the user sees a failed system call with this errno code.
  90. *
  91. * It's only valid to call this when @task is stopped for tracing on exit
  92. * from a system call, due to %TIF_SYSCALL_TRACE or %TIF_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. * @i: argument index [0,5]
  101. * @n: number of arguments; n+i must be [1,6].
  102. * @args: array filled with argument values
  103. *
  104. * Fetches @n arguments to the system call starting with the @i'th argument
  105. * (from 0 through 5). Argument @i is stored in @args[0], and so on.
  106. * An arch inline version is probably optimal when @i and @n are constants.
  107. *
  108. * It's only valid to call this when @task is stopped for tracing on
  109. * entry to a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
  110. * It's invalid to call this with @i + @n > 6; we only support system calls
  111. * taking up to 6 arguments.
  112. */
  113. void syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
  114. unsigned int i, unsigned int n, unsigned long *args);
  115. /**
  116. * syscall_set_arguments - change system call parameter value
  117. * @task: task of interest, must be in system call entry tracing
  118. * @regs: task_pt_regs() of @task
  119. * @i: argument index [0,5]
  120. * @n: number of arguments; n+i must be [1,6].
  121. * @args: array of argument values to store
  122. *
  123. * Changes @n arguments to the system call starting with the @i'th argument.
  124. * Argument @i gets value @args[0], and so on.
  125. * An arch inline version is probably optimal when @i and @n are constants.
  126. *
  127. * It's only valid to call this when @task is stopped for tracing on
  128. * entry to a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
  129. * It's invalid to call this with @i + @n > 6; we only support system calls
  130. * taking up to 6 arguments.
  131. */
  132. void syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
  133. unsigned int i, unsigned int n,
  134. const unsigned long *args);
  135. #endif /* _ASM_SYSCALL_H */