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