]> nv-tegra.nvidia Code Review - linux-3.10.git/blob - arch/x86/kernel/sys_i386_32.c
7955e90c8341504253f7e93010cf90c58f1b3d95
[linux-3.10.git] / arch / x86 / kernel / sys_i386_32.c
1 /*
2  * This file contains various random system calls that
3  * have a non-standard calling sequence on the Linux/i386
4  * platform.
5  */
6
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>
21
22 #include <linux/uaccess.h>
23 #include <linux/unistd.h>
24
25 #include <asm/syscalls.h>
26
27 /*
28  * sys_ipc() is the de-multiplexer for the SysV IPC calls..
29  *
30  * This is really horribly ugly.
31  */
32 asmlinkage int sys_ipc(uint call, int first, int second,
33                         int third, void __user *ptr, long fifth)
34 {
35         int version, ret;
36
37         version = call >> 16; /* hack for backward compatibility */
38         call &= 0xffff;
39
40         switch (call) {
41         case SEMOP:
42                 return sys_semtimedop(first, (struct sembuf __user *)ptr, second, NULL);
43         case SEMTIMEDOP:
44                 return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
45                                         (const struct timespec __user *)fifth);
46
47         case SEMGET:
48                 return sys_semget(first, second, third);
49         case SEMCTL: {
50                 union semun fourth;
51                 if (!ptr)
52                         return -EINVAL;
53                 if (get_user(fourth.__pad, (void __user * __user *) ptr))
54                         return -EFAULT;
55                 return sys_semctl(first, second, third, fourth);
56         }
57
58         case MSGSND:
59                 return sys_msgsnd(first, (struct msgbuf __user *) ptr,
60                                    second, third);
61         case MSGRCV:
62                 switch (version) {
63                 case 0: {
64                         struct ipc_kludge tmp;
65                         if (!ptr)
66                                 return -EINVAL;
67
68                         if (copy_from_user(&tmp,
69                                            (struct ipc_kludge __user *) ptr,
70                                            sizeof(tmp)))
71                                 return -EFAULT;
72                         return sys_msgrcv(first, tmp.msgp, second,
73                                            tmp.msgtyp, third);
74                 }
75                 default:
76                         return sys_msgrcv(first,
77                                            (struct msgbuf __user *) ptr,
78                                            second, fifth, third);
79                 }
80         case MSGGET:
81                 return sys_msgget((key_t) first, second);
82         case MSGCTL:
83                 return sys_msgctl(first, second, (struct msqid_ds __user *) ptr);
84
85         case SHMAT:
86                 switch (version) {
87                 default: {
88                         ulong raddr;
89                         ret = do_shmat(first, (char __user *) ptr, second, &raddr);
90                         if (ret)
91                                 return ret;
92                         return put_user(raddr, (ulong __user *) third);
93                 }
94                 case 1: /* iBCS2 emulator entry point */
95                         if (!segment_eq(get_fs(), get_ds()))
96                                 return -EINVAL;
97                         /* The "(ulong *) third" is valid _only_ because of the kernel segment thing */
98                         return do_shmat(first, (char __user *) ptr, second, (ulong *) third);
99                 }
100         case SHMDT:
101                 return sys_shmdt((char __user *)ptr);
102         case SHMGET:
103                 return sys_shmget(first, second, third);
104         case SHMCTL:
105                 return sys_shmctl(first, second,
106                                    (struct shmid_ds __user *) ptr);
107         default:
108                 return -ENOSYS;
109         }
110 }
111
112 /*
113  * Old cruft
114  */
115 asmlinkage int sys_uname(struct old_utsname __user *name)
116 {
117         int err;
118         if (!name)
119                 return -EFAULT;
120         down_read(&uts_sem);
121         err = copy_to_user(name, utsname(), sizeof(*name));
122         up_read(&uts_sem);
123         return err? -EFAULT:0;
124 }
125
126 asmlinkage int sys_olduname(struct oldold_utsname __user *name)
127 {
128         int error;
129
130         if (!name)
131                 return -EFAULT;
132         if (!access_ok(VERIFY_WRITE, name, sizeof(struct oldold_utsname)))
133                 return -EFAULT;
134
135         down_read(&uts_sem);
136
137         error = __copy_to_user(&name->sysname, &utsname()->sysname,
138                                __OLD_UTS_LEN);
139         error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
140         error |= __copy_to_user(&name->nodename, &utsname()->nodename,
141                                 __OLD_UTS_LEN);
142         error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
143         error |= __copy_to_user(&name->release, &utsname()->release,
144                                 __OLD_UTS_LEN);
145         error |= __put_user(0, name->release + __OLD_UTS_LEN);
146         error |= __copy_to_user(&name->version, &utsname()->version,
147                                 __OLD_UTS_LEN);
148         error |= __put_user(0, name->version + __OLD_UTS_LEN);
149         error |= __copy_to_user(&name->machine, &utsname()->machine,
150                                 __OLD_UTS_LEN);
151         error |= __put_user(0, name->machine + __OLD_UTS_LEN);
152
153         up_read(&uts_sem);
154
155         error = error ? -EFAULT : 0;
156
157         return error;
158 }
159
160
161 /*
162  * Do a system call from kernel instead of calling sys_execve so we
163  * end up with proper pt_regs.
164  */
165 int kernel_execve(const char *filename, char *const argv[], char *const envp[])
166 {
167         long __res;
168         asm volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx"
169         : "=a" (__res)
170         : "0" (__NR_execve), "ri" (filename), "c" (argv), "d" (envp) : "memory");
171         return __res;
172 }