18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Access to user system call parameters and results
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * See asm-generic/syscall.h for descriptions of what we must do here.
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef _ASM_ARM_SYSCALL_H
98c2ecf20Sopenharmony_ci#define _ASM_ARM_SYSCALL_H
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <uapi/linux/audit.h> /* for AUDIT_ARCH_* */
128c2ecf20Sopenharmony_ci#include <linux/elf.h> /* for ELF_EM */
138c2ecf20Sopenharmony_ci#include <linux/err.h>
148c2ecf20Sopenharmony_ci#include <linux/sched.h>
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#include <asm/unistd.h>
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#define NR_syscalls (__NR_syscalls)
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ciextern const unsigned long sys_call_table[];
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_cistatic inline int syscall_get_nr(struct task_struct *task,
238c2ecf20Sopenharmony_ci				 struct pt_regs *regs)
248c2ecf20Sopenharmony_ci{
258c2ecf20Sopenharmony_ci	return task_thread_info(task)->syscall;
268c2ecf20Sopenharmony_ci}
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_cistatic inline void syscall_rollback(struct task_struct *task,
298c2ecf20Sopenharmony_ci				    struct pt_regs *regs)
308c2ecf20Sopenharmony_ci{
318c2ecf20Sopenharmony_ci	regs->ARM_r0 = regs->ARM_ORIG_r0;
328c2ecf20Sopenharmony_ci}
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_cistatic inline long syscall_get_error(struct task_struct *task,
358c2ecf20Sopenharmony_ci				     struct pt_regs *regs)
368c2ecf20Sopenharmony_ci{
378c2ecf20Sopenharmony_ci	unsigned long error = regs->ARM_r0;
388c2ecf20Sopenharmony_ci	return IS_ERR_VALUE(error) ? error : 0;
398c2ecf20Sopenharmony_ci}
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_cistatic inline long syscall_get_return_value(struct task_struct *task,
428c2ecf20Sopenharmony_ci					    struct pt_regs *regs)
438c2ecf20Sopenharmony_ci{
448c2ecf20Sopenharmony_ci	return regs->ARM_r0;
458c2ecf20Sopenharmony_ci}
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_cistatic inline void syscall_set_return_value(struct task_struct *task,
488c2ecf20Sopenharmony_ci					    struct pt_regs *regs,
498c2ecf20Sopenharmony_ci					    int error, long val)
508c2ecf20Sopenharmony_ci{
518c2ecf20Sopenharmony_ci	regs->ARM_r0 = (long) error ? error : val;
528c2ecf20Sopenharmony_ci}
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci#define SYSCALL_MAX_ARGS 7
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cistatic inline void syscall_get_arguments(struct task_struct *task,
578c2ecf20Sopenharmony_ci					 struct pt_regs *regs,
588c2ecf20Sopenharmony_ci					 unsigned long *args)
598c2ecf20Sopenharmony_ci{
608c2ecf20Sopenharmony_ci	args[0] = regs->ARM_ORIG_r0;
618c2ecf20Sopenharmony_ci	args++;
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci	memcpy(args, &regs->ARM_r0 + 1, 5 * sizeof(args[0]));
648c2ecf20Sopenharmony_ci}
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_cistatic inline void syscall_set_arguments(struct task_struct *task,
678c2ecf20Sopenharmony_ci					 struct pt_regs *regs,
688c2ecf20Sopenharmony_ci					 const unsigned long *args)
698c2ecf20Sopenharmony_ci{
708c2ecf20Sopenharmony_ci	regs->ARM_ORIG_r0 = args[0];
718c2ecf20Sopenharmony_ci	args++;
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci	memcpy(&regs->ARM_r0 + 1, args, 5 * sizeof(args[0]));
748c2ecf20Sopenharmony_ci}
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_cistatic inline int syscall_get_arch(struct task_struct *task)
778c2ecf20Sopenharmony_ci{
788c2ecf20Sopenharmony_ci	/* ARM tasks don't change audit architectures on the fly. */
798c2ecf20Sopenharmony_ci	return AUDIT_ARCH_ARM;
808c2ecf20Sopenharmony_ci}
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci#endif /* _ASM_ARM_SYSCALL_H */
83