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