aboutsummaryrefslogtreecommitdiffstats
path: root/arch/i386/kernel/sys_i386.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/i386/kernel/sys_i386.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'arch/i386/kernel/sys_i386.c')
-rw-r--r--arch/i386/kernel/sys_i386.c252
1 files changed, 252 insertions, 0 deletions
diff --git a/arch/i386/kernel/sys_i386.c b/arch/i386/kernel/sys_i386.c
new file mode 100644
index 000000000000..a4a61976ecb9
--- /dev/null
+++ b/arch/i386/kernel/sys_i386.c
@@ -0,0 +1,252 @@
1/*
2 * linux/arch/i386/kernel/sys_i386.c
3 *
4 * This file contains various random system calls that
5 * have a non-standard calling sequence on the Linux/i386
6 * platform.
7 */
8
9#include <linux/errno.h>
10#include <linux/sched.h>
11#include <linux/mm.h>
12#include <linux/smp.h>
13#include <linux/smp_lock.h>
14#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>
22
23#include <asm/uaccess.h>
24#include <asm/ipc.h>
25
26/*
27 * sys_pipe() is the normal C calling standard for creating
28 * a pipe. It's not the way Unix traditionally does this, though.
29 */
30asmlinkage int sys_pipe(unsigned long __user * fildes)
31{
32 int fd[2];
33 int error;
34
35 error = do_pipe(fd);
36 if (!error) {
37 if (copy_to_user(fildes, fd, 2*sizeof(int)))
38 error = -EFAULT;
39 }
40 return error;
41}
42
43/* common code for old and new mmaps */
44static inline long do_mmap2(
45 unsigned long addr, unsigned long len,
46 unsigned long prot, unsigned long flags,
47 unsigned long fd, unsigned long pgoff)
48{
49 int error = -EBADF;
50 struct file * file = NULL;
51
52 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
53 if (!(flags & MAP_ANONYMOUS)) {
54 file = fget(fd);
55 if (!file)
56 goto out;
57 }
58
59 down_write(&current->mm->mmap_sem);
60 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
61 up_write(&current->mm->mmap_sem);
62
63 if (file)
64 fput(file);
65out:
66 return error;
67}
68
69asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
70 unsigned long prot, unsigned long flags,
71 unsigned long fd, unsigned long pgoff)
72{
73 return do_mmap2(addr, len, prot, flags, fd, pgoff);
74}
75
76/*
77 * Perform the select(nd, in, out, ex, tv) and mmap() system
78 * calls. Linux/i386 didn't use to be able to handle more than
79 * 4 system call parameters, so these system calls used a memory
80 * block for parameter passing..
81 */
82
83struct mmap_arg_struct {
84 unsigned long addr;
85 unsigned long len;
86 unsigned long prot;
87 unsigned long flags;
88 unsigned long fd;
89 unsigned long offset;
90};
91
92asmlinkage int old_mmap(struct mmap_arg_struct __user *arg)
93{
94 struct mmap_arg_struct a;
95 int err = -EFAULT;
96
97 if (copy_from_user(&a, arg, sizeof(a)))
98 goto out;
99
100 err = -EINVAL;
101 if (a.offset & ~PAGE_MASK)
102 goto out;
103
104 err = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
105out:
106 return err;
107}
108
109
110struct sel_arg_struct {
111 unsigned long n;
112 fd_set __user *inp, *outp, *exp;
113 struct timeval __user *tvp;
114};
115
116asmlinkage int old_select(struct sel_arg_struct __user *arg)
117{
118 struct sel_arg_struct a;
119
120 if (copy_from_user(&a, arg, sizeof(a)))
121 return -EFAULT;
122 /* sys_select() does the appropriate kernel locking */
123 return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
124}
125
126/*
127 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
128 *
129 * This is really horribly ugly.
130 */
131asmlinkage int sys_ipc (uint call, int first, int second,
132 int third, void __user *ptr, long fifth)
133{
134 int version, ret;
135
136 version = call >> 16; /* hack for backward compatibility */
137 call &= 0xffff;
138
139 switch (call) {
140 case SEMOP:
141 return sys_semtimedop (first, (struct sembuf __user *)ptr, second, NULL);
142 case SEMTIMEDOP:
143 return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
144 (const struct timespec __user *)fifth);
145
146 case SEMGET:
147 return sys_semget (first, second, third);
148 case SEMCTL: {
149 union semun fourth;
150 if (!ptr)
151 return -EINVAL;
152 if (get_user(fourth.__pad, (void __user * __user *) ptr))
153 return -EFAULT;
154 return sys_semctl (first, second, third, fourth);
155 }
156
157 case MSGSND:
158 return sys_msgsnd (first, (struct msgbuf __user *) ptr,
159 second, third);
160 case MSGRCV:
161 switch (version) {
162 case 0: {
163 struct ipc_kludge tmp;
164 if (!ptr)
165 return -EINVAL;
166
167 if (copy_from_user(&tmp,
168 (struct ipc_kludge __user *) ptr,
169 sizeof (tmp)))
170 return -EFAULT;
171 return sys_msgrcv (first, tmp.msgp, second,
172 tmp.msgtyp, third);
173 }
174 default:
175 return sys_msgrcv (first,
176 (struct msgbuf __user *) ptr,
177 second, fifth, third);
178 }
179 case MSGGET:
180 return sys_msgget ((key_t) first, second);
181 case MSGCTL:
182 return sys_msgctl (first, second, (struct msqid_ds __user *) ptr);
183
184 case SHMAT:
185 switch (version) {
186 default: {
187 ulong raddr;
188 ret = do_shmat (first, (char __user *) ptr, second, &raddr);
189 if (ret)
190 return ret;
191 return put_user (raddr, (ulong __user *) third);
192 }
193 case 1: /* iBCS2 emulator entry point */
194 if (!segment_eq(get_fs(), get_ds()))
195 return -EINVAL;
196 /* The "(ulong *) third" is valid _only_ because of the kernel segment thing */
197 return do_shmat (first, (char __user *) ptr, second, (ulong *) third);
198 }
199 case SHMDT:
200 return sys_shmdt ((char __user *)ptr);
201 case SHMGET:
202 return sys_shmget (first, second, third);
203 case SHMCTL:
204 return sys_shmctl (first, second,
205 (struct shmid_ds __user *) ptr);
206 default:
207 return -ENOSYS;
208 }
209}
210
211/*
212 * Old cruft
213 */
214asmlinkage int sys_uname(struct old_utsname __user * name)
215{
216 int err;
217 if (!name)
218 return -EFAULT;
219 down_read(&uts_sem);
220 err=copy_to_user(name, &system_utsname, sizeof (*name));
221 up_read(&uts_sem);
222 return err?-EFAULT:0;
223}
224
225asmlinkage int sys_olduname(struct oldold_utsname __user * name)
226{
227 int error;
228
229 if (!name)
230 return -EFAULT;
231 if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
232 return -EFAULT;
233
234 down_read(&uts_sem);
235
236 error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
237 error |= __put_user(0,name->sysname+__OLD_UTS_LEN);
238 error |= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
239 error |= __put_user(0,name->nodename+__OLD_UTS_LEN);
240 error |= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
241 error |= __put_user(0,name->release+__OLD_UTS_LEN);
242 error |= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
243 error |= __put_user(0,name->version+__OLD_UTS_LEN);
244 error |= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN);
245 error |= __put_user(0,name->machine+__OLD_UTS_LEN);
246
247 up_read(&uts_sem);
248
249 error = error ? -EFAULT : 0;
250
251 return error;
252}