blob: 58dfc02c7af13bd92431cf16dfc44d8ea9c75f31 [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{
66 return do_mmap2(addr, len, prot, flags, fd, pgoff);
67}
68
69/*
70 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
71 *
72 * This is really horribly ugly.
73 */
74asmlinkage int sys_ipc(uint call, int first, int second,
75 int third, void __user *ptr, long fifth)
76{
77 int version, ret;
78
79 version = call >> 16; /* hack for backward compatibility */
80 call &= 0xffff;
81
Paul Mundt3d586952008-09-21 13:56:39 +090082 trace_mark(kernel_arch_ipc_call, "call %u first %d", call, first);
83
Yoshihiro Shimoda3c31bf72008-08-27 20:16:46 +090084 if (call <= SEMTIMEDOP)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 switch (call) {
86 case SEMOP:
Paul Mundtbcb28e42007-11-20 15:50:59 +090087 return sys_semtimedop(first,
88 (struct sembuf __user *)ptr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 second, NULL);
90 case SEMTIMEDOP:
Paul Mundtbcb28e42007-11-20 15:50:59 +090091 return sys_semtimedop(first,
92 (struct sembuf __user *)ptr, second,
93 (const struct timespec __user *)fifth);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 case SEMGET:
95 return sys_semget (first, second, third);
96 case SEMCTL: {
97 union semun fourth;
98 if (!ptr)
99 return -EINVAL;
Paul Mundtfa439722008-09-04 18:53:58 +0900100 if (get_user(fourth.__pad, (void __user * __user *) ptr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 return -EFAULT;
102 return sys_semctl (first, second, third, fourth);
103 }
104 default:
105 return -EINVAL;
106 }
107
Paul Mundtbcb28e42007-11-20 15:50:59 +0900108 if (call <= MSGCTL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 switch (call) {
110 case MSGSND:
Paul Mundtbcb28e42007-11-20 15:50:59 +0900111 return sys_msgsnd (first, (struct msgbuf __user *) ptr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 second, third);
113 case MSGRCV:
114 switch (version) {
Paul Mundtbcb28e42007-11-20 15:50:59 +0900115 case 0:
116 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 struct ipc_kludge tmp;
Paul Mundtbcb28e42007-11-20 15:50:59 +0900118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 if (!ptr)
120 return -EINVAL;
Paul Mundtbcb28e42007-11-20 15:50:59 +0900121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 if (copy_from_user(&tmp,
Paul Mundtbcb28e42007-11-20 15:50:59 +0900123 (struct ipc_kludge __user *) ptr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 sizeof (tmp)))
125 return -EFAULT;
Paul Mundtbcb28e42007-11-20 15:50:59 +0900126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 return sys_msgrcv (first, tmp.msgp, second,
128 tmp.msgtyp, third);
Paul Mundtbcb28e42007-11-20 15:50:59 +0900129 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 default:
131 return sys_msgrcv (first,
132 (struct msgbuf __user *) ptr,
133 second, fifth, third);
134 }
135 case MSGGET:
136 return sys_msgget ((key_t) first, second);
137 case MSGCTL:
138 return sys_msgctl (first, second,
139 (struct msqid_ds __user *) ptr);
140 default:
141 return -EINVAL;
142 }
Paul Mundtbcb28e42007-11-20 15:50:59 +0900143 if (call <= SHMCTL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 switch (call) {
145 case SHMAT:
146 switch (version) {
147 default: {
148 ulong raddr;
149 ret = do_shmat (first, (char __user *) ptr,
150 second, &raddr);
151 if (ret)
152 return ret;
153 return put_user (raddr, (ulong __user *) third);
154 }
155 case 1: /* iBCS2 emulator entry point */
156 if (!segment_eq(get_fs(), get_ds()))
157 return -EINVAL;
158 return do_shmat (first, (char __user *) ptr,
159 second, (ulong *) third);
160 }
Paul Mundtbcb28e42007-11-20 15:50:59 +0900161 case SHMDT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 return sys_shmdt ((char __user *)ptr);
163 case SHMGET:
164 return sys_shmget (first, second, third);
165 case SHMCTL:
166 return sys_shmctl (first, second,
167 (struct shmid_ds __user *) ptr);
168 default:
169 return -EINVAL;
170 }
Paul Mundtbcb28e42007-11-20 15:50:59 +0900171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 return -EINVAL;
173}
174
Paul Mundtfa439722008-09-04 18:53:58 +0900175asmlinkage int sys_uname(struct old_utsname __user *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176{
177 int err;
178 if (!name)
179 return -EFAULT;
180 down_read(&uts_sem);
Paul Mundtfa439722008-09-04 18:53:58 +0900181 err = copy_to_user(name, utsname(), sizeof(*name));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 up_read(&uts_sem);
183 return err?-EFAULT:0;
184}