ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[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 * 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 *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 *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 *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 #else /* CONFIG_ARCH_S390X */
142 unsigned long
143 arch_get_unmapped_area(struct file *filp, unsigned long addr,
144                        unsigned long len, unsigned long pgoff,
145                        unsigned long flags)
146 {
147         struct vm_area_struct *vma;
148         unsigned long end;
149
150         if (test_thread_flag(TIF_31BIT)) { 
151                 if (!addr) 
152                         addr = 0x40000000; 
153                 end = 0x80000000;               
154         } else { 
155                 if (!addr) 
156                         addr = TASK_SIZE / 2;
157                 end = TASK_SIZE; 
158         }
159
160         if (len > end)
161                 return -ENOMEM;
162         addr = PAGE_ALIGN(addr);
163
164         for (vma = find_vma(current->mm, addr); ; vma = vma->vm_next) {
165                 /* At this point:  (!vma || addr < vma->vm_end). */
166                 if (end - len < addr)
167                         return -ENOMEM;
168                 if (!vma || addr + len <= vma->vm_start)
169                         return addr;
170                 addr = vma->vm_end;
171         }
172 }
173 #endif /* CONFIG_ARCH_S390X */
174
175 /*
176  * sys_ipc() is the de-multiplexer for the SysV IPC calls..
177  *
178  * This is really horribly ugly.
179  */
180 asmlinkage long sys_ipc (uint call, int first, int second,
181                                   unsigned long third, void *ptr)
182 {
183         struct ipc_kludge tmp;
184         int ret;
185
186         switch (call) {
187         case SEMOP:
188                 return sys_semtimedop (first, (struct sembuf *) ptr, second,
189                                        NULL);
190         case SEMTIMEDOP:
191                 return sys_semtimedop (first, (struct sembuf *) ptr, second,
192                                        (const struct timespec *) third);
193         case SEMGET:
194                 return sys_semget (first, second, third);
195         case SEMCTL: {
196                 union semun fourth;
197                 if (!ptr)
198                         return -EINVAL;
199                 if (get_user(fourth.__pad, (void **) ptr))
200                         return -EFAULT;
201                 return sys_semctl (first, second, third, fourth);
202         } 
203         case MSGSND:
204                 return sys_msgsnd (first, (struct msgbuf *) ptr, 
205                                    second, third);
206                 break;
207         case MSGRCV:
208                 if (!ptr)
209                         return -EINVAL;
210                 if (copy_from_user (&tmp, (struct ipc_kludge *) ptr,
211                                     sizeof (struct ipc_kludge)))
212                         return -EFAULT;
213                 return sys_msgrcv (first, tmp.msgp,
214                                    second, tmp.msgtyp, third);
215         case MSGGET:
216                 return sys_msgget ((key_t) first, second);
217         case MSGCTL:
218                 return sys_msgctl (first, second, (struct msqid_ds *) ptr);
219                 
220         case SHMAT: {
221                 ulong raddr;
222                 ret = do_shmat (first, (char *) ptr, second, &raddr);
223                 if (ret)
224                         return ret;
225                 return put_user (raddr, (ulong *) third);
226                 break;
227         }
228         case SHMDT: 
229                 return sys_shmdt ((char *)ptr);
230         case SHMGET:
231                 return sys_shmget (first, second, third);
232         case SHMCTL:
233                 return sys_shmctl (first, second,
234                                    (struct shmid_ds *) ptr);
235         default:
236                 return -ENOSYS;
237
238         }
239         
240         return -EINVAL;
241 }
242
243 #ifdef CONFIG_ARCH_S390X
244 asmlinkage long s390x_newuname(struct new_utsname * name)
245 {
246         int ret = sys_newuname(name);
247
248         if (current->personality == PER_LINUX32 && !ret) {
249                 ret = copy_to_user(name->machine, "s390\0\0\0\0", 8);
250                 if (ret) ret = -EFAULT;
251         }
252         return ret;
253 }
254
255 asmlinkage long s390x_personality(unsigned long personality)
256 {
257         int ret;
258
259         if (current->personality == PER_LINUX32 && personality == PER_LINUX)
260                 personality = PER_LINUX32;
261         ret = sys_personality(personality);
262         if (ret == PER_LINUX32)
263                 ret = PER_LINUX;
264
265         return ret;
266 }
267 #endif /* CONFIG_ARCH_S390X */
268
269 /*
270  * Wrapper function for sys_fadvise64/fadvise64_64
271  */
272 #ifndef CONFIG_ARCH_S390X
273
274 asmlinkage long
275 s390_fadvise64(int fd, u32 offset_high, u32 offset_low, size_t len, int advice)
276 {
277         return sys_fadvise64(fd, (u64) offset_high << 32 | offset_low,
278                         len, advice);
279 }
280
281 #endif
282
283 struct fadvise64_64_args {
284         int fd;
285         long long offset;
286         long long len;
287         int advice;
288 };
289
290 asmlinkage long
291 s390_fadvise64_64(struct fadvise64_64_args *args)
292 {
293         struct fadvise64_64_args a;
294
295         if ( copy_from_user(&a, args, sizeof(a)) )
296                 return -EFAULT;
297         return sys_fadvise64_64(a.fd, a.offset, a.len, a.advice);
298 }
299