xref: /linux-6.15/include/asm-generic/syscall.h (revision 7a77edf4)
12522fe45SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2828c365cSRoland McGrath /*
3828c365cSRoland McGrath  * Access to user system call parameters and results
4828c365cSRoland McGrath  *
5268e4671SRoland McGrath  * Copyright (C) 2008-2009 Red Hat, Inc.  All rights reserved.
6828c365cSRoland McGrath  *
7828c365cSRoland McGrath  * This file is a stub providing documentation for what functions
8*7a77edf4SGeert Uytterhoeven  * arch/ARCH/include/asm/syscall.h files need to define.  Most arch definitions
9828c365cSRoland McGrath  * will be simple inlines.
10828c365cSRoland McGrath  *
11828c365cSRoland McGrath  * All of these functions expect to be called with no locks,
12828c365cSRoland McGrath  * and only when the caller is sure that the task of interest
13828c365cSRoland McGrath  * cannot return to user mode while we are looking at it.
14828c365cSRoland McGrath  */
15828c365cSRoland McGrath 
16828c365cSRoland McGrath #ifndef _ASM_SYSCALL_H
17828c365cSRoland McGrath #define _ASM_SYSCALL_H	1
18828c365cSRoland McGrath 
19828c365cSRoland McGrath struct task_struct;
20828c365cSRoland McGrath struct pt_regs;
21828c365cSRoland McGrath 
22828c365cSRoland McGrath /**
23828c365cSRoland McGrath  * syscall_get_nr - find what system call a task is executing
24828c365cSRoland McGrath  * @task:	task of interest, must be blocked
25828c365cSRoland McGrath  * @regs:	task_pt_regs() of @task
26828c365cSRoland McGrath  *
27828c365cSRoland McGrath  * If @task is executing a system call or is at system call
28828c365cSRoland McGrath  * tracing about to attempt one, returns the system call number.
29828c365cSRoland McGrath  * If @task is not executing a system call, i.e. it's blocked
30828c365cSRoland McGrath  * inside the kernel for a fault or signal, returns -1.
31828c365cSRoland McGrath  *
32268e4671SRoland McGrath  * Note this returns int even on 64-bit machines.  Only 32 bits of
33268e4671SRoland McGrath  * system call number can be meaningful.  If the actual arch value
34268e4671SRoland McGrath  * is 64 bits, this truncates to 32 bits so 0xffffffff means -1.
35268e4671SRoland McGrath  *
36828c365cSRoland McGrath  * It's only valid to call this when @task is known to be blocked.
37828c365cSRoland McGrath  */
38268e4671SRoland McGrath int syscall_get_nr(struct task_struct *task, struct pt_regs *regs);
39828c365cSRoland McGrath 
40828c365cSRoland McGrath /**
41828c365cSRoland McGrath  * syscall_rollback - roll back registers after an aborted system call
42828c365cSRoland McGrath  * @task:	task of interest, must be in system call exit tracing
43828c365cSRoland McGrath  * @regs:	task_pt_regs() of @task
44828c365cSRoland McGrath  *
45828c365cSRoland McGrath  * It's only valid to call this when @task is stopped for system
46785dc4ebSGabriel Krisman Bertazi  * call exit tracing (due to %SYSCALL_WORK_SYSCALL_TRACE or
47153474baSEric W. Biederman  * %SYSCALL_WORK_SYSCALL_AUDIT), after ptrace_report_syscall_entry()
48785dc4ebSGabriel Krisman Bertazi  * returned nonzero to prevent the system call from taking place.
49828c365cSRoland McGrath  *
50828c365cSRoland McGrath  * This rolls back the register state in @regs so it's as if the
51828c365cSRoland McGrath  * system call instruction was a no-op.  The registers containing
52828c365cSRoland McGrath  * the system call number and arguments are as they were before the
53828c365cSRoland McGrath  * system call instruction.  This may not be the same as what the
54828c365cSRoland McGrath  * register state looked like at system call entry tracing.
55828c365cSRoland McGrath  */
56828c365cSRoland McGrath void syscall_rollback(struct task_struct *task, struct pt_regs *regs);
57828c365cSRoland McGrath 
58828c365cSRoland McGrath /**
59828c365cSRoland McGrath  * syscall_get_error - check result of traced system call
60828c365cSRoland McGrath  * @task:	task of interest, must be blocked
61828c365cSRoland McGrath  * @regs:	task_pt_regs() of @task
62828c365cSRoland McGrath  *
63828c365cSRoland McGrath  * Returns 0 if the system call succeeded, or -ERRORCODE if it failed.
64828c365cSRoland McGrath  *
65828c365cSRoland McGrath  * It's only valid to call this when @task is stopped for tracing on exit
66785dc4ebSGabriel Krisman Bertazi  * from a system call, due to %SYSCALL_WORK_SYSCALL_TRACE or
67785dc4ebSGabriel Krisman Bertazi  * %SYSCALL_WORK_SYSCALL_AUDIT.
68828c365cSRoland McGrath  */
69828c365cSRoland McGrath long syscall_get_error(struct task_struct *task, struct pt_regs *regs);
70828c365cSRoland McGrath 
71828c365cSRoland McGrath /**
72828c365cSRoland McGrath  * syscall_get_return_value - get the return value of a traced system call
73828c365cSRoland McGrath  * @task:	task of interest, must be blocked
74828c365cSRoland McGrath  * @regs:	task_pt_regs() of @task
75828c365cSRoland McGrath  *
76828c365cSRoland McGrath  * Returns the return value of the successful system call.
77828c365cSRoland McGrath  * This value is meaningless if syscall_get_error() returned nonzero.
78828c365cSRoland McGrath  *
79828c365cSRoland McGrath  * It's only valid to call this when @task is stopped for tracing on exit
80785dc4ebSGabriel Krisman Bertazi  * from a system call, due to %SYSCALL_WORK_SYSCALL_TRACE or
81785dc4ebSGabriel Krisman Bertazi  * %SYSCALL_WORK_SYSCALL_AUDIT.
82828c365cSRoland McGrath  */
83828c365cSRoland McGrath long syscall_get_return_value(struct task_struct *task, struct pt_regs *regs);
84828c365cSRoland McGrath 
85828c365cSRoland McGrath /**
86828c365cSRoland McGrath  * syscall_set_return_value - change the return value of a traced system call
87828c365cSRoland McGrath  * @task:	task of interest, must be blocked
88828c365cSRoland McGrath  * @regs:	task_pt_regs() of @task
89828c365cSRoland McGrath  * @error:	negative error code, or zero to indicate success
90828c365cSRoland McGrath  * @val:	user return value if @error is zero
91828c365cSRoland McGrath  *
92828c365cSRoland McGrath  * This changes the results of the system call that user mode will see.
93828c365cSRoland McGrath  * If @error is zero, the user sees a successful system call with a
94828c365cSRoland McGrath  * return value of @val.  If @error is nonzero, it's a negated errno
95828c365cSRoland McGrath  * code; the user sees a failed system call with this errno code.
96828c365cSRoland McGrath  *
97828c365cSRoland McGrath  * It's only valid to call this when @task is stopped for tracing on exit
98785dc4ebSGabriel Krisman Bertazi  * from a system call, due to %SYSCALL_WORK_SYSCALL_TRACE or
99785dc4ebSGabriel Krisman Bertazi  * %SYSCALL_WORK_SYSCALL_AUDIT.
100828c365cSRoland McGrath  */
101828c365cSRoland McGrath void syscall_set_return_value(struct task_struct *task, struct pt_regs *regs,
102828c365cSRoland McGrath 			      int error, long val);
103828c365cSRoland McGrath 
104828c365cSRoland McGrath /**
105828c365cSRoland McGrath  * syscall_get_arguments - extract system call parameter values
106828c365cSRoland McGrath  * @task:	task of interest, must be blocked
107828c365cSRoland McGrath  * @regs:	task_pt_regs() of @task
108828c365cSRoland McGrath  * @args:	array filled with argument values
109828c365cSRoland McGrath  *
110b35f549dSSteven Rostedt (Red Hat)  * Fetches 6 arguments to the system call.  First argument is stored in
111b35f549dSSteven Rostedt (Red Hat) *  @args[0], and so on.
112828c365cSRoland McGrath  *
113828c365cSRoland McGrath  * It's only valid to call this when @task is stopped for tracing on
114785dc4ebSGabriel Krisman Bertazi  * entry to a system call, due to %SYSCALL_WORK_SYSCALL_TRACE or
115785dc4ebSGabriel Krisman Bertazi  * %SYSCALL_WORK_SYSCALL_AUDIT.
116828c365cSRoland McGrath  */
117828c365cSRoland McGrath void syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
118b35f549dSSteven Rostedt (Red Hat) 			   unsigned long *args);
119828c365cSRoland McGrath 
120828c365cSRoland McGrath /**
12107bd18d0SWill Drewry  * syscall_get_arch - return the AUDIT_ARCH for the current system call
12216add411SDmitry V. Levin  * @task:	task of interest, must be blocked
12307bd18d0SWill Drewry  *
12407bd18d0SWill Drewry  * Returns the AUDIT_ARCH_* based on the system call convention in use.
12507bd18d0SWill Drewry  *
12616add411SDmitry V. Levin  * It's only valid to call this when @task is stopped on entry to a system
127785dc4ebSGabriel Krisman Bertazi  * call, due to %SYSCALL_WORK_SYSCALL_TRACE, %SYSCALL_WORK_SYSCALL_AUDIT, or
12864c19ba2SGabriel Krisman Bertazi  * %SYSCALL_WORK_SECCOMP.
12907bd18d0SWill Drewry  *
13007bd18d0SWill Drewry  * Architectures which permit CONFIG_HAVE_ARCH_SECCOMP_FILTER must
13107bd18d0SWill Drewry  * provide an implementation of this.
13207bd18d0SWill Drewry  */
13316add411SDmitry V. Levin int syscall_get_arch(struct task_struct *task);
134828c365cSRoland McGrath #endif	/* _ASM_SYSCALL_H */
135