x86/paravirt: common implementation for pte value ops
[linux-2.6/mini2440.git] / arch / s390 / kernel / sys_s390.c
blobfefee99f28aaa792031e4d849e3d2eecfaa9ae06
1 /*
2 * arch/s390/kernel/sys_s390.c
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)
9 * Derived from "arch/i386/kernel/sys_i386.c"
11 * This file contains various random system calls that
12 * have a non-standard calling sequence on the Linux/s390
13 * platform.
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>
33 #include <asm/uaccess.h>
36 * sys_pipe() is the normal C calling standard for creating
37 * a pipe. It's not the way Unix traditionally does this, though.
39 asmlinkage long sys_pipe(unsigned long __user *fildes)
41 int fd[2];
42 int error;
44 error = do_pipe(fd);
45 if (!error) {
46 if (copy_to_user(fildes, fd, 2*sizeof(int)))
47 error = -EFAULT;
49 return error;
52 /* common code for old and new mmaps */
53 static inline long do_mmap2(
54 unsigned long addr, unsigned long len,
55 unsigned long prot, unsigned long flags,
56 unsigned long fd, unsigned long pgoff)
58 long error = -EBADF;
59 struct file * file = NULL;
61 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
62 if (!(flags & MAP_ANONYMOUS)) {
63 file = fget(fd);
64 if (!file)
65 goto out;
68 down_write(&current->mm->mmap_sem);
69 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
70 up_write(&current->mm->mmap_sem);
72 if (file)
73 fput(file);
74 out:
75 return error;
79 * Perform the select(nd, in, out, ex, tv) and mmap() system
80 * calls. Linux for S/390 isn't able to handle more than 5
81 * system call parameters, so these system calls used a memory
82 * block for parameter passing..
85 struct mmap_arg_struct {
86 unsigned long addr;
87 unsigned long len;
88 unsigned long prot;
89 unsigned long flags;
90 unsigned long fd;
91 unsigned long offset;
94 asmlinkage long sys_mmap2(struct mmap_arg_struct __user *arg)
96 struct mmap_arg_struct a;
97 int error = -EFAULT;
99 if (copy_from_user(&a, arg, sizeof(a)))
100 goto out;
101 error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset);
102 out:
103 return error;
106 asmlinkage long old_mmap(struct mmap_arg_struct __user *arg)
108 struct mmap_arg_struct a;
109 long error = -EFAULT;
111 if (copy_from_user(&a, arg, sizeof(a)))
112 goto out;
114 error = -EINVAL;
115 if (a.offset & ~PAGE_MASK)
116 goto out;
118 error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
119 out:
120 return error;
123 #ifndef CONFIG_64BIT
124 struct sel_arg_struct {
125 unsigned long n;
126 fd_set __user *inp, *outp, *exp;
127 struct timeval __user *tvp;
130 asmlinkage long old_select(struct sel_arg_struct __user *arg)
132 struct sel_arg_struct a;
134 if (copy_from_user(&a, arg, sizeof(a)))
135 return -EFAULT;
136 /* sys_select() does the appropriate kernel locking */
137 return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
140 #endif /* CONFIG_64BIT */
143 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
145 * This is really horribly ugly.
147 asmlinkage long sys_ipc(uint call, int first, unsigned long second,
148 unsigned long third, void __user *ptr)
150 struct ipc_kludge tmp;
151 int ret;
153 switch (call) {
154 case SEMOP:
155 return sys_semtimedop(first, (struct sembuf __user *)ptr,
156 (unsigned)second, NULL);
157 case SEMTIMEDOP:
158 return sys_semtimedop(first, (struct sembuf __user *)ptr,
159 (unsigned)second,
160 (const struct timespec __user *) third);
161 case SEMGET:
162 return sys_semget(first, (int)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, (int)second, third, fourth);
171 case MSGSND:
172 return sys_msgsnd (first, (struct msgbuf __user *) ptr,
173 (size_t)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 (size_t)second, tmp.msgtyp, third);
183 case MSGGET:
184 return sys_msgget((key_t)first, (int)second);
185 case MSGCTL:
186 return sys_msgctl(first, (int)second,
187 (struct msqid_ds __user *)ptr);
189 case SHMAT: {
190 ulong raddr;
191 ret = do_shmat(first, (char __user *)ptr,
192 (int)second, &raddr);
193 if (ret)
194 return ret;
195 return put_user (raddr, (ulong __user *) third);
196 break;
198 case SHMDT:
199 return sys_shmdt ((char __user *)ptr);
200 case SHMGET:
201 return sys_shmget(first, (size_t)second, third);
202 case SHMCTL:
203 return sys_shmctl(first, (int)second,
204 (struct shmid_ds __user *) ptr);
205 default:
206 return -ENOSYS;
210 return -EINVAL;
213 #ifdef CONFIG_64BIT
214 asmlinkage long s390x_newuname(struct new_utsname __user *name)
216 int ret = sys_newuname(name);
218 if (current->personality == PER_LINUX32 && !ret) {
219 ret = copy_to_user(name->machine, "s390\0\0\0\0", 8);
220 if (ret) ret = -EFAULT;
222 return ret;
225 asmlinkage long s390x_personality(unsigned long personality)
227 int ret;
229 if (current->personality == PER_LINUX32 && personality == PER_LINUX)
230 personality = PER_LINUX32;
231 ret = sys_personality(personality);
232 if (ret == PER_LINUX32)
233 ret = PER_LINUX;
235 return ret;
237 #endif /* CONFIG_64BIT */
240 * Wrapper function for sys_fadvise64/fadvise64_64
242 #ifndef CONFIG_64BIT
244 asmlinkage long
245 s390_fadvise64(int fd, u32 offset_high, u32 offset_low, size_t len, int advice)
247 return sys_fadvise64(fd, (u64) offset_high << 32 | offset_low,
248 len, advice);
251 #endif
253 struct fadvise64_64_args {
254 int fd;
255 long long offset;
256 long long len;
257 int advice;
260 asmlinkage long
261 s390_fadvise64_64(struct fadvise64_64_args __user *args)
263 struct fadvise64_64_args a;
265 if ( copy_from_user(&a, args, sizeof(a)) )
266 return -EFAULT;
267 return sys_fadvise64_64(a.fd, a.offset, a.len, a.advice);
270 #ifndef CONFIG_64BIT
272 * This is a wrapper to call sys_fallocate(). For 31 bit s390 the last
273 * 64 bit argument "len" is split into the upper and lower 32 bits. The
274 * system call wrapper in the user space loads the value to %r6/%r7.
275 * The code in entry.S keeps the values in %r2 - %r6 where they are and
276 * stores %r7 to 96(%r15). But the standard C linkage requires that
277 * the whole 64 bit value for len is stored on the stack and doesn't
278 * use %r6 at all. So s390_fallocate has to convert the arguments from
279 * %r2: fd, %r3: mode, %r4/%r5: offset, %r6/96(%r15)-99(%r15): len
280 * to
281 * %r2: fd, %r3: mode, %r4/%r5: offset, 96(%r15)-103(%r15): len
283 asmlinkage long s390_fallocate(int fd, int mode, loff_t offset,
284 u32 len_high, u32 len_low)
286 return sys_fallocate(fd, mode, offset, ((u64)len_high << 32) | len_low);
288 #endif