Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/arch/i386/kernel/sys_i386.c | |
3 | * | |
4 | * This file contains various random system calls that | |
5 | * have a non-standard calling sequence on the Linux/i386 | |
6 | * platform. | |
7 | */ | |
8 | ||
9 | #include <linux/errno.h> | |
10 | #include <linux/sched.h> | |
11 | #include <linux/mm.h> | |
12 | #include <linux/smp.h> | |
13 | #include <linux/smp_lock.h> | |
14 | #include <linux/sem.h> | |
15 | #include <linux/msg.h> | |
16 | #include <linux/shm.h> | |
17 | #include <linux/stat.h> | |
18 | #include <linux/syscalls.h> | |
19 | #include <linux/mman.h> | |
20 | #include <linux/file.h> | |
21 | #include <linux/utsname.h> | |
22 | ||
23 | #include <asm/uaccess.h> | |
24 | #include <asm/ipc.h> | |
25 | ||
26 | /* | |
27 | * sys_pipe() is the normal C calling standard for creating | |
28 | * a pipe. It's not the way Unix traditionally does this, though. | |
29 | */ | |
30 | asmlinkage int sys_pipe(unsigned long __user * fildes) | |
31 | { | |
32 | int fd[2]; | |
33 | int error; | |
34 | ||
35 | error = do_pipe(fd); | |
36 | if (!error) { | |
37 | if (copy_to_user(fildes, fd, 2*sizeof(int))) | |
38 | error = -EFAULT; | |
39 | } | |
40 | return error; | |
41 | } | |
42 | ||
a7290ee0 MB |
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) | |
1da177e4 LT |
46 | { |
47 | int error = -EBADF; | |
a7290ee0 MB |
48 | struct file *file = NULL; |
49 | struct mm_struct *mm = current->mm; | |
1da177e4 LT |
50 | |
51 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | |
52 | if (!(flags & MAP_ANONYMOUS)) { | |
53 | file = fget(fd); | |
54 | if (!file) | |
55 | goto out; | |
56 | } | |
57 | ||
a7290ee0 | 58 | down_write(&mm->mmap_sem); |
1da177e4 | 59 | error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); |
a7290ee0 | 60 | up_write(&mm->mmap_sem); |
1da177e4 LT |
61 | |
62 | if (file) | |
63 | fput(file); | |
64 | out: | |
65 | return error; | |
66 | } | |
67 | ||
1da177e4 LT |
68 | /* |
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.. | |
73 | */ | |
74 | ||
75 | struct mmap_arg_struct { | |
76 | unsigned long addr; | |
77 | unsigned long len; | |
78 | unsigned long prot; | |
79 | unsigned long flags; | |
80 | unsigned long fd; | |
81 | unsigned long offset; | |
82 | }; | |
83 | ||
84 | asmlinkage int old_mmap(struct mmap_arg_struct __user *arg) | |
85 | { | |
86 | struct mmap_arg_struct a; | |
87 | int err = -EFAULT; | |
88 | ||
89 | if (copy_from_user(&a, arg, sizeof(a))) | |
90 | goto out; | |
91 | ||
92 | err = -EINVAL; | |
93 | if (a.offset & ~PAGE_MASK) | |
94 | goto out; | |
95 | ||
a7290ee0 MB |
96 | err = sys_mmap2(a.addr, a.len, a.prot, a.flags, |
97 | a.fd, a.offset >> PAGE_SHIFT); | |
1da177e4 LT |
98 | out: |
99 | return err; | |
100 | } | |
101 | ||
102 | ||
103 | struct sel_arg_struct { | |
104 | unsigned long n; | |
105 | fd_set __user *inp, *outp, *exp; | |
106 | struct timeval __user *tvp; | |
107 | }; | |
108 | ||
109 | asmlinkage int old_select(struct sel_arg_struct __user *arg) | |
110 | { | |
111 | struct sel_arg_struct a; | |
112 | ||
113 | if (copy_from_user(&a, arg, sizeof(a))) | |
114 | return -EFAULT; | |
115 | /* sys_select() does the appropriate kernel locking */ | |
116 | return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp); | |
117 | } | |
118 | ||
119 | /* | |
120 | * sys_ipc() is the de-multiplexer for the SysV IPC calls.. | |
121 | * | |
122 | * This is really horribly ugly. | |
123 | */ | |
124 | asmlinkage int sys_ipc (uint call, int first, int second, | |
125 | int third, void __user *ptr, long fifth) | |
126 | { | |
127 | int version, ret; | |
128 | ||
129 | version = call >> 16; /* hack for backward compatibility */ | |
130 | call &= 0xffff; | |
131 | ||
132 | switch (call) { | |
133 | case SEMOP: | |
134 | return sys_semtimedop (first, (struct sembuf __user *)ptr, second, NULL); | |
135 | case SEMTIMEDOP: | |
136 | return sys_semtimedop(first, (struct sembuf __user *)ptr, second, | |
137 | (const struct timespec __user *)fifth); | |
138 | ||
139 | case SEMGET: | |
140 | return sys_semget (first, second, third); | |
141 | case SEMCTL: { | |
142 | union semun fourth; | |
143 | if (!ptr) | |
144 | return -EINVAL; | |
145 | if (get_user(fourth.__pad, (void __user * __user *) ptr)) | |
146 | return -EFAULT; | |
147 | return sys_semctl (first, second, third, fourth); | |
148 | } | |
149 | ||
150 | case MSGSND: | |
151 | return sys_msgsnd (first, (struct msgbuf __user *) ptr, | |
152 | second, third); | |
153 | case MSGRCV: | |
154 | switch (version) { | |
155 | case 0: { | |
156 | struct ipc_kludge tmp; | |
157 | if (!ptr) | |
158 | return -EINVAL; | |
159 | ||
160 | if (copy_from_user(&tmp, | |
161 | (struct ipc_kludge __user *) ptr, | |
162 | sizeof (tmp))) | |
163 | return -EFAULT; | |
164 | return sys_msgrcv (first, tmp.msgp, second, | |
165 | tmp.msgtyp, third); | |
166 | } | |
167 | default: | |
168 | return sys_msgrcv (first, | |
169 | (struct msgbuf __user *) ptr, | |
170 | second, fifth, third); | |
171 | } | |
172 | case MSGGET: | |
173 | return sys_msgget ((key_t) first, second); | |
174 | case MSGCTL: | |
175 | return sys_msgctl (first, second, (struct msqid_ds __user *) ptr); | |
176 | ||
177 | case SHMAT: | |
178 | switch (version) { | |
179 | default: { | |
180 | ulong raddr; | |
181 | ret = do_shmat (first, (char __user *) ptr, second, &raddr); | |
182 | if (ret) | |
183 | return ret; | |
184 | return put_user (raddr, (ulong __user *) third); | |
185 | } | |
186 | case 1: /* iBCS2 emulator entry point */ | |
187 | if (!segment_eq(get_fs(), get_ds())) | |
188 | return -EINVAL; | |
189 | /* The "(ulong *) third" is valid _only_ because of the kernel segment thing */ | |
190 | return do_shmat (first, (char __user *) ptr, second, (ulong *) third); | |
191 | } | |
192 | case SHMDT: | |
193 | return sys_shmdt ((char __user *)ptr); | |
194 | case SHMGET: | |
195 | return sys_shmget (first, second, third); | |
196 | case SHMCTL: | |
197 | return sys_shmctl (first, second, | |
198 | (struct shmid_ds __user *) ptr); | |
199 | default: | |
200 | return -ENOSYS; | |
201 | } | |
202 | } | |
203 | ||
204 | /* | |
205 | * Old cruft | |
206 | */ | |
207 | asmlinkage int sys_uname(struct old_utsname __user * name) | |
208 | { | |
209 | int err; | |
210 | if (!name) | |
211 | return -EFAULT; | |
212 | down_read(&uts_sem); | |
213 | err=copy_to_user(name, &system_utsname, sizeof (*name)); | |
214 | up_read(&uts_sem); | |
215 | return err?-EFAULT:0; | |
216 | } | |
217 | ||
218 | asmlinkage int sys_olduname(struct oldold_utsname __user * name) | |
219 | { | |
220 | int error; | |
221 | ||
222 | if (!name) | |
223 | return -EFAULT; | |
224 | if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname))) | |
225 | return -EFAULT; | |
226 | ||
227 | down_read(&uts_sem); | |
228 | ||
229 | error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN); | |
230 | error |= __put_user(0,name->sysname+__OLD_UTS_LEN); | |
231 | error |= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN); | |
232 | error |= __put_user(0,name->nodename+__OLD_UTS_LEN); | |
233 | error |= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN); | |
234 | error |= __put_user(0,name->release+__OLD_UTS_LEN); | |
235 | error |= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN); | |
236 | error |= __put_user(0,name->version+__OLD_UTS_LEN); | |
237 | error |= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN); | |
238 | error |= __put_user(0,name->machine+__OLD_UTS_LEN); | |
239 | ||
240 | up_read(&uts_sem); | |
241 | ||
242 | error = error ? -EFAULT : 0; | |
243 | ||
244 | return error; | |
245 | } |