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