Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / s390 / kernel / sys_s390.c
blobefe6b83b53f76fb35881c8e82f3d3f9dbe0e7a2d
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/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 */
33 #include <asm/uaccess.h>
34 #include <asm/ipc.h>
37 * sys_pipe() is the normal C calling standard for creating
38 * a pipe. It's not the way Unix traditionally does this, though.
40 asmlinkage long sys_pipe(unsigned long __user *fildes)
42 int fd[2];
43 int error;
45 error = do_pipe(fd);
46 if (!error) {
47 if (copy_to_user(fildes, fd, 2*sizeof(int)))
48 error = -EFAULT;
50 return error;
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)
59 long error = -EBADF;
60 struct file * file = NULL;
62 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
63 if (!(flags & MAP_ANONYMOUS)) {
64 file = fget(fd);
65 if (!file)
66 goto out;
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);
73 if (file)
74 fput(file);
75 out:
76 return error;
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..
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;
95 asmlinkage long sys_mmap2(struct mmap_arg_struct __user *arg)
97 struct mmap_arg_struct a;
98 int error = -EFAULT;
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;
107 asmlinkage long old_mmap(struct mmap_arg_struct __user *arg)
109 struct mmap_arg_struct a;
110 long error = -EFAULT;
112 if (copy_from_user(&a, arg, sizeof(a)))
113 goto out;
115 error = -EINVAL;
116 if (a.offset & ~PAGE_MASK)
117 goto out;
119 error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
120 out:
121 return error;
124 #ifndef CONFIG_ARCH_S390X
125 struct sel_arg_struct {
126 unsigned long n;
127 fd_set *inp, *outp, *exp;
128 struct timeval *tvp;
131 asmlinkage long old_select(struct sel_arg_struct __user *arg)
133 struct sel_arg_struct a;
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);
141 #endif /* CONFIG_ARCH_S390X */
144 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
146 * This is really horribly ugly.
148 asmlinkage long sys_ipc(uint call, int first, unsigned long second,
149 unsigned long third, void __user *ptr)
151 struct ipc_kludge tmp;
152 int ret;
154 switch (call) {
155 case SEMOP:
156 return sys_semtimedop(first, (struct sembuf __user *)ptr,
157 (unsigned)second, NULL);
158 case SEMTIMEDOP:
159 return sys_semtimedop(first, (struct sembuf __user *)ptr,
160 (unsigned)second,
161 (const struct timespec __user *) third);
162 case SEMGET:
163 return sys_semget(first, (int)second, third);
164 case SEMCTL: {
165 union semun fourth;
166 if (!ptr)
167 return -EINVAL;
168 if (get_user(fourth.__pad, (void __user * __user *) ptr))
169 return -EFAULT;
170 return sys_semctl(first, (int)second, third, fourth);
172 case MSGSND:
173 return sys_msgsnd (first, (struct msgbuf __user *) ptr,
174 (size_t)second, third);
175 break;
176 case MSGRCV:
177 if (!ptr)
178 return -EINVAL;
179 if (copy_from_user (&tmp, (struct ipc_kludge __user *) ptr,
180 sizeof (struct ipc_kludge)))
181 return -EFAULT;
182 return sys_msgrcv (first, tmp.msgp,
183 (size_t)second, tmp.msgtyp, third);
184 case MSGGET:
185 return sys_msgget((key_t)first, (int)second);
186 case MSGCTL:
187 return sys_msgctl(first, (int)second,
188 (struct msqid_ds __user *)ptr);
190 case SHMAT: {
191 ulong raddr;
192 ret = do_shmat(first, (char __user *)ptr,
193 (int)second, &raddr);
194 if (ret)
195 return ret;
196 return put_user (raddr, (ulong __user *) third);
197 break;
199 case SHMDT:
200 return sys_shmdt ((char __user *)ptr);
201 case SHMGET:
202 return sys_shmget(first, (size_t)second, third);
203 case SHMCTL:
204 return sys_shmctl(first, (int)second,
205 (struct shmid_ds __user *) ptr);
206 default:
207 return -ENOSYS;
211 return -EINVAL;
214 #ifdef CONFIG_ARCH_S390X
215 asmlinkage long s390x_newuname(struct new_utsname __user *name)
217 int ret = sys_newuname(name);
219 if (current->personality == PER_LINUX32 && !ret) {
220 ret = copy_to_user(name->machine, "s390\0\0\0\0", 8);
221 if (ret) ret = -EFAULT;
223 return ret;
226 asmlinkage long s390x_personality(unsigned long personality)
228 int ret;
230 if (current->personality == PER_LINUX32 && personality == PER_LINUX)
231 personality = PER_LINUX32;
232 ret = sys_personality(personality);
233 if (ret == PER_LINUX32)
234 ret = PER_LINUX;
236 return ret;
238 #endif /* CONFIG_ARCH_S390X */
241 * Wrapper function for sys_fadvise64/fadvise64_64
243 #ifndef CONFIG_ARCH_S390X
245 asmlinkage long
246 s390_fadvise64(int fd, u32 offset_high, u32 offset_low, size_t len, int advice)
248 return sys_fadvise64(fd, (u64) offset_high << 32 | offset_low,
249 len, advice);
252 #endif
254 struct fadvise64_64_args {
255 int fd;
256 long long offset;
257 long long len;
258 int advice;
261 asmlinkage long
262 s390_fadvise64_64(struct fadvise64_64_args __user *args)
264 struct fadvise64_64_args a;
266 if ( copy_from_user(&a, args, sizeof(a)) )
267 return -EFAULT;
268 return sys_fadvise64_64(a.fd, a.offset, a.len, a.advice);