blob: ec65dd8842b16ff9b844795abd20679c2a1c03f7 [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>
Stuart Menefy6d243dd2009-08-24 18:16:56 +090028#include <asm/cacheflush.h>
29#include <asm/cachectl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Linus Torvalds1da177e2005-04-16 15:20:36 -070031static inline long
Paul Mundtbcb28e42007-11-20 15:50:59 +090032do_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 unsigned long flags, int fd, unsigned long pgoff)
34{
35 int error = -EBADF;
36 struct file *file = NULL;
37
38 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
39 if (!(flags & MAP_ANONYMOUS)) {
40 file = fget(fd);
41 if (!file)
42 goto out;
43 }
44
45 down_write(&current->mm->mmap_sem);
46 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
47 up_write(&current->mm->mmap_sem);
48
49 if (file)
50 fput(file);
51out:
52 return error;
53}
54
55asmlinkage int old_mmap(unsigned long addr, unsigned long len,
56 unsigned long prot, unsigned long flags,
57 int fd, unsigned long off)
58{
59 if (off & ~PAGE_MASK)
60 return -EINVAL;
61 return do_mmap2(addr, len, prot, flags, fd, off>>PAGE_SHIFT);
62}
63
64asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
65 unsigned long prot, unsigned long flags,
66 unsigned long fd, unsigned long pgoff)
67{
Toshinobu Sugioka8c318132009-04-21 07:34:53 +090068 /*
69 * The shift for mmap2 is constant, regardless of PAGE_SIZE
70 * setting.
71 */
72 if (pgoff & ((1 << (PAGE_SHIFT - 12)) - 1))
73 return -EINVAL;
74
75 pgoff >>= PAGE_SHIFT - 12;
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 return do_mmap2(addr, len, prot, flags, fd, pgoff);
78}
79
80/*
81 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
82 *
83 * This is really horribly ugly.
84 */
85asmlinkage int sys_ipc(uint call, int first, int second,
86 int third, void __user *ptr, long fifth)
87{
88 int version, ret;
89
90 version = call >> 16; /* hack for backward compatibility */
91 call &= 0xffff;
92
Yoshihiro Shimoda3c31bf72008-08-27 20:16:46 +090093 if (call <= SEMTIMEDOP)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 switch (call) {
95 case SEMOP:
Paul Mundtbcb28e42007-11-20 15:50:59 +090096 return sys_semtimedop(first,
97 (struct sembuf __user *)ptr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 second, NULL);
99 case SEMTIMEDOP:
Paul Mundtbcb28e42007-11-20 15:50:59 +0900100 return sys_semtimedop(first,
101 (struct sembuf __user *)ptr, second,
102 (const struct timespec __user *)fifth);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 case SEMGET:
104 return sys_semget (first, second, third);
105 case SEMCTL: {
106 union semun fourth;
107 if (!ptr)
108 return -EINVAL;
Paul Mundtfa439722008-09-04 18:53:58 +0900109 if (get_user(fourth.__pad, (void __user * __user *) ptr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 return -EFAULT;
111 return sys_semctl (first, second, third, fourth);
112 }
113 default:
114 return -EINVAL;
115 }
116
Paul Mundtbcb28e42007-11-20 15:50:59 +0900117 if (call <= MSGCTL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 switch (call) {
119 case MSGSND:
Paul Mundtbcb28e42007-11-20 15:50:59 +0900120 return sys_msgsnd (first, (struct msgbuf __user *) ptr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 second, third);
122 case MSGRCV:
123 switch (version) {
Paul Mundtbcb28e42007-11-20 15:50:59 +0900124 case 0:
125 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 struct ipc_kludge tmp;
Paul Mundtbcb28e42007-11-20 15:50:59 +0900127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 if (!ptr)
129 return -EINVAL;
Paul Mundtbcb28e42007-11-20 15:50:59 +0900130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 if (copy_from_user(&tmp,
Paul Mundtbcb28e42007-11-20 15:50:59 +0900132 (struct ipc_kludge __user *) ptr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 sizeof (tmp)))
134 return -EFAULT;
Paul Mundtbcb28e42007-11-20 15:50:59 +0900135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 return sys_msgrcv (first, tmp.msgp, second,
137 tmp.msgtyp, third);
Paul Mundtbcb28e42007-11-20 15:50:59 +0900138 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 default:
140 return sys_msgrcv (first,
141 (struct msgbuf __user *) ptr,
142 second, fifth, third);
143 }
144 case MSGGET:
145 return sys_msgget ((key_t) first, second);
146 case MSGCTL:
147 return sys_msgctl (first, second,
148 (struct msqid_ds __user *) ptr);
149 default:
150 return -EINVAL;
151 }
Paul Mundtbcb28e42007-11-20 15:50:59 +0900152 if (call <= SHMCTL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 switch (call) {
154 case SHMAT:
155 switch (version) {
156 default: {
157 ulong raddr;
158 ret = do_shmat (first, (char __user *) ptr,
159 second, &raddr);
160 if (ret)
161 return ret;
162 return put_user (raddr, (ulong __user *) third);
163 }
164 case 1: /* iBCS2 emulator entry point */
165 if (!segment_eq(get_fs(), get_ds()))
166 return -EINVAL;
167 return do_shmat (first, (char __user *) ptr,
168 second, (ulong *) third);
169 }
Paul Mundtbcb28e42007-11-20 15:50:59 +0900170 case SHMDT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 return sys_shmdt ((char __user *)ptr);
172 case SHMGET:
173 return sys_shmget (first, second, third);
174 case SHMCTL:
175 return sys_shmctl (first, second,
176 (struct shmid_ds __user *) ptr);
177 default:
178 return -EINVAL;
179 }
Paul Mundtbcb28e42007-11-20 15:50:59 +0900180
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 return -EINVAL;
182}
183
Stuart Menefy6d243dd2009-08-24 18:16:56 +0900184/* sys_cacheflush -- flush (part of) the processor cache. */
185asmlinkage int sys_cacheflush(unsigned long addr, unsigned long len, int op)
186{
187 struct vm_area_struct *vma;
188
189 if ((op < 0) || (op > (CACHEFLUSH_D_PURGE|CACHEFLUSH_I)))
190 return -EINVAL;
191
192 /*
193 * Verify that the specified address region actually belongs
194 * to this process.
195 */
196 if (addr + len < addr)
197 return -EFAULT;
198
199 down_read(&current->mm->mmap_sem);
200 vma = find_vma (current->mm, addr);
201 if (vma == NULL || addr < vma->vm_start || addr + len > vma->vm_end) {
202 up_read(&current->mm->mmap_sem);
203 return -EFAULT;
204 }
205
206 switch (op & CACHEFLUSH_D_PURGE) {
207 case CACHEFLUSH_D_INVAL:
208 __flush_invalidate_region((void *)addr, len);
209 break;
210 case CACHEFLUSH_D_WB:
211 __flush_wback_region((void *)addr, len);
212 break;
213 case CACHEFLUSH_D_PURGE:
214 __flush_purge_region((void *)addr, len);
215 break;
216 }
217
218 if (op & CACHEFLUSH_I)
219 flush_cache_all();
220
221 up_read(&current->mm->mmap_sem);
222 return 0;
223}
224
Paul Mundtfa439722008-09-04 18:53:58 +0900225asmlinkage int sys_uname(struct old_utsname __user *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226{
227 int err;
228 if (!name)
229 return -EFAULT;
230 down_read(&uts_sem);
Paul Mundtfa439722008-09-04 18:53:58 +0900231 err = copy_to_user(name, utsname(), sizeof(*name));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 up_read(&uts_sem);
233 return err?-EFAULT:0;
234}