162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Access to user system call parameters and results
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (C) 2008-2009 Red Hat, Inc.  All rights reserved.
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * This file is a stub providing documentation for what functions
862306a36Sopenharmony_ci * asm-ARCH/syscall.h files need to define.  Most arch definitions
962306a36Sopenharmony_ci * will be simple inlines.
1062306a36Sopenharmony_ci *
1162306a36Sopenharmony_ci * All of these functions expect to be called with no locks,
1262306a36Sopenharmony_ci * and only when the caller is sure that the task of interest
1362306a36Sopenharmony_ci * cannot return to user mode while we are looking at it.
1462306a36Sopenharmony_ci */
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#ifndef _ASM_SYSCALL_H
1762306a36Sopenharmony_ci#define _ASM_SYSCALL_H	1
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_cistruct task_struct;
2062306a36Sopenharmony_cistruct pt_regs;
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci/**
2362306a36Sopenharmony_ci * syscall_get_nr - find what system call a task is executing
2462306a36Sopenharmony_ci * @task:	task of interest, must be blocked
2562306a36Sopenharmony_ci * @regs:	task_pt_regs() of @task
2662306a36Sopenharmony_ci *
2762306a36Sopenharmony_ci * If @task is executing a system call or is at system call
2862306a36Sopenharmony_ci * tracing about to attempt one, returns the system call number.
2962306a36Sopenharmony_ci * If @task is not executing a system call, i.e. it's blocked
3062306a36Sopenharmony_ci * inside the kernel for a fault or signal, returns -1.
3162306a36Sopenharmony_ci *
3262306a36Sopenharmony_ci * Note this returns int even on 64-bit machines.  Only 32 bits of
3362306a36Sopenharmony_ci * system call number can be meaningful.  If the actual arch value
3462306a36Sopenharmony_ci * is 64 bits, this truncates to 32 bits so 0xffffffff means -1.
3562306a36Sopenharmony_ci *
3662306a36Sopenharmony_ci * It's only valid to call this when @task is known to be blocked.
3762306a36Sopenharmony_ci */
3862306a36Sopenharmony_ciint syscall_get_nr(struct task_struct *task, struct pt_regs *regs);
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci/**
4162306a36Sopenharmony_ci * syscall_rollback - roll back registers after an aborted system call
4262306a36Sopenharmony_ci * @task:	task of interest, must be in system call exit tracing
4362306a36Sopenharmony_ci * @regs:	task_pt_regs() of @task
4462306a36Sopenharmony_ci *
4562306a36Sopenharmony_ci * It's only valid to call this when @task is stopped for system
4662306a36Sopenharmony_ci * call exit tracing (due to %SYSCALL_WORK_SYSCALL_TRACE or
4762306a36Sopenharmony_ci * %SYSCALL_WORK_SYSCALL_AUDIT), after ptrace_report_syscall_entry()
4862306a36Sopenharmony_ci * returned nonzero to prevent the system call from taking place.
4962306a36Sopenharmony_ci *
5062306a36Sopenharmony_ci * This rolls back the register state in @regs so it's as if the
5162306a36Sopenharmony_ci * system call instruction was a no-op.  The registers containing
5262306a36Sopenharmony_ci * the system call number and arguments are as they were before the
5362306a36Sopenharmony_ci * system call instruction.  This may not be the same as what the
5462306a36Sopenharmony_ci * register state looked like at system call entry tracing.
5562306a36Sopenharmony_ci */
5662306a36Sopenharmony_civoid syscall_rollback(struct task_struct *task, struct pt_regs *regs);
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci/**
5962306a36Sopenharmony_ci * syscall_get_error - check result of traced system call
6062306a36Sopenharmony_ci * @task:	task of interest, must be blocked
6162306a36Sopenharmony_ci * @regs:	task_pt_regs() of @task
6262306a36Sopenharmony_ci *
6362306a36Sopenharmony_ci * Returns 0 if the system call succeeded, or -ERRORCODE if it failed.
6462306a36Sopenharmony_ci *
6562306a36Sopenharmony_ci * It's only valid to call this when @task is stopped for tracing on exit
6662306a36Sopenharmony_ci * from a system call, due to %SYSCALL_WORK_SYSCALL_TRACE or
6762306a36Sopenharmony_ci * %SYSCALL_WORK_SYSCALL_AUDIT.
6862306a36Sopenharmony_ci */
6962306a36Sopenharmony_cilong syscall_get_error(struct task_struct *task, struct pt_regs *regs);
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci/**
7262306a36Sopenharmony_ci * syscall_get_return_value - get the return value of a traced system call
7362306a36Sopenharmony_ci * @task:	task of interest, must be blocked
7462306a36Sopenharmony_ci * @regs:	task_pt_regs() of @task
7562306a36Sopenharmony_ci *
7662306a36Sopenharmony_ci * Returns the return value of the successful system call.
7762306a36Sopenharmony_ci * This value is meaningless if syscall_get_error() returned nonzero.
7862306a36Sopenharmony_ci *
7962306a36Sopenharmony_ci * It's only valid to call this when @task is stopped for tracing on exit
8062306a36Sopenharmony_ci * from a system call, due to %SYSCALL_WORK_SYSCALL_TRACE or
8162306a36Sopenharmony_ci * %SYSCALL_WORK_SYSCALL_AUDIT.
8262306a36Sopenharmony_ci */
8362306a36Sopenharmony_cilong syscall_get_return_value(struct task_struct *task, struct pt_regs *regs);
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci/**
8662306a36Sopenharmony_ci * syscall_set_return_value - change the return value of a traced system call
8762306a36Sopenharmony_ci * @task:	task of interest, must be blocked
8862306a36Sopenharmony_ci * @regs:	task_pt_regs() of @task
8962306a36Sopenharmony_ci * @error:	negative error code, or zero to indicate success
9062306a36Sopenharmony_ci * @val:	user return value if @error is zero
9162306a36Sopenharmony_ci *
9262306a36Sopenharmony_ci * This changes the results of the system call that user mode will see.
9362306a36Sopenharmony_ci * If @error is zero, the user sees a successful system call with a
9462306a36Sopenharmony_ci * return value of @val.  If @error is nonzero, it's a negated errno
9562306a36Sopenharmony_ci * code; the user sees a failed system call with this errno code.
9662306a36Sopenharmony_ci *
9762306a36Sopenharmony_ci * It's only valid to call this when @task is stopped for tracing on exit
9862306a36Sopenharmony_ci * from a system call, due to %SYSCALL_WORK_SYSCALL_TRACE or
9962306a36Sopenharmony_ci * %SYSCALL_WORK_SYSCALL_AUDIT.
10062306a36Sopenharmony_ci */
10162306a36Sopenharmony_civoid syscall_set_return_value(struct task_struct *task, struct pt_regs *regs,
10262306a36Sopenharmony_ci			      int error, long val);
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci/**
10562306a36Sopenharmony_ci * syscall_get_arguments - extract system call parameter values
10662306a36Sopenharmony_ci * @task:	task of interest, must be blocked
10762306a36Sopenharmony_ci * @regs:	task_pt_regs() of @task
10862306a36Sopenharmony_ci * @args:	array filled with argument values
10962306a36Sopenharmony_ci *
11062306a36Sopenharmony_ci * Fetches 6 arguments to the system call.  First argument is stored in
11162306a36Sopenharmony_ci*  @args[0], and so on.
11262306a36Sopenharmony_ci *
11362306a36Sopenharmony_ci * It's only valid to call this when @task is stopped for tracing on
11462306a36Sopenharmony_ci * entry to a system call, due to %SYSCALL_WORK_SYSCALL_TRACE or
11562306a36Sopenharmony_ci * %SYSCALL_WORK_SYSCALL_AUDIT.
11662306a36Sopenharmony_ci */
11762306a36Sopenharmony_civoid syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
11862306a36Sopenharmony_ci			   unsigned long *args);
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ci/**
12162306a36Sopenharmony_ci * syscall_get_arch - return the AUDIT_ARCH for the current system call
12262306a36Sopenharmony_ci * @task:	task of interest, must be blocked
12362306a36Sopenharmony_ci *
12462306a36Sopenharmony_ci * Returns the AUDIT_ARCH_* based on the system call convention in use.
12562306a36Sopenharmony_ci *
12662306a36Sopenharmony_ci * It's only valid to call this when @task is stopped on entry to a system
12762306a36Sopenharmony_ci * call, due to %SYSCALL_WORK_SYSCALL_TRACE, %SYSCALL_WORK_SYSCALL_AUDIT, or
12862306a36Sopenharmony_ci * %SYSCALL_WORK_SECCOMP.
12962306a36Sopenharmony_ci *
13062306a36Sopenharmony_ci * Architectures which permit CONFIG_HAVE_ARCH_SECCOMP_FILTER must
13162306a36Sopenharmony_ci * provide an implementation of this.
13262306a36Sopenharmony_ci */
13362306a36Sopenharmony_ciint syscall_get_arch(struct task_struct *task);
13462306a36Sopenharmony_ci#endif	/* _ASM_SYSCALL_H */
135