arch_mmap_check() on mn10300
[pandora-kernel.git] / arch / mn10300 / kernel / sys_mn10300.c
1 /* MN10300 Weird system calls
2  *
3  * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
4  * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public Licence
8  * as published by the Free Software Foundation; either version
9  * 2 of the Licence, or (at your option) any later version.
10  */
11 #include <linux/errno.h>
12 #include <linux/sched.h>
13 #include <linux/syscalls.h>
14 #include <linux/mm.h>
15 #include <linux/smp.h>
16 #include <linux/sem.h>
17 #include <linux/msg.h>
18 #include <linux/shm.h>
19 #include <linux/stat.h>
20 #include <linux/mman.h>
21 #include <linux/file.h>
22 #include <linux/tty.h>
23
24 #include <asm/uaccess.h>
25
26 /*
27  * memory mapping syscall
28  */
29 asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
30                           unsigned long prot, unsigned long flags,
31                           unsigned long fd, unsigned long pgoff)
32 {
33         struct file *file = NULL;
34         long error = -EINVAL;
35
36         flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
37
38         error = -EBADF;
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);
51 out:
52         return error;
53 }
54
55 asmlinkage long old_mmap(unsigned long addr, unsigned long len,
56                          unsigned long prot, unsigned long flags,
57                          unsigned long fd, unsigned long offset)
58 {
59         if (offset & ~PAGE_MASK)
60                 return -EINVAL;
61         return sys_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
62 }
63
64 struct sel_arg_struct {
65         unsigned long n;
66         fd_set *inp;
67         fd_set *outp;
68         fd_set *exp;
69         struct timeval *tvp;
70 };
71
72 asmlinkage int old_select(struct sel_arg_struct __user *arg)
73 {
74         struct sel_arg_struct a;
75
76         if (copy_from_user(&a, arg, sizeof(a)))
77                 return -EFAULT;
78         /* sys_select() does the appropriate kernel locking */
79         return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
80 }
81
82 /*
83  * sys_ipc() is the de-multiplexer for the SysV IPC calls..
84  *
85  * This is really horribly ugly.
86  */
87 asmlinkage long sys_ipc(uint call, int first, int second,
88                         int third, void __user *ptr, long fifth)
89 {
90         int version, ret;
91
92         version = call >> 16; /* hack for backward compatibility */
93         call &= 0xffff;
94
95         switch (call) {
96         case SEMOP:
97                 return sys_semtimedop(first, (struct sembuf __user *)ptr,
98                                       second, NULL);
99         case SEMTIMEDOP:
100                 return sys_semtimedop(first, (struct sembuf __user *)ptr,
101                                       second,
102                                       (const struct timespec __user *)fifth);
103         case SEMGET:
104                 return sys_semget(first, second, third);
105         case SEMCTL: {
106                 union semun fourth;
107                 if (!ptr)
108                         return -EINVAL;
109                 if (get_user(fourth.__pad, (void __user * __user *) ptr))
110                         return -EFAULT;
111                 return sys_semctl(first, second, third, fourth);
112         }
113
114         case MSGSND:
115                 return sys_msgsnd(first, (struct msgbuf __user *) ptr,
116                                   second, third);
117         case MSGRCV:
118                 switch (version) {
119                 case 0: {
120                         struct ipc_kludge tmp;
121                         if (!ptr)
122                                 return -EINVAL;
123
124                         if (copy_from_user(&tmp,
125                                            (struct ipc_kludge __user *) ptr,
126                                            sizeof(tmp)))
127                                 return -EFAULT;
128                         return sys_msgrcv(first, tmp.msgp, second,
129                                           tmp.msgtyp, third);
130                 }
131                 default:
132                         return sys_msgrcv(first,
133                                           (struct msgbuf __user *) ptr,
134                                            second, fifth, third);
135                 }
136         case MSGGET:
137                 return sys_msgget((key_t) first, second);
138         case MSGCTL:
139                 return sys_msgctl(first, second,
140                                    (struct msqid_ds __user *) ptr);
141
142         case SHMAT:
143                 switch (version) {
144                 default: {
145                         ulong raddr;
146                         ret = do_shmat(first, (char __user *) ptr, second,
147                                        &raddr);
148                         if (ret)
149                                 return ret;
150                         return put_user(raddr, (ulong *) third);
151                 }
152                 case 1: /* iBCS2 emulator entry point */
153                         if (!segment_eq(get_fs(), get_ds()))
154                                 return -EINVAL;
155                         return do_shmat(first, (char __user *) ptr, second,
156                                         (ulong *) third);
157                 }
158         case SHMDT:
159                 return sys_shmdt((char __user *)ptr);
160         case SHMGET:
161                 return sys_shmget(first, second, third);
162         case SHMCTL:
163                 return sys_shmctl(first, second,
164                                   (struct shmid_ds __user *) ptr);
165         default:
166                 return -EINVAL;
167         }
168 }