]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
1da177e4 LT |
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> | |
4e950f6f | 10 | #include <linux/fs.h> |
1da177e4 | 11 | #include <linux/smp.h> |
1da177e4 LT |
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> | |
cba4fbbf | 20 | #include <linux/ipc.h> |
1da177e4 | 21 | |
5b80fe8b PC |
22 | #include <linux/uaccess.h> |
23 | #include <linux/unistd.h> | |
1da177e4 | 24 | |
bbc1f698 JS |
25 | #include <asm/syscalls.h> |
26 | ||
1da177e4 LT |
27 | /* |
28 | * sys_ipc() is the de-multiplexer for the SysV IPC calls.. | |
29 | * | |
30 | * This is really horribly ugly. | |
31 | */ | |
5b80fe8b | 32 | asmlinkage int sys_ipc(uint call, int first, int second, |
1da177e4 LT |
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: | |
5b80fe8b | 42 | return sys_semtimedop(first, (struct sembuf __user *)ptr, second, NULL); |
1da177e4 LT |
43 | case SEMTIMEDOP: |
44 | return sys_semtimedop(first, (struct sembuf __user *)ptr, second, | |
45 | (const struct timespec __user *)fifth); | |
46 | ||
47 | case SEMGET: | |
5b80fe8b | 48 | return sys_semget(first, second, third); |
1da177e4 LT |
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; | |
5b80fe8b | 55 | return sys_semctl(first, second, third, fourth); |
1da177e4 LT |
56 | } |
57 | ||
58 | case MSGSND: | |
5b80fe8b | 59 | return sys_msgsnd(first, (struct msgbuf __user *) ptr, |
1da177e4 LT |
60 | second, third); |
61 | case MSGRCV: | |
62 | switch (version) { | |
63 | case 0: { | |
64 | struct ipc_kludge tmp; | |
65 | if (!ptr) | |
66 | return -EINVAL; | |
5b80fe8b | 67 | |
1da177e4 | 68 | if (copy_from_user(&tmp, |
5b80fe8b PC |
69 | (struct ipc_kludge __user *) ptr, |
70 | sizeof(tmp))) | |
1da177e4 | 71 | return -EFAULT; |
5b80fe8b | 72 | return sys_msgrcv(first, tmp.msgp, second, |
1da177e4 LT |
73 | tmp.msgtyp, third); |
74 | } | |
75 | default: | |
5b80fe8b | 76 | return sys_msgrcv(first, |
1da177e4 LT |
77 | (struct msgbuf __user *) ptr, |
78 | second, fifth, third); | |
79 | } | |
80 | case MSGGET: | |
5b80fe8b | 81 | return sys_msgget((key_t) first, second); |
1da177e4 | 82 | case MSGCTL: |
5b80fe8b | 83 | return sys_msgctl(first, second, (struct msqid_ds __user *) ptr); |
1da177e4 LT |
84 | |
85 | case SHMAT: | |
86 | switch (version) { | |
87 | default: { | |
88 | ulong raddr; | |
5b80fe8b | 89 | ret = do_shmat(first, (char __user *) ptr, second, &raddr); |
1da177e4 LT |
90 | if (ret) |
91 | return ret; | |
5b80fe8b | 92 | return put_user(raddr, (ulong __user *) third); |
1da177e4 LT |
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 */ | |
5b80fe8b | 98 | return do_shmat(first, (char __user *) ptr, second, (ulong *) third); |
1da177e4 | 99 | } |
5b80fe8b PC |
100 | case SHMDT: |
101 | return sys_shmdt((char __user *)ptr); | |
1da177e4 | 102 | case SHMGET: |
5b80fe8b | 103 | return sys_shmget(first, second, third); |
1da177e4 | 104 | case SHMCTL: |
5b80fe8b | 105 | return sys_shmctl(first, second, |
1da177e4 LT |
106 | (struct shmid_ds __user *) ptr); |
107 | default: | |
108 | return -ENOSYS; | |
109 | } | |
110 | } | |
111 | ||
112 | /* | |
113 | * Old cruft | |
114 | */ | |
5b80fe8b | 115 | asmlinkage int sys_uname(struct old_utsname __user *name) |
1da177e4 LT |
116 | { |
117 | int err; | |
118 | if (!name) | |
119 | return -EFAULT; | |
120 | down_read(&uts_sem); | |
5b80fe8b | 121 | err = copy_to_user(name, utsname(), sizeof(*name)); |
1da177e4 | 122 | up_read(&uts_sem); |
5b80fe8b | 123 | return err? -EFAULT:0; |
1da177e4 LT |
124 | } |
125 | ||
5b80fe8b | 126 | asmlinkage int sys_olduname(struct oldold_utsname __user *name) |
1da177e4 LT |
127 | { |
128 | int error; | |
129 | ||
130 | if (!name) | |
131 | return -EFAULT; | |
5b80fe8b | 132 | if (!access_ok(VERIFY_WRITE, name, sizeof(struct oldold_utsname))) |
1da177e4 | 133 | return -EFAULT; |
5b80fe8b PC |
134 | |
135 | down_read(&uts_sem); | |
136 | ||
e9ff3990 SH |
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); | |
5b80fe8b | 152 | |
1da177e4 | 153 | up_read(&uts_sem); |
5b80fe8b | 154 | |
1da177e4 LT |
155 | error = error ? -EFAULT : 0; |
156 | ||
157 | return error; | |
158 | } | |
fe74290d AB |
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) | |
5b80fe8b | 170 | : "0" (__NR_execve), "ri" (filename), "c" (argv), "d" (envp) : "memory"); |
fe74290d AB |
171 | return __res; |
172 | } |