patch-2_6_7-vs1_9_1_12
[linux-2.6.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/smp.h>
20 #include <linux/smp_lock.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 #ifdef CONFIG_ARCH_S390X
30 #include <linux/personality.h>
31 #endif /* CONFIG_ARCH_S390X */
32
33 #include <asm/uaccess.h>
34 #include <asm/ipc.h>
35
36 /*
37  * sys_pipe() is the normal C calling standard for creating
38  * a pipe. It's not the way Unix traditionally does this, though.
39  */
40 asmlinkage long sys_pipe(unsigned long __user *fildes)
41 {
42         int fd[2];
43         int error;
44
45         error = do_pipe(fd);
46         if (!error) {
47                 if (copy_to_user(fildes, fd, 2*sizeof(int)))
48                         error = -EFAULT;
49         }
50         return error;
51 }
52
53 /* common code for old and new mmaps */
54 static inline long do_mmap2(
55         unsigned long addr, unsigned long len,
56         unsigned long prot, unsigned long flags,
57         unsigned long fd, unsigned long pgoff)
58 {
59         long error = -EBADF;
60         struct file * file = NULL;
61
62         flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
63         if (!(flags & MAP_ANONYMOUS)) {
64                 file = fget(fd);
65                 if (!file)
66                         goto out;
67         }
68
69         down_write(&current->mm->mmap_sem);
70         error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
71         up_write(&current->mm->mmap_sem);
72
73         if (file)
74                 fput(file);
75 out:
76         return error;
77 }
78
79 /*
80  * Perform the select(nd, in, out, ex, tv) and mmap() system
81  * calls. Linux for S/390 isn't able to handle more than 5
82  * system call parameters, so these system calls used a memory
83  * block for parameter passing..
84  */
85
86 struct mmap_arg_struct {
87         unsigned long addr;
88         unsigned long len;
89         unsigned long prot;
90         unsigned long flags;
91         unsigned long fd;
92         unsigned long offset;
93 };
94
95 asmlinkage long sys_mmap2(struct mmap_arg_struct __user  *arg)
96 {
97         struct mmap_arg_struct a;
98         int error = -EFAULT;
99
100         if (copy_from_user(&a, arg, sizeof(a)))
101                 goto out;
102         error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset);
103 out:
104         return error;
105 }
106
107 asmlinkage long old_mmap(struct mmap_arg_struct __user *arg)
108 {
109         struct mmap_arg_struct a;
110         long error = -EFAULT;
111
112         if (copy_from_user(&a, arg, sizeof(a)))
113                 goto out;
114
115         error = -EINVAL;
116         if (a.offset & ~PAGE_MASK)
117                 goto out;
118
119         error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
120 out:
121         return error;
122 }
123
124 #ifndef CONFIG_ARCH_S390X
125 struct sel_arg_struct {
126         unsigned long n;
127         fd_set *inp, *outp, *exp;
128         struct timeval *tvp;
129 };
130
131 asmlinkage long old_select(struct sel_arg_struct __user *arg)
132 {
133         struct sel_arg_struct a;
134
135         if (copy_from_user(&a, arg, sizeof(a)))
136                 return -EFAULT;
137         /* sys_select() does the appropriate kernel locking */
138         return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
139
140 }
141 #endif /* CONFIG_ARCH_S390X */
142
143 /*
144  * sys_ipc() is the de-multiplexer for the SysV IPC calls..
145  *
146  * This is really horribly ugly.
147  */
148 asmlinkage long sys_ipc(uint call, int first, int second,
149                                   unsigned long third, void __user *ptr)
150 {
151         struct ipc_kludge tmp;
152         int ret;
153
154         switch (call) {
155         case SEMOP:
156                 return sys_semtimedop (first, (struct sembuf __user *) ptr, second,
157                                        NULL);
158         case SEMTIMEDOP:
159                 return sys_semtimedop (first, (struct sembuf __user *) ptr, second,
160                                        (const struct timespec __user *) third);
161         case SEMGET:
162                 return sys_semget (first, second, third);
163         case SEMCTL: {
164                 union semun fourth;
165                 if (!ptr)
166                         return -EINVAL;
167                 if (get_user(fourth.__pad, (void __user * __user *) ptr))
168                         return -EFAULT;
169                 return sys_semctl (first, second, third, fourth);
170         }
171         case MSGSND:
172                 return sys_msgsnd (first, (struct msgbuf __user *) ptr,
173                                    second, third);
174                 break;
175         case MSGRCV:
176                 if (!ptr)
177                         return -EINVAL;
178                 if (copy_from_user (&tmp, (struct ipc_kludge __user *) ptr,
179                                     sizeof (struct ipc_kludge)))
180                         return -EFAULT;
181                 return sys_msgrcv (first, tmp.msgp,
182                                    second, tmp.msgtyp, third);
183         case MSGGET:
184                 return sys_msgget ((key_t) first, second);
185         case MSGCTL:
186                 return sys_msgctl (first, second, (struct msqid_ds __user *) ptr);
187
188         case SHMAT: {
189                 ulong raddr;
190                 ret = do_shmat (first, (char __user *) ptr, second, &raddr);
191                 if (ret)
192                         return ret;
193                 return put_user (raddr, (ulong __user *) third);
194                 break;
195         }
196         case SHMDT:
197                 return sys_shmdt ((char __user *)ptr);
198         case SHMGET:
199                 return sys_shmget (first, second, third);
200         case SHMCTL:
201                 return sys_shmctl (first, second,
202                                    (struct shmid_ds __user *) ptr);
203         default:
204                 return -ENOSYS;
205
206         }
207
208         return -EINVAL;
209 }
210
211 #ifdef CONFIG_ARCH_S390X
212 asmlinkage long s390x_newuname(struct new_utsname __user *name)
213 {
214         int ret = sys_newuname(name);
215
216         if (current->personality == PER_LINUX32 && !ret) {
217                 ret = copy_to_user(name->machine, "s390\0\0\0\0", 8);
218                 if (ret) ret = -EFAULT;
219         }
220         return ret;
221 }
222
223 asmlinkage long s390x_personality(unsigned long personality)
224 {
225         int ret;
226
227         if (current->personality == PER_LINUX32 && personality == PER_LINUX)
228                 personality = PER_LINUX32;
229         ret = sys_personality(personality);
230         if (ret == PER_LINUX32)
231                 ret = PER_LINUX;
232
233         return ret;
234 }
235 #endif /* CONFIG_ARCH_S390X */
236
237 /*
238  * Wrapper function for sys_fadvise64/fadvise64_64
239  */
240 #ifndef CONFIG_ARCH_S390X
241
242 asmlinkage long
243 s390_fadvise64(int fd, u32 offset_high, u32 offset_low, size_t len, int advice)
244 {
245         return sys_fadvise64(fd, (u64) offset_high << 32 | offset_low,
246                         len, advice);
247 }
248
249 #endif
250
251 struct fadvise64_64_args {
252         int fd;
253         long long offset;
254         long long len;
255         int advice;
256 };
257
258 asmlinkage long
259 s390_fadvise64_64(struct fadvise64_64_args __user *args)
260 {
261         struct fadvise64_64_args a;
262
263         if ( copy_from_user(&a, args, sizeof(a)) )
264                 return -EFAULT;
265         return sys_fadvise64_64(a.fd, a.offset, a.len, a.advice);
266 }
267