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