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 | /* |
Christoph Hellwig | a467937 | 2010-03-10 15:21:15 -0800 | [diff] [blame] | 36 | * Perform the mmap() system call. Linux for S/390 isn't able to handle more |
| 37 | * than 5 system call parameters, so this system call uses a memory block |
| 38 | * for parameter passing. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | */ |
| 40 | |
Christoph Hellwig | a467937 | 2010-03-10 15:21:15 -0800 | [diff] [blame] | 41 | struct s390_mmap_arg_struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | unsigned long addr; |
| 43 | unsigned long len; |
| 44 | unsigned long prot; |
| 45 | unsigned long flags; |
| 46 | unsigned long fd; |
| 47 | unsigned long offset; |
| 48 | }; |
| 49 | |
Christoph Hellwig | a467937 | 2010-03-10 15:21:15 -0800 | [diff] [blame] | 50 | SYSCALL_DEFINE1(mmap2, struct s390_mmap_arg_struct __user *, arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | { |
Christoph Hellwig | a467937 | 2010-03-10 15:21:15 -0800 | [diff] [blame] | 52 | struct s390_mmap_arg_struct a; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | int error = -EFAULT; |
| 54 | |
| 55 | if (copy_from_user(&a, arg, sizeof(a))) |
| 56 | goto out; |
Al Viro | f8b7256 | 2009-11-30 17:37:04 -0500 | [diff] [blame] | 57 | 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] | 58 | out: |
| 59 | return error; |
| 60 | } |
| 61 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | /* |
Heiko Carstens | 3a3954c | 2011-12-27 11:27:21 +0100 | [diff] [blame] | 63 | * sys_ipc() is the de-multiplexer for the SysV IPC calls. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | */ |
Christoph Hellwig | baed7fc | 2010-03-10 15:21:18 -0800 | [diff] [blame] | 65 | SYSCALL_DEFINE5(s390_ipc, uint, call, int, first, unsigned long, second, |
Heiko Carstens | 2668945 | 2009-01-14 14:14:36 +0100 | [diff] [blame] | 66 | unsigned long, third, void __user *, ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | { |
Heiko Carstens | 3a3954c | 2011-12-27 11:27:21 +0100 | [diff] [blame] | 68 | if (call >> 16) |
| 69 | return -EINVAL; |
| 70 | /* The s390 sys_ipc variant has only five parameters instead of six |
| 71 | * like the generic variant. The only difference is the handling of |
| 72 | * the SEMTIMEDOP subcall where on s390 the third parameter is used |
| 73 | * as a pointer to a struct timespec where the generic variant uses |
| 74 | * the fifth parameter. |
| 75 | * Therefore we can call the generic variant by simply passing the |
| 76 | * third parameter also as fifth parameter. |
| 77 | */ |
| 78 | return sys_ipc(call, first, second, third, ptr, third); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 81 | #ifdef CONFIG_64BIT |
Heiko Carstens | 3a11037 | 2010-08-13 10:06:39 +0200 | [diff] [blame] | 82 | SYSCALL_DEFINE1(s390_personality, unsigned int, personality) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | { |
Heiko Carstens | 3a11037 | 2010-08-13 10:06:39 +0200 | [diff] [blame] | 84 | unsigned int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
| 86 | if (current->personality == PER_LINUX32 && personality == PER_LINUX) |
| 87 | personality = PER_LINUX32; |
| 88 | ret = sys_personality(personality); |
| 89 | if (ret == PER_LINUX32) |
| 90 | ret = PER_LINUX; |
| 91 | |
| 92 | return ret; |
| 93 | } |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 94 | #endif /* CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
| 96 | /* |
| 97 | * Wrapper function for sys_fadvise64/fadvise64_64 |
| 98 | */ |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 99 | #ifndef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
Heiko Carstens | 2668945 | 2009-01-14 14:14:36 +0100 | [diff] [blame] | 101 | SYSCALL_DEFINE5(s390_fadvise64, int, fd, u32, offset_high, u32, offset_low, |
| 102 | size_t, len, int, advice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | { |
| 104 | return sys_fadvise64(fd, (u64) offset_high << 32 | offset_low, |
| 105 | len, advice); |
| 106 | } |
| 107 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | struct fadvise64_64_args { |
| 109 | int fd; |
| 110 | long long offset; |
| 111 | long long len; |
| 112 | int advice; |
| 113 | }; |
| 114 | |
Heiko Carstens | 2668945 | 2009-01-14 14:14:36 +0100 | [diff] [blame] | 115 | SYSCALL_DEFINE1(s390_fadvise64_64, struct fadvise64_64_args __user *, args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | { |
| 117 | struct fadvise64_64_args a; |
| 118 | |
| 119 | if ( copy_from_user(&a, args, sizeof(a)) ) |
| 120 | return -EFAULT; |
| 121 | return sys_fadvise64_64(a.fd, a.offset, a.len, a.advice); |
| 122 | } |
Martin Schwidefsky | 7a8e0c8 | 2007-07-27 12:29:16 +0200 | [diff] [blame] | 123 | |
Martin Schwidefsky | 7a8e0c8 | 2007-07-27 12:29:16 +0200 | [diff] [blame] | 124 | /* |
| 125 | * This is a wrapper to call sys_fallocate(). For 31 bit s390 the last |
| 126 | * 64 bit argument "len" is split into the upper and lower 32 bits. The |
| 127 | * system call wrapper in the user space loads the value to %r6/%r7. |
| 128 | * The code in entry.S keeps the values in %r2 - %r6 where they are and |
| 129 | * stores %r7 to 96(%r15). But the standard C linkage requires that |
| 130 | * the whole 64 bit value for len is stored on the stack and doesn't |
| 131 | * use %r6 at all. So s390_fallocate has to convert the arguments from |
| 132 | * %r2: fd, %r3: mode, %r4/%r5: offset, %r6/96(%r15)-99(%r15): len |
| 133 | * to |
| 134 | * %r2: fd, %r3: mode, %r4/%r5: offset, 96(%r15)-103(%r15): len |
| 135 | */ |
Heiko Carstens | 2668945 | 2009-01-14 14:14:36 +0100 | [diff] [blame] | 136 | SYSCALL_DEFINE(s390_fallocate)(int fd, int mode, loff_t offset, |
Martin Schwidefsky | 7a8e0c8 | 2007-07-27 12:29:16 +0200 | [diff] [blame] | 137 | u32 len_high, u32 len_low) |
| 138 | { |
| 139 | return sys_fallocate(fd, mode, offset, ((u64)len_high << 32) | len_low); |
| 140 | } |
Heiko Carstens | 2668945 | 2009-01-14 14:14:36 +0100 | [diff] [blame] | 141 | #ifdef CONFIG_HAVE_SYSCALL_WRAPPERS |
| 142 | asmlinkage long SyS_s390_fallocate(long fd, long mode, loff_t offset, |
| 143 | long len_high, long len_low) |
| 144 | { |
| 145 | return SYSC_s390_fallocate((int) fd, (int) mode, offset, |
| 146 | (u32) len_high, (u32) len_low); |
| 147 | } |
| 148 | SYSCALL_ALIAS(sys_s390_fallocate, SyS_s390_fallocate); |
| 149 | #endif |
| 150 | |
Martin Schwidefsky | 7a8e0c8 | 2007-07-27 12:29:16 +0200 | [diff] [blame] | 151 | #endif |