Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Alexey Dobriyan | 4e950f6 | 2007-07-30 02:36:13 +0400 | [diff] [blame] | 19 | #include <linux/fs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/personality.h> |
Arnd Bergmann | fe74290 | 2006-10-02 02:18:34 -0700 | [diff] [blame] | 30 | #include <linux/unistd.h> |
Adrian Bunk | cba4fbb | 2007-10-16 23:29:24 -0700 | [diff] [blame] | 31 | #include <linux/ipc.h> |
Heiko Carstens | 2668945 | 2009-01-14 14:14:36 +0100 | [diff] [blame^] | 32 | #include <linux/syscalls.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <asm/uaccess.h> |
Heiko Carstens | a806170 | 2008-04-17 07:46:26 +0200 | [diff] [blame] | 34 | #include "entry.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | /* common code for old and new mmaps */ |
| 37 | static inline long do_mmap2( |
| 38 | unsigned long addr, unsigned long len, |
| 39 | unsigned long prot, unsigned long flags, |
| 40 | unsigned long fd, unsigned long pgoff) |
| 41 | { |
| 42 | long error = -EBADF; |
| 43 | struct file * file = NULL; |
| 44 | |
| 45 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); |
| 46 | if (!(flags & MAP_ANONYMOUS)) { |
| 47 | file = fget(fd); |
| 48 | if (!file) |
| 49 | goto out; |
| 50 | } |
| 51 | |
| 52 | down_write(¤t->mm->mmap_sem); |
| 53 | error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); |
| 54 | up_write(¤t->mm->mmap_sem); |
| 55 | |
| 56 | if (file) |
| 57 | fput(file); |
| 58 | out: |
| 59 | return error; |
| 60 | } |
| 61 | |
| 62 | /* |
| 63 | * Perform the select(nd, in, out, ex, tv) and mmap() system |
| 64 | * calls. Linux for S/390 isn't able to handle more than 5 |
| 65 | * system call parameters, so these system calls used a memory |
| 66 | * block for parameter passing.. |
| 67 | */ |
| 68 | |
| 69 | struct mmap_arg_struct { |
| 70 | unsigned long addr; |
| 71 | unsigned long len; |
| 72 | unsigned long prot; |
| 73 | unsigned long flags; |
| 74 | unsigned long fd; |
| 75 | unsigned long offset; |
| 76 | }; |
| 77 | |
Heiko Carstens | 2668945 | 2009-01-14 14:14:36 +0100 | [diff] [blame^] | 78 | SYSCALL_DEFINE1(mmap2, struct mmap_arg_struct __user *, arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | { |
| 80 | struct mmap_arg_struct a; |
| 81 | int error = -EFAULT; |
| 82 | |
| 83 | if (copy_from_user(&a, arg, sizeof(a))) |
| 84 | goto out; |
| 85 | error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset); |
| 86 | out: |
| 87 | return error; |
| 88 | } |
| 89 | |
Heiko Carstens | 2668945 | 2009-01-14 14:14:36 +0100 | [diff] [blame^] | 90 | SYSCALL_DEFINE1(s390_old_mmap, struct mmap_arg_struct __user *, arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | { |
| 92 | struct mmap_arg_struct a; |
| 93 | long error = -EFAULT; |
| 94 | |
| 95 | if (copy_from_user(&a, arg, sizeof(a))) |
| 96 | goto out; |
| 97 | |
| 98 | error = -EINVAL; |
| 99 | if (a.offset & ~PAGE_MASK) |
| 100 | goto out; |
| 101 | |
| 102 | error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT); |
| 103 | out: |
| 104 | return error; |
| 105 | } |
| 106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | /* |
| 108 | * sys_ipc() is the de-multiplexer for the SysV IPC calls.. |
| 109 | * |
| 110 | * This is really horribly ugly. |
| 111 | */ |
Heiko Carstens | 2668945 | 2009-01-14 14:14:36 +0100 | [diff] [blame^] | 112 | SYSCALL_DEFINE5(ipc, uint, call, int, first, unsigned long, second, |
| 113 | unsigned long, third, void __user *, ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | { |
| 115 | struct ipc_kludge tmp; |
| 116 | int ret; |
| 117 | |
| 118 | switch (call) { |
| 119 | case SEMOP: |
| 120 | return sys_semtimedop(first, (struct sembuf __user *)ptr, |
| 121 | (unsigned)second, NULL); |
| 122 | case SEMTIMEDOP: |
| 123 | return sys_semtimedop(first, (struct sembuf __user *)ptr, |
| 124 | (unsigned)second, |
| 125 | (const struct timespec __user *) third); |
| 126 | case SEMGET: |
| 127 | return sys_semget(first, (int)second, third); |
| 128 | case SEMCTL: { |
| 129 | union semun fourth; |
| 130 | if (!ptr) |
| 131 | return -EINVAL; |
| 132 | if (get_user(fourth.__pad, (void __user * __user *) ptr)) |
| 133 | return -EFAULT; |
| 134 | return sys_semctl(first, (int)second, third, fourth); |
| 135 | } |
| 136 | case MSGSND: |
| 137 | return sys_msgsnd (first, (struct msgbuf __user *) ptr, |
| 138 | (size_t)second, third); |
| 139 | break; |
| 140 | case MSGRCV: |
| 141 | if (!ptr) |
| 142 | return -EINVAL; |
| 143 | if (copy_from_user (&tmp, (struct ipc_kludge __user *) ptr, |
| 144 | sizeof (struct ipc_kludge))) |
| 145 | return -EFAULT; |
| 146 | return sys_msgrcv (first, tmp.msgp, |
| 147 | (size_t)second, tmp.msgtyp, third); |
| 148 | case MSGGET: |
| 149 | return sys_msgget((key_t)first, (int)second); |
| 150 | case MSGCTL: |
| 151 | return sys_msgctl(first, (int)second, |
| 152 | (struct msqid_ds __user *)ptr); |
| 153 | |
| 154 | case SHMAT: { |
| 155 | ulong raddr; |
| 156 | ret = do_shmat(first, (char __user *)ptr, |
| 157 | (int)second, &raddr); |
| 158 | if (ret) |
| 159 | return ret; |
| 160 | return put_user (raddr, (ulong __user *) third); |
| 161 | break; |
| 162 | } |
| 163 | case SHMDT: |
| 164 | return sys_shmdt ((char __user *)ptr); |
| 165 | case SHMGET: |
| 166 | return sys_shmget(first, (size_t)second, third); |
| 167 | case SHMCTL: |
| 168 | return sys_shmctl(first, (int)second, |
| 169 | (struct shmid_ds __user *) ptr); |
| 170 | default: |
| 171 | return -ENOSYS; |
| 172 | |
| 173 | } |
| 174 | |
| 175 | return -EINVAL; |
| 176 | } |
| 177 | |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 178 | #ifdef CONFIG_64BIT |
Heiko Carstens | 2668945 | 2009-01-14 14:14:36 +0100 | [diff] [blame^] | 179 | SYSCALL_DEFINE1(s390_newuname, struct new_utsname __user *, name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | { |
| 181 | int ret = sys_newuname(name); |
| 182 | |
Martin Schwidefsky | d2f019f | 2008-11-14 18:18:09 +0100 | [diff] [blame] | 183 | if (personality(current->personality) == PER_LINUX32 && !ret) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | ret = copy_to_user(name->machine, "s390\0\0\0\0", 8); |
| 185 | if (ret) ret = -EFAULT; |
| 186 | } |
| 187 | return ret; |
| 188 | } |
| 189 | |
Heiko Carstens | 2668945 | 2009-01-14 14:14:36 +0100 | [diff] [blame^] | 190 | SYSCALL_DEFINE1(s390_personality, unsigned long, personality) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | { |
| 192 | int ret; |
| 193 | |
| 194 | if (current->personality == PER_LINUX32 && personality == PER_LINUX) |
| 195 | personality = PER_LINUX32; |
| 196 | ret = sys_personality(personality); |
| 197 | if (ret == PER_LINUX32) |
| 198 | ret = PER_LINUX; |
| 199 | |
| 200 | return ret; |
| 201 | } |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 202 | #endif /* CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
| 204 | /* |
| 205 | * Wrapper function for sys_fadvise64/fadvise64_64 |
| 206 | */ |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 207 | #ifndef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
Heiko Carstens | 2668945 | 2009-01-14 14:14:36 +0100 | [diff] [blame^] | 209 | SYSCALL_DEFINE5(s390_fadvise64, int, fd, u32, offset_high, u32, offset_low, |
| 210 | size_t, len, int, advice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | { |
| 212 | return sys_fadvise64(fd, (u64) offset_high << 32 | offset_low, |
| 213 | len, advice); |
| 214 | } |
| 215 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | struct fadvise64_64_args { |
| 217 | int fd; |
| 218 | long long offset; |
| 219 | long long len; |
| 220 | int advice; |
| 221 | }; |
| 222 | |
Heiko Carstens | 2668945 | 2009-01-14 14:14:36 +0100 | [diff] [blame^] | 223 | SYSCALL_DEFINE1(s390_fadvise64_64, struct fadvise64_64_args __user *, args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | { |
| 225 | struct fadvise64_64_args a; |
| 226 | |
| 227 | if ( copy_from_user(&a, args, sizeof(a)) ) |
| 228 | return -EFAULT; |
| 229 | return sys_fadvise64_64(a.fd, a.offset, a.len, a.advice); |
| 230 | } |
Martin Schwidefsky | 7a8e0c8 | 2007-07-27 12:29:16 +0200 | [diff] [blame] | 231 | |
Martin Schwidefsky | 7a8e0c8 | 2007-07-27 12:29:16 +0200 | [diff] [blame] | 232 | /* |
| 233 | * This is a wrapper to call sys_fallocate(). For 31 bit s390 the last |
| 234 | * 64 bit argument "len" is split into the upper and lower 32 bits. The |
| 235 | * system call wrapper in the user space loads the value to %r6/%r7. |
| 236 | * The code in entry.S keeps the values in %r2 - %r6 where they are and |
| 237 | * stores %r7 to 96(%r15). But the standard C linkage requires that |
| 238 | * the whole 64 bit value for len is stored on the stack and doesn't |
| 239 | * use %r6 at all. So s390_fallocate has to convert the arguments from |
| 240 | * %r2: fd, %r3: mode, %r4/%r5: offset, %r6/96(%r15)-99(%r15): len |
| 241 | * to |
| 242 | * %r2: fd, %r3: mode, %r4/%r5: offset, 96(%r15)-103(%r15): len |
| 243 | */ |
Heiko Carstens | 2668945 | 2009-01-14 14:14:36 +0100 | [diff] [blame^] | 244 | SYSCALL_DEFINE(s390_fallocate)(int fd, int mode, loff_t offset, |
Martin Schwidefsky | 7a8e0c8 | 2007-07-27 12:29:16 +0200 | [diff] [blame] | 245 | u32 len_high, u32 len_low) |
| 246 | { |
| 247 | return sys_fallocate(fd, mode, offset, ((u64)len_high << 32) | len_low); |
| 248 | } |
Heiko Carstens | 2668945 | 2009-01-14 14:14:36 +0100 | [diff] [blame^] | 249 | #ifdef CONFIG_HAVE_SYSCALL_WRAPPERS |
| 250 | asmlinkage long SyS_s390_fallocate(long fd, long mode, loff_t offset, |
| 251 | long len_high, long len_low) |
| 252 | { |
| 253 | return SYSC_s390_fallocate((int) fd, (int) mode, offset, |
| 254 | (u32) len_high, (u32) len_low); |
| 255 | } |
| 256 | SYSCALL_ALIAS(sys_s390_fallocate, SyS_s390_fallocate); |
| 257 | #endif |
| 258 | |
Martin Schwidefsky | 7a8e0c8 | 2007-07-27 12:29:16 +0200 | [diff] [blame] | 259 | #endif |