blob: 5fdb799062b7abfa1471488fd2582660cd56b08a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/s390/kernel/sys_s390.c
3 *
4 * S390 version
5 * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
6 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
7 * Thomas Spatzier (tspat@de.ibm.com)
8 *
9 * Derived from "arch/i386/kernel/sys_i386.c"
10 *
11 * This file contains various random system calls that
12 * have a non-standard calling sequence on the Linux/s390
13 * platform.
14 */
15
16#include <linux/errno.h>
17#include <linux/sched.h>
18#include <linux/mm.h>
Alexey Dobriyan4e950f62007-07-30 02:36:13 +040019#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/sem.h>
22#include <linux/msg.h>
23#include <linux/shm.h>
24#include <linux/stat.h>
25#include <linux/syscalls.h>
26#include <linux/mman.h>
27#include <linux/file.h>
28#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/personality.h>
Arnd Bergmannfe742902006-10-02 02:18:34 -070030#include <linux/unistd.h>
Adrian Bunkcba4fbb2007-10-16 23:29:24 -070031#include <linux/ipc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <asm/uaccess.h>
Heiko Carstensa8061702008-04-17 07:46:26 +020033#include "entry.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Linus Torvalds1da177e2005-04-16 15:20:36 -070035/* common code for old and new mmaps */
36static inline long do_mmap2(
37 unsigned long addr, unsigned long len,
38 unsigned long prot, unsigned long flags,
39 unsigned long fd, unsigned long pgoff)
40{
41 long error = -EBADF;
42 struct file * file = NULL;
43
44 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
45 if (!(flags & MAP_ANONYMOUS)) {
46 file = fget(fd);
47 if (!file)
48 goto out;
49 }
50
51 down_write(&current->mm->mmap_sem);
52 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
53 up_write(&current->mm->mmap_sem);
54
55 if (file)
56 fput(file);
57out:
58 return error;
59}
60
61/*
62 * Perform the select(nd, in, out, ex, tv) and mmap() system
63 * calls. Linux for S/390 isn't able to handle more than 5
64 * system call parameters, so these system calls used a memory
65 * block for parameter passing..
66 */
67
68struct mmap_arg_struct {
69 unsigned long addr;
70 unsigned long len;
71 unsigned long prot;
72 unsigned long flags;
73 unsigned long fd;
74 unsigned long offset;
75};
76
77asmlinkage long sys_mmap2(struct mmap_arg_struct __user *arg)
78{
79 struct mmap_arg_struct a;
80 int error = -EFAULT;
81
82 if (copy_from_user(&a, arg, sizeof(a)))
83 goto out;
84 error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset);
85out:
86 return error;
87}
88
89asmlinkage long old_mmap(struct mmap_arg_struct __user *arg)
90{
91 struct mmap_arg_struct a;
92 long error = -EFAULT;
93
94 if (copy_from_user(&a, arg, sizeof(a)))
95 goto out;
96
97 error = -EINVAL;
98 if (a.offset & ~PAGE_MASK)
99 goto out;
100
101 error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
102out:
103 return error;
104}
105
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800106#ifndef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107struct sel_arg_struct {
108 unsigned long n;
Al Viro793af242006-02-01 06:55:59 -0500109 fd_set __user *inp, *outp, *exp;
110 struct timeval __user *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111};
112
113asmlinkage long old_select(struct sel_arg_struct __user *arg)
114{
115 struct sel_arg_struct a;
116
117 if (copy_from_user(&a, arg, sizeof(a)))
118 return -EFAULT;
119 /* sys_select() does the appropriate kernel locking */
120 return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
121
122}
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800123#endif /* CONFIG_64BIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125/*
126 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
127 *
128 * This is really horribly ugly.
129 */
130asmlinkage long sys_ipc(uint call, int first, unsigned long second,
131 unsigned long third, void __user *ptr)
132{
133 struct ipc_kludge tmp;
134 int ret;
135
136 switch (call) {
137 case SEMOP:
138 return sys_semtimedop(first, (struct sembuf __user *)ptr,
139 (unsigned)second, NULL);
140 case SEMTIMEDOP:
141 return sys_semtimedop(first, (struct sembuf __user *)ptr,
142 (unsigned)second,
143 (const struct timespec __user *) third);
144 case SEMGET:
145 return sys_semget(first, (int)second, third);
146 case SEMCTL: {
147 union semun fourth;
148 if (!ptr)
149 return -EINVAL;
150 if (get_user(fourth.__pad, (void __user * __user *) ptr))
151 return -EFAULT;
152 return sys_semctl(first, (int)second, third, fourth);
153 }
154 case MSGSND:
155 return sys_msgsnd (first, (struct msgbuf __user *) ptr,
156 (size_t)second, third);
157 break;
158 case MSGRCV:
159 if (!ptr)
160 return -EINVAL;
161 if (copy_from_user (&tmp, (struct ipc_kludge __user *) ptr,
162 sizeof (struct ipc_kludge)))
163 return -EFAULT;
164 return sys_msgrcv (first, tmp.msgp,
165 (size_t)second, tmp.msgtyp, third);
166 case MSGGET:
167 return sys_msgget((key_t)first, (int)second);
168 case MSGCTL:
169 return sys_msgctl(first, (int)second,
170 (struct msqid_ds __user *)ptr);
171
172 case SHMAT: {
173 ulong raddr;
174 ret = do_shmat(first, (char __user *)ptr,
175 (int)second, &raddr);
176 if (ret)
177 return ret;
178 return put_user (raddr, (ulong __user *) third);
179 break;
180 }
181 case SHMDT:
182 return sys_shmdt ((char __user *)ptr);
183 case SHMGET:
184 return sys_shmget(first, (size_t)second, third);
185 case SHMCTL:
186 return sys_shmctl(first, (int)second,
187 (struct shmid_ds __user *) ptr);
188 default:
189 return -ENOSYS;
190
191 }
192
193 return -EINVAL;
194}
195
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800196#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197asmlinkage long s390x_newuname(struct new_utsname __user *name)
198{
199 int ret = sys_newuname(name);
200
201 if (current->personality == PER_LINUX32 && !ret) {
202 ret = copy_to_user(name->machine, "s390\0\0\0\0", 8);
203 if (ret) ret = -EFAULT;
204 }
205 return ret;
206}
207
208asmlinkage long s390x_personality(unsigned long personality)
209{
210 int ret;
211
212 if (current->personality == PER_LINUX32 && personality == PER_LINUX)
213 personality = PER_LINUX32;
214 ret = sys_personality(personality);
215 if (ret == PER_LINUX32)
216 ret = PER_LINUX;
217
218 return ret;
219}
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800220#endif /* CONFIG_64BIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222/*
223 * Wrapper function for sys_fadvise64/fadvise64_64
224 */
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800225#ifndef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
227asmlinkage long
228s390_fadvise64(int fd, u32 offset_high, u32 offset_low, size_t len, int advice)
229{
230 return sys_fadvise64(fd, (u64) offset_high << 32 | offset_low,
231 len, advice);
232}
233
234#endif
235
236struct fadvise64_64_args {
237 int fd;
238 long long offset;
239 long long len;
240 int advice;
241};
242
243asmlinkage long
244s390_fadvise64_64(struct fadvise64_64_args __user *args)
245{
246 struct fadvise64_64_args a;
247
248 if ( copy_from_user(&a, args, sizeof(a)) )
249 return -EFAULT;
250 return sys_fadvise64_64(a.fd, a.offset, a.len, a.advice);
251}
Martin Schwidefsky7a8e0c82007-07-27 12:29:16 +0200252
253#ifndef CONFIG_64BIT
254/*
255 * This is a wrapper to call sys_fallocate(). For 31 bit s390 the last
256 * 64 bit argument "len" is split into the upper and lower 32 bits. The
257 * system call wrapper in the user space loads the value to %r6/%r7.
258 * The code in entry.S keeps the values in %r2 - %r6 where they are and
259 * stores %r7 to 96(%r15). But the standard C linkage requires that
260 * the whole 64 bit value for len is stored on the stack and doesn't
261 * use %r6 at all. So s390_fallocate has to convert the arguments from
262 * %r2: fd, %r3: mode, %r4/%r5: offset, %r6/96(%r15)-99(%r15): len
263 * to
264 * %r2: fd, %r3: mode, %r4/%r5: offset, 96(%r15)-103(%r15): len
265 */
266asmlinkage long s390_fallocate(int fd, int mode, loff_t offset,
267 u32 len_high, u32 len_low)
268{
269 return sys_fallocate(fd, mode, offset, ((u64)len_high << 32) | len_low);
270}
271#endif