Import 2.3.12pre3
[davej-history.git] / arch / i386 / kernel / sys_i386.c
blobf7987718b95246b58753ac1a2982dc18ae1624cf
1 /*
2 * linux/arch/i386/kernel/sys_i386.c
4 * This file contains various random system calls that
5 * have a non-standard calling sequence on the Linux/i386
6 * platform.
7 */
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/mman.h>
19 #include <linux/file.h>
20 #include <linux/utsname.h>
22 #include <asm/uaccess.h>
23 #include <asm/ipc.h>
26 * sys_pipe() is the normal C calling standard for creating
27 * a pipe. It's not the way Unix traditionally does this, though.
29 asmlinkage int sys_pipe(unsigned long * fildes)
31 int fd[2];
32 int error;
34 lock_kernel();
35 error = do_pipe(fd);
36 unlock_kernel();
37 if (!error) {
38 if (copy_to_user(fildes, fd, 2*sizeof(int)))
39 error = -EFAULT;
41 return error;
45 * Perform the select(nd, in, out, ex, tv) and mmap() system
46 * calls. Linux/i386 didn't use to be able to handle more than
47 * 4 system call parameters, so these system calls used a memory
48 * block for parameter passing..
51 struct mmap_arg_struct {
52 unsigned long addr;
53 unsigned long len;
54 unsigned long prot;
55 unsigned long flags;
56 unsigned long fd;
57 unsigned long offset;
60 asmlinkage int old_mmap(struct mmap_arg_struct *arg)
62 int error = -EFAULT;
63 struct file * file = NULL;
64 struct mmap_arg_struct a;
66 if (copy_from_user(&a, arg, sizeof(a)))
67 return -EFAULT;
69 down(&current->mm->mmap_sem);
70 lock_kernel();
71 if (!(a.flags & MAP_ANONYMOUS)) {
72 error = -EBADF;
73 file = fget(a.fd);
74 if (!file)
75 goto out;
77 a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
79 error = do_mmap(file, a.addr, a.len, a.prot, a.flags, a.offset);
80 if (file)
81 fput(file);
82 out:
83 unlock_kernel();
84 up(&current->mm->mmap_sem);
85 return error;
88 extern asmlinkage int sys_select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
90 struct sel_arg_struct {
91 unsigned long n;
92 fd_set *inp, *outp, *exp;
93 struct timeval *tvp;
96 asmlinkage int old_select(struct sel_arg_struct *arg)
98 struct sel_arg_struct a;
100 if (copy_from_user(&a, arg, sizeof(a)))
101 return -EFAULT;
102 /* sys_select() does the appropriate kernel locking */
103 return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
107 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
109 * This is really horribly ugly.
111 asmlinkage int sys_ipc (uint call, int first, int second,
112 int third, void *ptr, long fifth)
114 int version, ret;
116 version = call >> 16; /* hack for backward compatibility */
117 call &= 0xffff;
119 if (call <= SEMCTL)
120 switch (call) {
121 case SEMOP:
122 return sys_semop (first, (struct sembuf *)ptr, second);
123 case SEMGET:
124 return sys_semget (first, second, third);
125 case SEMCTL: {
126 union semun fourth;
127 if (!ptr)
128 return -EINVAL;
129 if (get_user(fourth.__pad, (void **) ptr))
130 return -EFAULT;
131 return sys_semctl (first, second, third, fourth);
133 default:
134 return -EINVAL;
137 if (call <= MSGCTL)
138 switch (call) {
139 case MSGSND:
140 return sys_msgsnd (first, (struct msgbuf *) ptr,
141 second, third);
142 case MSGRCV:
143 switch (version) {
144 case 0: {
145 struct ipc_kludge tmp;
146 if (!ptr)
147 return -EINVAL;
149 if (copy_from_user(&tmp,
150 (struct ipc_kludge *) ptr,
151 sizeof (tmp)))
152 return -EFAULT;
153 return sys_msgrcv (first, tmp.msgp, second,
154 tmp.msgtyp, third);
156 default:
157 return sys_msgrcv (first,
158 (struct msgbuf *) ptr,
159 second, fifth, third);
161 case MSGGET:
162 return sys_msgget ((key_t) first, second);
163 case MSGCTL:
164 return sys_msgctl (first, second,
165 (struct msqid_ds *) ptr);
166 default:
167 return -EINVAL;
169 if (call <= SHMCTL)
170 switch (call) {
171 case SHMAT:
172 switch (version) {
173 default: {
174 ulong raddr;
175 ret = sys_shmat (first, (char *) ptr,
176 second, &raddr);
177 if (ret)
178 return ret;
179 return put_user (raddr, (ulong *) third);
181 case 1: /* iBCS2 emulator entry point */
182 if (!segment_eq(get_fs(), get_ds()))
183 return -EINVAL;
184 return sys_shmat (first, (char *) ptr,
185 second, (ulong *) third);
187 case SHMDT:
188 return sys_shmdt ((char *)ptr);
189 case SHMGET:
190 return sys_shmget (first, second, third);
191 case SHMCTL:
192 return sys_shmctl (first, second,
193 (struct shmid_ds *) ptr);
194 default:
195 return -EINVAL;
198 return -EINVAL;
202 * Old cruft
204 asmlinkage int sys_uname(struct old_utsname * name)
206 int err;
207 if (!name)
208 return -EFAULT;
209 down(&uts_sem);
210 err=copy_to_user(name, &system_utsname, sizeof (*name));
211 up(&uts_sem);
212 return err?-EFAULT:0;
215 asmlinkage int sys_olduname(struct oldold_utsname * name)
217 int error;
219 if (!name)
220 return -EFAULT;
221 if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
222 return -EFAULT;
224 down(&uts_sem);
226 error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
227 error |= __put_user(0,name->sysname+__OLD_UTS_LEN);
228 error |= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
229 error |= __put_user(0,name->nodename+__OLD_UTS_LEN);
230 error |= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
231 error |= __put_user(0,name->release+__OLD_UTS_LEN);
232 error |= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
233 error |= __put_user(0,name->version+__OLD_UTS_LEN);
234 error |= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN);
235 error |= __put_user(0,name->machine+__OLD_UTS_LEN);
237 up(&uts_sem);
239 error = error ? -EFAULT : 0;
241 return error;
244 asmlinkage int sys_pause(void)
246 current->state = TASK_INTERRUPTIBLE;
247 schedule();
248 return -ERESTARTNOHAND;