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
9 #include <linux/errno.h>
10 #include <linux/sched.h>
12 #include <linux/smp.h>
13 #include <linux/sem.h>
14 #include <linux/msg.h>
15 #include <linux/shm.h>
16 #include <linux/stat.h>
17 #include <linux/syscalls.h>
18 #include <linux/mman.h>
19 #include <linux/file.h>
20 #include <linux/utsname.h>
22 #include <asm/uaccess.h>
23 #include <asm/unistd.h>
27 * sys_pipe() is the normal C calling standard for creating
28 * a pipe. It's not the way Unix traditionally does this, though.
30 asmlinkage int sys_pipe(unsigned long __user * fildes)
37 if (copy_to_user(fildes, fd, 2*sizeof(int)))
43 asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
44 unsigned long prot, unsigned long flags,
45 unsigned long fd, unsigned long pgoff)
48 struct file *file = NULL;
49 struct mm_struct *mm = current->mm;
51 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
52 if (!(flags & MAP_ANONYMOUS)) {
58 down_write(&mm->mmap_sem);
59 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
60 up_write(&mm->mmap_sem);
69 * Perform the select(nd, in, out, ex, tv) and mmap() system
70 * calls. Linux/i386 didn't use to be able to handle more than
71 * 4 system call parameters, so these system calls used a memory
72 * block for parameter passing..
75 struct mmap_arg_struct {
84 asmlinkage int old_mmap(struct mmap_arg_struct __user *arg)
86 struct mmap_arg_struct a;
89 if (copy_from_user(&a, arg, sizeof(a)))
93 if (a.offset & ~PAGE_MASK)
96 err = sys_mmap2(a.addr, a.len, a.prot, a.flags,
97 a.fd, a.offset >> PAGE_SHIFT);
103 struct sel_arg_struct {
105 fd_set __user *inp, *outp, *exp;
106 struct timeval __user *tvp;
109 asmlinkage int old_select(struct sel_arg_struct __user *arg)
111 struct sel_arg_struct a;
113 if (copy_from_user(&a, arg, sizeof(a)))
115 /* sys_select() does the appropriate kernel locking */
116 return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
120 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
122 * This is really horribly ugly.
124 asmlinkage int sys_ipc (uint call, int first, int second,
125 int third, void __user *ptr, long fifth)
129 version = call >> 16; /* hack for backward compatibility */
134 return sys_semtimedop (first, (struct sembuf __user *)ptr, second, NULL);
136 return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
137 (const struct timespec __user *)fifth);
140 return sys_semget (first, second, third);
145 if (get_user(fourth.__pad, (void __user * __user *) ptr))
147 return sys_semctl (first, second, third, fourth);
151 return sys_msgsnd (first, (struct msgbuf __user *) ptr,
156 struct ipc_kludge tmp;
160 if (copy_from_user(&tmp,
161 (struct ipc_kludge __user *) ptr,
164 return sys_msgrcv (first, tmp.msgp, second,
168 return sys_msgrcv (first,
169 (struct msgbuf __user *) ptr,
170 second, fifth, third);
173 return sys_msgget ((key_t) first, second);
175 return sys_msgctl (first, second, (struct msqid_ds __user *) ptr);
181 ret = do_shmat (first, (char __user *) ptr, second, &raddr);
184 return put_user (raddr, (ulong __user *) third);
186 case 1: /* iBCS2 emulator entry point */
187 if (!segment_eq(get_fs(), get_ds()))
189 /* The "(ulong *) third" is valid _only_ because of the kernel segment thing */
190 return do_shmat (first, (char __user *) ptr, second, (ulong *) third);
193 return sys_shmdt ((char __user *)ptr);
195 return sys_shmget (first, second, third);
197 return sys_shmctl (first, second,
198 (struct shmid_ds __user *) ptr);
207 asmlinkage int sys_uname(struct old_utsname __user * name)
213 err = copy_to_user(name, utsname(), sizeof (*name));
215 return err?-EFAULT:0;
218 asmlinkage int sys_olduname(struct oldold_utsname __user * name)
224 if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
229 error = __copy_to_user(&name->sysname, &utsname()->sysname,
231 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
232 error |= __copy_to_user(&name->nodename, &utsname()->nodename,
234 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
235 error |= __copy_to_user(&name->release, &utsname()->release,
237 error |= __put_user(0, name->release + __OLD_UTS_LEN);
238 error |= __copy_to_user(&name->version, &utsname()->version,
240 error |= __put_user(0, name->version + __OLD_UTS_LEN);
241 error |= __copy_to_user(&name->machine, &utsname()->machine,
243 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
247 error = error ? -EFAULT : 0;
254 * Do a system call from kernel instead of calling sys_execve so we
255 * end up with proper pt_regs.
257 int kernel_execve(const char *filename, char *const argv[], char *const envp[])
260 asm volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx"
262 : "0" (__NR_execve),"ri" (filename),"c" (argv), "d" (envp) : "memory");