This commit was manufactured by cvs2svn to create branch
[linux-2.6.git] / arch / um / kernel / syscall_kern.c
1 /* 
2  * Copyright (C) 2000 - 2003 Jeff Dike (jdike@addtoit.com)
3  * Licensed under the GPL
4  */
5
6 #include "linux/sched.h"
7 #include "linux/file.h"
8 #include "linux/smp_lock.h"
9 #include "linux/mm.h"
10 #include "linux/utsname.h"
11 #include "linux/msg.h"
12 #include "linux/shm.h"
13 #include "linux/sys.h"
14 #include "linux/syscalls.h"
15 #include "linux/unistd.h"
16 #include "linux/slab.h"
17 #include "linux/utime.h"
18 #include <linux/vs_cvirt.h>
19
20 #include "asm/mman.h"
21 #include "asm/uaccess.h"
22 #include "asm/ipc.h"
23 #include "kern_util.h"
24 #include "user_util.h"
25 #include "sysdep/syscalls.h"
26 #include "mode_kern.h"
27 #include "choose-mode.h"
28
29 /*  Unlocked, I don't care if this is a bit off */
30 int nsyscalls = 0;
31
32 long um_mount(char * dev_name, char * dir_name, char * type,
33               unsigned long new_flags, void * data)
34 {
35         if(type == NULL) type = "";
36         return(sys_mount(dev_name, dir_name, type, new_flags, data));
37 }
38
39 long sys_fork(void)
40 {
41         long ret;
42
43         current->thread.forking = 1;
44         ret = do_fork(SIGCHLD, 0, NULL, 0, NULL, NULL);
45         current->thread.forking = 0;
46         return(ret);
47 }
48
49 long sys_clone(unsigned long clone_flags, unsigned long newsp, 
50                int *parent_tid, int *child_tid)
51 {
52         long ret;
53
54         current->thread.forking = 1;
55         ret = do_fork(clone_flags, newsp, NULL, 0, parent_tid, child_tid);
56         current->thread.forking = 0;
57         return(ret);
58 }
59
60 long sys_vfork(void)
61 {
62         long ret;
63
64         current->thread.forking = 1;
65         ret = do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, 0, NULL, 0, NULL, 
66                       NULL);
67         current->thread.forking = 0;
68         return(ret);
69 }
70
71 /* common code for old and new mmaps */
72 long do_mmap2(struct mm_struct *mm, unsigned long addr, unsigned long len,
73               unsigned long prot, unsigned long flags, unsigned long fd,
74               unsigned long pgoff)
75 {
76         int error = -EBADF;
77         struct file * file = NULL;
78
79         flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
80         if (!(flags & MAP_ANONYMOUS)) {
81                 file = fget(fd);
82                 if (!file)
83                         goto out;
84         }
85
86         down_write(&mm->mmap_sem);
87         error = do_mmap_pgoff(mm, file, addr, len, prot, flags, pgoff);
88         up_write(&mm->mmap_sem);
89
90         if (file)
91                 fput(file);
92  out:
93         return error;
94 }
95
96 long sys_mmap2(unsigned long addr, unsigned long len,
97                unsigned long prot, unsigned long flags,
98                unsigned long fd, unsigned long pgoff)
99 {
100         return do_mmap2(current->mm, addr, len, prot, flags, fd, pgoff);
101 }
102
103 /*
104  * Perform the select(nd, in, out, ex, tv) and mmap() system
105  * calls. Linux/i386 didn't use to be able to handle more than
106  * 4 system call parameters, so these system calls used a memory
107  * block for parameter passing..
108  */
109
110 struct mmap_arg_struct {
111         unsigned long addr;
112         unsigned long len;
113         unsigned long prot;
114         unsigned long flags;
115         unsigned long fd;
116         unsigned long offset;
117 };
118
119 int old_mmap(unsigned long addr, unsigned long len,
120              unsigned long prot, unsigned long flags,
121              unsigned long fd, unsigned long offset)
122 {
123         int err = -EINVAL;
124         if (offset & ~PAGE_MASK)
125                 goto out;
126
127         err = do_mmap2(current->mm, addr, len, prot, flags, fd, 
128                        offset >> PAGE_SHIFT);
129  out:
130         return err;
131 }
132 /*
133  * sys_pipe() is the normal C calling standard for creating
134  * a pipe. It's not the way unix traditionally does this, though.
135  */
136 int sys_pipe(unsigned long * fildes)
137 {
138         int fd[2];
139         int error;
140
141         error = do_pipe(fd);
142         if (!error) {
143                 if (copy_to_user(fildes, fd, sizeof(fd)))
144                         error = -EFAULT;
145         }
146         return error;
147 }
148
149 /*
150  * sys_ipc() is the de-multiplexer for the SysV IPC calls..
151  *
152  * This is really horribly ugly.
153  */
154 int sys_ipc (uint call, int first, int second,
155              int third, void *ptr, long fifth)
156 {
157         int version, ret;
158
159         version = call >> 16; /* hack for backward compatibility */
160         call &= 0xffff;
161
162         switch (call) {
163         case SEMOP:
164                 return sys_semtimedop(first, (struct sembuf *) ptr, second, 
165                                       NULL);
166         case SEMTIMEDOP:
167                 return sys_semtimedop(first, (struct sembuf *) ptr, second,
168                                       (const struct timespec *) fifth);
169         case SEMGET:
170                 return sys_semget (first, second, third);
171         case SEMCTL: {
172                 union semun fourth;
173                 if (!ptr)
174                         return -EINVAL;
175                 if (get_user(fourth.__pad, (void **) ptr))
176                         return -EFAULT;
177                 return sys_semctl (first, second, third, fourth);
178         }
179
180         case MSGSND:
181                 return sys_msgsnd (first, (struct msgbuf *) ptr, 
182                                    second, third);
183         case MSGRCV:
184                 switch (version) {
185                 case 0: {
186                         struct ipc_kludge tmp;
187                         if (!ptr)
188                                 return -EINVAL;
189                         
190                         if (copy_from_user(&tmp,
191                                            (struct ipc_kludge *) ptr, 
192                                            sizeof (tmp)))
193                                 return -EFAULT;
194                         return sys_msgrcv (first, tmp.msgp, second,
195                                            tmp.msgtyp, third);
196                 }
197                 default:
198                         panic("msgrcv with version != 0");
199                         return sys_msgrcv (first,
200                                            (struct msgbuf *) ptr,
201                                            second, fifth, third);
202                 }
203         case MSGGET:
204                 return sys_msgget ((key_t) first, second);
205         case MSGCTL:
206                 return sys_msgctl (first, second, (struct msqid_ds *) ptr);
207
208         case SHMAT:
209                 switch (version) {
210                 default: {
211                         ulong raddr;
212                         ret = do_shmat (first, (char *) ptr, second, &raddr);
213                         if (ret)
214                                 return ret;
215                         return put_user (raddr, (ulong *) third);
216                 }
217                 case 1: /* iBCS2 emulator entry point */
218                         if (!segment_eq(get_fs(), get_ds()))
219                                 return -EINVAL;
220                         return do_shmat (first, (char *) ptr, second, (ulong *) third);
221                 }
222         case SHMDT: 
223                 return sys_shmdt ((char *)ptr);
224         case SHMGET:
225                 return sys_shmget (first, second, third);
226         case SHMCTL:
227                 return sys_shmctl (first, second,
228                                    (struct shmid_ds *) ptr);
229         default:
230                 return -ENOSYS;
231         }
232 }
233
234 int sys_uname(struct old_utsname * name)
235 {
236         int err;
237         if (!name)
238                 return -EFAULT;
239         down_read(&uts_sem);
240         err=copy_to_user(name, vx_new_utsname(), sizeof (*name));
241         up_read(&uts_sem);
242         return err?-EFAULT:0;
243 }
244
245 int sys_olduname(struct oldold_utsname * name)
246 {
247         int error;
248         struct new_utsname *ptr;
249
250         if (!name)
251                 return -EFAULT;
252         if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
253                 return -EFAULT;
254   
255         down_read(&uts_sem);
256         
257         ptr = vx_new_utsname();
258         error = __copy_to_user(&name->sysname,ptr->sysname,
259                                __OLD_UTS_LEN);
260         error |= __put_user(0,name->sysname+__OLD_UTS_LEN);
261         error |= __copy_to_user(&name->nodename,ptr->nodename,
262                                 __OLD_UTS_LEN);
263         error |= __put_user(0,name->nodename+__OLD_UTS_LEN);
264         error |= __copy_to_user(&name->release,ptr->release,
265                                 __OLD_UTS_LEN);
266         error |= __put_user(0,name->release+__OLD_UTS_LEN);
267         error |= __copy_to_user(&name->version,ptr->version,
268                                 __OLD_UTS_LEN);
269         error |= __put_user(0,name->version+__OLD_UTS_LEN);
270         error |= __copy_to_user(&name->machine,ptr->machine,
271                                 __OLD_UTS_LEN);
272         error |= __put_user(0,name->machine+__OLD_UTS_LEN);
273         
274         up_read(&uts_sem);
275         
276         error = error ? -EFAULT : 0;
277
278         return error;
279 }
280
281 long execute_syscall(void *r)
282 {
283         return(CHOOSE_MODE_PROC(execute_syscall_tt, execute_syscall_skas, r));
284 }
285
286 spinlock_t syscall_lock = SPIN_LOCK_UNLOCKED;
287
288 static int syscall_index = 0;
289
290 int next_syscall_index(int limit)
291 {
292         int ret;
293
294         spin_lock(&syscall_lock);
295         ret = syscall_index;
296         if(++syscall_index == limit)
297                 syscall_index = 0;
298         spin_unlock(&syscall_lock);
299         return(ret);
300 }
301
302 /*
303  * Overrides for Emacs so that we follow Linus's tabbing style.
304  * Emacs will notice this stuff at the end of the file and automatically
305  * adjust the settings for this buffer only.  This must remain at the end
306  * of the file.
307  * ---------------------------------------------------------------------------
308  * Local variables:
309  * c-file-style: "linux"
310  * End:
311  */