18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Access to user system call parameters and results
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2008-2009 Red Hat, Inc.  All rights reserved.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * This file is a stub providing documentation for what functions
88c2ecf20Sopenharmony_ci * asm-ARCH/syscall.h files need to define.  Most arch definitions
98c2ecf20Sopenharmony_ci * will be simple inlines.
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * All of these functions expect to be called with no locks,
128c2ecf20Sopenharmony_ci * and only when the caller is sure that the task of interest
138c2ecf20Sopenharmony_ci * cannot return to user mode while we are looking at it.
148c2ecf20Sopenharmony_ci */
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#ifndef _ASM_SYSCALL_H
178c2ecf20Sopenharmony_ci#define _ASM_SYSCALL_H	1
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_cistruct task_struct;
208c2ecf20Sopenharmony_cistruct pt_regs;
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci/**
238c2ecf20Sopenharmony_ci * syscall_get_nr - find what system call a task is executing
248c2ecf20Sopenharmony_ci * @task:	task of interest, must be blocked
258c2ecf20Sopenharmony_ci * @regs:	task_pt_regs() of @task
268c2ecf20Sopenharmony_ci *
278c2ecf20Sopenharmony_ci * If @task is executing a system call or is at system call
288c2ecf20Sopenharmony_ci * tracing about to attempt one, returns the system call number.
298c2ecf20Sopenharmony_ci * If @task is not executing a system call, i.e. it's blocked
308c2ecf20Sopenharmony_ci * inside the kernel for a fault or signal, returns -1.
318c2ecf20Sopenharmony_ci *
328c2ecf20Sopenharmony_ci * Note this returns int even on 64-bit machines.  Only 32 bits of
338c2ecf20Sopenharmony_ci * system call number can be meaningful.  If the actual arch value
348c2ecf20Sopenharmony_ci * is 64 bits, this truncates to 32 bits so 0xffffffff means -1.
358c2ecf20Sopenharmony_ci *
368c2ecf20Sopenharmony_ci * It's only valid to call this when @task is known to be blocked.
378c2ecf20Sopenharmony_ci */
388c2ecf20Sopenharmony_ciint syscall_get_nr(struct task_struct *task, struct pt_regs *regs);
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci/**
418c2ecf20Sopenharmony_ci * syscall_rollback - roll back registers after an aborted system call
428c2ecf20Sopenharmony_ci * @task:	task of interest, must be in system call exit tracing
438c2ecf20Sopenharmony_ci * @regs:	task_pt_regs() of @task
448c2ecf20Sopenharmony_ci *
458c2ecf20Sopenharmony_ci * It's only valid to call this when @task is stopped for system
468c2ecf20Sopenharmony_ci * call exit tracing (due to TIF_SYSCALL_TRACE or TIF_SYSCALL_AUDIT),
478c2ecf20Sopenharmony_ci * after tracehook_report_syscall_entry() returned nonzero to prevent
488c2ecf20Sopenharmony_ci * the system call from taking place.
498c2ecf20Sopenharmony_ci *
508c2ecf20Sopenharmony_ci * This rolls back the register state in @regs so it's as if the
518c2ecf20Sopenharmony_ci * system call instruction was a no-op.  The registers containing
528c2ecf20Sopenharmony_ci * the system call number and arguments are as they were before the
538c2ecf20Sopenharmony_ci * system call instruction.  This may not be the same as what the
548c2ecf20Sopenharmony_ci * register state looked like at system call entry tracing.
558c2ecf20Sopenharmony_ci */
568c2ecf20Sopenharmony_civoid syscall_rollback(struct task_struct *task, struct pt_regs *regs);
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci/**
598c2ecf20Sopenharmony_ci * syscall_get_error - check result of traced system call
608c2ecf20Sopenharmony_ci * @task:	task of interest, must be blocked
618c2ecf20Sopenharmony_ci * @regs:	task_pt_regs() of @task
628c2ecf20Sopenharmony_ci *
638c2ecf20Sopenharmony_ci * Returns 0 if the system call succeeded, or -ERRORCODE if it failed.
648c2ecf20Sopenharmony_ci *
658c2ecf20Sopenharmony_ci * It's only valid to call this when @task is stopped for tracing on exit
668c2ecf20Sopenharmony_ci * from a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
678c2ecf20Sopenharmony_ci */
688c2ecf20Sopenharmony_cilong syscall_get_error(struct task_struct *task, struct pt_regs *regs);
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci/**
718c2ecf20Sopenharmony_ci * syscall_get_return_value - get the return value of a traced system call
728c2ecf20Sopenharmony_ci * @task:	task of interest, must be blocked
738c2ecf20Sopenharmony_ci * @regs:	task_pt_regs() of @task
748c2ecf20Sopenharmony_ci *
758c2ecf20Sopenharmony_ci * Returns the return value of the successful system call.
768c2ecf20Sopenharmony_ci * This value is meaningless if syscall_get_error() returned nonzero.
778c2ecf20Sopenharmony_ci *
788c2ecf20Sopenharmony_ci * It's only valid to call this when @task is stopped for tracing on exit
798c2ecf20Sopenharmony_ci * from a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
808c2ecf20Sopenharmony_ci */
818c2ecf20Sopenharmony_cilong syscall_get_return_value(struct task_struct *task, struct pt_regs *regs);
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci/**
848c2ecf20Sopenharmony_ci * syscall_set_return_value - change the return value of a traced system call
858c2ecf20Sopenharmony_ci * @task:	task of interest, must be blocked
868c2ecf20Sopenharmony_ci * @regs:	task_pt_regs() of @task
878c2ecf20Sopenharmony_ci * @error:	negative error code, or zero to indicate success
888c2ecf20Sopenharmony_ci * @val:	user return value if @error is zero
898c2ecf20Sopenharmony_ci *
908c2ecf20Sopenharmony_ci * This changes the results of the system call that user mode will see.
918c2ecf20Sopenharmony_ci * If @error is zero, the user sees a successful system call with a
928c2ecf20Sopenharmony_ci * return value of @val.  If @error is nonzero, it's a negated errno
938c2ecf20Sopenharmony_ci * code; the user sees a failed system call with this errno code.
948c2ecf20Sopenharmony_ci *
958c2ecf20Sopenharmony_ci * It's only valid to call this when @task is stopped for tracing on exit
968c2ecf20Sopenharmony_ci * from a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
978c2ecf20Sopenharmony_ci */
988c2ecf20Sopenharmony_civoid syscall_set_return_value(struct task_struct *task, struct pt_regs *regs,
998c2ecf20Sopenharmony_ci			      int error, long val);
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci/**
1028c2ecf20Sopenharmony_ci * syscall_get_arguments - extract system call parameter values
1038c2ecf20Sopenharmony_ci * @task:	task of interest, must be blocked
1048c2ecf20Sopenharmony_ci * @regs:	task_pt_regs() of @task
1058c2ecf20Sopenharmony_ci * @args:	array filled with argument values
1068c2ecf20Sopenharmony_ci *
1078c2ecf20Sopenharmony_ci * Fetches 6 arguments to the system call.  First argument is stored in
1088c2ecf20Sopenharmony_ci*  @args[0], and so on.
1098c2ecf20Sopenharmony_ci *
1108c2ecf20Sopenharmony_ci * It's only valid to call this when @task is stopped for tracing on
1118c2ecf20Sopenharmony_ci * entry to a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
1128c2ecf20Sopenharmony_ci */
1138c2ecf20Sopenharmony_civoid syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
1148c2ecf20Sopenharmony_ci			   unsigned long *args);
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci/**
1178c2ecf20Sopenharmony_ci * syscall_set_arguments - change system call parameter value
1188c2ecf20Sopenharmony_ci * @task:	task of interest, must be in system call entry tracing
1198c2ecf20Sopenharmony_ci * @regs:	task_pt_regs() of @task
1208c2ecf20Sopenharmony_ci * @args:	array of argument values to store
1218c2ecf20Sopenharmony_ci *
1228c2ecf20Sopenharmony_ci * Changes 6 arguments to the system call.
1238c2ecf20Sopenharmony_ci * The first argument gets value @args[0], and so on.
1248c2ecf20Sopenharmony_ci *
1258c2ecf20Sopenharmony_ci * It's only valid to call this when @task is stopped for tracing on
1268c2ecf20Sopenharmony_ci * entry to a system call, due to %TIF_SYSCALL_TRACE or %TIF_SYSCALL_AUDIT.
1278c2ecf20Sopenharmony_ci */
1288c2ecf20Sopenharmony_civoid syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
1298c2ecf20Sopenharmony_ci			   const unsigned long *args);
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci/**
1328c2ecf20Sopenharmony_ci * syscall_get_arch - return the AUDIT_ARCH for the current system call
1338c2ecf20Sopenharmony_ci * @task:	task of interest, must be blocked
1348c2ecf20Sopenharmony_ci *
1358c2ecf20Sopenharmony_ci * Returns the AUDIT_ARCH_* based on the system call convention in use.
1368c2ecf20Sopenharmony_ci *
1378c2ecf20Sopenharmony_ci * It's only valid to call this when @task is stopped on entry to a system
1388c2ecf20Sopenharmony_ci * call, due to %TIF_SYSCALL_TRACE, %TIF_SYSCALL_AUDIT, or %TIF_SECCOMP.
1398c2ecf20Sopenharmony_ci *
1408c2ecf20Sopenharmony_ci * Architectures which permit CONFIG_HAVE_ARCH_SECCOMP_FILTER must
1418c2ecf20Sopenharmony_ci * provide an implementation of this.
1428c2ecf20Sopenharmony_ci */
1438c2ecf20Sopenharmony_ciint syscall_get_arch(struct task_struct *task);
1448c2ecf20Sopenharmony_ci#endif	/* _ASM_SYSCALL_H */
145