blob: 202fa73ac1677d1a04d381519c2b046fcfb4c326 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * S390 version
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02004 * Copyright IBM Corp. 1999, 2000
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
6 * Thomas Spatzier (tspat@de.ibm.com)
7 *
8 * Derived from "arch/i386/kernel/sys_i386.c"
9 *
10 * This file contains various random system calls that
11 * have a non-standard calling sequence on the Linux/s390
12 * platform.
13 */
14
15#include <linux/errno.h>
16#include <linux/sched.h>
17#include <linux/mm.h>
Alexey Dobriyan4e950f62007-07-30 02:36:13 +040018#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/sem.h>
21#include <linux/msg.h>
22#include <linux/shm.h>
23#include <linux/stat.h>
24#include <linux/syscalls.h>
25#include <linux/mman.h>
26#include <linux/file.h>
27#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/personality.h>
Arnd Bergmannfe742902006-10-02 02:18:34 -070029#include <linux/unistd.h>
Adrian Bunkcba4fbb2007-10-16 23:29:24 -070030#include <linux/ipc.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080031#include <linux/uaccess.h>
Heiko Carstensa8061702008-04-17 07:46:26 +020032#include "entry.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Linus Torvalds1da177e2005-04-16 15:20:36 -070034/*
Christoph Hellwiga4679372010-03-10 15:21:15 -080035 * Perform the mmap() system call. Linux for S/390 isn't able to handle more
36 * than 5 system call parameters, so this system call uses a memory block
37 * for parameter passing.
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 */
39
Christoph Hellwiga4679372010-03-10 15:21:15 -080040struct s390_mmap_arg_struct {
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 unsigned long addr;
42 unsigned long len;
43 unsigned long prot;
44 unsigned long flags;
45 unsigned long fd;
46 unsigned long offset;
47};
48
Christoph Hellwiga4679372010-03-10 15:21:15 -080049SYSCALL_DEFINE1(mmap2, struct s390_mmap_arg_struct __user *, arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070050{
Christoph Hellwiga4679372010-03-10 15:21:15 -080051 struct s390_mmap_arg_struct a;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 int error = -EFAULT;
53
54 if (copy_from_user(&a, arg, sizeof(a)))
55 goto out;
Dominik Brodowskia90f5902018-03-11 11:34:46 +010056 error = ksys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, a.offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057out:
58 return error;
59}
60
Arnd Bergmann58fa4a42019-01-16 14:15:20 +010061#ifdef CONFIG_SYSVIPC
Linus Torvalds1da177e2005-04-16 15:20:36 -070062/*
Heiko Carstens3a3954c2011-12-27 11:27:21 +010063 * sys_ipc() is the de-multiplexer for the SysV IPC calls.
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 */
Christoph Hellwigbaed7fc2010-03-10 15:21:18 -080065SYSCALL_DEFINE5(s390_ipc, uint, call, int, first, unsigned long, second,
Heiko Carstens26689452009-01-14 14:14:36 +010066 unsigned long, third, void __user *, ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
Heiko Carstens3a3954c2011-12-27 11:27:21 +010068 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 */
Arnd Bergmann58fa4a42019-01-16 14:15:20 +010078 return ksys_ipc(call, first, second, third, ptr, third);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079}
Arnd Bergmann58fa4a42019-01-16 14:15:20 +010080#endif /* CONFIG_SYSVIPC */
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Heiko Carstens3a110372010-08-13 10:06:39 +020082SYSCALL_DEFINE1(s390_personality, unsigned int, personality)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
Arnd Bergmann1ecff5e2019-01-16 14:15:19 +010084 unsigned int ret = current->personality;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Jiri Kosina5ab37e12012-08-02 09:11:23 +020086 if (personality(current->personality) == PER_LINUX32 &&
87 personality(personality) == PER_LINUX)
88 personality |= PER_LINUX32;
Arnd Bergmann1ecff5e2019-01-16 14:15:19 +010089
90 if (personality != 0xffffffff)
91 set_personality(personality);
92
Jiri Kosina5ab37e12012-08-02 09:11:23 +020093 if (personality(ret) == PER_LINUX32)
94 ret &= ~PER_LINUX32;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96 return ret;
97}
Arnd Bergmannaa0d6e72019-01-16 14:15:22 +010098
99SYSCALL_DEFINE0(ni_syscall)
100{
101 return -ENOSYS;
102}