workqueues: schedule_on_each_cpu: use flush_work()
[linux-2.6/mini2440.git] / arch / x86 / kernel / sys_i386_32.c
blob7066cb855a60154ea077f855b704bb40c0d58a53
1 /*
2 * This file contains various random system calls that
3 * have a non-standard calling sequence on the Linux/i386
4 * platform.
5 */
7 #include <linux/errno.h>
8 #include <linux/sched.h>
9 #include <linux/mm.h>
10 #include <linux/fs.h>
11 #include <linux/smp.h>
12 #include <linux/sem.h>
13 #include <linux/msg.h>
14 #include <linux/shm.h>
15 #include <linux/stat.h>
16 #include <linux/syscalls.h>
17 #include <linux/mman.h>
18 #include <linux/file.h>
19 #include <linux/utsname.h>
20 #include <linux/ipc.h>
22 #include <linux/uaccess.h>
23 #include <linux/unistd.h>
25 asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
26 unsigned long prot, unsigned long flags,
27 unsigned long fd, unsigned long pgoff)
29 int error = -EBADF;
30 struct file *file = NULL;
31 struct mm_struct *mm = current->mm;
33 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
34 if (!(flags & MAP_ANONYMOUS)) {
35 file = fget(fd);
36 if (!file)
37 goto out;
40 down_write(&mm->mmap_sem);
41 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
42 up_write(&mm->mmap_sem);
44 if (file)
45 fput(file);
46 out:
47 return error;
51 * Perform the select(nd, in, out, ex, tv) and mmap() system
52 * calls. Linux/i386 didn't use to be able to handle more than
53 * 4 system call parameters, so these system calls used a memory
54 * block for parameter passing..
57 struct mmap_arg_struct {
58 unsigned long addr;
59 unsigned long len;
60 unsigned long prot;
61 unsigned long flags;
62 unsigned long fd;
63 unsigned long offset;
66 asmlinkage int old_mmap(struct mmap_arg_struct __user *arg)
68 struct mmap_arg_struct a;
69 int err = -EFAULT;
71 if (copy_from_user(&a, arg, sizeof(a)))
72 goto out;
74 err = -EINVAL;
75 if (a.offset & ~PAGE_MASK)
76 goto out;
78 err = sys_mmap2(a.addr, a.len, a.prot, a.flags,
79 a.fd, a.offset >> PAGE_SHIFT);
80 out:
81 return err;
85 struct sel_arg_struct {
86 unsigned long n;
87 fd_set __user *inp, *outp, *exp;
88 struct timeval __user *tvp;
91 asmlinkage int old_select(struct sel_arg_struct __user *arg)
93 struct sel_arg_struct a;
95 if (copy_from_user(&a, arg, sizeof(a)))
96 return -EFAULT;
97 /* sys_select() does the appropriate kernel locking */
98 return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
102 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
104 * This is really horribly ugly.
106 asmlinkage int sys_ipc(uint call, int first, int second,
107 int third, void __user *ptr, long fifth)
109 int version, ret;
111 version = call >> 16; /* hack for backward compatibility */
112 call &= 0xffff;
114 switch (call) {
115 case SEMOP:
116 return sys_semtimedop(first, (struct sembuf __user *)ptr, second, NULL);
117 case SEMTIMEDOP:
118 return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
119 (const struct timespec __user *)fifth);
121 case SEMGET:
122 return sys_semget(first, second, third);
123 case SEMCTL: {
124 union semun fourth;
125 if (!ptr)
126 return -EINVAL;
127 if (get_user(fourth.__pad, (void __user * __user *) ptr))
128 return -EFAULT;
129 return sys_semctl(first, second, third, fourth);
132 case MSGSND:
133 return sys_msgsnd(first, (struct msgbuf __user *) ptr,
134 second, third);
135 case MSGRCV:
136 switch (version) {
137 case 0: {
138 struct ipc_kludge tmp;
139 if (!ptr)
140 return -EINVAL;
142 if (copy_from_user(&tmp,
143 (struct ipc_kludge __user *) ptr,
144 sizeof(tmp)))
145 return -EFAULT;
146 return sys_msgrcv(first, tmp.msgp, second,
147 tmp.msgtyp, third);
149 default:
150 return sys_msgrcv(first,
151 (struct msgbuf __user *) ptr,
152 second, fifth, third);
154 case MSGGET:
155 return sys_msgget((key_t) first, second);
156 case MSGCTL:
157 return sys_msgctl(first, second, (struct msqid_ds __user *) ptr);
159 case SHMAT:
160 switch (version) {
161 default: {
162 ulong raddr;
163 ret = do_shmat(first, (char __user *) ptr, second, &raddr);
164 if (ret)
165 return ret;
166 return put_user(raddr, (ulong __user *) third);
168 case 1: /* iBCS2 emulator entry point */
169 if (!segment_eq(get_fs(), get_ds()))
170 return -EINVAL;
171 /* The "(ulong *) third" is valid _only_ because of the kernel segment thing */
172 return do_shmat(first, (char __user *) ptr, second, (ulong *) third);
174 case SHMDT:
175 return sys_shmdt((char __user *)ptr);
176 case SHMGET:
177 return sys_shmget(first, second, third);
178 case SHMCTL:
179 return sys_shmctl(first, second,
180 (struct shmid_ds __user *) ptr);
181 default:
182 return -ENOSYS;
187 * Old cruft
189 asmlinkage int sys_uname(struct old_utsname __user *name)
191 int err;
192 if (!name)
193 return -EFAULT;
194 down_read(&uts_sem);
195 err = copy_to_user(name, utsname(), sizeof(*name));
196 up_read(&uts_sem);
197 return err? -EFAULT:0;
200 asmlinkage int sys_olduname(struct oldold_utsname __user *name)
202 int error;
204 if (!name)
205 return -EFAULT;
206 if (!access_ok(VERIFY_WRITE, name, sizeof(struct oldold_utsname)))
207 return -EFAULT;
209 down_read(&uts_sem);
211 error = __copy_to_user(&name->sysname, &utsname()->sysname,
212 __OLD_UTS_LEN);
213 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
214 error |= __copy_to_user(&name->nodename, &utsname()->nodename,
215 __OLD_UTS_LEN);
216 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
217 error |= __copy_to_user(&name->release, &utsname()->release,
218 __OLD_UTS_LEN);
219 error |= __put_user(0, name->release + __OLD_UTS_LEN);
220 error |= __copy_to_user(&name->version, &utsname()->version,
221 __OLD_UTS_LEN);
222 error |= __put_user(0, name->version + __OLD_UTS_LEN);
223 error |= __copy_to_user(&name->machine, &utsname()->machine,
224 __OLD_UTS_LEN);
225 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
227 up_read(&uts_sem);
229 error = error ? -EFAULT : 0;
231 return error;
236 * Do a system call from kernel instead of calling sys_execve so we
237 * end up with proper pt_regs.
239 int kernel_execve(const char *filename, char *const argv[], char *const envp[])
241 long __res;
242 asm volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx"
243 : "=a" (__res)
244 : "0" (__NR_execve), "ri" (filename), "c" (argv), "d" (envp) : "memory");
245 return __res;