blob: 81695eb02a129c186ceeffd458925baf810235ba [file] [log] [blame]
Thomas Gleixner2522fe42019-05-28 09:57:20 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Roland McGrath828c3652008-07-25 19:45:57 -07002/*
3 * Access to user system call parameters and results
4 *
Roland McGrath268e4672009-09-22 19:56:50 -07005 * Copyright (C) 2008-2009 Red Hat, Inc. All rights reserved.
Roland McGrath828c3652008-07-25 19:45:57 -07006 *
Roland McGrath828c3652008-07-25 19:45:57 -07007 * 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
16#ifndef _ASM_SYSCALL_H
17#define _ASM_SYSCALL_H 1
18
19struct task_struct;
20struct pt_regs;
21
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 *
Roland McGrath268e4672009-09-22 19:56:50 -070032 * 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 *
Roland McGrath828c3652008-07-25 19:45:57 -070036 * It's only valid to call this when @task is known to be blocked.
37 */
Roland McGrath268e4672009-09-22 19:56:50 -070038int syscall_get_nr(struct task_struct *task, struct pt_regs *regs);
Roland McGrath828c3652008-07-25 19:45:57 -070039
40/**
41 * syscall_rollback - roll back registers after an aborted system call
42 * @task: task of interest, must be in system call exit tracing
43 * @regs: task_pt_regs() of @task
44 *
45 * It's only valid to call this when @task is stopped for system
Gabriel Krisman Bertazi785dc4e2020-11-16 12:42:04 -050046 * call exit tracing (due to %SYSCALL_WORK_SYSCALL_TRACE or
47 * %SYSCALL_WORK_SYSCALL_AUDIT), after tracehook_report_syscall_entry()
48 * returned nonzero to prevent the system call from taking place.
Roland McGrath828c3652008-07-25 19:45:57 -070049 *
50 * This rolls back the register state in @regs so it's as if the
51 * system call instruction was a no-op. The registers containing
52 * the system call number and arguments are as they were before the
53 * system call instruction. This may not be the same as what the
54 * register state looked like at system call entry tracing.
55 */
56void syscall_rollback(struct task_struct *task, struct pt_regs *regs);
57
58/**
59 * syscall_get_error - check result of traced system call
60 * @task: task of interest, must be blocked
61 * @regs: task_pt_regs() of @task
62 *
63 * Returns 0 if the system call succeeded, or -ERRORCODE if it failed.
64 *
65 * It's only valid to call this when @task is stopped for tracing on exit
Gabriel Krisman Bertazi785dc4e2020-11-16 12:42:04 -050066 * from a system call, due to %SYSCALL_WORK_SYSCALL_TRACE or
67 * %SYSCALL_WORK_SYSCALL_AUDIT.
Roland McGrath828c3652008-07-25 19:45:57 -070068 */
69long syscall_get_error(struct task_struct *task, struct pt_regs *regs);
70
71/**
72 * syscall_get_return_value - get the return value of a traced system call
73 * @task: task of interest, must be blocked
74 * @regs: task_pt_regs() of @task
75 *
76 * Returns the return value of the successful system call.
77 * This value is meaningless if syscall_get_error() returned nonzero.
78 *
79 * It's only valid to call this when @task is stopped for tracing on exit
Gabriel Krisman Bertazi785dc4e2020-11-16 12:42:04 -050080 * from a system call, due to %SYSCALL_WORK_SYSCALL_TRACE or
81 * %SYSCALL_WORK_SYSCALL_AUDIT.
Roland McGrath828c3652008-07-25 19:45:57 -070082 */
83long syscall_get_return_value(struct task_struct *task, struct pt_regs *regs);
84
85/**
86 * syscall_set_return_value - change the return value of a traced system call
87 * @task: task of interest, must be blocked
88 * @regs: task_pt_regs() of @task
89 * @error: negative error code, or zero to indicate success
90 * @val: user return value if @error is zero
91 *
92 * This changes the results of the system call that user mode will see.
93 * If @error is zero, the user sees a successful system call with a
94 * return value of @val. If @error is nonzero, it's a negated errno
95 * code; the user sees a failed system call with this errno code.
96 *
97 * It's only valid to call this when @task is stopped for tracing on exit
Gabriel Krisman Bertazi785dc4e2020-11-16 12:42:04 -050098 * from a system call, due to %SYSCALL_WORK_SYSCALL_TRACE or
99 * %SYSCALL_WORK_SYSCALL_AUDIT.
Roland McGrath828c3652008-07-25 19:45:57 -0700100 */
101void syscall_set_return_value(struct task_struct *task, struct pt_regs *regs,
102 int error, long val);
103
104/**
105 * syscall_get_arguments - extract system call parameter values
106 * @task: task of interest, must be blocked
107 * @regs: task_pt_regs() of @task
Roland McGrath828c3652008-07-25 19:45:57 -0700108 * @args: array filled with argument values
109 *
Steven Rostedt (Red Hat)b35f5492016-11-07 16:26:37 -0500110 * Fetches 6 arguments to the system call. First argument is stored in
111* @args[0], and so on.
Roland McGrath828c3652008-07-25 19:45:57 -0700112 *
113 * It's only valid to call this when @task is stopped for tracing on
Gabriel Krisman Bertazi785dc4e2020-11-16 12:42:04 -0500114 * entry to a system call, due to %SYSCALL_WORK_SYSCALL_TRACE or
115 * %SYSCALL_WORK_SYSCALL_AUDIT.
Roland McGrath828c3652008-07-25 19:45:57 -0700116 */
117void syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
Steven Rostedt (Red Hat)b35f5492016-11-07 16:26:37 -0500118 unsigned long *args);
Roland McGrath828c3652008-07-25 19:45:57 -0700119
120/**
Will Drewry07bd18d2012-04-12 16:47:55 -0500121 * syscall_get_arch - return the AUDIT_ARCH for the current system call
Dmitry V. Levin16add412019-03-18 02:30:18 +0300122 * @task: task of interest, must be blocked
Will Drewry07bd18d2012-04-12 16:47:55 -0500123 *
124 * Returns the AUDIT_ARCH_* based on the system call convention in use.
125 *
Dmitry V. Levin16add412019-03-18 02:30:18 +0300126 * It's only valid to call this when @task is stopped on entry to a system
Gabriel Krisman Bertazi785dc4e2020-11-16 12:42:04 -0500127 * call, due to %SYSCALL_WORK_SYSCALL_TRACE, %SYSCALL_WORK_SYSCALL_AUDIT, or
Gabriel Krisman Bertazi64c19ba2020-11-16 12:42:02 -0500128 * %SYSCALL_WORK_SECCOMP.
Will Drewry07bd18d2012-04-12 16:47:55 -0500129 *
130 * Architectures which permit CONFIG_HAVE_ARCH_SECCOMP_FILTER must
131 * provide an implementation of this.
132 */
Dmitry V. Levin16add412019-03-18 02:30:18 +0300133int syscall_get_arch(struct task_struct *task);
Roland McGrath828c3652008-07-25 19:45:57 -0700134#endif /* _ASM_SYSCALL_H */