diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/mips/kernel/linux32.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'arch/mips/kernel/linux32.c')
-rw-r--r-- | arch/mips/kernel/linux32.c | 1469 |
1 files changed, 1469 insertions, 0 deletions
diff --git a/arch/mips/kernel/linux32.c b/arch/mips/kernel/linux32.c new file mode 100644 index 000000000000..993abc868e54 --- /dev/null +++ b/arch/mips/kernel/linux32.c | |||
@@ -0,0 +1,1469 @@ | |||
1 | /* | ||
2 | * Conversion between 32-bit and 64-bit native system calls. | ||
3 | * | ||
4 | * Copyright (C) 2000 Silicon Graphics, Inc. | ||
5 | * Written by Ulf Carlsson (ulfc@engr.sgi.com) | ||
6 | * sys32_execve from ia64/ia32 code, Feb 2000, Kanoj Sarcar (kanoj@sgi.com) | ||
7 | */ | ||
8 | #include <linux/config.h> | ||
9 | #include <linux/compiler.h> | ||
10 | #include <linux/mm.h> | ||
11 | #include <linux/errno.h> | ||
12 | #include <linux/file.h> | ||
13 | #include <linux/smp_lock.h> | ||
14 | #include <linux/highuid.h> | ||
15 | #include <linux/dirent.h> | ||
16 | #include <linux/resource.h> | ||
17 | #include <linux/highmem.h> | ||
18 | #include <linux/time.h> | ||
19 | #include <linux/times.h> | ||
20 | #include <linux/poll.h> | ||
21 | #include <linux/slab.h> | ||
22 | #include <linux/skbuff.h> | ||
23 | #include <linux/filter.h> | ||
24 | #include <linux/shm.h> | ||
25 | #include <linux/sem.h> | ||
26 | #include <linux/msg.h> | ||
27 | #include <linux/icmpv6.h> | ||
28 | #include <linux/syscalls.h> | ||
29 | #include <linux/sysctl.h> | ||
30 | #include <linux/utime.h> | ||
31 | #include <linux/utsname.h> | ||
32 | #include <linux/personality.h> | ||
33 | #include <linux/timex.h> | ||
34 | #include <linux/dnotify.h> | ||
35 | #include <linux/module.h> | ||
36 | #include <linux/binfmts.h> | ||
37 | #include <linux/security.h> | ||
38 | #include <linux/compat.h> | ||
39 | #include <linux/vfs.h> | ||
40 | |||
41 | #include <net/sock.h> | ||
42 | #include <net/scm.h> | ||
43 | |||
44 | #include <asm/ipc.h> | ||
45 | #include <asm/sim.h> | ||
46 | #include <asm/uaccess.h> | ||
47 | #include <asm/mmu_context.h> | ||
48 | #include <asm/mman.h> | ||
49 | |||
50 | /* Use this to get at 32-bit user passed pointers. */ | ||
51 | /* A() macro should be used for places where you e.g. | ||
52 | have some internal variable u32 and just want to get | ||
53 | rid of a compiler warning. AA() has to be used in | ||
54 | places where you want to convert a function argument | ||
55 | to 32bit pointer or when you e.g. access pt_regs | ||
56 | structure and want to consider 32bit registers only. | ||
57 | */ | ||
58 | #define A(__x) ((unsigned long)(__x)) | ||
59 | #define AA(__x) ((unsigned long)((int)__x)) | ||
60 | |||
61 | #ifdef __MIPSEB__ | ||
62 | #define merge_64(r1,r2) ((((r1) & 0xffffffffUL) << 32) + ((r2) & 0xffffffffUL)) | ||
63 | #endif | ||
64 | #ifdef __MIPSEL__ | ||
65 | #define merge_64(r1,r2) ((((r2) & 0xffffffffUL) << 32) + ((r1) & 0xffffffffUL)) | ||
66 | #endif | ||
67 | |||
68 | /* | ||
69 | * Revalidate the inode. This is required for proper NFS attribute caching. | ||
70 | */ | ||
71 | |||
72 | int cp_compat_stat(struct kstat *stat, struct compat_stat *statbuf) | ||
73 | { | ||
74 | struct compat_stat tmp; | ||
75 | |||
76 | if (!new_valid_dev(stat->dev) || !new_valid_dev(stat->rdev)) | ||
77 | return -EOVERFLOW; | ||
78 | |||
79 | memset(&tmp, 0, sizeof(tmp)); | ||
80 | tmp.st_dev = new_encode_dev(stat->dev); | ||
81 | tmp.st_ino = stat->ino; | ||
82 | tmp.st_mode = stat->mode; | ||
83 | tmp.st_nlink = stat->nlink; | ||
84 | SET_UID(tmp.st_uid, stat->uid); | ||
85 | SET_GID(tmp.st_gid, stat->gid); | ||
86 | tmp.st_rdev = new_encode_dev(stat->rdev); | ||
87 | tmp.st_size = stat->size; | ||
88 | tmp.st_atime = stat->atime.tv_sec; | ||
89 | tmp.st_mtime = stat->mtime.tv_sec; | ||
90 | tmp.st_ctime = stat->ctime.tv_sec; | ||
91 | #ifdef STAT_HAVE_NSEC | ||
92 | tmp.st_atime_nsec = stat->atime.tv_nsec; | ||
93 | tmp.st_mtime_nsec = stat->mtime.tv_nsec; | ||
94 | tmp.st_ctime_nsec = stat->ctime.tv_nsec; | ||
95 | #endif | ||
96 | tmp.st_blocks = stat->blocks; | ||
97 | tmp.st_blksize = stat->blksize; | ||
98 | return copy_to_user(statbuf,&tmp,sizeof(tmp)) ? -EFAULT : 0; | ||
99 | } | ||
100 | |||
101 | asmlinkage unsigned long | ||
102 | sys32_mmap2(unsigned long addr, unsigned long len, unsigned long prot, | ||
103 | unsigned long flags, unsigned long fd, unsigned long pgoff) | ||
104 | { | ||
105 | struct file * file = NULL; | ||
106 | unsigned long error; | ||
107 | |||
108 | error = -EINVAL; | ||
109 | if (!(flags & MAP_ANONYMOUS)) { | ||
110 | error = -EBADF; | ||
111 | file = fget(fd); | ||
112 | if (!file) | ||
113 | goto out; | ||
114 | } | ||
115 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
116 | |||
117 | down_write(¤t->mm->mmap_sem); | ||
118 | error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); | ||
119 | up_write(¤t->mm->mmap_sem); | ||
120 | if (file) | ||
121 | fput(file); | ||
122 | |||
123 | out: | ||
124 | return error; | ||
125 | } | ||
126 | |||
127 | |||
128 | asmlinkage int sys_truncate64(const char *path, unsigned int high, | ||
129 | unsigned int low) | ||
130 | { | ||
131 | if ((int)high < 0) | ||
132 | return -EINVAL; | ||
133 | return sys_truncate(path, ((long) high << 32) | low); | ||
134 | } | ||
135 | |||
136 | asmlinkage int sys_ftruncate64(unsigned int fd, unsigned int high, | ||
137 | unsigned int low) | ||
138 | { | ||
139 | if ((int)high < 0) | ||
140 | return -EINVAL; | ||
141 | return sys_ftruncate(fd, ((long) high << 32) | low); | ||
142 | } | ||
143 | |||
144 | /* | ||
145 | * sys_execve() executes a new program. | ||
146 | */ | ||
147 | asmlinkage int sys32_execve(nabi_no_regargs struct pt_regs regs) | ||
148 | { | ||
149 | int error; | ||
150 | char * filename; | ||
151 | |||
152 | filename = getname(compat_ptr(regs.regs[4])); | ||
153 | error = PTR_ERR(filename); | ||
154 | if (IS_ERR(filename)) | ||
155 | goto out; | ||
156 | error = compat_do_execve(filename, compat_ptr(regs.regs[5]), | ||
157 | compat_ptr(regs.regs[6]), ®s); | ||
158 | putname(filename); | ||
159 | |||
160 | out: | ||
161 | return error; | ||
162 | } | ||
163 | |||
164 | struct dirent32 { | ||
165 | unsigned int d_ino; | ||
166 | unsigned int d_off; | ||
167 | unsigned short d_reclen; | ||
168 | char d_name[NAME_MAX + 1]; | ||
169 | }; | ||
170 | |||
171 | static void | ||
172 | xlate_dirent(void *dirent64, void *dirent32, long n) | ||
173 | { | ||
174 | long off; | ||
175 | struct dirent *dirp; | ||
176 | struct dirent32 *dirp32; | ||
177 | |||
178 | off = 0; | ||
179 | while (off < n) { | ||
180 | dirp = (struct dirent *)(dirent64 + off); | ||
181 | dirp32 = (struct dirent32 *)(dirent32 + off); | ||
182 | off += dirp->d_reclen; | ||
183 | dirp32->d_ino = dirp->d_ino; | ||
184 | dirp32->d_off = (unsigned int)dirp->d_off; | ||
185 | dirp32->d_reclen = dirp->d_reclen; | ||
186 | strncpy(dirp32->d_name, dirp->d_name, dirp->d_reclen - ((3 * 4) + 2)); | ||
187 | } | ||
188 | return; | ||
189 | } | ||
190 | |||
191 | asmlinkage long | ||
192 | sys32_getdents(unsigned int fd, void * dirent32, unsigned int count) | ||
193 | { | ||
194 | long n; | ||
195 | void *dirent64; | ||
196 | |||
197 | dirent64 = (void *)((unsigned long)(dirent32 + (sizeof(long) - 1)) & ~(sizeof(long) - 1)); | ||
198 | if ((n = sys_getdents(fd, dirent64, count - (dirent64 - dirent32))) < 0) | ||
199 | return(n); | ||
200 | xlate_dirent(dirent64, dirent32, n); | ||
201 | return(n); | ||
202 | } | ||
203 | |||
204 | asmlinkage int old_readdir(unsigned int fd, void * dirent, unsigned int count); | ||
205 | |||
206 | asmlinkage int | ||
207 | sys32_readdir(unsigned int fd, void * dirent32, unsigned int count) | ||
208 | { | ||
209 | int n; | ||
210 | struct dirent dirent64; | ||
211 | |||
212 | if ((n = old_readdir(fd, &dirent64, count)) < 0) | ||
213 | return(n); | ||
214 | xlate_dirent(&dirent64, dirent32, dirent64.d_reclen); | ||
215 | return(n); | ||
216 | } | ||
217 | |||
218 | struct rusage32 { | ||
219 | struct compat_timeval ru_utime; | ||
220 | struct compat_timeval ru_stime; | ||
221 | int ru_maxrss; | ||
222 | int ru_ixrss; | ||
223 | int ru_idrss; | ||
224 | int ru_isrss; | ||
225 | int ru_minflt; | ||
226 | int ru_majflt; | ||
227 | int ru_nswap; | ||
228 | int ru_inblock; | ||
229 | int ru_oublock; | ||
230 | int ru_msgsnd; | ||
231 | int ru_msgrcv; | ||
232 | int ru_nsignals; | ||
233 | int ru_nvcsw; | ||
234 | int ru_nivcsw; | ||
235 | }; | ||
236 | |||
237 | static int | ||
238 | put_rusage (struct rusage32 *ru, struct rusage *r) | ||
239 | { | ||
240 | int err; | ||
241 | |||
242 | if (!access_ok(VERIFY_WRITE, ru, sizeof *ru)) | ||
243 | return -EFAULT; | ||
244 | |||
245 | err = __put_user (r->ru_utime.tv_sec, &ru->ru_utime.tv_sec); | ||
246 | err |= __put_user (r->ru_utime.tv_usec, &ru->ru_utime.tv_usec); | ||
247 | err |= __put_user (r->ru_stime.tv_sec, &ru->ru_stime.tv_sec); | ||
248 | err |= __put_user (r->ru_stime.tv_usec, &ru->ru_stime.tv_usec); | ||
249 | err |= __put_user (r->ru_maxrss, &ru->ru_maxrss); | ||
250 | err |= __put_user (r->ru_ixrss, &ru->ru_ixrss); | ||
251 | err |= __put_user (r->ru_idrss, &ru->ru_idrss); | ||
252 | err |= __put_user (r->ru_isrss, &ru->ru_isrss); | ||
253 | err |= __put_user (r->ru_minflt, &ru->ru_minflt); | ||
254 | err |= __put_user (r->ru_majflt, &ru->ru_majflt); | ||
255 | err |= __put_user (r->ru_nswap, &ru->ru_nswap); | ||
256 | err |= __put_user (r->ru_inblock, &ru->ru_inblock); | ||
257 | err |= __put_user (r->ru_oublock, &ru->ru_oublock); | ||
258 | err |= __put_user (r->ru_msgsnd, &ru->ru_msgsnd); | ||
259 | err |= __put_user (r->ru_msgrcv, &ru->ru_msgrcv); | ||
260 | err |= __put_user (r->ru_nsignals, &ru->ru_nsignals); | ||
261 | err |= __put_user (r->ru_nvcsw, &ru->ru_nvcsw); | ||
262 | err |= __put_user (r->ru_nivcsw, &ru->ru_nivcsw); | ||
263 | |||
264 | return err; | ||
265 | } | ||
266 | |||
267 | asmlinkage int | ||
268 | sys32_wait4(compat_pid_t pid, unsigned int * stat_addr, int options, | ||
269 | struct rusage32 * ru) | ||
270 | { | ||
271 | if (!ru) | ||
272 | return sys_wait4(pid, stat_addr, options, NULL); | ||
273 | else { | ||
274 | struct rusage r; | ||
275 | int ret; | ||
276 | unsigned int status; | ||
277 | mm_segment_t old_fs = get_fs(); | ||
278 | |||
279 | set_fs(KERNEL_DS); | ||
280 | ret = sys_wait4(pid, stat_addr ? &status : NULL, options, &r); | ||
281 | set_fs(old_fs); | ||
282 | if (put_rusage (ru, &r)) return -EFAULT; | ||
283 | if (stat_addr && put_user (status, stat_addr)) | ||
284 | return -EFAULT; | ||
285 | return ret; | ||
286 | } | ||
287 | } | ||
288 | |||
289 | asmlinkage int | ||
290 | sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr, int options) | ||
291 | { | ||
292 | return sys32_wait4(pid, stat_addr, options, NULL); | ||
293 | } | ||
294 | |||
295 | struct sysinfo32 { | ||
296 | s32 uptime; | ||
297 | u32 loads[3]; | ||
298 | u32 totalram; | ||
299 | u32 freeram; | ||
300 | u32 sharedram; | ||
301 | u32 bufferram; | ||
302 | u32 totalswap; | ||
303 | u32 freeswap; | ||
304 | u16 procs; | ||
305 | u32 totalhigh; | ||
306 | u32 freehigh; | ||
307 | u32 mem_unit; | ||
308 | char _f[8]; | ||
309 | }; | ||
310 | |||
311 | asmlinkage int sys32_sysinfo(struct sysinfo32 *info) | ||
312 | { | ||
313 | struct sysinfo s; | ||
314 | int ret, err; | ||
315 | mm_segment_t old_fs = get_fs (); | ||
316 | |||
317 | set_fs (KERNEL_DS); | ||
318 | ret = sys_sysinfo(&s); | ||
319 | set_fs (old_fs); | ||
320 | err = put_user (s.uptime, &info->uptime); | ||
321 | err |= __put_user (s.loads[0], &info->loads[0]); | ||
322 | err |= __put_user (s.loads[1], &info->loads[1]); | ||
323 | err |= __put_user (s.loads[2], &info->loads[2]); | ||
324 | err |= __put_user (s.totalram, &info->totalram); | ||
325 | err |= __put_user (s.freeram, &info->freeram); | ||
326 | err |= __put_user (s.sharedram, &info->sharedram); | ||
327 | err |= __put_user (s.bufferram, &info->bufferram); | ||
328 | err |= __put_user (s.totalswap, &info->totalswap); | ||
329 | err |= __put_user (s.freeswap, &info->freeswap); | ||
330 | err |= __put_user (s.procs, &info->procs); | ||
331 | err |= __put_user (s.totalhigh, &info->totalhigh); | ||
332 | err |= __put_user (s.freehigh, &info->freehigh); | ||
333 | err |= __put_user (s.mem_unit, &info->mem_unit); | ||
334 | if (err) | ||
335 | return -EFAULT; | ||
336 | return ret; | ||
337 | } | ||
338 | |||
339 | #define RLIM_INFINITY32 0x7fffffff | ||
340 | #define RESOURCE32(x) ((x > RLIM_INFINITY32) ? RLIM_INFINITY32 : x) | ||
341 | |||
342 | struct rlimit32 { | ||
343 | int rlim_cur; | ||
344 | int rlim_max; | ||
345 | }; | ||
346 | |||
347 | #ifdef __MIPSEB__ | ||
348 | asmlinkage long sys32_truncate64(const char * path, unsigned long __dummy, | ||
349 | int length_hi, int length_lo) | ||
350 | #endif | ||
351 | #ifdef __MIPSEL__ | ||
352 | asmlinkage long sys32_truncate64(const char * path, unsigned long __dummy, | ||
353 | int length_lo, int length_hi) | ||
354 | #endif | ||
355 | { | ||
356 | loff_t length; | ||
357 | |||
358 | length = ((unsigned long) length_hi << 32) | (unsigned int) length_lo; | ||
359 | |||
360 | return sys_truncate(path, length); | ||
361 | } | ||
362 | |||
363 | #ifdef __MIPSEB__ | ||
364 | asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long __dummy, | ||
365 | int length_hi, int length_lo) | ||
366 | #endif | ||
367 | #ifdef __MIPSEL__ | ||
368 | asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long __dummy, | ||
369 | int length_lo, int length_hi) | ||
370 | #endif | ||
371 | { | ||
372 | loff_t length; | ||
373 | |||
374 | length = ((unsigned long) length_hi << 32) | (unsigned int) length_lo; | ||
375 | |||
376 | return sys_ftruncate(fd, length); | ||
377 | } | ||
378 | |||
379 | static inline long | ||
380 | get_tv32(struct timeval *o, struct compat_timeval *i) | ||
381 | { | ||
382 | return (!access_ok(VERIFY_READ, i, sizeof(*i)) || | ||
383 | (__get_user(o->tv_sec, &i->tv_sec) | | ||
384 | __get_user(o->tv_usec, &i->tv_usec))); | ||
385 | } | ||
386 | |||
387 | static inline long | ||
388 | put_tv32(struct compat_timeval *o, struct timeval *i) | ||
389 | { | ||
390 | return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) || | ||
391 | (__put_user(i->tv_sec, &o->tv_sec) | | ||
392 | __put_user(i->tv_usec, &o->tv_usec))); | ||
393 | } | ||
394 | |||
395 | extern struct timezone sys_tz; | ||
396 | |||
397 | asmlinkage int | ||
398 | sys32_gettimeofday(struct compat_timeval *tv, struct timezone *tz) | ||
399 | { | ||
400 | if (tv) { | ||
401 | struct timeval ktv; | ||
402 | do_gettimeofday(&ktv); | ||
403 | if (put_tv32(tv, &ktv)) | ||
404 | return -EFAULT; | ||
405 | } | ||
406 | if (tz) { | ||
407 | if (copy_to_user(tz, &sys_tz, sizeof(sys_tz))) | ||
408 | return -EFAULT; | ||
409 | } | ||
410 | return 0; | ||
411 | } | ||
412 | |||
413 | static inline long get_ts32(struct timespec *o, struct compat_timeval *i) | ||
414 | { | ||
415 | long usec; | ||
416 | |||
417 | if (!access_ok(VERIFY_READ, i, sizeof(*i))) | ||
418 | return -EFAULT; | ||
419 | if (__get_user(o->tv_sec, &i->tv_sec)) | ||
420 | return -EFAULT; | ||
421 | if (__get_user(usec, &i->tv_usec)) | ||
422 | return -EFAULT; | ||
423 | o->tv_nsec = usec * 1000; | ||
424 | return 0; | ||
425 | } | ||
426 | |||
427 | asmlinkage int | ||
428 | sys32_settimeofday(struct compat_timeval *tv, struct timezone *tz) | ||
429 | { | ||
430 | struct timespec kts; | ||
431 | struct timezone ktz; | ||
432 | |||
433 | if (tv) { | ||
434 | if (get_ts32(&kts, tv)) | ||
435 | return -EFAULT; | ||
436 | } | ||
437 | if (tz) { | ||
438 | if (copy_from_user(&ktz, tz, sizeof(ktz))) | ||
439 | return -EFAULT; | ||
440 | } | ||
441 | |||
442 | return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL); | ||
443 | } | ||
444 | |||
445 | asmlinkage int sys32_llseek(unsigned int fd, unsigned int offset_high, | ||
446 | unsigned int offset_low, loff_t * result, | ||
447 | unsigned int origin) | ||
448 | { | ||
449 | return sys_llseek(fd, offset_high, offset_low, result, origin); | ||
450 | } | ||
451 | |||
452 | /* From the Single Unix Spec: pread & pwrite act like lseek to pos + op + | ||
453 | lseek back to original location. They fail just like lseek does on | ||
454 | non-seekable files. */ | ||
455 | |||
456 | asmlinkage ssize_t sys32_pread(unsigned int fd, char * buf, | ||
457 | size_t count, u32 unused, u64 a4, u64 a5) | ||
458 | { | ||
459 | ssize_t ret; | ||
460 | struct file * file; | ||
461 | ssize_t (*read)(struct file *, char *, size_t, loff_t *); | ||
462 | loff_t pos; | ||
463 | |||
464 | ret = -EBADF; | ||
465 | file = fget(fd); | ||
466 | if (!file) | ||
467 | goto bad_file; | ||
468 | if (!(file->f_mode & FMODE_READ)) | ||
469 | goto out; | ||
470 | pos = merge_64(a4, a5); | ||
471 | ret = rw_verify_area(READ, file, &pos, count); | ||
472 | if (ret) | ||
473 | goto out; | ||
474 | ret = -EINVAL; | ||
475 | if (!file->f_op || !(read = file->f_op->read)) | ||
476 | goto out; | ||
477 | if (pos < 0) | ||
478 | goto out; | ||
479 | ret = -ESPIPE; | ||
480 | if (!(file->f_mode & FMODE_PREAD)) | ||
481 | goto out; | ||
482 | ret = read(file, buf, count, &pos); | ||
483 | if (ret > 0) | ||
484 | dnotify_parent(file->f_dentry, DN_ACCESS); | ||
485 | out: | ||
486 | fput(file); | ||
487 | bad_file: | ||
488 | return ret; | ||
489 | } | ||
490 | |||
491 | asmlinkage ssize_t sys32_pwrite(unsigned int fd, const char * buf, | ||
492 | size_t count, u32 unused, u64 a4, u64 a5) | ||
493 | { | ||
494 | ssize_t ret; | ||
495 | struct file * file; | ||
496 | ssize_t (*write)(struct file *, const char *, size_t, loff_t *); | ||
497 | loff_t pos; | ||
498 | |||
499 | ret = -EBADF; | ||
500 | file = fget(fd); | ||
501 | if (!file) | ||
502 | goto bad_file; | ||
503 | if (!(file->f_mode & FMODE_WRITE)) | ||
504 | goto out; | ||
505 | pos = merge_64(a4, a5); | ||
506 | ret = rw_verify_area(WRITE, file, &pos, count); | ||
507 | if (ret) | ||
508 | goto out; | ||
509 | ret = -EINVAL; | ||
510 | if (!file->f_op || !(write = file->f_op->write)) | ||
511 | goto out; | ||
512 | if (pos < 0) | ||
513 | goto out; | ||
514 | |||
515 | ret = -ESPIPE; | ||
516 | if (!(file->f_mode & FMODE_PWRITE)) | ||
517 | goto out; | ||
518 | |||
519 | ret = write(file, buf, count, &pos); | ||
520 | if (ret > 0) | ||
521 | dnotify_parent(file->f_dentry, DN_MODIFY); | ||
522 | out: | ||
523 | fput(file); | ||
524 | bad_file: | ||
525 | return ret; | ||
526 | } | ||
527 | |||
528 | asmlinkage int sys32_sched_rr_get_interval(compat_pid_t pid, | ||
529 | struct compat_timespec *interval) | ||
530 | { | ||
531 | struct timespec t; | ||
532 | int ret; | ||
533 | mm_segment_t old_fs = get_fs (); | ||
534 | |||
535 | set_fs (KERNEL_DS); | ||
536 | ret = sys_sched_rr_get_interval(pid, &t); | ||
537 | set_fs (old_fs); | ||
538 | if (put_user (t.tv_sec, &interval->tv_sec) || | ||
539 | __put_user (t.tv_nsec, &interval->tv_nsec)) | ||
540 | return -EFAULT; | ||
541 | return ret; | ||
542 | } | ||
543 | |||
544 | struct msgbuf32 { s32 mtype; char mtext[1]; }; | ||
545 | |||
546 | struct ipc_perm32 | ||
547 | { | ||
548 | key_t key; | ||
549 | compat_uid_t uid; | ||
550 | compat_gid_t gid; | ||
551 | compat_uid_t cuid; | ||
552 | compat_gid_t cgid; | ||
553 | compat_mode_t mode; | ||
554 | unsigned short seq; | ||
555 | }; | ||
556 | |||
557 | struct ipc64_perm32 { | ||
558 | key_t key; | ||
559 | compat_uid_t uid; | ||
560 | compat_gid_t gid; | ||
561 | compat_uid_t cuid; | ||
562 | compat_gid_t cgid; | ||
563 | compat_mode_t mode; | ||
564 | unsigned short seq; | ||
565 | unsigned short __pad1; | ||
566 | unsigned int __unused1; | ||
567 | unsigned int __unused2; | ||
568 | }; | ||
569 | |||
570 | struct semid_ds32 { | ||
571 | struct ipc_perm32 sem_perm; /* permissions .. see ipc.h */ | ||
572 | compat_time_t sem_otime; /* last semop time */ | ||
573 | compat_time_t sem_ctime; /* last change time */ | ||
574 | u32 sem_base; /* ptr to first semaphore in array */ | ||
575 | u32 sem_pending; /* pending operations to be processed */ | ||
576 | u32 sem_pending_last; /* last pending operation */ | ||
577 | u32 undo; /* undo requests on this array */ | ||
578 | unsigned short sem_nsems; /* no. of semaphores in array */ | ||
579 | }; | ||
580 | |||
581 | struct semid64_ds32 { | ||
582 | struct ipc64_perm32 sem_perm; | ||
583 | compat_time_t sem_otime; | ||
584 | compat_time_t sem_ctime; | ||
585 | unsigned int sem_nsems; | ||
586 | unsigned int __unused1; | ||
587 | unsigned int __unused2; | ||
588 | }; | ||
589 | |||
590 | struct msqid_ds32 | ||
591 | { | ||
592 | struct ipc_perm32 msg_perm; | ||
593 | u32 msg_first; | ||
594 | u32 msg_last; | ||
595 | compat_time_t msg_stime; | ||
596 | compat_time_t msg_rtime; | ||
597 | compat_time_t msg_ctime; | ||
598 | u32 wwait; | ||
599 | u32 rwait; | ||
600 | unsigned short msg_cbytes; | ||
601 | unsigned short msg_qnum; | ||
602 | unsigned short msg_qbytes; | ||
603 | compat_ipc_pid_t msg_lspid; | ||
604 | compat_ipc_pid_t msg_lrpid; | ||
605 | }; | ||
606 | |||
607 | struct msqid64_ds32 { | ||
608 | struct ipc64_perm32 msg_perm; | ||
609 | compat_time_t msg_stime; | ||
610 | unsigned int __unused1; | ||
611 | compat_time_t msg_rtime; | ||
612 | unsigned int __unused2; | ||
613 | compat_time_t msg_ctime; | ||
614 | unsigned int __unused3; | ||
615 | unsigned int msg_cbytes; | ||
616 | unsigned int msg_qnum; | ||
617 | unsigned int msg_qbytes; | ||
618 | compat_pid_t msg_lspid; | ||
619 | compat_pid_t msg_lrpid; | ||
620 | unsigned int __unused4; | ||
621 | unsigned int __unused5; | ||
622 | }; | ||
623 | |||
624 | struct shmid_ds32 { | ||
625 | struct ipc_perm32 shm_perm; | ||
626 | int shm_segsz; | ||
627 | compat_time_t shm_atime; | ||
628 | compat_time_t shm_dtime; | ||
629 | compat_time_t shm_ctime; | ||
630 | compat_ipc_pid_t shm_cpid; | ||
631 | compat_ipc_pid_t shm_lpid; | ||
632 | unsigned short shm_nattch; | ||
633 | }; | ||
634 | |||
635 | struct shmid64_ds32 { | ||
636 | struct ipc64_perm32 shm_perm; | ||
637 | compat_size_t shm_segsz; | ||
638 | compat_time_t shm_atime; | ||
639 | compat_time_t shm_dtime; | ||
640 | compat_time_t shm_ctime; | ||
641 | compat_pid_t shm_cpid; | ||
642 | compat_pid_t shm_lpid; | ||
643 | unsigned int shm_nattch; | ||
644 | unsigned int __unused1; | ||
645 | unsigned int __unused2; | ||
646 | }; | ||
647 | |||
648 | struct ipc_kludge32 { | ||
649 | u32 msgp; | ||
650 | s32 msgtyp; | ||
651 | }; | ||
652 | |||
653 | static int | ||
654 | do_sys32_semctl(int first, int second, int third, void *uptr) | ||
655 | { | ||
656 | union semun fourth; | ||
657 | u32 pad; | ||
658 | int err, err2; | ||
659 | struct semid64_ds s; | ||
660 | mm_segment_t old_fs; | ||
661 | |||
662 | if (!uptr) | ||
663 | return -EINVAL; | ||
664 | err = -EFAULT; | ||
665 | if (get_user (pad, (u32 *)uptr)) | ||
666 | return err; | ||
667 | if ((third & ~IPC_64) == SETVAL) | ||
668 | fourth.val = (int)pad; | ||
669 | else | ||
670 | fourth.__pad = (void *)A(pad); | ||
671 | switch (third & ~IPC_64) { | ||
672 | case IPC_INFO: | ||
673 | case IPC_RMID: | ||
674 | case IPC_SET: | ||
675 | case SEM_INFO: | ||
676 | case GETVAL: | ||
677 | case GETPID: | ||
678 | case GETNCNT: | ||
679 | case GETZCNT: | ||
680 | case GETALL: | ||
681 | case SETVAL: | ||
682 | case SETALL: | ||
683 | err = sys_semctl (first, second, third, fourth); | ||
684 | break; | ||
685 | |||
686 | case IPC_STAT: | ||
687 | case SEM_STAT: | ||
688 | fourth.__pad = &s; | ||
689 | old_fs = get_fs(); | ||
690 | set_fs(KERNEL_DS); | ||
691 | err = sys_semctl(first, second, third | IPC_64, fourth); | ||
692 | set_fs(old_fs); | ||
693 | |||
694 | if (third & IPC_64) { | ||
695 | struct semid64_ds32 *usp64 = (struct semid64_ds32 *) A(pad); | ||
696 | |||
697 | if (!access_ok(VERIFY_WRITE, usp64, sizeof(*usp64))) { | ||
698 | err = -EFAULT; | ||
699 | break; | ||
700 | } | ||
701 | err2 = __put_user(s.sem_perm.key, &usp64->sem_perm.key); | ||
702 | err2 |= __put_user(s.sem_perm.uid, &usp64->sem_perm.uid); | ||
703 | err2 |= __put_user(s.sem_perm.gid, &usp64->sem_perm.gid); | ||
704 | err2 |= __put_user(s.sem_perm.cuid, &usp64->sem_perm.cuid); | ||
705 | err2 |= __put_user(s.sem_perm.cgid, &usp64->sem_perm.cgid); | ||
706 | err2 |= __put_user(s.sem_perm.mode, &usp64->sem_perm.mode); | ||
707 | err2 |= __put_user(s.sem_perm.seq, &usp64->sem_perm.seq); | ||
708 | err2 |= __put_user(s.sem_otime, &usp64->sem_otime); | ||
709 | err2 |= __put_user(s.sem_ctime, &usp64->sem_ctime); | ||
710 | err2 |= __put_user(s.sem_nsems, &usp64->sem_nsems); | ||
711 | } else { | ||
712 | struct semid_ds32 *usp32 = (struct semid_ds32 *) A(pad); | ||
713 | |||
714 | if (!access_ok(VERIFY_WRITE, usp32, sizeof(*usp32))) { | ||
715 | err = -EFAULT; | ||
716 | break; | ||
717 | } | ||
718 | err2 = __put_user(s.sem_perm.key, &usp32->sem_perm.key); | ||
719 | err2 |= __put_user(s.sem_perm.uid, &usp32->sem_perm.uid); | ||
720 | err2 |= __put_user(s.sem_perm.gid, &usp32->sem_perm.gid); | ||
721 | err2 |= __put_user(s.sem_perm.cuid, &usp32->sem_perm.cuid); | ||
722 | err2 |= __put_user(s.sem_perm.cgid, &usp32->sem_perm.cgid); | ||
723 | err2 |= __put_user(s.sem_perm.mode, &usp32->sem_perm.mode); | ||
724 | err2 |= __put_user(s.sem_perm.seq, &usp32->sem_perm.seq); | ||
725 | err2 |= __put_user(s.sem_otime, &usp32->sem_otime); | ||
726 | err2 |= __put_user(s.sem_ctime, &usp32->sem_ctime); | ||
727 | err2 |= __put_user(s.sem_nsems, &usp32->sem_nsems); | ||
728 | } | ||
729 | if (err2) | ||
730 | err = -EFAULT; | ||
731 | break; | ||
732 | |||
733 | default: | ||
734 | err = - EINVAL; | ||
735 | break; | ||
736 | } | ||
737 | |||
738 | return err; | ||
739 | } | ||
740 | |||
741 | static int | ||
742 | do_sys32_msgsnd (int first, int second, int third, void *uptr) | ||
743 | { | ||
744 | struct msgbuf32 *up = (struct msgbuf32 *)uptr; | ||
745 | struct msgbuf *p; | ||
746 | mm_segment_t old_fs; | ||
747 | int err; | ||
748 | |||
749 | if (second < 0) | ||
750 | return -EINVAL; | ||
751 | p = kmalloc (second + sizeof (struct msgbuf) | ||
752 | + 4, GFP_USER); | ||
753 | if (!p) | ||
754 | return -ENOMEM; | ||
755 | err = get_user (p->mtype, &up->mtype); | ||
756 | if (err) | ||
757 | goto out; | ||
758 | err |= __copy_from_user (p->mtext, &up->mtext, second); | ||
759 | if (err) | ||
760 | goto out; | ||
761 | old_fs = get_fs (); | ||
762 | set_fs (KERNEL_DS); | ||
763 | err = sys_msgsnd (first, p, second, third); | ||
764 | set_fs (old_fs); | ||
765 | out: | ||
766 | kfree (p); | ||
767 | |||
768 | return err; | ||
769 | } | ||
770 | |||
771 | static int | ||
772 | do_sys32_msgrcv (int first, int second, int msgtyp, int third, | ||
773 | int version, void *uptr) | ||
774 | { | ||
775 | struct msgbuf32 *up; | ||
776 | struct msgbuf *p; | ||
777 | mm_segment_t old_fs; | ||
778 | int err; | ||
779 | |||
780 | if (!version) { | ||
781 | struct ipc_kludge32 *uipck = (struct ipc_kludge32 *)uptr; | ||
782 | struct ipc_kludge32 ipck; | ||
783 | |||
784 | err = -EINVAL; | ||
785 | if (!uptr) | ||
786 | goto out; | ||
787 | err = -EFAULT; | ||
788 | if (copy_from_user (&ipck, uipck, sizeof (struct ipc_kludge32))) | ||
789 | goto out; | ||
790 | uptr = (void *)AA(ipck.msgp); | ||
791 | msgtyp = ipck.msgtyp; | ||
792 | } | ||
793 | |||
794 | if (second < 0) | ||
795 | return -EINVAL; | ||
796 | err = -ENOMEM; | ||
797 | p = kmalloc (second + sizeof (struct msgbuf) + 4, GFP_USER); | ||
798 | if (!p) | ||
799 | goto out; | ||
800 | old_fs = get_fs (); | ||
801 | set_fs (KERNEL_DS); | ||
802 | err = sys_msgrcv (first, p, second + 4, msgtyp, third); | ||
803 | set_fs (old_fs); | ||
804 | if (err < 0) | ||
805 | goto free_then_out; | ||
806 | up = (struct msgbuf32 *)uptr; | ||
807 | if (put_user (p->mtype, &up->mtype) || | ||
808 | __copy_to_user (&up->mtext, p->mtext, err)) | ||
809 | err = -EFAULT; | ||
810 | free_then_out: | ||
811 | kfree (p); | ||
812 | out: | ||
813 | return err; | ||
814 | } | ||
815 | |||
816 | static int | ||
817 | do_sys32_msgctl (int first, int second, void *uptr) | ||
818 | { | ||
819 | int err = -EINVAL, err2; | ||
820 | struct msqid64_ds m; | ||
821 | struct msqid_ds32 *up32 = (struct msqid_ds32 *)uptr; | ||
822 | struct msqid64_ds32 *up64 = (struct msqid64_ds32 *)uptr; | ||
823 | mm_segment_t old_fs; | ||
824 | |||
825 | switch (second & ~IPC_64) { | ||
826 | case IPC_INFO: | ||
827 | case IPC_RMID: | ||
828 | case MSG_INFO: | ||
829 | err = sys_msgctl (first, second, (struct msqid_ds *)uptr); | ||
830 | break; | ||
831 | |||
832 | case IPC_SET: | ||
833 | if (second & IPC_64) { | ||
834 | if (!access_ok(VERIFY_READ, up64, sizeof(*up64))) { | ||
835 | err = -EFAULT; | ||
836 | break; | ||
837 | } | ||
838 | err = __get_user(m.msg_perm.uid, &up64->msg_perm.uid); | ||
839 | err |= __get_user(m.msg_perm.gid, &up64->msg_perm.gid); | ||
840 | err |= __get_user(m.msg_perm.mode, &up64->msg_perm.mode); | ||
841 | err |= __get_user(m.msg_qbytes, &up64->msg_qbytes); | ||
842 | } else { | ||
843 | if (!access_ok(VERIFY_READ, up32, sizeof(*up32))) { | ||
844 | err = -EFAULT; | ||
845 | break; | ||
846 | } | ||
847 | err = __get_user(m.msg_perm.uid, &up32->msg_perm.uid); | ||
848 | err |= __get_user(m.msg_perm.gid, &up32->msg_perm.gid); | ||
849 | err |= __get_user(m.msg_perm.mode, &up32->msg_perm.mode); | ||
850 | err |= __get_user(m.msg_qbytes, &up32->msg_qbytes); | ||
851 | } | ||
852 | if (err) | ||
853 | break; | ||
854 | old_fs = get_fs(); | ||
855 | set_fs(KERNEL_DS); | ||
856 | err = sys_msgctl(first, second | IPC_64, (struct msqid_ds *)&m); | ||
857 | set_fs(old_fs); | ||
858 | break; | ||
859 | |||
860 | case IPC_STAT: | ||
861 | case MSG_STAT: | ||
862 | old_fs = get_fs(); | ||
863 | set_fs(KERNEL_DS); | ||
864 | err = sys_msgctl(first, second | IPC_64, (struct msqid_ds *)&m); | ||
865 | set_fs(old_fs); | ||
866 | if (second & IPC_64) { | ||
867 | if (!access_ok(VERIFY_WRITE, up64, sizeof(*up64))) { | ||
868 | err = -EFAULT; | ||
869 | break; | ||
870 | } | ||
871 | err2 = __put_user(m.msg_perm.key, &up64->msg_perm.key); | ||
872 | err2 |= __put_user(m.msg_perm.uid, &up64->msg_perm.uid); | ||
873 | err2 |= __put_user(m.msg_perm.gid, &up64->msg_perm.gid); | ||
874 | err2 |= __put_user(m.msg_perm.cuid, &up64->msg_perm.cuid); | ||
875 | err2 |= __put_user(m.msg_perm.cgid, &up64->msg_perm.cgid); | ||
876 | err2 |= __put_user(m.msg_perm.mode, &up64->msg_perm.mode); | ||
877 | err2 |= __put_user(m.msg_perm.seq, &up64->msg_perm.seq); | ||
878 | err2 |= __put_user(m.msg_stime, &up64->msg_stime); | ||
879 | err2 |= __put_user(m.msg_rtime, &up64->msg_rtime); | ||
880 | err2 |= __put_user(m.msg_ctime, &up64->msg_ctime); | ||
881 | err2 |= __put_user(m.msg_cbytes, &up64->msg_cbytes); | ||
882 | err2 |= __put_user(m.msg_qnum, &up64->msg_qnum); | ||
883 | err2 |= __put_user(m.msg_qbytes, &up64->msg_qbytes); | ||
884 | err2 |= __put_user(m.msg_lspid, &up64->msg_lspid); | ||
885 | err2 |= __put_user(m.msg_lrpid, &up64->msg_lrpid); | ||
886 | if (err2) | ||
887 | err = -EFAULT; | ||
888 | } else { | ||
889 | if (!access_ok(VERIFY_WRITE, up32, sizeof(*up32))) { | ||
890 | err = -EFAULT; | ||
891 | break; | ||
892 | } | ||
893 | err2 = __put_user(m.msg_perm.key, &up32->msg_perm.key); | ||
894 | err2 |= __put_user(m.msg_perm.uid, &up32->msg_perm.uid); | ||
895 | err2 |= __put_user(m.msg_perm.gid, &up32->msg_perm.gid); | ||
896 | err2 |= __put_user(m.msg_perm.cuid, &up32->msg_perm.cuid); | ||
897 | err2 |= __put_user(m.msg_perm.cgid, &up32->msg_perm.cgid); | ||
898 | err2 |= __put_user(m.msg_perm.mode, &up32->msg_perm.mode); | ||
899 | err2 |= __put_user(m.msg_perm.seq, &up32->msg_perm.seq); | ||
900 | err2 |= __put_user(m.msg_stime, &up32->msg_stime); | ||
901 | err2 |= __put_user(m.msg_rtime, &up32->msg_rtime); | ||
902 | err2 |= __put_user(m.msg_ctime, &up32->msg_ctime); | ||
903 | err2 |= __put_user(m.msg_cbytes, &up32->msg_cbytes); | ||
904 | err2 |= __put_user(m.msg_qnum, &up32->msg_qnum); | ||
905 | err2 |= __put_user(m.msg_qbytes, &up32->msg_qbytes); | ||
906 | err2 |= __put_user(m.msg_lspid, &up32->msg_lspid); | ||
907 | err2 |= __put_user(m.msg_lrpid, &up32->msg_lrpid); | ||
908 | if (err2) | ||
909 | err = -EFAULT; | ||
910 | } | ||
911 | break; | ||
912 | } | ||
913 | |||
914 | return err; | ||
915 | } | ||
916 | |||
917 | static int | ||
918 | do_sys32_shmat (int first, int second, int third, int version, void *uptr) | ||
919 | { | ||
920 | unsigned long raddr; | ||
921 | u32 *uaddr = (u32 *)A((u32)third); | ||
922 | int err = -EINVAL; | ||
923 | |||
924 | if (version == 1) | ||
925 | return err; | ||
926 | err = do_shmat (first, uptr, second, &raddr); | ||
927 | if (err) | ||
928 | return err; | ||
929 | err = put_user (raddr, uaddr); | ||
930 | return err; | ||
931 | } | ||
932 | |||
933 | struct shm_info32 { | ||
934 | int used_ids; | ||
935 | u32 shm_tot, shm_rss, shm_swp; | ||
936 | u32 swap_attempts, swap_successes; | ||
937 | }; | ||
938 | |||
939 | static int | ||
940 | do_sys32_shmctl (int first, int second, void *uptr) | ||
941 | { | ||
942 | struct shmid64_ds32 *up64 = (struct shmid64_ds32 *)uptr; | ||
943 | struct shmid_ds32 *up32 = (struct shmid_ds32 *)uptr; | ||
944 | struct shm_info32 *uip = (struct shm_info32 *)uptr; | ||
945 | int err = -EFAULT, err2; | ||
946 | struct shmid64_ds s64; | ||
947 | mm_segment_t old_fs; | ||
948 | struct shm_info si; | ||
949 | struct shmid_ds s; | ||
950 | |||
951 | switch (second & ~IPC_64) { | ||
952 | case IPC_INFO: | ||
953 | second = IPC_INFO; /* So that we don't have to translate it */ | ||
954 | case IPC_RMID: | ||
955 | case SHM_LOCK: | ||
956 | case SHM_UNLOCK: | ||
957 | err = sys_shmctl(first, second, (struct shmid_ds *)uptr); | ||
958 | break; | ||
959 | case IPC_SET: | ||
960 | if (second & IPC_64) { | ||
961 | err = get_user(s.shm_perm.uid, &up64->shm_perm.uid); | ||
962 | err |= get_user(s.shm_perm.gid, &up64->shm_perm.gid); | ||
963 | err |= get_user(s.shm_perm.mode, &up64->shm_perm.mode); | ||
964 | } else { | ||
965 | err = get_user(s.shm_perm.uid, &up32->shm_perm.uid); | ||
966 | err |= get_user(s.shm_perm.gid, &up32->shm_perm.gid); | ||
967 | err |= get_user(s.shm_perm.mode, &up32->shm_perm.mode); | ||
968 | } | ||
969 | if (err) | ||
970 | break; | ||
971 | old_fs = get_fs(); | ||
972 | set_fs(KERNEL_DS); | ||
973 | err = sys_shmctl(first, second & ~IPC_64, &s); | ||
974 | set_fs(old_fs); | ||
975 | break; | ||
976 | |||
977 | case IPC_STAT: | ||
978 | case SHM_STAT: | ||
979 | old_fs = get_fs(); | ||
980 | set_fs(KERNEL_DS); | ||
981 | err = sys_shmctl(first, second | IPC_64, (void *) &s64); | ||
982 | set_fs(old_fs); | ||
983 | if (err < 0) | ||
984 | break; | ||
985 | if (second & IPC_64) { | ||
986 | if (!access_ok(VERIFY_WRITE, up64, sizeof(*up64))) { | ||
987 | err = -EFAULT; | ||
988 | break; | ||
989 | } | ||
990 | err2 = __put_user(s64.shm_perm.key, &up64->shm_perm.key); | ||
991 | err2 |= __put_user(s64.shm_perm.uid, &up64->shm_perm.uid); | ||
992 | err2 |= __put_user(s64.shm_perm.gid, &up64->shm_perm.gid); | ||
993 | err2 |= __put_user(s64.shm_perm.cuid, &up64->shm_perm.cuid); | ||
994 | err2 |= __put_user(s64.shm_perm.cgid, &up64->shm_perm.cgid); | ||
995 | err2 |= __put_user(s64.shm_perm.mode, &up64->shm_perm.mode); | ||
996 | err2 |= __put_user(s64.shm_perm.seq, &up64->shm_perm.seq); | ||
997 | err2 |= __put_user(s64.shm_atime, &up64->shm_atime); | ||
998 | err2 |= __put_user(s64.shm_dtime, &up64->shm_dtime); | ||
999 | err2 |= __put_user(s64.shm_ctime, &up64->shm_ctime); | ||
1000 | err2 |= __put_user(s64.shm_segsz, &up64->shm_segsz); | ||
1001 | err2 |= __put_user(s64.shm_nattch, &up64->shm_nattch); | ||
1002 | err2 |= __put_user(s64.shm_cpid, &up64->shm_cpid); | ||
1003 | err2 |= __put_user(s64.shm_lpid, &up64->shm_lpid); | ||
1004 | } else { | ||
1005 | if (!access_ok(VERIFY_WRITE, up32, sizeof(*up32))) { | ||
1006 | err = -EFAULT; | ||
1007 | break; | ||
1008 | } | ||
1009 | err2 = __put_user(s64.shm_perm.key, &up32->shm_perm.key); | ||
1010 | err2 |= __put_user(s64.shm_perm.uid, &up32->shm_perm.uid); | ||
1011 | err2 |= __put_user(s64.shm_perm.gid, &up32->shm_perm.gid); | ||
1012 | err2 |= __put_user(s64.shm_perm.cuid, &up32->shm_perm.cuid); | ||
1013 | err2 |= __put_user(s64.shm_perm.cgid, &up32->shm_perm.cgid); | ||
1014 | err2 |= __put_user(s64.shm_perm.mode, &up32->shm_perm.mode); | ||
1015 | err2 |= __put_user(s64.shm_perm.seq, &up32->shm_perm.seq); | ||
1016 | err2 |= __put_user(s64.shm_atime, &up32->shm_atime); | ||
1017 | err2 |= __put_user(s64.shm_dtime, &up32->shm_dtime); | ||
1018 | err2 |= __put_user(s64.shm_ctime, &up32->shm_ctime); | ||
1019 | err2 |= __put_user(s64.shm_segsz, &up32->shm_segsz); | ||
1020 | err2 |= __put_user(s64.shm_nattch, &up32->shm_nattch); | ||
1021 | err2 |= __put_user(s64.shm_cpid, &up32->shm_cpid); | ||
1022 | err2 |= __put_user(s64.shm_lpid, &up32->shm_lpid); | ||
1023 | } | ||
1024 | if (err2) | ||
1025 | err = -EFAULT; | ||
1026 | break; | ||
1027 | |||
1028 | case SHM_INFO: | ||
1029 | old_fs = get_fs(); | ||
1030 | set_fs(KERNEL_DS); | ||
1031 | err = sys_shmctl(first, second, (void *)&si); | ||
1032 | set_fs(old_fs); | ||
1033 | if (err < 0) | ||
1034 | break; | ||
1035 | err2 = put_user(si.used_ids, &uip->used_ids); | ||
1036 | err2 |= __put_user(si.shm_tot, &uip->shm_tot); | ||
1037 | err2 |= __put_user(si.shm_rss, &uip->shm_rss); | ||
1038 | err2 |= __put_user(si.shm_swp, &uip->shm_swp); | ||
1039 | err2 |= __put_user(si.swap_attempts, &uip->swap_attempts); | ||
1040 | err2 |= __put_user (si.swap_successes, &uip->swap_successes); | ||
1041 | if (err2) | ||
1042 | err = -EFAULT; | ||
1043 | break; | ||
1044 | |||
1045 | default: | ||
1046 | err = -EINVAL; | ||
1047 | break; | ||
1048 | } | ||
1049 | |||
1050 | return err; | ||
1051 | } | ||
1052 | |||
1053 | static int sys32_semtimedop(int semid, struct sembuf *tsems, int nsems, | ||
1054 | const struct compat_timespec *timeout32) | ||
1055 | { | ||
1056 | struct compat_timespec t32; | ||
1057 | struct timespec *t64 = compat_alloc_user_space(sizeof(*t64)); | ||
1058 | |||
1059 | if (copy_from_user(&t32, timeout32, sizeof(t32))) | ||
1060 | return -EFAULT; | ||
1061 | |||
1062 | if (put_user(t32.tv_sec, &t64->tv_sec) || | ||
1063 | put_user(t32.tv_nsec, &t64->tv_nsec)) | ||
1064 | return -EFAULT; | ||
1065 | |||
1066 | return sys_semtimedop(semid, tsems, nsems, t64); | ||
1067 | } | ||
1068 | |||
1069 | asmlinkage long | ||
1070 | sys32_ipc (u32 call, int first, int second, int third, u32 ptr, u32 fifth) | ||
1071 | { | ||
1072 | int version, err; | ||
1073 | |||
1074 | version = call >> 16; /* hack for backward compatibility */ | ||
1075 | call &= 0xffff; | ||
1076 | |||
1077 | switch (call) { | ||
1078 | case SEMOP: | ||
1079 | /* struct sembuf is the same on 32 and 64bit :)) */ | ||
1080 | err = sys_semtimedop (first, (struct sembuf *)AA(ptr), second, | ||
1081 | NULL); | ||
1082 | break; | ||
1083 | case SEMTIMEDOP: | ||
1084 | err = sys32_semtimedop (first, (struct sembuf *)AA(ptr), second, | ||
1085 | (const struct compat_timespec __user *)AA(fifth)); | ||
1086 | break; | ||
1087 | case SEMGET: | ||
1088 | err = sys_semget (first, second, third); | ||
1089 | break; | ||
1090 | case SEMCTL: | ||
1091 | err = do_sys32_semctl (first, second, third, | ||
1092 | (void *)AA(ptr)); | ||
1093 | break; | ||
1094 | |||
1095 | case MSGSND: | ||
1096 | err = do_sys32_msgsnd (first, second, third, | ||
1097 | (void *)AA(ptr)); | ||
1098 | break; | ||
1099 | case MSGRCV: | ||
1100 | err = do_sys32_msgrcv (first, second, fifth, third, | ||
1101 | version, (void *)AA(ptr)); | ||
1102 | break; | ||
1103 | case MSGGET: | ||
1104 | err = sys_msgget ((key_t) first, second); | ||
1105 | break; | ||
1106 | case MSGCTL: | ||
1107 | err = do_sys32_msgctl (first, second, (void *)AA(ptr)); | ||
1108 | break; | ||
1109 | |||
1110 | case SHMAT: | ||
1111 | err = do_sys32_shmat (first, second, third, | ||
1112 | version, (void *)AA(ptr)); | ||
1113 | break; | ||
1114 | case SHMDT: | ||
1115 | err = sys_shmdt ((char *)A(ptr)); | ||
1116 | break; | ||
1117 | case SHMGET: | ||
1118 | err = sys_shmget (first, (unsigned)second, third); | ||
1119 | break; | ||
1120 | case SHMCTL: | ||
1121 | err = do_sys32_shmctl (first, second, (void *)AA(ptr)); | ||
1122 | break; | ||
1123 | default: | ||
1124 | err = -EINVAL; | ||
1125 | break; | ||
1126 | } | ||
1127 | |||
1128 | return err; | ||
1129 | } | ||
1130 | |||
1131 | asmlinkage long sys32_shmat(int shmid, char __user *shmaddr, | ||
1132 | int shmflg, int32_t *addr) | ||
1133 | { | ||
1134 | unsigned long raddr; | ||
1135 | int err; | ||
1136 | |||
1137 | err = do_shmat(shmid, shmaddr, shmflg, &raddr); | ||
1138 | if (err) | ||
1139 | return err; | ||
1140 | |||
1141 | return put_user(raddr, addr); | ||
1142 | } | ||
1143 | |||
1144 | struct sysctl_args32 | ||
1145 | { | ||
1146 | compat_caddr_t name; | ||
1147 | int nlen; | ||
1148 | compat_caddr_t oldval; | ||
1149 | compat_caddr_t oldlenp; | ||
1150 | compat_caddr_t newval; | ||
1151 | compat_size_t newlen; | ||
1152 | unsigned int __unused[4]; | ||
1153 | }; | ||
1154 | |||
1155 | #ifdef CONFIG_SYSCTL | ||
1156 | |||
1157 | asmlinkage long sys32_sysctl(struct sysctl_args32 *args) | ||
1158 | { | ||
1159 | struct sysctl_args32 tmp; | ||
1160 | int error; | ||
1161 | size_t oldlen, *oldlenp = NULL; | ||
1162 | unsigned long addr = (((long)&args->__unused[0]) + 7) & ~7; | ||
1163 | |||
1164 | if (copy_from_user(&tmp, args, sizeof(tmp))) | ||
1165 | return -EFAULT; | ||
1166 | |||
1167 | if (tmp.oldval && tmp.oldlenp) { | ||
1168 | /* Duh, this is ugly and might not work if sysctl_args | ||
1169 | is in read-only memory, but do_sysctl does indirectly | ||
1170 | a lot of uaccess in both directions and we'd have to | ||
1171 | basically copy the whole sysctl.c here, and | ||
1172 | glibc's __sysctl uses rw memory for the structure | ||
1173 | anyway. */ | ||
1174 | if (get_user(oldlen, (u32 *)A(tmp.oldlenp)) || | ||
1175 | put_user(oldlen, (size_t *)addr)) | ||
1176 | return -EFAULT; | ||
1177 | oldlenp = (size_t *)addr; | ||
1178 | } | ||
1179 | |||
1180 | lock_kernel(); | ||
1181 | error = do_sysctl((int *)A(tmp.name), tmp.nlen, (void *)A(tmp.oldval), | ||
1182 | oldlenp, (void *)A(tmp.newval), tmp.newlen); | ||
1183 | unlock_kernel(); | ||
1184 | if (oldlenp) { | ||
1185 | if (!error) { | ||
1186 | if (get_user(oldlen, (size_t *)addr) || | ||
1187 | put_user(oldlen, (u32 *)A(tmp.oldlenp))) | ||
1188 | error = -EFAULT; | ||
1189 | } | ||
1190 | copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused)); | ||
1191 | } | ||
1192 | return error; | ||
1193 | } | ||
1194 | |||
1195 | #endif /* CONFIG_SYSCTL */ | ||
1196 | |||
1197 | asmlinkage long sys32_newuname(struct new_utsname * name) | ||
1198 | { | ||
1199 | int ret = 0; | ||
1200 | |||
1201 | down_read(&uts_sem); | ||
1202 | if (copy_to_user(name,&system_utsname,sizeof *name)) | ||
1203 | ret = -EFAULT; | ||
1204 | up_read(&uts_sem); | ||
1205 | |||
1206 | if (current->personality == PER_LINUX32 && !ret) | ||
1207 | if (copy_to_user(name->machine, "mips\0\0\0", 8)) | ||
1208 | ret = -EFAULT; | ||
1209 | |||
1210 | return ret; | ||
1211 | } | ||
1212 | |||
1213 | asmlinkage int sys32_personality(unsigned long personality) | ||
1214 | { | ||
1215 | int ret; | ||
1216 | if (current->personality == PER_LINUX32 && personality == PER_LINUX) | ||
1217 | personality = PER_LINUX32; | ||
1218 | ret = sys_personality(personality); | ||
1219 | if (ret == PER_LINUX32) | ||
1220 | ret = PER_LINUX; | ||
1221 | return ret; | ||
1222 | } | ||
1223 | |||
1224 | /* ustat compatibility */ | ||
1225 | struct ustat32 { | ||
1226 | compat_daddr_t f_tfree; | ||
1227 | compat_ino_t f_tinode; | ||
1228 | char f_fname[6]; | ||
1229 | char f_fpack[6]; | ||
1230 | }; | ||
1231 | |||
1232 | extern asmlinkage long sys_ustat(dev_t dev, struct ustat * ubuf); | ||
1233 | |||
1234 | asmlinkage int sys32_ustat(dev_t dev, struct ustat32 * ubuf32) | ||
1235 | { | ||
1236 | int err; | ||
1237 | struct ustat tmp; | ||
1238 | struct ustat32 tmp32; | ||
1239 | mm_segment_t old_fs = get_fs(); | ||
1240 | |||
1241 | set_fs(KERNEL_DS); | ||
1242 | err = sys_ustat(dev, &tmp); | ||
1243 | set_fs (old_fs); | ||
1244 | |||
1245 | if (err) | ||
1246 | goto out; | ||
1247 | |||
1248 | memset(&tmp32,0,sizeof(struct ustat32)); | ||
1249 | tmp32.f_tfree = tmp.f_tfree; | ||
1250 | tmp32.f_tinode = tmp.f_tinode; | ||
1251 | |||
1252 | err = copy_to_user(ubuf32,&tmp32,sizeof(struct ustat32)) ? -EFAULT : 0; | ||
1253 | |||
1254 | out: | ||
1255 | return err; | ||
1256 | } | ||
1257 | |||
1258 | /* Handle adjtimex compatibility. */ | ||
1259 | |||
1260 | struct timex32 { | ||
1261 | u32 modes; | ||
1262 | s32 offset, freq, maxerror, esterror; | ||
1263 | s32 status, constant, precision, tolerance; | ||
1264 | struct compat_timeval time; | ||
1265 | s32 tick; | ||
1266 | s32 ppsfreq, jitter, shift, stabil; | ||
1267 | s32 jitcnt, calcnt, errcnt, stbcnt; | ||
1268 | s32 :32; s32 :32; s32 :32; s32 :32; | ||
1269 | s32 :32; s32 :32; s32 :32; s32 :32; | ||
1270 | s32 :32; s32 :32; s32 :32; s32 :32; | ||
1271 | }; | ||
1272 | |||
1273 | extern int do_adjtimex(struct timex *); | ||
1274 | |||
1275 | asmlinkage int sys32_adjtimex(struct timex32 *utp) | ||
1276 | { | ||
1277 | struct timex txc; | ||
1278 | int ret; | ||
1279 | |||
1280 | memset(&txc, 0, sizeof(struct timex)); | ||
1281 | |||
1282 | if (get_user(txc.modes, &utp->modes) || | ||
1283 | __get_user(txc.offset, &utp->offset) || | ||
1284 | __get_user(txc.freq, &utp->freq) || | ||
1285 | __get_user(txc.maxerror, &utp->maxerror) || | ||
1286 | __get_user(txc.esterror, &utp->esterror) || | ||
1287 | __get_user(txc.status, &utp->status) || | ||
1288 | __get_user(txc.constant, &utp->constant) || | ||
1289 | __get_user(txc.precision, &utp->precision) || | ||
1290 | __get_user(txc.tolerance, &utp->tolerance) || | ||
1291 | __get_user(txc.time.tv_sec, &utp->time.tv_sec) || | ||
1292 | __get_user(txc.time.tv_usec, &utp->time.tv_usec) || | ||
1293 | __get_user(txc.tick, &utp->tick) || | ||
1294 | __get_user(txc.ppsfreq, &utp->ppsfreq) || | ||
1295 | __get_user(txc.jitter, &utp->jitter) || | ||
1296 | __get_user(txc.shift, &utp->shift) || | ||
1297 | __get_user(txc.stabil, &utp->stabil) || | ||
1298 | __get_user(txc.jitcnt, &utp->jitcnt) || | ||
1299 | __get_user(txc.calcnt, &utp->calcnt) || | ||
1300 | __get_user(txc.errcnt, &utp->errcnt) || | ||
1301 | __get_user(txc.stbcnt, &utp->stbcnt)) | ||
1302 | return -EFAULT; | ||
1303 | |||
1304 | ret = do_adjtimex(&txc); | ||
1305 | |||
1306 | if (put_user(txc.modes, &utp->modes) || | ||
1307 | __put_user(txc.offset, &utp->offset) || | ||
1308 | __put_user(txc.freq, &utp->freq) || | ||
1309 | __put_user(txc.maxerror, &utp->maxerror) || | ||
1310 | __put_user(txc.esterror, &utp->esterror) || | ||
1311 | __put_user(txc.status, &utp->status) || | ||
1312 | __put_user(txc.constant, &utp->constant) || | ||
1313 | __put_user(txc.precision, &utp->precision) || | ||
1314 | __put_user(txc.tolerance, &utp->tolerance) || | ||
1315 | __put_user(txc.time.tv_sec, &utp->time.tv_sec) || | ||
1316 | __put_user(txc.time.tv_usec, &utp->time.tv_usec) || | ||
1317 | __put_user(txc.tick, &utp->tick) || | ||
1318 | __put_user(txc.ppsfreq, &utp->ppsfreq) || | ||
1319 | __put_user(txc.jitter, &utp->jitter) || | ||
1320 | __put_user(txc.shift, &utp->shift) || | ||
1321 | __put_user(txc.stabil, &utp->stabil) || | ||
1322 | __put_user(txc.jitcnt, &utp->jitcnt) || | ||
1323 | __put_user(txc.calcnt, &utp->calcnt) || | ||
1324 | __put_user(txc.errcnt, &utp->errcnt) || | ||
1325 | __put_user(txc.stbcnt, &utp->stbcnt)) | ||
1326 | ret = -EFAULT; | ||
1327 | |||
1328 | return ret; | ||
1329 | } | ||
1330 | |||
1331 | asmlinkage int sys32_sendfile(int out_fd, int in_fd, compat_off_t *offset, | ||
1332 | s32 count) | ||
1333 | { | ||
1334 | mm_segment_t old_fs = get_fs(); | ||
1335 | int ret; | ||
1336 | off_t of; | ||
1337 | |||
1338 | if (offset && get_user(of, offset)) | ||
1339 | return -EFAULT; | ||
1340 | |||
1341 | set_fs(KERNEL_DS); | ||
1342 | ret = sys_sendfile(out_fd, in_fd, offset ? &of : NULL, count); | ||
1343 | set_fs(old_fs); | ||
1344 | |||
1345 | if (offset && put_user(of, offset)) | ||
1346 | return -EFAULT; | ||
1347 | |||
1348 | return ret; | ||
1349 | } | ||
1350 | |||
1351 | asmlinkage ssize_t sys32_readahead(int fd, u32 pad0, u64 a2, u64 a3, | ||
1352 | size_t count) | ||
1353 | { | ||
1354 | return sys_readahead(fd, merge_64(a2, a3), count); | ||
1355 | } | ||
1356 | |||
1357 | /* Argument list sizes for sys_socketcall */ | ||
1358 | #define AL(x) ((x) * sizeof(unsigned int)) | ||
1359 | static unsigned char socketcall_nargs[18]={AL(0),AL(3),AL(3),AL(3),AL(2),AL(3), | ||
1360 | AL(3),AL(3),AL(4),AL(4),AL(4),AL(6), | ||
1361 | AL(6),AL(2),AL(5),AL(5),AL(3),AL(3)}; | ||
1362 | #undef AL | ||
1363 | |||
1364 | /* | ||
1365 | * System call vectors. | ||
1366 | * | ||
1367 | * Argument checking cleaned up. Saved 20% in size. | ||
1368 | * This function doesn't need to set the kernel lock because | ||
1369 | * it is set by the callees. | ||
1370 | */ | ||
1371 | |||
1372 | asmlinkage long sys32_socketcall(int call, unsigned int *args32) | ||
1373 | { | ||
1374 | unsigned int a[6]; | ||
1375 | unsigned int a0,a1; | ||
1376 | int err; | ||
1377 | |||
1378 | extern asmlinkage long sys_socket(int family, int type, int protocol); | ||
1379 | extern asmlinkage long sys_bind(int fd, struct sockaddr __user *umyaddr, int addrlen); | ||
1380 | extern asmlinkage long sys_connect(int fd, struct sockaddr __user *uservaddr, int addrlen); | ||
1381 | extern asmlinkage long sys_listen(int fd, int backlog); | ||
1382 | extern asmlinkage long sys_accept(int fd, struct sockaddr __user *upeer_sockaddr, int __user *upeer_addrlen); | ||
1383 | extern asmlinkage long sys_getsockname(int fd, struct sockaddr __user *usockaddr, int __user *usockaddr_len); | ||
1384 | extern asmlinkage long sys_getpeername(int fd, struct sockaddr __user *usockaddr, int __user *usockaddr_len); | ||
1385 | extern asmlinkage long sys_socketpair(int family, int type, int protocol, int __user *usockvec); | ||
1386 | extern asmlinkage long sys_send(int fd, void __user * buff, size_t len, unsigned flags); | ||
1387 | extern asmlinkage long sys_sendto(int fd, void __user * buff, size_t len, unsigned flags, | ||
1388 | struct sockaddr __user *addr, int addr_len); | ||
1389 | extern asmlinkage long sys_recv(int fd, void __user * ubuf, size_t size, unsigned flags); | ||
1390 | extern asmlinkage long sys_recvfrom(int fd, void __user * ubuf, size_t size, unsigned flags, | ||
1391 | struct sockaddr __user *addr, int __user *addr_len); | ||
1392 | extern asmlinkage long sys_shutdown(int fd, int how); | ||
1393 | extern asmlinkage long sys_setsockopt(int fd, int level, int optname, char __user *optval, int optlen); | ||
1394 | extern asmlinkage long sys_getsockopt(int fd, int level, int optname, char __user *optval, int *optlen); | ||
1395 | extern asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags); | ||
1396 | extern asmlinkage long sys_recvmsg(int fd, struct msghdr __user *msg, unsigned int flags); | ||
1397 | |||
1398 | |||
1399 | if(call<1||call>SYS_RECVMSG) | ||
1400 | return -EINVAL; | ||
1401 | |||
1402 | /* copy_from_user should be SMP safe. */ | ||
1403 | if (copy_from_user(a, args32, socketcall_nargs[call])) | ||
1404 | return -EFAULT; | ||
1405 | |||
1406 | a0=a[0]; | ||
1407 | a1=a[1]; | ||
1408 | |||
1409 | switch(call) | ||
1410 | { | ||
1411 | case SYS_SOCKET: | ||
1412 | err = sys_socket(a0,a1,a[2]); | ||
1413 | break; | ||
1414 | case SYS_BIND: | ||
1415 | err = sys_bind(a0,(struct sockaddr __user *)A(a1), a[2]); | ||
1416 | break; | ||
1417 | case SYS_CONNECT: | ||
1418 | err = sys_connect(a0, (struct sockaddr __user *)A(a1), a[2]); | ||
1419 | break; | ||
1420 | case SYS_LISTEN: | ||
1421 | err = sys_listen(a0,a1); | ||
1422 | break; | ||
1423 | case SYS_ACCEPT: | ||
1424 | err = sys_accept(a0,(struct sockaddr __user *)A(a1), (int __user *)A(a[2])); | ||
1425 | break; | ||
1426 | case SYS_GETSOCKNAME: | ||
1427 | err = sys_getsockname(a0,(struct sockaddr __user *)A(a1), (int __user *)A(a[2])); | ||
1428 | break; | ||
1429 | case SYS_GETPEERNAME: | ||
1430 | err = sys_getpeername(a0, (struct sockaddr __user *)A(a1), (int __user *)A(a[2])); | ||
1431 | break; | ||
1432 | case SYS_SOCKETPAIR: | ||
1433 | err = sys_socketpair(a0,a1, a[2], (int __user *)A(a[3])); | ||
1434 | break; | ||
1435 | case SYS_SEND: | ||
1436 | err = sys_send(a0, (void __user *)A(a1), a[2], a[3]); | ||
1437 | break; | ||
1438 | case SYS_SENDTO: | ||
1439 | err = sys_sendto(a0,(void __user *)A(a1), a[2], a[3], | ||
1440 | (struct sockaddr __user *)A(a[4]), a[5]); | ||
1441 | break; | ||
1442 | case SYS_RECV: | ||
1443 | err = sys_recv(a0, (void __user *)A(a1), a[2], a[3]); | ||
1444 | break; | ||
1445 | case SYS_RECVFROM: | ||
1446 | err = sys_recvfrom(a0, (void __user *)A(a1), a[2], a[3], | ||
1447 | (struct sockaddr __user *)A(a[4]), (int __user *)A(a[5])); | ||
1448 | break; | ||
1449 | case SYS_SHUTDOWN: | ||
1450 | err = sys_shutdown(a0,a1); | ||
1451 | break; | ||
1452 | case SYS_SETSOCKOPT: | ||
1453 | err = sys_setsockopt(a0, a1, a[2], (char __user *)A(a[3]), a[4]); | ||
1454 | break; | ||
1455 | case SYS_GETSOCKOPT: | ||
1456 | err = sys_getsockopt(a0, a1, a[2], (char __user *)A(a[3]), (int __user *)A(a[4])); | ||
1457 | break; | ||
1458 | case SYS_SENDMSG: | ||
1459 | err = sys_sendmsg(a0, (struct msghdr __user *) A(a1), a[2]); | ||
1460 | break; | ||
1461 | case SYS_RECVMSG: | ||
1462 | err = sys_recvmsg(a0, (struct msghdr __user *) A(a1), a[2]); | ||
1463 | break; | ||
1464 | default: | ||
1465 | err = -EINVAL; | ||
1466 | break; | ||
1467 | } | ||
1468 | return err; | ||
1469 | } | ||