s390 specific system call wrappers
[pandora-kernel.git] / arch / s390 / kernel / sys_s390.c
1 /*
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>
19 #include <linux/fs.h>
20 #include <linux/smp.h>
21 #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>
29 #include <linux/personality.h>
30 #include <linux/unistd.h>
31 #include <linux/ipc.h>
32 #include <linux/syscalls.h>
33 #include <asm/uaccess.h>
34 #include "entry.h"
35
36 /* common code for old and new mmaps */
37 static inline long do_mmap2(
38         unsigned long addr, unsigned long len,
39         unsigned long prot, unsigned long flags,
40         unsigned long fd, unsigned long pgoff)
41 {
42         long error = -EBADF;
43         struct file * file = NULL;
44
45         flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
46         if (!(flags & MAP_ANONYMOUS)) {
47                 file = fget(fd);
48                 if (!file)
49                         goto out;
50         }
51
52         down_write(&current->mm->mmap_sem);
53         error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
54         up_write(&current->mm->mmap_sem);
55
56         if (file)
57                 fput(file);
58 out:
59         return error;
60 }
61
62 /*
63  * Perform the select(nd, in, out, ex, tv) and mmap() system
64  * calls. Linux for S/390 isn't able to handle more than 5
65  * system call parameters, so these system calls used a memory
66  * block for parameter passing..
67  */
68
69 struct mmap_arg_struct {
70         unsigned long addr;
71         unsigned long len;
72         unsigned long prot;
73         unsigned long flags;
74         unsigned long fd;
75         unsigned long offset;
76 };
77
78 SYSCALL_DEFINE1(mmap2, struct mmap_arg_struct __user *, arg)
79 {
80         struct mmap_arg_struct a;
81         int error = -EFAULT;
82
83         if (copy_from_user(&a, arg, sizeof(a)))
84                 goto out;
85         error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset);
86 out:
87         return error;
88 }
89
90 SYSCALL_DEFINE1(s390_old_mmap, struct mmap_arg_struct __user *, arg)
91 {
92         struct mmap_arg_struct a;
93         long error = -EFAULT;
94
95         if (copy_from_user(&a, arg, sizeof(a)))
96                 goto out;
97
98         error = -EINVAL;
99         if (a.offset & ~PAGE_MASK)
100                 goto out;
101
102         error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
103 out:
104         return error;
105 }
106
107 #ifndef CONFIG_64BIT
108 struct sel_arg_struct {
109         unsigned long n;
110         fd_set __user *inp, *outp, *exp;
111         struct timeval __user *tvp;
112 };
113
114 asmlinkage long old_select(struct sel_arg_struct __user *arg)
115 {
116         struct sel_arg_struct a;
117
118         if (copy_from_user(&a, arg, sizeof(a)))
119                 return -EFAULT;
120         /* sys_select() does the appropriate kernel locking */
121         return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
122
123 }
124 #endif /* CONFIG_64BIT */
125
126 /*
127  * sys_ipc() is the de-multiplexer for the SysV IPC calls..
128  *
129  * This is really horribly ugly.
130  */
131 SYSCALL_DEFINE5(ipc, uint, call, int, first, unsigned long, second,
132                 unsigned long, third, void __user *, ptr)
133 {
134         struct ipc_kludge tmp;
135         int ret;
136
137         switch (call) {
138         case SEMOP:
139                 return sys_semtimedop(first, (struct sembuf __user *)ptr,
140                                        (unsigned)second, NULL);
141         case SEMTIMEDOP:
142                 return sys_semtimedop(first, (struct sembuf __user *)ptr,
143                                        (unsigned)second,
144                                        (const struct timespec __user *) third);
145         case SEMGET:
146                 return sys_semget(first, (int)second, third);
147         case SEMCTL: {
148                 union semun fourth;
149                 if (!ptr)
150                         return -EINVAL;
151                 if (get_user(fourth.__pad, (void __user * __user *) ptr))
152                         return -EFAULT;
153                 return sys_semctl(first, (int)second, third, fourth);
154         }
155         case MSGSND:
156                 return sys_msgsnd (first, (struct msgbuf __user *) ptr,
157                                    (size_t)second, third);
158                 break;
159         case MSGRCV:
160                 if (!ptr)
161                         return -EINVAL;
162                 if (copy_from_user (&tmp, (struct ipc_kludge __user *) ptr,
163                                     sizeof (struct ipc_kludge)))
164                         return -EFAULT;
165                 return sys_msgrcv (first, tmp.msgp,
166                                    (size_t)second, tmp.msgtyp, third);
167         case MSGGET:
168                 return sys_msgget((key_t)first, (int)second);
169         case MSGCTL:
170                 return sys_msgctl(first, (int)second,
171                                    (struct msqid_ds __user *)ptr);
172
173         case SHMAT: {
174                 ulong raddr;
175                 ret = do_shmat(first, (char __user *)ptr,
176                                 (int)second, &raddr);
177                 if (ret)
178                         return ret;
179                 return put_user (raddr, (ulong __user *) third);
180                 break;
181         }
182         case SHMDT:
183                 return sys_shmdt ((char __user *)ptr);
184         case SHMGET:
185                 return sys_shmget(first, (size_t)second, third);
186         case SHMCTL:
187                 return sys_shmctl(first, (int)second,
188                                    (struct shmid_ds __user *) ptr);
189         default:
190                 return -ENOSYS;
191
192         }
193
194         return -EINVAL;
195 }
196
197 #ifdef CONFIG_64BIT
198 SYSCALL_DEFINE1(s390_newuname, struct new_utsname __user *, name)
199 {
200         int ret = sys_newuname(name);
201
202         if (current->personality == PER_LINUX32 && !ret) {
203                 ret = copy_to_user(name->machine, "s390\0\0\0\0", 8);
204                 if (ret) ret = -EFAULT;
205         }
206         return ret;
207 }
208
209 SYSCALL_DEFINE1(s390_personality, unsigned long, personality)
210 {
211         int ret;
212
213         if (current->personality == PER_LINUX32 && personality == PER_LINUX)
214                 personality = PER_LINUX32;
215         ret = sys_personality(personality);
216         if (ret == PER_LINUX32)
217                 ret = PER_LINUX;
218
219         return ret;
220 }
221 #endif /* CONFIG_64BIT */
222
223 /*
224  * Wrapper function for sys_fadvise64/fadvise64_64
225  */
226 #ifndef CONFIG_64BIT
227
228 SYSCALL_DEFINE5(s390_fadvise64, int, fd, u32, offset_high, u32, offset_low,
229                 size_t, len, int, advice)
230 {
231         return sys_fadvise64(fd, (u64) offset_high << 32 | offset_low,
232                         len, advice);
233 }
234
235 struct fadvise64_64_args {
236         int fd;
237         long long offset;
238         long long len;
239         int advice;
240 };
241
242 SYSCALL_DEFINE1(s390_fadvise64_64, struct fadvise64_64_args __user *, args)
243 {
244         struct fadvise64_64_args a;
245
246         if ( copy_from_user(&a, args, sizeof(a)) )
247                 return -EFAULT;
248         return sys_fadvise64_64(a.fd, a.offset, a.len, a.advice);
249 }
250
251 /*
252  * This is a wrapper to call sys_fallocate(). For 31 bit s390 the last
253  * 64 bit argument "len" is split into the upper and lower 32 bits. The
254  * system call wrapper in the user space loads the value to %r6/%r7.
255  * The code in entry.S keeps the values in %r2 - %r6 where they are and
256  * stores %r7 to 96(%r15). But the standard C linkage requires that
257  * the whole 64 bit value for len is stored on the stack and doesn't
258  * use %r6 at all. So s390_fallocate has to convert the arguments from
259  *   %r2: fd, %r3: mode, %r4/%r5: offset, %r6/96(%r15)-99(%r15): len
260  * to
261  *   %r2: fd, %r3: mode, %r4/%r5: offset, 96(%r15)-103(%r15): len
262  */
263 SYSCALL_DEFINE(s390_fallocate)(int fd, int mode, loff_t offset,
264                                u32 len_high, u32 len_low)
265 {
266         return sys_fallocate(fd, mode, offset, ((u64)len_high << 32) | len_low);
267 }
268 #ifdef CONFIG_HAVE_SYSCALL_WRAPPERS
269 asmlinkage long SyS_s390_fallocate(long fd, long mode, loff_t offset,
270                                    long len_high, long len_low)
271 {
272         return SYSC_s390_fallocate((int) fd, (int) mode, offset,
273                                    (u32) len_high, (u32) len_low);
274 }
275 SYSCALL_ALIAS(sys_s390_fallocate, SyS_s390_fallocate);
276 #endif
277
278 #endif