backported vs2.1.x fix to irq handling, which caused incorrect scheduler behavior
[linux-2.6.git] / arch / i386 / kernel / sys_i386.c
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 #include <linux/vs_base.h>
23 #include <linux/vs_cvirt.h>
24
25 #include <asm/uaccess.h>
26 #include <asm/ipc.h>
27
28 /*
29  * sys_pipe() is the normal C calling standard for creating
30  * a pipe. It's not the way Unix traditionally does this, though.
31  */
32 asmlinkage int sys_pipe(unsigned long __user * fildes)
33 {
34         int fd[2];
35         int error;
36
37         error = do_pipe(fd);
38         if (!error) {
39                 if (copy_to_user(fildes, fd, 2*sizeof(int)))
40                         error = -EFAULT;
41         }
42         return error;
43 }
44
45 asmlinkage long sys_mmap2(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         struct mm_struct *mm = current->mm;
52
53         flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
54         if (!(flags & MAP_ANONYMOUS)) {
55                 file = fget(fd);
56                 if (!file)
57                         goto out;
58         }
59
60         down_write(&mm->mmap_sem);
61         error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
62         up_write(&mm->mmap_sem);
63
64         if (file)
65                 fput(file);
66 out:
67         return error;
68 }
69
70 /*
71  * Perform the select(nd, in, out, ex, tv) and mmap() system
72  * calls. Linux/i386 didn't use to be able to handle more than
73  * 4 system call parameters, so these system calls used a memory
74  * block for parameter passing..
75  */
76
77 struct mmap_arg_struct {
78         unsigned long addr;
79         unsigned long len;
80         unsigned long prot;
81         unsigned long flags;
82         unsigned long fd;
83         unsigned long offset;
84 };
85
86 asmlinkage int old_mmap(struct mmap_arg_struct __user *arg)
87 {
88         struct mmap_arg_struct a;
89         int err = -EFAULT;
90
91         if (copy_from_user(&a, arg, sizeof(a)))
92                 goto out;
93
94         err = -EINVAL;
95         if (a.offset & ~PAGE_MASK)
96                 goto out;
97
98         err = sys_mmap2(a.addr, a.len, a.prot, a.flags,
99                         a.fd, a.offset >> PAGE_SHIFT);
100 out:
101         return err;
102 }
103
104
105 struct sel_arg_struct {
106         unsigned long n;
107         fd_set __user *inp, *outp, *exp;
108         struct timeval __user *tvp;
109 };
110
111 asmlinkage int old_select(struct sel_arg_struct __user *arg)
112 {
113         struct sel_arg_struct a;
114
115         if (copy_from_user(&a, arg, sizeof(a)))
116                 return -EFAULT;
117         /* sys_select() does the appropriate kernel locking */
118         return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
119 }
120
121 /*
122  * sys_ipc() is the de-multiplexer for the SysV IPC calls..
123  *
124  * This is really horribly ugly.
125  */
126 asmlinkage int sys_ipc (uint call, int first, int second,
127                         int third, void __user *ptr, long fifth)
128 {
129         int version, ret;
130
131         version = call >> 16; /* hack for backward compatibility */
132         call &= 0xffff;
133
134         switch (call) {
135         case SEMOP:
136                 return sys_semtimedop (first, (struct sembuf __user *)ptr, second, NULL);
137         case SEMTIMEDOP:
138                 return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
139                                         (const struct timespec __user *)fifth);
140
141         case SEMGET:
142                 return sys_semget (first, second, third);
143         case SEMCTL: {
144                 union semun fourth;
145                 if (!ptr)
146                         return -EINVAL;
147                 if (get_user(fourth.__pad, (void __user * __user *) ptr))
148                         return -EFAULT;
149                 return sys_semctl (first, second, third, fourth);
150         }
151
152         case MSGSND:
153                 return sys_msgsnd (first, (struct msgbuf __user *) ptr, 
154                                    second, third);
155         case MSGRCV:
156                 switch (version) {
157                 case 0: {
158                         struct ipc_kludge tmp;
159                         if (!ptr)
160                                 return -EINVAL;
161                         
162                         if (copy_from_user(&tmp,
163                                            (struct ipc_kludge __user *) ptr, 
164                                            sizeof (tmp)))
165                                 return -EFAULT;
166                         return sys_msgrcv (first, tmp.msgp, second,
167                                            tmp.msgtyp, third);
168                 }
169                 default:
170                         return sys_msgrcv (first,
171                                            (struct msgbuf __user *) ptr,
172                                            second, fifth, third);
173                 }
174         case MSGGET:
175                 return sys_msgget ((key_t) first, second);
176         case MSGCTL:
177                 return sys_msgctl (first, second, (struct msqid_ds __user *) ptr);
178
179         case SHMAT:
180                 switch (version) {
181                 default: {
182                         ulong raddr;
183                         ret = do_shmat (first, (char __user *) ptr, second, &raddr);
184                         if (ret)
185                                 return ret;
186                         return put_user (raddr, (ulong __user *) third);
187                 }
188                 case 1: /* iBCS2 emulator entry point */
189                         if (!segment_eq(get_fs(), get_ds()))
190                                 return -EINVAL;
191                         /* The "(ulong *) third" is valid _only_ because of the kernel segment thing */
192                         return do_shmat (first, (char __user *) ptr, second, (ulong *) third);
193                 }
194         case SHMDT: 
195                 return sys_shmdt ((char __user *)ptr);
196         case SHMGET:
197                 return sys_shmget (first, second, third);
198         case SHMCTL:
199                 return sys_shmctl (first, second,
200                                    (struct shmid_ds __user *) ptr);
201         default:
202                 return -ENOSYS;
203         }
204 }
205
206 /*
207  * Old cruft
208  */
209 asmlinkage int sys_uname(struct old_utsname __user * name)
210 {
211         int err;
212         if (!name)
213                 return -EFAULT;
214         down_read(&uts_sem);
215         err=copy_to_user(name, vx_new_utsname(), sizeof (*name));
216         up_read(&uts_sem);
217         return err?-EFAULT:0;
218 }
219
220 asmlinkage int sys_olduname(struct oldold_utsname __user * name)
221 {
222         int error;
223         struct new_utsname *ptr;
224
225         if (!name)
226                 return -EFAULT;
227         if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
228                 return -EFAULT;
229   
230         down_read(&uts_sem);
231         
232         ptr = vx_new_utsname();
233         error = __copy_to_user(&name->sysname,ptr->sysname,__OLD_UTS_LEN);
234         error |= __put_user(0,name->sysname+__OLD_UTS_LEN);
235         error |= __copy_to_user(&name->nodename,ptr->nodename,__OLD_UTS_LEN);
236         error |= __put_user(0,name->nodename+__OLD_UTS_LEN);
237         error |= __copy_to_user(&name->release,ptr->release,__OLD_UTS_LEN);
238         error |= __put_user(0,name->release+__OLD_UTS_LEN);
239         error |= __copy_to_user(&name->version,ptr->version,__OLD_UTS_LEN);
240         error |= __put_user(0,name->version+__OLD_UTS_LEN);
241         error |= __copy_to_user(&name->machine,ptr->machine,__OLD_UTS_LEN);
242         error |= __put_user(0,name->machine+__OLD_UTS_LEN);
243         
244         up_read(&uts_sem);
245         
246         error = error ? -EFAULT : 0;
247
248         return error;
249 }