b2563509b5a9d1fb01ad30d6e1f2e63d6db9dcc9
[safe/jmp/linux-2.6] / 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 <asm/uaccess.h>
33 #include "entry.h"
34
35 /*
36  * Perform the mmap() system call. Linux for S/390 isn't able to handle more
37  * than 5 system call parameters, so this system call uses a memory block
38  * for parameter passing.
39  */
40
41 struct s390_mmap_arg_struct {
42         unsigned long addr;
43         unsigned long len;
44         unsigned long prot;
45         unsigned long flags;
46         unsigned long fd;
47         unsigned long offset;
48 };
49
50 SYSCALL_DEFINE1(mmap2, struct s390_mmap_arg_struct __user *, arg)
51 {
52         struct s390_mmap_arg_struct a;
53         int error = -EFAULT;
54
55         if (copy_from_user(&a, arg, sizeof(a)))
56                 goto out;
57         error = sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, a.offset);
58 out:
59         return error;
60 }
61
62 /*
63  * sys_ipc() is the de-multiplexer for the SysV IPC calls..
64  *
65  * This is really horribly ugly.
66  */
67 SYSCALL_DEFINE5(ipc, uint, call, int, first, unsigned long, second,
68                 unsigned long, third, void __user *, ptr)
69 {
70         struct ipc_kludge tmp;
71         int ret;
72
73         switch (call) {
74         case SEMOP:
75                 return sys_semtimedop(first, (struct sembuf __user *)ptr,
76                                        (unsigned)second, NULL);
77         case SEMTIMEDOP:
78                 return sys_semtimedop(first, (struct sembuf __user *)ptr,
79                                        (unsigned)second,
80                                        (const struct timespec __user *) third);
81         case SEMGET:
82                 return sys_semget(first, (int)second, third);
83         case SEMCTL: {
84                 union semun fourth;
85                 if (!ptr)
86                         return -EINVAL;
87                 if (get_user(fourth.__pad, (void __user * __user *) ptr))
88                         return -EFAULT;
89                 return sys_semctl(first, (int)second, third, fourth);
90         }
91         case MSGSND:
92                 return sys_msgsnd (first, (struct msgbuf __user *) ptr,
93                                    (size_t)second, third);
94                 break;
95         case MSGRCV:
96                 if (!ptr)
97                         return -EINVAL;
98                 if (copy_from_user (&tmp, (struct ipc_kludge __user *) ptr,
99                                     sizeof (struct ipc_kludge)))
100                         return -EFAULT;
101                 return sys_msgrcv (first, tmp.msgp,
102                                    (size_t)second, tmp.msgtyp, third);
103         case MSGGET:
104                 return sys_msgget((key_t)first, (int)second);
105         case MSGCTL:
106                 return sys_msgctl(first, (int)second,
107                                    (struct msqid_ds __user *)ptr);
108
109         case SHMAT: {
110                 ulong raddr;
111                 ret = do_shmat(first, (char __user *)ptr,
112                                 (int)second, &raddr);
113                 if (ret)
114                         return ret;
115                 return put_user (raddr, (ulong __user *) third);
116                 break;
117         }
118         case SHMDT:
119                 return sys_shmdt ((char __user *)ptr);
120         case SHMGET:
121                 return sys_shmget(first, (size_t)second, third);
122         case SHMCTL:
123                 return sys_shmctl(first, (int)second,
124                                    (struct shmid_ds __user *) ptr);
125         default:
126                 return -ENOSYS;
127
128         }
129
130         return -EINVAL;
131 }
132
133 #ifdef CONFIG_64BIT
134 SYSCALL_DEFINE1(s390_newuname, struct new_utsname __user *, name)
135 {
136         int ret = sys_newuname(name);
137
138         if (personality(current->personality) == PER_LINUX32 && !ret) {
139                 ret = copy_to_user(name->machine, "s390\0\0\0\0", 8);
140                 if (ret) ret = -EFAULT;
141         }
142         return ret;
143 }
144
145 SYSCALL_DEFINE1(s390_personality, unsigned long, personality)
146 {
147         int ret;
148
149         if (current->personality == PER_LINUX32 && personality == PER_LINUX)
150                 personality = PER_LINUX32;
151         ret = sys_personality(personality);
152         if (ret == PER_LINUX32)
153                 ret = PER_LINUX;
154
155         return ret;
156 }
157 #endif /* CONFIG_64BIT */
158
159 /*
160  * Wrapper function for sys_fadvise64/fadvise64_64
161  */
162 #ifndef CONFIG_64BIT
163
164 SYSCALL_DEFINE5(s390_fadvise64, int, fd, u32, offset_high, u32, offset_low,
165                 size_t, len, int, advice)
166 {
167         return sys_fadvise64(fd, (u64) offset_high << 32 | offset_low,
168                         len, advice);
169 }
170
171 struct fadvise64_64_args {
172         int fd;
173         long long offset;
174         long long len;
175         int advice;
176 };
177
178 SYSCALL_DEFINE1(s390_fadvise64_64, struct fadvise64_64_args __user *, args)
179 {
180         struct fadvise64_64_args a;
181
182         if ( copy_from_user(&a, args, sizeof(a)) )
183                 return -EFAULT;
184         return sys_fadvise64_64(a.fd, a.offset, a.len, a.advice);
185 }
186
187 /*
188  * This is a wrapper to call sys_fallocate(). For 31 bit s390 the last
189  * 64 bit argument "len" is split into the upper and lower 32 bits. The
190  * system call wrapper in the user space loads the value to %r6/%r7.
191  * The code in entry.S keeps the values in %r2 - %r6 where they are and
192  * stores %r7 to 96(%r15). But the standard C linkage requires that
193  * the whole 64 bit value for len is stored on the stack and doesn't
194  * use %r6 at all. So s390_fallocate has to convert the arguments from
195  *   %r2: fd, %r3: mode, %r4/%r5: offset, %r6/96(%r15)-99(%r15): len
196  * to
197  *   %r2: fd, %r3: mode, %r4/%r5: offset, 96(%r15)-103(%r15): len
198  */
199 SYSCALL_DEFINE(s390_fallocate)(int fd, int mode, loff_t offset,
200                                u32 len_high, u32 len_low)
201 {
202         return sys_fallocate(fd, mode, offset, ((u64)len_high << 32) | len_low);
203 }
204 #ifdef CONFIG_HAVE_SYSCALL_WRAPPERS
205 asmlinkage long SyS_s390_fallocate(long fd, long mode, loff_t offset,
206                                    long len_high, long len_low)
207 {
208         return SYSC_s390_fallocate((int) fd, (int) mode, offset,
209                                    (u32) len_high, (u32) len_low);
210 }
211 SYSCALL_ALIAS(sys_s390_fallocate, SyS_s390_fallocate);
212 #endif
213
214 #endif