18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2008-2009 Red Hat, Inc. All rights reserved. 48c2ecf20Sopenharmony_ci * Copyright 2010 Tilera Corporation. All Rights Reserved. 58c2ecf20Sopenharmony_ci * Copyright 2015 Regents of the University of California, Berkeley 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_RISCV_SYSCALL_H 118c2ecf20Sopenharmony_ci#define _ASM_RISCV_SYSCALL_H 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <uapi/linux/audit.h> 148c2ecf20Sopenharmony_ci#include <linux/sched.h> 158c2ecf20Sopenharmony_ci#include <linux/err.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci/* The array of function pointers for syscalls. */ 188c2ecf20Sopenharmony_ciextern void *sys_call_table[]; 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci/* 218c2ecf20Sopenharmony_ci * Only the low 32 bits of orig_r0 are meaningful, so we return int. 228c2ecf20Sopenharmony_ci * This importantly ignores the high bits on 64-bit, so comparisons 238c2ecf20Sopenharmony_ci * sign-extend the low 32 bits. 248c2ecf20Sopenharmony_ci */ 258c2ecf20Sopenharmony_cistatic inline int syscall_get_nr(struct task_struct *task, 268c2ecf20Sopenharmony_ci struct pt_regs *regs) 278c2ecf20Sopenharmony_ci{ 288c2ecf20Sopenharmony_ci return regs->a7; 298c2ecf20Sopenharmony_ci} 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_cistatic inline void syscall_rollback(struct task_struct *task, 328c2ecf20Sopenharmony_ci struct pt_regs *regs) 338c2ecf20Sopenharmony_ci{ 348c2ecf20Sopenharmony_ci regs->a0 = regs->orig_a0; 358c2ecf20Sopenharmony_ci} 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_cistatic inline long syscall_get_error(struct task_struct *task, 388c2ecf20Sopenharmony_ci struct pt_regs *regs) 398c2ecf20Sopenharmony_ci{ 408c2ecf20Sopenharmony_ci unsigned long error = regs->a0; 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci return IS_ERR_VALUE(error) ? error : 0; 438c2ecf20Sopenharmony_ci} 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_cistatic inline long syscall_get_return_value(struct task_struct *task, 468c2ecf20Sopenharmony_ci struct pt_regs *regs) 478c2ecf20Sopenharmony_ci{ 488c2ecf20Sopenharmony_ci return regs->a0; 498c2ecf20Sopenharmony_ci} 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_cistatic inline void syscall_set_return_value(struct task_struct *task, 528c2ecf20Sopenharmony_ci struct pt_regs *regs, 538c2ecf20Sopenharmony_ci int error, long val) 548c2ecf20Sopenharmony_ci{ 558c2ecf20Sopenharmony_ci regs->a0 = (long) error ?: val; 568c2ecf20Sopenharmony_ci} 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_cistatic inline void syscall_get_arguments(struct task_struct *task, 598c2ecf20Sopenharmony_ci struct pt_regs *regs, 608c2ecf20Sopenharmony_ci unsigned long *args) 618c2ecf20Sopenharmony_ci{ 628c2ecf20Sopenharmony_ci args[0] = regs->orig_a0; 638c2ecf20Sopenharmony_ci args++; 648c2ecf20Sopenharmony_ci memcpy(args, ®s->a1, 5 * sizeof(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 const unsigned long *args) 708c2ecf20Sopenharmony_ci{ 718c2ecf20Sopenharmony_ci regs->orig_a0 = args[0]; 728c2ecf20Sopenharmony_ci args++; 738c2ecf20Sopenharmony_ci memcpy(®s->a1, args, 5 * sizeof(regs->a1)); 748c2ecf20Sopenharmony_ci} 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_cistatic inline int syscall_get_arch(struct task_struct *task) 778c2ecf20Sopenharmony_ci{ 788c2ecf20Sopenharmony_ci#ifdef CONFIG_64BIT 798c2ecf20Sopenharmony_ci return AUDIT_ARCH_RISCV64; 808c2ecf20Sopenharmony_ci#else 818c2ecf20Sopenharmony_ci return AUDIT_ARCH_RISCV32; 828c2ecf20Sopenharmony_ci#endif 838c2ecf20Sopenharmony_ci} 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci#endif /* _ASM_RISCV_SYSCALL_H */ 86