2 * This file contains various random system calls that
3 * have a non-standard calling sequence on the Linux/i386
7 #include <linux/errno.h>
8 #include <linux/sched.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 #include <asm/syscalls.h>
28 * Perform the select(nd, in, out, ex, tv) and mmap() system
29 * calls. Linux/i386 didn't use to be able to handle more than
30 * 4 system call parameters, so these system calls used a memory
31 * block for parameter passing..
34 struct mmap_arg_struct {
43 asmlinkage int old_mmap(struct mmap_arg_struct __user *arg)
45 struct mmap_arg_struct a;
48 if (copy_from_user(&a, arg, sizeof(a)))
52 if (a.offset & ~PAGE_MASK)
55 err = sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags,
56 a.fd, a.offset >> PAGE_SHIFT);
62 struct sel_arg_struct {
64 fd_set __user *inp, *outp, *exp;
65 struct timeval __user *tvp;
68 asmlinkage int old_select(struct sel_arg_struct __user *arg)
70 struct sel_arg_struct a;
72 if (copy_from_user(&a, arg, sizeof(a)))
74 /* sys_select() does the appropriate kernel locking */
75 return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
79 * sys_ipc() is the de-multiplexer for the SysV IPC calls..
81 * This is really horribly ugly.
83 asmlinkage int sys_ipc(uint call, int first, int second,
84 int third, void __user *ptr, long fifth)
88 version = call >> 16; /* hack for backward compatibility */
93 return sys_semtimedop(first, (struct sembuf __user *)ptr, second, NULL);
95 return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
96 (const struct timespec __user *)fifth);
99 return sys_semget(first, second, third);
104 if (get_user(fourth.__pad, (void __user * __user *) ptr))
106 return sys_semctl(first, second, third, fourth);
110 return sys_msgsnd(first, (struct msgbuf __user *) ptr,
115 struct ipc_kludge tmp;
119 if (copy_from_user(&tmp,
120 (struct ipc_kludge __user *) ptr,
123 return sys_msgrcv(first, tmp.msgp, second,
127 return sys_msgrcv(first,
128 (struct msgbuf __user *) ptr,
129 second, fifth, third);
132 return sys_msgget((key_t) first, second);
134 return sys_msgctl(first, second, (struct msqid_ds __user *) ptr);
140 ret = do_shmat(first, (char __user *) ptr, second, &raddr);
143 return put_user(raddr, (ulong __user *) third);
145 case 1: /* iBCS2 emulator entry point */
146 if (!segment_eq(get_fs(), get_ds()))
148 /* The "(ulong *) third" is valid _only_ because of the kernel segment thing */
149 return do_shmat(first, (char __user *) ptr, second, (ulong *) third);
152 return sys_shmdt((char __user *)ptr);
154 return sys_shmget(first, second, third);
156 return sys_shmctl(first, second,
157 (struct shmid_ds __user *) ptr);
166 asmlinkage int sys_uname(struct old_utsname __user *name)
172 err = copy_to_user(name, utsname(), sizeof(*name));
174 return err? -EFAULT:0;
177 asmlinkage int sys_olduname(struct oldold_utsname __user *name)
183 if (!access_ok(VERIFY_WRITE, name, sizeof(struct oldold_utsname)))
188 error = __copy_to_user(&name->sysname, &utsname()->sysname,
190 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
191 error |= __copy_to_user(&name->nodename, &utsname()->nodename,
193 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
194 error |= __copy_to_user(&name->release, &utsname()->release,
196 error |= __put_user(0, name->release + __OLD_UTS_LEN);
197 error |= __copy_to_user(&name->version, &utsname()->version,
199 error |= __put_user(0, name->version + __OLD_UTS_LEN);
200 error |= __copy_to_user(&name->machine, &utsname()->machine,
202 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
206 error = error ? -EFAULT : 0;
213 * Do a system call from kernel instead of calling sys_execve so we
214 * end up with proper pt_regs.
216 int kernel_execve(const char *filename, char *const argv[], char *const envp[])
219 asm volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx"
221 : "0" (__NR_execve), "ri" (filename), "c" (argv), "d" (envp) : "memory");