18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Access to user system call parameters and results 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright IBM Corp. 2008 68c2ecf20Sopenharmony_ci * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com) 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#ifndef _ASM_SYSCALL_H 108c2ecf20Sopenharmony_ci#define _ASM_SYSCALL_H 1 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include <uapi/linux/audit.h> 138c2ecf20Sopenharmony_ci#include <linux/sched.h> 148c2ecf20Sopenharmony_ci#include <linux/err.h> 158c2ecf20Sopenharmony_ci#include <asm/ptrace.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ciextern const unsigned long sys_call_table[]; 188c2ecf20Sopenharmony_ciextern const unsigned long sys_call_table_emu[]; 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_cistatic inline long syscall_get_nr(struct task_struct *task, 218c2ecf20Sopenharmony_ci struct pt_regs *regs) 228c2ecf20Sopenharmony_ci{ 238c2ecf20Sopenharmony_ci return test_pt_regs_flag(regs, PIF_SYSCALL) ? 248c2ecf20Sopenharmony_ci (regs->int_code & 0xffff) : -1; 258c2ecf20Sopenharmony_ci} 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_cistatic inline void syscall_rollback(struct task_struct *task, 288c2ecf20Sopenharmony_ci struct pt_regs *regs) 298c2ecf20Sopenharmony_ci{ 308c2ecf20Sopenharmony_ci regs->gprs[2] = regs->orig_gpr2; 318c2ecf20Sopenharmony_ci} 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_cistatic inline long syscall_get_error(struct task_struct *task, 348c2ecf20Sopenharmony_ci struct pt_regs *regs) 358c2ecf20Sopenharmony_ci{ 368c2ecf20Sopenharmony_ci unsigned long error = regs->gprs[2]; 378c2ecf20Sopenharmony_ci#ifdef CONFIG_COMPAT 388c2ecf20Sopenharmony_ci if (test_tsk_thread_flag(task, TIF_31BIT)) { 398c2ecf20Sopenharmony_ci /* 408c2ecf20Sopenharmony_ci * Sign-extend the value so (int)-EFOO becomes (long)-EFOO 418c2ecf20Sopenharmony_ci * and will match correctly in comparisons. 428c2ecf20Sopenharmony_ci */ 438c2ecf20Sopenharmony_ci error = (long)(int)error; 448c2ecf20Sopenharmony_ci } 458c2ecf20Sopenharmony_ci#endif 468c2ecf20Sopenharmony_ci return IS_ERR_VALUE(error) ? error : 0; 478c2ecf20Sopenharmony_ci} 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_cistatic inline long syscall_get_return_value(struct task_struct *task, 508c2ecf20Sopenharmony_ci struct pt_regs *regs) 518c2ecf20Sopenharmony_ci{ 528c2ecf20Sopenharmony_ci return regs->gprs[2]; 538c2ecf20Sopenharmony_ci} 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_cistatic inline void syscall_set_return_value(struct task_struct *task, 568c2ecf20Sopenharmony_ci struct pt_regs *regs, 578c2ecf20Sopenharmony_ci int error, long val) 588c2ecf20Sopenharmony_ci{ 598c2ecf20Sopenharmony_ci regs->gprs[2] = error ? error : val; 608c2ecf20Sopenharmony_ci} 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_cistatic inline void syscall_get_arguments(struct task_struct *task, 638c2ecf20Sopenharmony_ci struct pt_regs *regs, 648c2ecf20Sopenharmony_ci unsigned long *args) 658c2ecf20Sopenharmony_ci{ 668c2ecf20Sopenharmony_ci unsigned long mask = -1UL; 678c2ecf20Sopenharmony_ci unsigned int n = 6; 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci#ifdef CONFIG_COMPAT 708c2ecf20Sopenharmony_ci if (test_tsk_thread_flag(task, TIF_31BIT)) 718c2ecf20Sopenharmony_ci mask = 0xffffffff; 728c2ecf20Sopenharmony_ci#endif 738c2ecf20Sopenharmony_ci while (n-- > 0) 748c2ecf20Sopenharmony_ci if (n > 0) 758c2ecf20Sopenharmony_ci args[n] = regs->gprs[2 + n] & mask; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci args[0] = regs->orig_gpr2 & mask; 788c2ecf20Sopenharmony_ci} 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_cistatic inline void syscall_set_arguments(struct task_struct *task, 818c2ecf20Sopenharmony_ci struct pt_regs *regs, 828c2ecf20Sopenharmony_ci const unsigned long *args) 838c2ecf20Sopenharmony_ci{ 848c2ecf20Sopenharmony_ci unsigned int n = 6; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci while (n-- > 0) 878c2ecf20Sopenharmony_ci if (n > 0) 888c2ecf20Sopenharmony_ci regs->gprs[2 + n] = args[n]; 898c2ecf20Sopenharmony_ci regs->orig_gpr2 = args[0]; 908c2ecf20Sopenharmony_ci} 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_cistatic inline int syscall_get_arch(struct task_struct *task) 938c2ecf20Sopenharmony_ci{ 948c2ecf20Sopenharmony_ci#ifdef CONFIG_COMPAT 958c2ecf20Sopenharmony_ci if (test_tsk_thread_flag(task, TIF_31BIT)) 968c2ecf20Sopenharmony_ci return AUDIT_ARCH_S390; 978c2ecf20Sopenharmony_ci#endif 988c2ecf20Sopenharmony_ci return AUDIT_ARCH_S390X; 998c2ecf20Sopenharmony_ci} 1008c2ecf20Sopenharmony_ci#endif /* _ASM_SYSCALL_H */ 101