vserver 2.0 rc7
[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 "kern_util.h"
23 #include "user_util.h"
24 #include "sysdep/syscalls.h"
25 #include "mode_kern.h"
26 #include "choose-mode.h"
27
28 /*  Unlocked, I don't care if this is a bit off */
29 int nsyscalls = 0;
30
31 long sys_fork(void)
32 {
33         long ret;
34
35         current->thread.forking = 1;
36         ret = do_fork(SIGCHLD, 0, NULL, 0, NULL, NULL);
37         current->thread.forking = 0;
38         return(ret);
39 }
40
41 long sys_vfork(void)
42 {
43         long ret;
44
45         current->thread.forking = 1;
46         ret = do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, 0, NULL, 0, NULL,
47                       NULL);
48         current->thread.forking = 0;
49         return(ret);
50 }
51
52 /* common code for old and new mmaps */
53 long sys_mmap2(unsigned long addr, unsigned long len,
54                unsigned long prot, unsigned long flags,
55                unsigned long fd, unsigned long pgoff)
56 {
57         long error = -EBADF;
58         struct file * file = NULL;
59
60         flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
61         if (!(flags & MAP_ANONYMOUS)) {
62                 file = fget(fd);
63                 if (!file)
64                         goto out;
65         }
66
67         down_write(&current->mm->mmap_sem);
68         error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
69         up_write(&current->mm->mmap_sem);
70
71         if (file)
72                 fput(file);
73  out:
74         return error;
75 }
76
77 long old_mmap(unsigned long addr, unsigned long len,
78               unsigned long prot, unsigned long flags,
79               unsigned long fd, unsigned long offset)
80 {
81         long err = -EINVAL;
82         if (offset & ~PAGE_MASK)
83                 goto out;
84
85         err = sys_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
86  out:
87         return err;
88 }
89 /*
90  * sys_pipe() is the normal C calling standard for creating
91  * a pipe. It's not the way unix traditionally does this, though.
92  */
93 long sys_pipe(unsigned long __user * fildes)
94 {
95         int fd[2];
96         long error;
97
98         error = do_pipe(fd);
99         if (!error) {
100                 if (copy_to_user(fildes, fd, sizeof(fd)))
101                         error = -EFAULT;
102         }
103         return error;
104 }
105
106
107 long sys_uname(struct old_utsname * name)
108 {
109         long err;
110         if (!name)
111                 return -EFAULT;
112         down_read(&uts_sem);
113         err=copy_to_user(name, vx_new_utsname(), sizeof (*name));
114         up_read(&uts_sem);
115         return err?-EFAULT:0;
116 }
117
118 long sys_olduname(struct oldold_utsname * name)
119 {
120         long error;
121         struct new_utsname *ptr;
122
123         if (!name)
124                 return -EFAULT;
125         if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
126                 return -EFAULT;
127   
128         down_read(&uts_sem);
129         
130         ptr = vx_new_utsname();
131         error = __copy_to_user(&name->sysname,ptr->sysname,
132                                __OLD_UTS_LEN);
133         error |= __put_user(0,name->sysname+__OLD_UTS_LEN);
134         error |= __copy_to_user(&name->nodename,ptr->nodename,
135                                 __OLD_UTS_LEN);
136         error |= __put_user(0,name->nodename+__OLD_UTS_LEN);
137         error |= __copy_to_user(&name->release,ptr->release,
138                                 __OLD_UTS_LEN);
139         error |= __put_user(0,name->release+__OLD_UTS_LEN);
140         error |= __copy_to_user(&name->version,ptr->version,
141                                 __OLD_UTS_LEN);
142         error |= __put_user(0,name->version+__OLD_UTS_LEN);
143         error |= __copy_to_user(&name->machine,ptr->machine,
144                                 __OLD_UTS_LEN);
145         error |= __put_user(0,name->machine+__OLD_UTS_LEN);
146         
147         up_read(&uts_sem);
148         
149         error = error ? -EFAULT : 0;
150
151         return error;
152 }
153
154 DEFINE_SPINLOCK(syscall_lock);
155
156 static int syscall_index = 0;
157
158 int next_syscall_index(int limit)
159 {
160         int ret;
161
162         spin_lock(&syscall_lock);
163         ret = syscall_index;
164         if(++syscall_index == limit)
165                 syscall_index = 0;
166         spin_unlock(&syscall_lock);
167         return(ret);
168 }
169
170 /*
171  * Overrides for Emacs so that we follow Linus's tabbing style.
172  * Emacs will notice this stuff at the end of the file and automatically
173  * adjust the settings for this buffer only.  This must remain at the end
174  * of the file.
175  * ---------------------------------------------------------------------------
176  * Local variables:
177  * c-file-style: "linux"
178  * End:
179  */