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 Intel Corp.  Shaohua Li <shaohua.li@intel.com>
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * See asm-generic/syscall.h for descriptions of what we must do here.
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#ifndef _ASM_SYSCALL_H
118c2ecf20Sopenharmony_ci#define _ASM_SYSCALL_H	1
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#include <uapi/linux/audit.h>
148c2ecf20Sopenharmony_ci#include <linux/sched.h>
158c2ecf20Sopenharmony_ci#include <linux/err.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_cistatic inline long syscall_get_nr(struct task_struct *task,
188c2ecf20Sopenharmony_ci				  struct pt_regs *regs)
198c2ecf20Sopenharmony_ci{
208c2ecf20Sopenharmony_ci	if ((long)regs->cr_ifs < 0) /* Not a syscall */
218c2ecf20Sopenharmony_ci		return -1;
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci	return regs->r15;
248c2ecf20Sopenharmony_ci}
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_cistatic inline void syscall_rollback(struct task_struct *task,
278c2ecf20Sopenharmony_ci				    struct pt_regs *regs)
288c2ecf20Sopenharmony_ci{
298c2ecf20Sopenharmony_ci	/* do nothing */
308c2ecf20Sopenharmony_ci}
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cistatic inline long syscall_get_error(struct task_struct *task,
338c2ecf20Sopenharmony_ci				     struct pt_regs *regs)
348c2ecf20Sopenharmony_ci{
358c2ecf20Sopenharmony_ci	return regs->r10 == -1 ? -regs->r8:0;
368c2ecf20Sopenharmony_ci}
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_cistatic inline long syscall_get_return_value(struct task_struct *task,
398c2ecf20Sopenharmony_ci					    struct pt_regs *regs)
408c2ecf20Sopenharmony_ci{
418c2ecf20Sopenharmony_ci	return regs->r8;
428c2ecf20Sopenharmony_ci}
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cistatic inline void syscall_set_return_value(struct task_struct *task,
458c2ecf20Sopenharmony_ci					    struct pt_regs *regs,
468c2ecf20Sopenharmony_ci					    int error, long val)
478c2ecf20Sopenharmony_ci{
488c2ecf20Sopenharmony_ci	if (error) {
498c2ecf20Sopenharmony_ci		/* error < 0, but ia64 uses > 0 return value */
508c2ecf20Sopenharmony_ci		regs->r8 = -error;
518c2ecf20Sopenharmony_ci		regs->r10 = -1;
528c2ecf20Sopenharmony_ci	} else {
538c2ecf20Sopenharmony_ci		regs->r8 = val;
548c2ecf20Sopenharmony_ci		regs->r10 = 0;
558c2ecf20Sopenharmony_ci	}
568c2ecf20Sopenharmony_ci}
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ciextern void ia64_syscall_get_set_arguments(struct task_struct *task,
598c2ecf20Sopenharmony_ci	struct pt_regs *regs, unsigned long *args, int rw);
608c2ecf20Sopenharmony_cistatic inline void syscall_get_arguments(struct task_struct *task,
618c2ecf20Sopenharmony_ci					 struct pt_regs *regs,
628c2ecf20Sopenharmony_ci					 unsigned long *args)
638c2ecf20Sopenharmony_ci{
648c2ecf20Sopenharmony_ci	ia64_syscall_get_set_arguments(task, regs, args, 0);
658c2ecf20Sopenharmony_ci}
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_cistatic inline void syscall_set_arguments(struct task_struct *task,
688c2ecf20Sopenharmony_ci					 struct pt_regs *regs,
698c2ecf20Sopenharmony_ci					 unsigned long *args)
708c2ecf20Sopenharmony_ci{
718c2ecf20Sopenharmony_ci	ia64_syscall_get_set_arguments(task, regs, args, 1);
728c2ecf20Sopenharmony_ci}
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_cistatic inline int syscall_get_arch(struct task_struct *task)
758c2ecf20Sopenharmony_ci{
768c2ecf20Sopenharmony_ci	return AUDIT_ARCH_IA64;
778c2ecf20Sopenharmony_ci}
788c2ecf20Sopenharmony_ci#endif	/* _ASM_SYSCALL_H */
79