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