]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
1da177e4 | 2 | /* |
1da177e4 | 3 | * S390 version |
a53c8fab | 4 | * Copyright IBM Corp. 1999, 2000 |
1da177e4 LT |
5 | * Author(s): Martin Schwidefsky ([email protected]), |
6 | * Thomas Spatzier ([email protected]) | |
7 | * | |
8 | * Derived from "arch/i386/kernel/sys_i386.c" | |
9 | * | |
10 | * This file contains various random system calls that | |
11 | * have a non-standard calling sequence on the Linux/s390 | |
12 | * platform. | |
13 | */ | |
14 | ||
15 | #include <linux/errno.h> | |
16 | #include <linux/sched.h> | |
17 | #include <linux/mm.h> | |
4e950f6f | 18 | #include <linux/fs.h> |
1da177e4 | 19 | #include <linux/smp.h> |
1da177e4 LT |
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> | |
1da177e4 | 28 | #include <linux/personality.h> |
fe74290d | 29 | #include <linux/unistd.h> |
cba4fbbf | 30 | #include <linux/ipc.h> |
7c0f6ba6 | 31 | #include <linux/uaccess.h> |
56e62a73 SS |
32 | #include <linux/string.h> |
33 | #include <linux/thread_info.h> | |
34 | #include <linux/entry-common.h> | |
35 | ||
36 | #include <asm/ptrace.h> | |
37 | #include <asm/vtime.h> | |
38 | ||
a806170e | 39 | #include "entry.h" |
1da177e4 | 40 | |
1da177e4 | 41 | /* |
a4679373 CH |
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. | |
1da177e4 LT |
45 | */ |
46 | ||
a4679373 | 47 | struct s390_mmap_arg_struct { |
1da177e4 LT |
48 | unsigned long addr; |
49 | unsigned long len; | |
50 | unsigned long prot; | |
51 | unsigned long flags; | |
52 | unsigned long fd; | |
53 | unsigned long offset; | |
54 | }; | |
55 | ||
a4679373 | 56 | SYSCALL_DEFINE1(mmap2, struct s390_mmap_arg_struct __user *, arg) |
1da177e4 | 57 | { |
a4679373 | 58 | struct s390_mmap_arg_struct a; |
1da177e4 LT |
59 | int error = -EFAULT; |
60 | ||
61 | if (copy_from_user(&a, arg, sizeof(a))) | |
62 | goto out; | |
a90f590a | 63 | error = ksys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, a.offset); |
1da177e4 LT |
64 | out: |
65 | return error; | |
66 | } | |
67 | ||
58fa4a41 | 68 | #ifdef CONFIG_SYSVIPC |
1da177e4 | 69 | /* |
3a3954ce | 70 | * sys_ipc() is the de-multiplexer for the SysV IPC calls. |
1da177e4 | 71 | */ |
baed7fc9 | 72 | SYSCALL_DEFINE5(s390_ipc, uint, call, int, first, unsigned long, second, |
26689452 | 73 | unsigned long, third, void __user *, ptr) |
1da177e4 | 74 | { |
3a3954ce HC |
75 | if (call >> 16) |
76 | return -EINVAL; | |
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. | |
84 | */ | |
58fa4a41 | 85 | return ksys_ipc(call, first, second, third, ptr, third); |
1da177e4 | 86 | } |
58fa4a41 | 87 | #endif /* CONFIG_SYSVIPC */ |
1da177e4 | 88 | |
3a110370 | 89 | SYSCALL_DEFINE1(s390_personality, unsigned int, personality) |
1da177e4 | 90 | { |
1ecff5ef | 91 | unsigned int ret = current->personality; |
1da177e4 | 92 | |
5ab37e1b JK |
93 | if (personality(current->personality) == PER_LINUX32 && |
94 | personality(personality) == PER_LINUX) | |
95 | personality |= PER_LINUX32; | |
1ecff5ef AB |
96 | |
97 | if (personality != 0xffffffff) | |
98 | set_personality(personality); | |
99 | ||
5ab37e1b JK |
100 | if (personality(ret) == PER_LINUX32) |
101 | ret &= ~PER_LINUX32; | |
1da177e4 LT |
102 | |
103 | return ret; | |
104 | } | |
aa0d6e70 AB |
105 | |
106 | SYSCALL_DEFINE0(ni_syscall) | |
107 | { | |
108 | return -ENOSYS; | |
109 | } | |
56e62a73 | 110 | |
fbf50f47 | 111 | static void do_syscall(struct pt_regs *regs) |
56e62a73 SS |
112 | { |
113 | unsigned long nr; | |
114 | ||
115 | nr = regs->int_code & 0xffff; | |
116 | if (!nr) { | |
117 | nr = regs->gprs[1] & 0xffff; | |
118 | regs->int_code &= ~0xffffUL; | |
119 | regs->int_code |= nr; | |
120 | } | |
121 | ||
122 | regs->gprs[2] = nr; | |
123 | ||
df29a744 SS |
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; | |
127 | } | |
56e62a73 SS |
128 | nr = syscall_enter_from_user_mode_work(regs, nr); |
129 | ||
130 | /* | |
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. | |
136 | */ | |
d26a357f | 137 | |
e3c7a8d7 SS |
138 | if (unlikely(test_and_clear_pt_regs_flag(regs, PIF_SYSCALL_RET_SET))) |
139 | goto out; | |
140 | regs->gprs[2] = -ENOSYS; | |
141 | if (likely(nr >= NR_syscalls)) | |
142 | goto out; | |
143 | do { | |
144 | regs->gprs[2] = current->thread.sys_call_table[nr](regs); | |
d26a357f | 145 | } while (test_and_clear_pt_regs_flag(regs, PIF_EXECVE_PGSTE_RESTART)); |
e3c7a8d7 | 146 | out: |
56e62a73 SS |
147 | syscall_exit_to_user_mode_work(regs); |
148 | } | |
149 | ||
150 | void noinstr __do_syscall(struct pt_regs *regs, int per_trap) | |
151 | { | |
bae1cd36 | 152 | add_random_kstack_offset(); |
56e62a73 | 153 | enter_from_user_mode(regs); |
56e62a73 | 154 | regs->psw = S390_lowcore.svc_old_psw; |
af9ad822 | 155 | regs->int_code = S390_lowcore.svc_int_code; |
56e62a73 | 156 | update_timer_sys(); |
3b051e89 SS |
157 | if (static_branch_likely(&cpu_has_bear)) |
158 | current->thread.last_break = regs->last_break; | |
56e62a73 SS |
159 | |
160 | local_irq_enable(); | |
161 | regs->orig_gpr2 = regs->gprs[2]; | |
162 | ||
163 | if (per_trap) | |
164 | set_thread_flag(TIF_PER_TRAP); | |
165 | ||
e3c7a8d7 SS |
166 | regs->flags = 0; |
167 | set_pt_regs_flag(regs, PIF_SYSCALL); | |
168 | do_syscall(regs); | |
56e62a73 SS |
169 | exit_to_user_mode(); |
170 | } |