[S390] Get rid of a lot of sparse warnings.
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / s390 / kernel / compat_linux.c
blobcf84d697daedac35f03fd0c85f93d853f3daf4cc
1 /*
2 * arch/s390x/kernel/linux32.c
4 * S390 version
5 * Copyright (C) 2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
6 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
7 * Gerhard Tonn (ton@de.ibm.com)
8 * Thomas Spatzier (tspat@de.ibm.com)
10 * Conversion between 31bit and 64bit native syscalls.
12 * Heavily inspired by the 32-bit Sparc compat code which is
13 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
14 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
19 #include <linux/kernel.h>
20 #include <linux/sched.h>
21 #include <linux/fs.h>
22 #include <linux/mm.h>
23 #include <linux/file.h>
24 #include <linux/signal.h>
25 #include <linux/resource.h>
26 #include <linux/times.h>
27 #include <linux/utsname.h>
28 #include <linux/smp.h>
29 #include <linux/smp_lock.h>
30 #include <linux/sem.h>
31 #include <linux/msg.h>
32 #include <linux/shm.h>
33 #include <linux/slab.h>
34 #include <linux/uio.h>
35 #include <linux/nfs_fs.h>
36 #include <linux/quota.h>
37 #include <linux/module.h>
38 #include <linux/sunrpc/svc.h>
39 #include <linux/nfsd/nfsd.h>
40 #include <linux/nfsd/cache.h>
41 #include <linux/nfsd/xdr.h>
42 #include <linux/nfsd/syscall.h>
43 #include <linux/poll.h>
44 #include <linux/personality.h>
45 #include <linux/stat.h>
46 #include <linux/filter.h>
47 #include <linux/highmem.h>
48 #include <linux/highuid.h>
49 #include <linux/mman.h>
50 #include <linux/ipv6.h>
51 #include <linux/in.h>
52 #include <linux/icmpv6.h>
53 #include <linux/syscalls.h>
54 #include <linux/sysctl.h>
55 #include <linux/binfmts.h>
56 #include <linux/capability.h>
57 #include <linux/compat.h>
58 #include <linux/vfs.h>
59 #include <linux/ptrace.h>
60 #include <linux/fadvise.h>
62 #include <asm/types.h>
63 #include <asm/ipc.h>
64 #include <asm/uaccess.h>
65 #include <asm/semaphore.h>
67 #include <net/scm.h>
68 #include <net/sock.h>
70 #include "compat_linux.h"
73 /* For this source file, we want overflow handling. */
75 #undef high2lowuid
76 #undef high2lowgid
77 #undef low2highuid
78 #undef low2highgid
79 #undef SET_UID16
80 #undef SET_GID16
81 #undef NEW_TO_OLD_UID
82 #undef NEW_TO_OLD_GID
83 #undef SET_OLDSTAT_UID
84 #undef SET_OLDSTAT_GID
85 #undef SET_STAT_UID
86 #undef SET_STAT_GID
88 #define high2lowuid(uid) ((uid) > 65535) ? (u16)overflowuid : (u16)(uid)
89 #define high2lowgid(gid) ((gid) > 65535) ? (u16)overflowgid : (u16)(gid)
90 #define low2highuid(uid) ((uid) == (u16)-1) ? (uid_t)-1 : (uid_t)(uid)
91 #define low2highgid(gid) ((gid) == (u16)-1) ? (gid_t)-1 : (gid_t)(gid)
92 #define SET_UID16(var, uid) var = high2lowuid(uid)
93 #define SET_GID16(var, gid) var = high2lowgid(gid)
94 #define NEW_TO_OLD_UID(uid) high2lowuid(uid)
95 #define NEW_TO_OLD_GID(gid) high2lowgid(gid)
96 #define SET_OLDSTAT_UID(stat, uid) (stat).st_uid = high2lowuid(uid)
97 #define SET_OLDSTAT_GID(stat, gid) (stat).st_gid = high2lowgid(gid)
98 #define SET_STAT_UID(stat, uid) (stat).st_uid = high2lowuid(uid)
99 #define SET_STAT_GID(stat, gid) (stat).st_gid = high2lowgid(gid)
101 asmlinkage long sys32_chown16(const char __user * filename, u16 user, u16 group)
103 return sys_chown(filename, low2highuid(user), low2highgid(group));
106 asmlinkage long sys32_lchown16(const char __user * filename, u16 user, u16 group)
108 return sys_lchown(filename, low2highuid(user), low2highgid(group));
111 asmlinkage long sys32_fchown16(unsigned int fd, u16 user, u16 group)
113 return sys_fchown(fd, low2highuid(user), low2highgid(group));
116 asmlinkage long sys32_setregid16(u16 rgid, u16 egid)
118 return sys_setregid(low2highgid(rgid), low2highgid(egid));
121 asmlinkage long sys32_setgid16(u16 gid)
123 return sys_setgid((gid_t)gid);
126 asmlinkage long sys32_setreuid16(u16 ruid, u16 euid)
128 return sys_setreuid(low2highuid(ruid), low2highuid(euid));
131 asmlinkage long sys32_setuid16(u16 uid)
133 return sys_setuid((uid_t)uid);
136 asmlinkage long sys32_setresuid16(u16 ruid, u16 euid, u16 suid)
138 return sys_setresuid(low2highuid(ruid), low2highuid(euid),
139 low2highuid(suid));
142 asmlinkage long sys32_getresuid16(u16 __user *ruid, u16 __user *euid, u16 __user *suid)
144 int retval;
146 if (!(retval = put_user(high2lowuid(current->uid), ruid)) &&
147 !(retval = put_user(high2lowuid(current->euid), euid)))
148 retval = put_user(high2lowuid(current->suid), suid);
150 return retval;
153 asmlinkage long sys32_setresgid16(u16 rgid, u16 egid, u16 sgid)
155 return sys_setresgid(low2highgid(rgid), low2highgid(egid),
156 low2highgid(sgid));
159 asmlinkage long sys32_getresgid16(u16 __user *rgid, u16 __user *egid, u16 __user *sgid)
161 int retval;
163 if (!(retval = put_user(high2lowgid(current->gid), rgid)) &&
164 !(retval = put_user(high2lowgid(current->egid), egid)))
165 retval = put_user(high2lowgid(current->sgid), sgid);
167 return retval;
170 asmlinkage long sys32_setfsuid16(u16 uid)
172 return sys_setfsuid((uid_t)uid);
175 asmlinkage long sys32_setfsgid16(u16 gid)
177 return sys_setfsgid((gid_t)gid);
180 static int groups16_to_user(u16 __user *grouplist, struct group_info *group_info)
182 int i;
183 u16 group;
185 for (i = 0; i < group_info->ngroups; i++) {
186 group = (u16)GROUP_AT(group_info, i);
187 if (put_user(group, grouplist+i))
188 return -EFAULT;
191 return 0;
194 static int groups16_from_user(struct group_info *group_info, u16 __user *grouplist)
196 int i;
197 u16 group;
199 for (i = 0; i < group_info->ngroups; i++) {
200 if (get_user(group, grouplist+i))
201 return -EFAULT;
202 GROUP_AT(group_info, i) = (gid_t)group;
205 return 0;
208 asmlinkage long sys32_getgroups16(int gidsetsize, u16 __user *grouplist)
210 int i;
212 if (gidsetsize < 0)
213 return -EINVAL;
215 get_group_info(current->group_info);
216 i = current->group_info->ngroups;
217 if (gidsetsize) {
218 if (i > gidsetsize) {
219 i = -EINVAL;
220 goto out;
222 if (groups16_to_user(grouplist, current->group_info)) {
223 i = -EFAULT;
224 goto out;
227 out:
228 put_group_info(current->group_info);
229 return i;
232 asmlinkage long sys32_setgroups16(int gidsetsize, u16 __user *grouplist)
234 struct group_info *group_info;
235 int retval;
237 if (!capable(CAP_SETGID))
238 return -EPERM;
239 if ((unsigned)gidsetsize > NGROUPS_MAX)
240 return -EINVAL;
242 group_info = groups_alloc(gidsetsize);
243 if (!group_info)
244 return -ENOMEM;
245 retval = groups16_from_user(group_info, grouplist);
246 if (retval) {
247 put_group_info(group_info);
248 return retval;
251 retval = set_current_groups(group_info);
252 put_group_info(group_info);
254 return retval;
257 asmlinkage long sys32_getuid16(void)
259 return high2lowuid(current->uid);
262 asmlinkage long sys32_geteuid16(void)
264 return high2lowuid(current->euid);
267 asmlinkage long sys32_getgid16(void)
269 return high2lowgid(current->gid);
272 asmlinkage long sys32_getegid16(void)
274 return high2lowgid(current->egid);
277 /* 32-bit timeval and related flotsam. */
279 static inline long get_tv32(struct timeval *o, struct compat_timeval __user *i)
281 return (!access_ok(VERIFY_READ, o, sizeof(*o)) ||
282 (__get_user(o->tv_sec, &i->tv_sec) ||
283 __get_user(o->tv_usec, &i->tv_usec)));
286 static inline long put_tv32(struct compat_timeval __user *o, struct timeval *i)
288 return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
289 (__put_user(i->tv_sec, &o->tv_sec) ||
290 __put_user(i->tv_usec, &o->tv_usec)));
294 * sys32_ipc() is the de-multiplexer for the SysV IPC calls in 32bit emulation.
296 * This is really horribly ugly.
298 #ifdef CONFIG_SYSVIPC
299 asmlinkage long sys32_ipc(u32 call, int first, int second, int third, u32 ptr)
301 if (call >> 16) /* hack for backward compatibility */
302 return -EINVAL;
304 call &= 0xffff;
306 switch (call) {
307 case SEMTIMEDOP:
308 return compat_sys_semtimedop(first, compat_ptr(ptr),
309 second, compat_ptr(third));
310 case SEMOP:
311 /* struct sembuf is the same on 32 and 64bit :)) */
312 return sys_semtimedop(first, compat_ptr(ptr),
313 second, NULL);
314 case SEMGET:
315 return sys_semget(first, second, third);
316 case SEMCTL:
317 return compat_sys_semctl(first, second, third,
318 compat_ptr(ptr));
319 case MSGSND:
320 return compat_sys_msgsnd(first, second, third,
321 compat_ptr(ptr));
322 case MSGRCV:
323 return compat_sys_msgrcv(first, second, 0, third,
324 0, compat_ptr(ptr));
325 case MSGGET:
326 return sys_msgget((key_t) first, second);
327 case MSGCTL:
328 return compat_sys_msgctl(first, second, compat_ptr(ptr));
329 case SHMAT:
330 return compat_sys_shmat(first, second, third,
331 0, compat_ptr(ptr));
332 case SHMDT:
333 return sys_shmdt(compat_ptr(ptr));
334 case SHMGET:
335 return sys_shmget(first, (unsigned)second, third);
336 case SHMCTL:
337 return compat_sys_shmctl(first, second, compat_ptr(ptr));
340 return -ENOSYS;
342 #endif
344 asmlinkage long sys32_truncate64(const char __user * path, unsigned long high, unsigned long low)
346 if ((int)high < 0)
347 return -EINVAL;
348 else
349 return sys_truncate(path, (high << 32) | low);
352 asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long high, unsigned long low)
354 if ((int)high < 0)
355 return -EINVAL;
356 else
357 return sys_ftruncate(fd, (high << 32) | low);
360 int cp_compat_stat(struct kstat *stat, struct compat_stat __user *statbuf)
362 compat_ino_t ino;
363 int err;
365 if (!old_valid_dev(stat->dev) || !old_valid_dev(stat->rdev))
366 return -EOVERFLOW;
368 ino = stat->ino;
369 if (sizeof(ino) < sizeof(stat->ino) && ino != stat->ino)
370 return -EOVERFLOW;
372 err = put_user(old_encode_dev(stat->dev), &statbuf->st_dev);
373 err |= put_user(stat->ino, &statbuf->st_ino);
374 err |= put_user(stat->mode, &statbuf->st_mode);
375 err |= put_user(stat->nlink, &statbuf->st_nlink);
376 err |= put_user(high2lowuid(stat->uid), &statbuf->st_uid);
377 err |= put_user(high2lowgid(stat->gid), &statbuf->st_gid);
378 err |= put_user(old_encode_dev(stat->rdev), &statbuf->st_rdev);
379 err |= put_user(stat->size, &statbuf->st_size);
380 err |= put_user(stat->atime.tv_sec, &statbuf->st_atime);
381 err |= put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);
382 err |= put_user(stat->mtime.tv_sec, &statbuf->st_mtime);
383 err |= put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);
384 err |= put_user(stat->ctime.tv_sec, &statbuf->st_ctime);
385 err |= put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);
386 err |= put_user(stat->blksize, &statbuf->st_blksize);
387 err |= put_user(stat->blocks, &statbuf->st_blocks);
388 /* fixme
389 err |= put_user(0, &statbuf->__unused4[0]);
390 err |= put_user(0, &statbuf->__unused4[1]);
392 return err;
395 struct sysinfo32 {
396 s32 uptime;
397 u32 loads[3];
398 u32 totalram;
399 u32 freeram;
400 u32 sharedram;
401 u32 bufferram;
402 u32 totalswap;
403 u32 freeswap;
404 unsigned short procs;
405 unsigned short pads;
406 u32 totalhigh;
407 u32 freehigh;
408 unsigned int mem_unit;
409 char _f[8];
412 asmlinkage long sys32_sysinfo(struct sysinfo32 __user *info)
414 struct sysinfo s;
415 int ret, err;
416 mm_segment_t old_fs = get_fs ();
418 set_fs (KERNEL_DS);
419 ret = sys_sysinfo((struct sysinfo __force __user *) &s);
420 set_fs (old_fs);
421 err = put_user (s.uptime, &info->uptime);
422 err |= __put_user (s.loads[0], &info->loads[0]);
423 err |= __put_user (s.loads[1], &info->loads[1]);
424 err |= __put_user (s.loads[2], &info->loads[2]);
425 err |= __put_user (s.totalram, &info->totalram);
426 err |= __put_user (s.freeram, &info->freeram);
427 err |= __put_user (s.sharedram, &info->sharedram);
428 err |= __put_user (s.bufferram, &info->bufferram);
429 err |= __put_user (s.totalswap, &info->totalswap);
430 err |= __put_user (s.freeswap, &info->freeswap);
431 err |= __put_user (s.procs, &info->procs);
432 err |= __put_user (s.totalhigh, &info->totalhigh);
433 err |= __put_user (s.freehigh, &info->freehigh);
434 err |= __put_user (s.mem_unit, &info->mem_unit);
435 if (err)
436 return -EFAULT;
437 return ret;
440 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
441 struct compat_timespec __user *interval)
443 struct timespec t;
444 int ret;
445 mm_segment_t old_fs = get_fs ();
447 set_fs (KERNEL_DS);
448 ret = sys_sched_rr_get_interval(pid,
449 (struct timespec __force __user *) &t);
450 set_fs (old_fs);
451 if (put_compat_timespec(&t, interval))
452 return -EFAULT;
453 return ret;
456 asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
457 compat_sigset_t __user *oset, size_t sigsetsize)
459 sigset_t s;
460 compat_sigset_t s32;
461 int ret;
462 mm_segment_t old_fs = get_fs();
464 if (set) {
465 if (copy_from_user (&s32, set, sizeof(compat_sigset_t)))
466 return -EFAULT;
467 switch (_NSIG_WORDS) {
468 case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
469 case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
470 case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
471 case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
474 set_fs (KERNEL_DS);
475 ret = sys_rt_sigprocmask(how,
476 set ? (sigset_t __force __user *) &s : NULL,
477 oset ? (sigset_t __force __user *) &s : NULL,
478 sigsetsize);
479 set_fs (old_fs);
480 if (ret) return ret;
481 if (oset) {
482 switch (_NSIG_WORDS) {
483 case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
484 case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
485 case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
486 case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
488 if (copy_to_user (oset, &s32, sizeof(compat_sigset_t)))
489 return -EFAULT;
491 return 0;
494 asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
495 size_t sigsetsize)
497 sigset_t s;
498 compat_sigset_t s32;
499 int ret;
500 mm_segment_t old_fs = get_fs();
502 set_fs (KERNEL_DS);
503 ret = sys_rt_sigpending((sigset_t __force __user *) &s, sigsetsize);
504 set_fs (old_fs);
505 if (!ret) {
506 switch (_NSIG_WORDS) {
507 case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
508 case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
509 case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
510 case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
512 if (copy_to_user (set, &s32, sizeof(compat_sigset_t)))
513 return -EFAULT;
515 return ret;
518 asmlinkage long
519 sys32_rt_sigqueueinfo(int pid, int sig, compat_siginfo_t __user *uinfo)
521 siginfo_t info;
522 int ret;
523 mm_segment_t old_fs = get_fs();
525 if (copy_siginfo_from_user32(&info, uinfo))
526 return -EFAULT;
527 set_fs (KERNEL_DS);
528 ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force __user *) &info);
529 set_fs (old_fs);
530 return ret;
534 * sys32_execve() executes a new program after the asm stub has set
535 * things up for us. This should basically do what I want it to.
537 asmlinkage long
538 sys32_execve(struct pt_regs regs)
540 int error;
541 char * filename;
543 filename = getname(compat_ptr(regs.orig_gpr2));
544 error = PTR_ERR(filename);
545 if (IS_ERR(filename))
546 goto out;
547 error = compat_do_execve(filename, compat_ptr(regs.gprs[3]),
548 compat_ptr(regs.gprs[4]), &regs);
549 if (error == 0)
551 task_lock(current);
552 current->ptrace &= ~PT_DTRACE;
553 task_unlock(current);
554 current->thread.fp_regs.fpc=0;
555 asm volatile("sfpc %0,0" : : "d" (0));
557 putname(filename);
558 out:
559 return error;
563 #ifdef CONFIG_MODULES
565 asmlinkage long
566 sys32_init_module(void __user *umod, unsigned long len,
567 const char __user *uargs)
569 return sys_init_module(umod, len, uargs);
572 asmlinkage long
573 sys32_delete_module(const char __user *name_user, unsigned int flags)
575 return sys_delete_module(name_user, flags);
578 #else /* CONFIG_MODULES */
580 asmlinkage long
581 sys32_init_module(void __user *umod, unsigned long len,
582 const char __user *uargs)
584 return -ENOSYS;
587 asmlinkage long
588 sys32_delete_module(const char __user *name_user, unsigned int flags)
590 return -ENOSYS;
593 #endif /* CONFIG_MODULES */
595 /* Translations due to time_t size differences. Which affects all
596 sorts of things, like timeval and itimerval. */
598 extern struct timezone sys_tz;
600 asmlinkage long sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
602 if (tv) {
603 struct timeval ktv;
604 do_gettimeofday(&ktv);
605 if (put_tv32(tv, &ktv))
606 return -EFAULT;
608 if (tz) {
609 if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
610 return -EFAULT;
612 return 0;
615 static inline long get_ts32(struct timespec *o, struct compat_timeval __user *i)
617 long usec;
619 if (!access_ok(VERIFY_READ, i, sizeof(*i)))
620 return -EFAULT;
621 if (__get_user(o->tv_sec, &i->tv_sec))
622 return -EFAULT;
623 if (__get_user(usec, &i->tv_usec))
624 return -EFAULT;
625 o->tv_nsec = usec * 1000;
626 return 0;
629 asmlinkage long sys32_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
631 struct timespec kts;
632 struct timezone ktz;
634 if (tv) {
635 if (get_ts32(&kts, tv))
636 return -EFAULT;
638 if (tz) {
639 if (copy_from_user(&ktz, tz, sizeof(ktz)))
640 return -EFAULT;
643 return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
646 /* These are here just in case some old sparc32 binary calls it. */
647 asmlinkage long sys32_pause(void)
649 current->state = TASK_INTERRUPTIBLE;
650 schedule();
651 return -ERESTARTNOHAND;
654 asmlinkage long sys32_pread64(unsigned int fd, char __user *ubuf,
655 size_t count, u32 poshi, u32 poslo)
657 if ((compat_ssize_t) count < 0)
658 return -EINVAL;
659 return sys_pread64(fd, ubuf, count, ((loff_t)AA(poshi) << 32) | AA(poslo));
662 asmlinkage long sys32_pwrite64(unsigned int fd, const char __user *ubuf,
663 size_t count, u32 poshi, u32 poslo)
665 if ((compat_ssize_t) count < 0)
666 return -EINVAL;
667 return sys_pwrite64(fd, ubuf, count, ((loff_t)AA(poshi) << 32) | AA(poslo));
670 asmlinkage compat_ssize_t sys32_readahead(int fd, u32 offhi, u32 offlo, s32 count)
672 return sys_readahead(fd, ((loff_t)AA(offhi) << 32) | AA(offlo), count);
675 asmlinkage long sys32_sendfile(int out_fd, int in_fd, compat_off_t __user *offset, size_t count)
677 mm_segment_t old_fs = get_fs();
678 int ret;
679 off_t of;
681 if (offset && get_user(of, offset))
682 return -EFAULT;
684 set_fs(KERNEL_DS);
685 ret = sys_sendfile(out_fd, in_fd,
686 offset ? (off_t __force __user *) &of : NULL, count);
687 set_fs(old_fs);
689 if (offset && put_user(of, offset))
690 return -EFAULT;
692 return ret;
695 asmlinkage long sys32_sendfile64(int out_fd, int in_fd,
696 compat_loff_t __user *offset, s32 count)
698 mm_segment_t old_fs = get_fs();
699 int ret;
700 loff_t lof;
702 if (offset && get_user(lof, offset))
703 return -EFAULT;
705 set_fs(KERNEL_DS);
706 ret = sys_sendfile64(out_fd, in_fd,
707 offset ? (loff_t __force __user *) &lof : NULL,
708 count);
709 set_fs(old_fs);
711 if (offset && put_user(lof, offset))
712 return -EFAULT;
714 return ret;
717 #ifdef CONFIG_SYSCTL_SYSCALL
718 struct __sysctl_args32 {
719 u32 name;
720 int nlen;
721 u32 oldval;
722 u32 oldlenp;
723 u32 newval;
724 u32 newlen;
725 u32 __unused[4];
728 asmlinkage long sys32_sysctl(struct __sysctl_args32 __user *args)
730 struct __sysctl_args32 tmp;
731 int error;
732 size_t oldlen;
733 size_t __user *oldlenp = NULL;
734 unsigned long addr = (((unsigned long)&args->__unused[0]) + 7) & ~7;
736 if (copy_from_user(&tmp, args, sizeof(tmp)))
737 return -EFAULT;
739 if (tmp.oldval && tmp.oldlenp) {
740 /* Duh, this is ugly and might not work if sysctl_args
741 is in read-only memory, but do_sysctl does indirectly
742 a lot of uaccess in both directions and we'd have to
743 basically copy the whole sysctl.c here, and
744 glibc's __sysctl uses rw memory for the structure
745 anyway. */
746 if (get_user(oldlen, (u32 __user *)compat_ptr(tmp.oldlenp)) ||
747 put_user(oldlen, (size_t __user *)addr))
748 return -EFAULT;
749 oldlenp = (size_t __user *)addr;
752 lock_kernel();
753 error = do_sysctl(compat_ptr(tmp.name), tmp.nlen, compat_ptr(tmp.oldval),
754 oldlenp, compat_ptr(tmp.newval), tmp.newlen);
755 unlock_kernel();
756 if (oldlenp) {
757 if (!error) {
758 if (get_user(oldlen, (size_t __user *)addr) ||
759 put_user(oldlen, (u32 __user *)compat_ptr(tmp.oldlenp)))
760 error = -EFAULT;
762 if (copy_to_user(args->__unused, tmp.__unused,
763 sizeof(tmp.__unused)))
764 error = -EFAULT;
766 return error;
768 #endif
770 struct stat64_emu31 {
771 unsigned long long st_dev;
772 unsigned int __pad1;
773 #define STAT64_HAS_BROKEN_ST_INO 1
774 u32 __st_ino;
775 unsigned int st_mode;
776 unsigned int st_nlink;
777 u32 st_uid;
778 u32 st_gid;
779 unsigned long long st_rdev;
780 unsigned int __pad3;
781 long st_size;
782 u32 st_blksize;
783 unsigned char __pad4[4];
784 u32 __pad5; /* future possible st_blocks high bits */
785 u32 st_blocks; /* Number 512-byte blocks allocated. */
786 u32 st_atime;
787 u32 __pad6;
788 u32 st_mtime;
789 u32 __pad7;
790 u32 st_ctime;
791 u32 __pad8; /* will be high 32 bits of ctime someday */
792 unsigned long st_ino;
795 static int cp_stat64(struct stat64_emu31 __user *ubuf, struct kstat *stat)
797 struct stat64_emu31 tmp;
799 memset(&tmp, 0, sizeof(tmp));
801 tmp.st_dev = huge_encode_dev(stat->dev);
802 tmp.st_ino = stat->ino;
803 tmp.__st_ino = (u32)stat->ino;
804 tmp.st_mode = stat->mode;
805 tmp.st_nlink = (unsigned int)stat->nlink;
806 tmp.st_uid = stat->uid;
807 tmp.st_gid = stat->gid;
808 tmp.st_rdev = huge_encode_dev(stat->rdev);
809 tmp.st_size = stat->size;
810 tmp.st_blksize = (u32)stat->blksize;
811 tmp.st_blocks = (u32)stat->blocks;
812 tmp.st_atime = (u32)stat->atime.tv_sec;
813 tmp.st_mtime = (u32)stat->mtime.tv_sec;
814 tmp.st_ctime = (u32)stat->ctime.tv_sec;
816 return copy_to_user(ubuf,&tmp,sizeof(tmp)) ? -EFAULT : 0;
819 asmlinkage long sys32_stat64(char __user * filename, struct stat64_emu31 __user * statbuf)
821 struct kstat stat;
822 int ret = vfs_stat(filename, &stat);
823 if (!ret)
824 ret = cp_stat64(statbuf, &stat);
825 return ret;
828 asmlinkage long sys32_lstat64(char __user * filename, struct stat64_emu31 __user * statbuf)
830 struct kstat stat;
831 int ret = vfs_lstat(filename, &stat);
832 if (!ret)
833 ret = cp_stat64(statbuf, &stat);
834 return ret;
837 asmlinkage long sys32_fstat64(unsigned long fd, struct stat64_emu31 __user * statbuf)
839 struct kstat stat;
840 int ret = vfs_fstat(fd, &stat);
841 if (!ret)
842 ret = cp_stat64(statbuf, &stat);
843 return ret;
846 asmlinkage long sys32_fstatat64(unsigned int dfd, char __user *filename,
847 struct stat64_emu31 __user* statbuf, int flag)
849 struct kstat stat;
850 int error = -EINVAL;
852 if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
853 goto out;
855 if (flag & AT_SYMLINK_NOFOLLOW)
856 error = vfs_lstat_fd(dfd, filename, &stat);
857 else
858 error = vfs_stat_fd(dfd, filename, &stat);
860 if (!error)
861 error = cp_stat64(statbuf, &stat);
862 out:
863 return error;
867 * Linux/i386 didn't use to be able to handle more than
868 * 4 system call parameters, so these system calls used a memory
869 * block for parameter passing..
872 struct mmap_arg_struct_emu31 {
873 u32 addr;
874 u32 len;
875 u32 prot;
876 u32 flags;
877 u32 fd;
878 u32 offset;
881 /* common code for old and new mmaps */
882 static inline long do_mmap2(
883 unsigned long addr, unsigned long len,
884 unsigned long prot, unsigned long flags,
885 unsigned long fd, unsigned long pgoff)
887 struct file * file = NULL;
888 unsigned long error = -EBADF;
890 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
891 if (!(flags & MAP_ANONYMOUS)) {
892 file = fget(fd);
893 if (!file)
894 goto out;
897 down_write(&current->mm->mmap_sem);
898 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
899 if (!IS_ERR((void *) error) && error + len >= 0x80000000ULL) {
900 /* Result is out of bounds. */
901 do_munmap(current->mm, addr, len);
902 error = -ENOMEM;
904 up_write(&current->mm->mmap_sem);
906 if (file)
907 fput(file);
908 out:
909 return error;
913 asmlinkage unsigned long
914 old32_mmap(struct mmap_arg_struct_emu31 __user *arg)
916 struct mmap_arg_struct_emu31 a;
917 int error = -EFAULT;
919 if (copy_from_user(&a, arg, sizeof(a)))
920 goto out;
922 error = -EINVAL;
923 if (a.offset & ~PAGE_MASK)
924 goto out;
926 error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
927 out:
928 return error;
931 asmlinkage long
932 sys32_mmap2(struct mmap_arg_struct_emu31 __user *arg)
934 struct mmap_arg_struct_emu31 a;
935 int error = -EFAULT;
937 if (copy_from_user(&a, arg, sizeof(a)))
938 goto out;
939 error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset);
940 out:
941 return error;
944 asmlinkage long sys32_read(unsigned int fd, char __user * buf, size_t count)
946 if ((compat_ssize_t) count < 0)
947 return -EINVAL;
949 return sys_read(fd, buf, count);
952 asmlinkage long sys32_write(unsigned int fd, char __user * buf, size_t count)
954 if ((compat_ssize_t) count < 0)
955 return -EINVAL;
957 return sys_write(fd, buf, count);
960 asmlinkage long sys32_clone(struct pt_regs regs)
962 unsigned long clone_flags;
963 unsigned long newsp;
964 int __user *parent_tidptr, *child_tidptr;
966 clone_flags = regs.gprs[3] & 0xffffffffUL;
967 newsp = regs.orig_gpr2 & 0x7fffffffUL;
968 parent_tidptr = compat_ptr(regs.gprs[4]);
969 child_tidptr = compat_ptr(regs.gprs[5]);
970 if (!newsp)
971 newsp = regs.gprs[15];
972 return do_fork(clone_flags, newsp, &regs, 0,
973 parent_tidptr, child_tidptr);
977 * 31 bit emulation wrapper functions for sys_fadvise64/fadvise64_64.
978 * These need to rewrite the advise values for POSIX_FADV_{DONTNEED,NOREUSE}
979 * because the 31 bit values differ from the 64 bit values.
982 asmlinkage long
983 sys32_fadvise64(int fd, loff_t offset, size_t len, int advise)
985 if (advise == 4)
986 advise = POSIX_FADV_DONTNEED;
987 else if (advise == 5)
988 advise = POSIX_FADV_NOREUSE;
989 return sys_fadvise64(fd, offset, len, advise);
992 struct fadvise64_64_args {
993 int fd;
994 long long offset;
995 long long len;
996 int advice;
999 asmlinkage long
1000 sys32_fadvise64_64(struct fadvise64_64_args __user *args)
1002 struct fadvise64_64_args a;
1004 if ( copy_from_user(&a, args, sizeof(a)) )
1005 return -EFAULT;
1006 if (a.advice == 4)
1007 a.advice = POSIX_FADV_DONTNEED;
1008 else if (a.advice == 5)
1009 a.advice = POSIX_FADV_NOREUSE;
1010 return sys_fadvise64_64(a.fd, a.offset, a.len, a.advice);