18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ci#ifndef __ASM_SYSCALL_H
48c2ecf20Sopenharmony_ci#define __ASM_SYSCALL_H
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#include <linux/sched.h>
78c2ecf20Sopenharmony_ci#include <linux/err.h>
88c2ecf20Sopenharmony_ci#include <abi/regdef.h>
98c2ecf20Sopenharmony_ci#include <uapi/linux/audit.h>
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ciextern void *sys_call_table[];
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_cistatic inline int
148c2ecf20Sopenharmony_cisyscall_get_nr(struct task_struct *task, struct pt_regs *regs)
158c2ecf20Sopenharmony_ci{
168c2ecf20Sopenharmony_ci	return regs_syscallid(regs);
178c2ecf20Sopenharmony_ci}
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_cistatic inline void
208c2ecf20Sopenharmony_cisyscall_set_nr(struct task_struct *task, struct pt_regs *regs,
218c2ecf20Sopenharmony_ci	       int sysno)
228c2ecf20Sopenharmony_ci{
238c2ecf20Sopenharmony_ci	regs_syscallid(regs) = sysno;
248c2ecf20Sopenharmony_ci}
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_cistatic inline void
278c2ecf20Sopenharmony_cisyscall_rollback(struct task_struct *task, struct pt_regs *regs)
288c2ecf20Sopenharmony_ci{
298c2ecf20Sopenharmony_ci	regs->a0 = regs->orig_a0;
308c2ecf20Sopenharmony_ci}
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cistatic inline long
338c2ecf20Sopenharmony_cisyscall_get_error(struct task_struct *task, struct pt_regs *regs)
348c2ecf20Sopenharmony_ci{
358c2ecf20Sopenharmony_ci	unsigned long error = regs->a0;
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci	return IS_ERR_VALUE(error) ? error : 0;
388c2ecf20Sopenharmony_ci}
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cistatic inline long
418c2ecf20Sopenharmony_cisyscall_get_return_value(struct task_struct *task, struct pt_regs *regs)
428c2ecf20Sopenharmony_ci{
438c2ecf20Sopenharmony_ci	return regs->a0;
448c2ecf20Sopenharmony_ci}
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistatic inline void
478c2ecf20Sopenharmony_cisyscall_set_return_value(struct task_struct *task, struct pt_regs *regs,
488c2ecf20Sopenharmony_ci		int error, long val)
498c2ecf20Sopenharmony_ci{
508c2ecf20Sopenharmony_ci	regs->a0 = (long) error ?: val;
518c2ecf20Sopenharmony_ci}
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_cistatic inline void
548c2ecf20Sopenharmony_cisyscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
558c2ecf20Sopenharmony_ci		      unsigned long *args)
568c2ecf20Sopenharmony_ci{
578c2ecf20Sopenharmony_ci	args[0] = regs->orig_a0;
588c2ecf20Sopenharmony_ci	args++;
598c2ecf20Sopenharmony_ci	memcpy(args, &regs->a1, 5 * sizeof(args[0]));
608c2ecf20Sopenharmony_ci}
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_cistatic inline void
638c2ecf20Sopenharmony_cisyscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
648c2ecf20Sopenharmony_ci		      const unsigned long *args)
658c2ecf20Sopenharmony_ci{
668c2ecf20Sopenharmony_ci	regs->orig_a0 = args[0];
678c2ecf20Sopenharmony_ci	args++;
688c2ecf20Sopenharmony_ci	memcpy(&regs->a1, args, 5 * sizeof(regs->a1));
698c2ecf20Sopenharmony_ci}
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_cistatic inline int
728c2ecf20Sopenharmony_cisyscall_get_arch(struct task_struct *task)
738c2ecf20Sopenharmony_ci{
748c2ecf20Sopenharmony_ci	return AUDIT_ARCH_CSKY;
758c2ecf20Sopenharmony_ci}
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci#endif	/* __ASM_SYSCALL_H */
78