blob: 90d00e47264dad66fdc2f0a83f31c4224b61c3a0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/sh/kernel/sys_sh.c
3 *
4 * This file contains various random system calls that
5 * have a non-standard calling sequence on the Linux/SuperH
6 * platform.
7 *
8 * Taken from i386 version.
9 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/errno.h>
11#include <linux/sched.h>
12#include <linux/mm.h>
13#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/sem.h>
15#include <linux/msg.h>
16#include <linux/shm.h>
17#include <linux/stat.h>
18#include <linux/syscalls.h>
19#include <linux/mman.h>
20#include <linux/file.h>
21#include <linux/utsname.h>
Paul Mundtf3c25752006-09-27 18:36:17 +090022#include <linux/module.h>
Paul Mundte06c4e52007-07-31 13:01:43 +090023#include <linux/fs.h>
Adrian Bunkcba4fbb2007-10-16 23:29:24 -070024#include <linux/ipc.h>
Paul Mundtfa439722008-09-04 18:53:58 +090025#include <asm/syscalls.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <asm/uaccess.h>
Arnd Bergmannfe742902006-10-02 02:18:34 -070027#include <asm/unistd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Linus Torvalds1da177e2005-04-16 15:20:36 -070029static inline long
Paul Mundtbcb28e42007-11-20 15:50:59 +090030do_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 unsigned long flags, int fd, unsigned long pgoff)
32{
33 int error = -EBADF;
34 struct file *file = NULL;
35
36 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
37 if (!(flags & MAP_ANONYMOUS)) {
38 file = fget(fd);
39 if (!file)
40 goto out;
41 }
42
43 down_write(&current->mm->mmap_sem);
44 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
45 up_write(&current->mm->mmap_sem);
46
47 if (file)
48 fput(file);
49out:
50 return error;
51}
52
53asmlinkage int old_mmap(unsigned long addr, unsigned long len,
54 unsigned long prot, unsigned long flags,
55 int fd, unsigned long off)
56{
57 if (off & ~PAGE_MASK)
58 return -EINVAL;
59 return do_mmap2(addr, len, prot, flags, fd, off>>PAGE_SHIFT);
60}
61
62asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
63 unsigned long prot, unsigned long flags,
64 unsigned long fd, unsigned long pgoff)
65{
Toshinobu Sugioka8c318132009-04-21 07:34:53 +090066 /*
67 * The shift for mmap2 is constant, regardless of PAGE_SIZE
68 * setting.
69 */
70 if (pgoff & ((1 << (PAGE_SHIFT - 12)) - 1))
71 return -EINVAL;
72
73 pgoff >>= PAGE_SHIFT - 12;
74
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 return do_mmap2(addr, len, prot, flags, fd, pgoff);
76}
77
78/*
79 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
80 *
81 * This is really horribly ugly.
82 */
83asmlinkage int sys_ipc(uint call, int first, int second,
84 int third, void __user *ptr, long fifth)
85{
86 int version, ret;
87
88 version = call >> 16; /* hack for backward compatibility */
89 call &= 0xffff;
90
Yoshihiro Shimoda3c31bf72008-08-27 20:16:46 +090091 if (call <= SEMTIMEDOP)
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 switch (call) {
93 case SEMOP:
Paul Mundtbcb28e42007-11-20 15:50:59 +090094 return sys_semtimedop(first,
95 (struct sembuf __user *)ptr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 second, NULL);
97 case SEMTIMEDOP:
Paul Mundtbcb28e42007-11-20 15:50:59 +090098 return sys_semtimedop(first,
99 (struct sembuf __user *)ptr, second,
100 (const struct timespec __user *)fifth);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 case SEMGET:
102 return sys_semget (first, second, third);
103 case SEMCTL: {
104 union semun fourth;
105 if (!ptr)
106 return -EINVAL;
Paul Mundtfa439722008-09-04 18:53:58 +0900107 if (get_user(fourth.__pad, (void __user * __user *) ptr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 return -EFAULT;
109 return sys_semctl (first, second, third, fourth);
110 }
111 default:
112 return -EINVAL;
113 }
114
Paul Mundtbcb28e42007-11-20 15:50:59 +0900115 if (call <= MSGCTL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 switch (call) {
117 case MSGSND:
Paul Mundtbcb28e42007-11-20 15:50:59 +0900118 return sys_msgsnd (first, (struct msgbuf __user *) ptr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 second, third);
120 case MSGRCV:
121 switch (version) {
Paul Mundtbcb28e42007-11-20 15:50:59 +0900122 case 0:
123 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 struct ipc_kludge tmp;
Paul Mundtbcb28e42007-11-20 15:50:59 +0900125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 if (!ptr)
127 return -EINVAL;
Paul Mundtbcb28e42007-11-20 15:50:59 +0900128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 if (copy_from_user(&tmp,
Paul Mundtbcb28e42007-11-20 15:50:59 +0900130 (struct ipc_kludge __user *) ptr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 sizeof (tmp)))
132 return -EFAULT;
Paul Mundtbcb28e42007-11-20 15:50:59 +0900133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 return sys_msgrcv (first, tmp.msgp, second,
135 tmp.msgtyp, third);
Paul Mundtbcb28e42007-11-20 15:50:59 +0900136 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 default:
138 return sys_msgrcv (first,
139 (struct msgbuf __user *) ptr,
140 second, fifth, third);
141 }
142 case MSGGET:
143 return sys_msgget ((key_t) first, second);
144 case MSGCTL:
145 return sys_msgctl (first, second,
146 (struct msqid_ds __user *) ptr);
147 default:
148 return -EINVAL;
149 }
Paul Mundtbcb28e42007-11-20 15:50:59 +0900150 if (call <= SHMCTL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 switch (call) {
152 case SHMAT:
153 switch (version) {
154 default: {
155 ulong raddr;
156 ret = do_shmat (first, (char __user *) ptr,
157 second, &raddr);
158 if (ret)
159 return ret;
160 return put_user (raddr, (ulong __user *) third);
161 }
162 case 1: /* iBCS2 emulator entry point */
163 if (!segment_eq(get_fs(), get_ds()))
164 return -EINVAL;
165 return do_shmat (first, (char __user *) ptr,
166 second, (ulong *) third);
167 }
Paul Mundtbcb28e42007-11-20 15:50:59 +0900168 case SHMDT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 return sys_shmdt ((char __user *)ptr);
170 case SHMGET:
171 return sys_shmget (first, second, third);
172 case SHMCTL:
173 return sys_shmctl (first, second,
174 (struct shmid_ds __user *) ptr);
175 default:
176 return -EINVAL;
177 }
Paul Mundtbcb28e42007-11-20 15:50:59 +0900178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 return -EINVAL;
180}
181
Paul Mundtfa439722008-09-04 18:53:58 +0900182asmlinkage int sys_uname(struct old_utsname __user *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183{
184 int err;
185 if (!name)
186 return -EFAULT;
187 down_read(&uts_sem);
Paul Mundtfa439722008-09-04 18:53:58 +0900188 err = copy_to_user(name, utsname(), sizeof(*name));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 up_read(&uts_sem);
190 return err?-EFAULT:0;
191}