sys_s390.c revision 4e950f6f0189f65f8bf069cf2272649ef418f5e4
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 32#include <asm/uaccess.h> 33#include <asm/ipc.h> 34 35/* 36 * sys_pipe() is the normal C calling standard for creating 37 * a pipe. It's not the way Unix traditionally does this, though. 38 */ 39asmlinkage long sys_pipe(unsigned long __user *fildes) 40{ 41 int fd[2]; 42 int error; 43 44 error = do_pipe(fd); 45 if (!error) { 46 if (copy_to_user(fildes, fd, 2*sizeof(int))) 47 error = -EFAULT; 48 } 49 return error; 50} 51 52/* common code for old and new mmaps */ 53static 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) 57{ 58 long error = -EBADF; 59 struct file * file = NULL; 60 61 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); 62 if (!(flags & MAP_ANONYMOUS)) { 63 file = fget(fd); 64 if (!file) 65 goto out; 66 } 67 68 down_write(¤t->mm->mmap_sem); 69 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); 70 up_write(¤t->mm->mmap_sem); 71 72 if (file) 73 fput(file); 74out: 75 return error; 76} 77 78/* 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.. 83 */ 84 85struct 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; 92}; 93 94asmlinkage long sys_mmap2(struct mmap_arg_struct __user *arg) 95{ 96 struct mmap_arg_struct a; 97 int error = -EFAULT; 98 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); 102out: 103 return error; 104} 105 106asmlinkage long old_mmap(struct mmap_arg_struct __user *arg) 107{ 108 struct mmap_arg_struct a; 109 long error = -EFAULT; 110 111 if (copy_from_user(&a, arg, sizeof(a))) 112 goto out; 113 114 error = -EINVAL; 115 if (a.offset & ~PAGE_MASK) 116 goto out; 117 118 error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT); 119out: 120 return error; 121} 122 123#ifndef CONFIG_64BIT 124struct sel_arg_struct { 125 unsigned long n; 126 fd_set __user *inp, *outp, *exp; 127 struct timeval __user *tvp; 128}; 129 130asmlinkage long old_select(struct sel_arg_struct __user *arg) 131{ 132 struct sel_arg_struct a; 133 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); 138 139} 140#endif /* CONFIG_64BIT */ 141 142/* 143 * sys_ipc() is the de-multiplexer for the SysV IPC calls.. 144 * 145 * This is really horribly ugly. 146 */ 147asmlinkage long sys_ipc(uint call, int first, unsigned long second, 148 unsigned long third, void __user *ptr) 149{ 150 struct ipc_kludge tmp; 151 int ret; 152 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); 170 } 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); 188 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; 197 } 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; 207 208 } 209 210 return -EINVAL; 211} 212 213#ifdef CONFIG_64BIT 214asmlinkage long s390x_newuname(struct new_utsname __user *name) 215{ 216 int ret = sys_newuname(name); 217 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; 221 } 222 return ret; 223} 224 225asmlinkage long s390x_personality(unsigned long personality) 226{ 227 int ret; 228 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; 234 235 return ret; 236} 237#endif /* CONFIG_64BIT */ 238 239/* 240 * Wrapper function for sys_fadvise64/fadvise64_64 241 */ 242#ifndef CONFIG_64BIT 243 244asmlinkage long 245s390_fadvise64(int fd, u32 offset_high, u32 offset_low, size_t len, int advice) 246{ 247 return sys_fadvise64(fd, (u64) offset_high << 32 | offset_low, 248 len, advice); 249} 250 251#endif 252 253struct fadvise64_64_args { 254 int fd; 255 long long offset; 256 long long len; 257 int advice; 258}; 259 260asmlinkage long 261s390_fadvise64_64(struct fadvise64_64_args __user *args) 262{ 263 struct fadvise64_64_args a; 264 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); 268} 269 270#ifndef CONFIG_64BIT 271/* 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 282 */ 283asmlinkage long s390_fallocate(int fd, int mode, loff_t offset, 284 u32 len_high, u32 len_low) 285{ 286 return sys_fallocate(fd, mode, offset, ((u64)len_high << 32) | len_low); 287} 288#endif 289