1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright IBM Corp. 1999, 2000
5 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
6 * Thomas Spatzier (tspat@de.ibm.com)
8 * Derived from "arch/i386/kernel/sys_i386.c"
10 * This file contains various random system calls that
11 * have a non-standard calling sequence on the Linux/s390
15 #include <linux/errno.h>
16 #include <linux/sched.h>
19 #include <linux/smp.h>
20 #include <linux/sem.h>
21 #include <linux/msg.h>
22 #include <linux/shm.h>
23 #include <linux/stat.h>
24 #include <linux/syscalls.h>
25 #include <linux/mman.h>
26 #include <linux/file.h>
27 #include <linux/utsname.h>
28 #include <linux/personality.h>
29 #include <linux/unistd.h>
30 #include <linux/ipc.h>
31 #include <linux/uaccess.h>
32 #include <linux/string.h>
33 #include <linux/thread_info.h>
34 #include <linux/entry-common.h>
36 #include <asm/ptrace.h>
37 #include <asm/vtime.h>
42 * Perform the mmap() system call. Linux for S/390 isn't able to handle more
43 * than 5 system call parameters, so this system call uses a memory block
44 * for parameter passing.
47 struct s390_mmap_arg_struct {
56 SYSCALL_DEFINE1(mmap2, struct s390_mmap_arg_struct __user *, arg)
58 struct s390_mmap_arg_struct a;
61 if (copy_from_user(&a, arg, sizeof(a)))
63 error = ksys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, a.offset);
70 * sys_ipc() is the de-multiplexer for the SysV IPC calls.
72 SYSCALL_DEFINE5(s390_ipc, uint, call, int, first, unsigned long, second,
73 unsigned long, third, void __user *, ptr)
77 /* The s390 sys_ipc variant has only five parameters instead of six
78 * like the generic variant. The only difference is the handling of
79 * the SEMTIMEDOP subcall where on s390 the third parameter is used
80 * as a pointer to a struct timespec where the generic variant uses
81 * the fifth parameter.
82 * Therefore we can call the generic variant by simply passing the
83 * third parameter also as fifth parameter.
85 return ksys_ipc(call, first, second, third, ptr, third);
87 #endif /* CONFIG_SYSVIPC */
89 SYSCALL_DEFINE1(s390_personality, unsigned int, personality)
91 unsigned int ret = current->personality;
93 if (personality(current->personality) == PER_LINUX32 &&
94 personality(personality) == PER_LINUX)
95 personality |= PER_LINUX32;
97 if (personality != 0xffffffff)
98 set_personality(personality);
100 if (personality(ret) == PER_LINUX32)
106 SYSCALL_DEFINE0(ni_syscall)
111 static void do_syscall(struct pt_regs *regs)
115 nr = regs->int_code & 0xffff;
117 nr = regs->gprs[1] & 0xffff;
118 regs->int_code &= ~0xffffUL;
119 regs->int_code |= nr;
124 if (nr == __NR_restart_syscall && !(current->restart_block.arch_data & 1)) {
125 regs->psw.addr = current->restart_block.arch_data;
126 current->restart_block.arch_data = 1;
128 nr = syscall_enter_from_user_mode_work(regs, nr);
131 * In the s390 ptrace ABI, both the syscall number and the return value
132 * use gpr2. However, userspace puts the syscall number either in the
133 * svc instruction itself, or uses gpr1. To make at least skipping syscalls
134 * work, the ptrace code sets PIF_SYSCALL_RET_SET, which is checked here
135 * and if set, the syscall will be skipped.
138 if (unlikely(test_and_clear_pt_regs_flag(regs, PIF_SYSCALL_RET_SET)))
140 regs->gprs[2] = -ENOSYS;
141 if (likely(nr >= NR_syscalls))
144 regs->gprs[2] = current->thread.sys_call_table[nr](regs);
145 } while (test_and_clear_pt_regs_flag(regs, PIF_EXECVE_PGSTE_RESTART));
147 syscall_exit_to_user_mode_work(regs);
150 void noinstr __do_syscall(struct pt_regs *regs, int per_trap)
152 add_random_kstack_offset();
153 enter_from_user_mode(regs);
154 regs->psw = S390_lowcore.svc_old_psw;
155 regs->int_code = S390_lowcore.svc_int_code;
157 if (static_branch_likely(&cpu_has_bear))
158 current->thread.last_break = regs->last_break;
161 regs->orig_gpr2 = regs->gprs[2];
164 set_thread_flag(TIF_PER_TRAP);
167 set_pt_regs_flag(regs, PIF_SYSCALL);