[PATCH] Fix most sparse warnings in sys_ia32.c
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / x86_64 / ia32 / sys_ia32.c
blob33cd0a4fe388f591ee26428b20a79aa9035bfdef
1 /*
2 * sys_ia32.c: Conversion between 32bit and 64bit native syscalls. Based on
3 * sys_sparc32
5 * Copyright (C) 2000 VA Linux Co
6 * Copyright (C) 2000 Don Dugger <n0ano@valinux.com>
7 * Copyright (C) 1999 Arun Sharma <arun.sharma@intel.com>
8 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
9 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
10 * Copyright (C) 2000 Hewlett-Packard Co.
11 * Copyright (C) 2000 David Mosberger-Tang <davidm@hpl.hp.com>
12 * Copyright (C) 2000,2001,2002 Andi Kleen, SuSE Labs (x86-64 port)
14 * These routines maintain argument size conversion between 32bit and 64bit
15 * environment. In 2.5 most of this should be moved to a generic directory.
17 * This file assumes that there is a hole at the end of user address space.
19 * Some of the functions are LE specific currently. These are hopefully all marked.
20 * This should be fixed.
23 #include <linux/kernel.h>
24 #include <linux/sched.h>
25 #include <linux/fs.h>
26 #include <linux/file.h>
27 #include <linux/signal.h>
28 #include <linux/syscalls.h>
29 #include <linux/resource.h>
30 #include <linux/times.h>
31 #include <linux/utsname.h>
32 #include <linux/smp.h>
33 #include <linux/smp_lock.h>
34 #include <linux/sem.h>
35 #include <linux/msg.h>
36 #include <linux/mm.h>
37 #include <linux/shm.h>
38 #include <linux/slab.h>
39 #include <linux/uio.h>
40 #include <linux/nfs_fs.h>
41 #include <linux/quota.h>
42 #include <linux/module.h>
43 #include <linux/sunrpc/svc.h>
44 #include <linux/nfsd/nfsd.h>
45 #include <linux/nfsd/cache.h>
46 #include <linux/nfsd/xdr.h>
47 #include <linux/nfsd/syscall.h>
48 #include <linux/poll.h>
49 #include <linux/personality.h>
50 #include <linux/stat.h>
51 #include <linux/ipc.h>
52 #include <linux/rwsem.h>
53 #include <linux/binfmts.h>
54 #include <linux/init.h>
55 #include <linux/aio_abi.h>
56 #include <linux/aio.h>
57 #include <linux/compat.h>
58 #include <linux/vfs.h>
59 #include <linux/ptrace.h>
60 #include <linux/highuid.h>
61 #include <linux/vmalloc.h>
62 #include <linux/fsnotify.h>
63 #include <linux/sysctl.h>
64 #include <asm/mman.h>
65 #include <asm/types.h>
66 #include <asm/uaccess.h>
67 #include <asm/semaphore.h>
68 #include <asm/atomic.h>
69 #include <asm/ldt.h>
71 #include <net/scm.h>
72 #include <net/sock.h>
73 #include <asm/ia32.h>
75 #define AA(__x) ((unsigned long)(__x))
77 int cp_compat_stat(struct kstat *kbuf, struct compat_stat __user *ubuf)
79 typeof(ubuf->st_uid) uid = 0;
80 typeof(ubuf->st_gid) gid = 0;
81 SET_UID(uid, kbuf->uid);
82 SET_GID(gid, kbuf->gid);
83 if (!old_valid_dev(kbuf->dev) || !old_valid_dev(kbuf->rdev))
84 return -EOVERFLOW;
85 if (kbuf->size >= 0x7fffffff)
86 return -EOVERFLOW;
87 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct compat_stat)) ||
88 __put_user (old_encode_dev(kbuf->dev), &ubuf->st_dev) ||
89 __put_user (kbuf->ino, &ubuf->st_ino) ||
90 __put_user (kbuf->mode, &ubuf->st_mode) ||
91 __put_user (kbuf->nlink, &ubuf->st_nlink) ||
92 __put_user (uid, &ubuf->st_uid) ||
93 __put_user (gid, &ubuf->st_gid) ||
94 __put_user (old_encode_dev(kbuf->rdev), &ubuf->st_rdev) ||
95 __put_user (kbuf->size, &ubuf->st_size) ||
96 __put_user (kbuf->atime.tv_sec, &ubuf->st_atime) ||
97 __put_user (kbuf->atime.tv_nsec, &ubuf->st_atime_nsec) ||
98 __put_user (kbuf->mtime.tv_sec, &ubuf->st_mtime) ||
99 __put_user (kbuf->mtime.tv_nsec, &ubuf->st_mtime_nsec) ||
100 __put_user (kbuf->ctime.tv_sec, &ubuf->st_ctime) ||
101 __put_user (kbuf->ctime.tv_nsec, &ubuf->st_ctime_nsec) ||
102 __put_user (kbuf->blksize, &ubuf->st_blksize) ||
103 __put_user (kbuf->blocks, &ubuf->st_blocks))
104 return -EFAULT;
105 return 0;
108 asmlinkage long
109 sys32_truncate64(char __user * filename, unsigned long offset_low, unsigned long offset_high)
111 return sys_truncate(filename, ((loff_t) offset_high << 32) | offset_low);
114 asmlinkage long
115 sys32_ftruncate64(unsigned int fd, unsigned long offset_low, unsigned long offset_high)
117 return sys_ftruncate(fd, ((loff_t) offset_high << 32) | offset_low);
120 /* Another set for IA32/LFS -- x86_64 struct stat is different due to
121 support for 64bit inode numbers. */
123 static int
124 cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
126 typeof(ubuf->st_uid) uid = 0;
127 typeof(ubuf->st_gid) gid = 0;
128 SET_UID(uid, stat->uid);
129 SET_GID(gid, stat->gid);
130 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
131 __put_user(huge_encode_dev(stat->dev), &ubuf->st_dev) ||
132 __put_user (stat->ino, &ubuf->__st_ino) ||
133 __put_user (stat->ino, &ubuf->st_ino) ||
134 __put_user (stat->mode, &ubuf->st_mode) ||
135 __put_user (stat->nlink, &ubuf->st_nlink) ||
136 __put_user (uid, &ubuf->st_uid) ||
137 __put_user (gid, &ubuf->st_gid) ||
138 __put_user (huge_encode_dev(stat->rdev), &ubuf->st_rdev) ||
139 __put_user (stat->size, &ubuf->st_size) ||
140 __put_user (stat->atime.tv_sec, &ubuf->st_atime) ||
141 __put_user (stat->atime.tv_nsec, &ubuf->st_atime_nsec) ||
142 __put_user (stat->mtime.tv_sec, &ubuf->st_mtime) ||
143 __put_user (stat->mtime.tv_nsec, &ubuf->st_mtime_nsec) ||
144 __put_user (stat->ctime.tv_sec, &ubuf->st_ctime) ||
145 __put_user (stat->ctime.tv_nsec, &ubuf->st_ctime_nsec) ||
146 __put_user (stat->blksize, &ubuf->st_blksize) ||
147 __put_user (stat->blocks, &ubuf->st_blocks))
148 return -EFAULT;
149 return 0;
152 asmlinkage long
153 sys32_stat64(char __user * filename, struct stat64 __user *statbuf)
155 struct kstat stat;
156 int ret = vfs_stat(filename, &stat);
157 if (!ret)
158 ret = cp_stat64(statbuf, &stat);
159 return ret;
162 asmlinkage long
163 sys32_lstat64(char __user * filename, struct stat64 __user *statbuf)
165 struct kstat stat;
166 int ret = vfs_lstat(filename, &stat);
167 if (!ret)
168 ret = cp_stat64(statbuf, &stat);
169 return ret;
172 asmlinkage long
173 sys32_fstat64(unsigned int fd, struct stat64 __user *statbuf)
175 struct kstat stat;
176 int ret = vfs_fstat(fd, &stat);
177 if (!ret)
178 ret = cp_stat64(statbuf, &stat);
179 return ret;
182 asmlinkage long
183 sys32_fstatat(unsigned int dfd, char __user *filename,
184 struct stat64 __user* statbuf, int flag)
186 struct kstat stat;
187 int error = -EINVAL;
189 if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
190 goto out;
192 if (flag & AT_SYMLINK_NOFOLLOW)
193 error = vfs_lstat_fd(dfd, filename, &stat);
194 else
195 error = vfs_stat_fd(dfd, filename, &stat);
197 if (!error)
198 error = cp_stat64(statbuf, &stat);
200 out:
201 return error;
205 * Linux/i386 didn't use to be able to handle more than
206 * 4 system call parameters, so these system calls used a memory
207 * block for parameter passing..
210 struct mmap_arg_struct {
211 unsigned int addr;
212 unsigned int len;
213 unsigned int prot;
214 unsigned int flags;
215 unsigned int fd;
216 unsigned int offset;
219 asmlinkage long
220 sys32_mmap(struct mmap_arg_struct __user *arg)
222 struct mmap_arg_struct a;
223 struct file *file = NULL;
224 unsigned long retval;
225 struct mm_struct *mm ;
227 if (copy_from_user(&a, arg, sizeof(a)))
228 return -EFAULT;
230 if (a.offset & ~PAGE_MASK)
231 return -EINVAL;
233 if (!(a.flags & MAP_ANONYMOUS)) {
234 file = fget(a.fd);
235 if (!file)
236 return -EBADF;
239 mm = current->mm;
240 down_write(&mm->mmap_sem);
241 retval = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags, a.offset>>PAGE_SHIFT);
242 if (file)
243 fput(file);
245 up_write(&mm->mmap_sem);
247 return retval;
250 asmlinkage long
251 sys32_mprotect(unsigned long start, size_t len, unsigned long prot)
253 return sys_mprotect(start,len,prot);
256 asmlinkage long
257 sys32_pipe(int __user *fd)
259 int retval;
260 int fds[2];
262 retval = do_pipe(fds);
263 if (retval)
264 goto out;
265 if (copy_to_user(fd, fds, sizeof(fds)))
266 retval = -EFAULT;
267 out:
268 return retval;
271 asmlinkage long
272 sys32_rt_sigaction(int sig, struct sigaction32 __user *act,
273 struct sigaction32 __user *oact, unsigned int sigsetsize)
275 struct k_sigaction new_ka, old_ka;
276 int ret;
277 compat_sigset_t set32;
279 /* XXX: Don't preclude handling different sized sigset_t's. */
280 if (sigsetsize != sizeof(compat_sigset_t))
281 return -EINVAL;
283 if (act) {
284 compat_uptr_t handler, restorer;
286 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
287 __get_user(handler, &act->sa_handler) ||
288 __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
289 __get_user(restorer, &act->sa_restorer)||
290 __copy_from_user(&set32, &act->sa_mask, sizeof(compat_sigset_t)))
291 return -EFAULT;
292 new_ka.sa.sa_handler = compat_ptr(handler);
293 new_ka.sa.sa_restorer = compat_ptr(restorer);
294 /* FIXME: here we rely on _COMPAT_NSIG_WORS to be >= than _NSIG_WORDS << 1 */
295 switch (_NSIG_WORDS) {
296 case 4: new_ka.sa.sa_mask.sig[3] = set32.sig[6]
297 | (((long)set32.sig[7]) << 32);
298 case 3: new_ka.sa.sa_mask.sig[2] = set32.sig[4]
299 | (((long)set32.sig[5]) << 32);
300 case 2: new_ka.sa.sa_mask.sig[1] = set32.sig[2]
301 | (((long)set32.sig[3]) << 32);
302 case 1: new_ka.sa.sa_mask.sig[0] = set32.sig[0]
303 | (((long)set32.sig[1]) << 32);
307 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
309 if (!ret && oact) {
310 /* FIXME: here we rely on _COMPAT_NSIG_WORS to be >= than _NSIG_WORDS << 1 */
311 switch (_NSIG_WORDS) {
312 case 4:
313 set32.sig[7] = (old_ka.sa.sa_mask.sig[3] >> 32);
314 set32.sig[6] = old_ka.sa.sa_mask.sig[3];
315 case 3:
316 set32.sig[5] = (old_ka.sa.sa_mask.sig[2] >> 32);
317 set32.sig[4] = old_ka.sa.sa_mask.sig[2];
318 case 2:
319 set32.sig[3] = (old_ka.sa.sa_mask.sig[1] >> 32);
320 set32.sig[2] = old_ka.sa.sa_mask.sig[1];
321 case 1:
322 set32.sig[1] = (old_ka.sa.sa_mask.sig[0] >> 32);
323 set32.sig[0] = old_ka.sa.sa_mask.sig[0];
325 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
326 __put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler) ||
327 __put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer) ||
328 __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
329 __copy_to_user(&oact->sa_mask, &set32, sizeof(compat_sigset_t)))
330 return -EFAULT;
333 return ret;
336 asmlinkage long
337 sys32_sigaction (int sig, struct old_sigaction32 __user *act, struct old_sigaction32 __user *oact)
339 struct k_sigaction new_ka, old_ka;
340 int ret;
342 if (act) {
343 compat_old_sigset_t mask;
344 compat_uptr_t handler, restorer;
346 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
347 __get_user(handler, &act->sa_handler) ||
348 __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
349 __get_user(restorer, &act->sa_restorer) ||
350 __get_user(mask, &act->sa_mask))
351 return -EFAULT;
353 new_ka.sa.sa_handler = compat_ptr(handler);
354 new_ka.sa.sa_restorer = compat_ptr(restorer);
356 siginitset(&new_ka.sa.sa_mask, mask);
359 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
361 if (!ret && oact) {
362 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
363 __put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler) ||
364 __put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer) ||
365 __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
366 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
367 return -EFAULT;
370 return ret;
373 asmlinkage long
374 sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
375 compat_sigset_t __user *oset, unsigned int sigsetsize)
377 sigset_t s;
378 compat_sigset_t s32;
379 int ret;
380 mm_segment_t old_fs = get_fs();
382 if (set) {
383 if (copy_from_user (&s32, set, sizeof(compat_sigset_t)))
384 return -EFAULT;
385 switch (_NSIG_WORDS) {
386 case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
387 case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
388 case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
389 case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
392 set_fs (KERNEL_DS);
393 ret = sys_rt_sigprocmask(how,
394 set ? (sigset_t __user *)&s : NULL,
395 oset ? (sigset_t __user *)&s : NULL,
396 sigsetsize);
397 set_fs (old_fs);
398 if (ret) return ret;
399 if (oset) {
400 switch (_NSIG_WORDS) {
401 case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
402 case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
403 case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
404 case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
406 if (copy_to_user (oset, &s32, sizeof(compat_sigset_t)))
407 return -EFAULT;
409 return 0;
412 static inline long
413 get_tv32(struct timeval *o, struct compat_timeval __user *i)
415 int err = -EFAULT;
416 if (access_ok(VERIFY_READ, i, sizeof(*i))) {
417 err = __get_user(o->tv_sec, &i->tv_sec);
418 err |= __get_user(o->tv_usec, &i->tv_usec);
420 return err;
423 static inline long
424 put_tv32(struct compat_timeval __user *o, struct timeval *i)
426 int err = -EFAULT;
427 if (access_ok(VERIFY_WRITE, o, sizeof(*o))) {
428 err = __put_user(i->tv_sec, &o->tv_sec);
429 err |= __put_user(i->tv_usec, &o->tv_usec);
431 return err;
434 extern unsigned int alarm_setitimer(unsigned int seconds);
436 asmlinkage long
437 sys32_alarm(unsigned int seconds)
439 return alarm_setitimer(seconds);
442 /* Translations due to time_t size differences. Which affects all
443 sorts of things, like timeval and itimerval. */
445 extern struct timezone sys_tz;
447 asmlinkage long
448 sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
450 if (tv) {
451 struct timeval ktv;
452 do_gettimeofday(&ktv);
453 if (put_tv32(tv, &ktv))
454 return -EFAULT;
456 if (tz) {
457 if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
458 return -EFAULT;
460 return 0;
463 asmlinkage long
464 sys32_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
466 struct timeval ktv;
467 struct timespec kts;
468 struct timezone ktz;
470 if (tv) {
471 if (get_tv32(&ktv, tv))
472 return -EFAULT;
473 kts.tv_sec = ktv.tv_sec;
474 kts.tv_nsec = ktv.tv_usec * NSEC_PER_USEC;
476 if (tz) {
477 if (copy_from_user(&ktz, tz, sizeof(ktz)))
478 return -EFAULT;
481 return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
484 struct sel_arg_struct {
485 unsigned int n;
486 unsigned int inp;
487 unsigned int outp;
488 unsigned int exp;
489 unsigned int tvp;
492 asmlinkage long
493 sys32_old_select(struct sel_arg_struct __user *arg)
495 struct sel_arg_struct a;
497 if (copy_from_user(&a, arg, sizeof(a)))
498 return -EFAULT;
499 return compat_sys_select(a.n, compat_ptr(a.inp), compat_ptr(a.outp),
500 compat_ptr(a.exp), compat_ptr(a.tvp));
503 extern asmlinkage long
504 compat_sys_wait4(compat_pid_t pid, compat_uint_t * stat_addr, int options,
505 struct compat_rusage *ru);
507 asmlinkage long
508 sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr, int options)
510 return compat_sys_wait4(pid, stat_addr, options, NULL);
513 /* 32-bit timeval and related flotsam. */
515 asmlinkage long
516 sys32_sysfs(int option, u32 arg1, u32 arg2)
518 return sys_sysfs(option, arg1, arg2);
521 struct sysinfo32 {
522 s32 uptime;
523 u32 loads[3];
524 u32 totalram;
525 u32 freeram;
526 u32 sharedram;
527 u32 bufferram;
528 u32 totalswap;
529 u32 freeswap;
530 unsigned short procs;
531 unsigned short pad;
532 u32 totalhigh;
533 u32 freehigh;
534 u32 mem_unit;
535 char _f[20-2*sizeof(u32)-sizeof(int)];
538 asmlinkage long
539 sys32_sysinfo(struct sysinfo32 __user *info)
541 struct sysinfo s;
542 int ret;
543 mm_segment_t old_fs = get_fs ();
544 int bitcount = 0;
546 set_fs (KERNEL_DS);
547 ret = sys_sysinfo((struct sysinfo __user *)&s);
548 set_fs (old_fs);
550 /* Check to see if any memory value is too large for 32-bit and scale
551 * down if needed
553 if ((s.totalram >> 32) || (s.totalswap >> 32)) {
554 while (s.mem_unit < PAGE_SIZE) {
555 s.mem_unit <<= 1;
556 bitcount++;
558 s.totalram >>= bitcount;
559 s.freeram >>= bitcount;
560 s.sharedram >>= bitcount;
561 s.bufferram >>= bitcount;
562 s.totalswap >>= bitcount;
563 s.freeswap >>= bitcount;
564 s.totalhigh >>= bitcount;
565 s.freehigh >>= bitcount;
568 if (!access_ok(VERIFY_WRITE, info, sizeof(struct sysinfo32)) ||
569 __put_user (s.uptime, &info->uptime) ||
570 __put_user (s.loads[0], &info->loads[0]) ||
571 __put_user (s.loads[1], &info->loads[1]) ||
572 __put_user (s.loads[2], &info->loads[2]) ||
573 __put_user (s.totalram, &info->totalram) ||
574 __put_user (s.freeram, &info->freeram) ||
575 __put_user (s.sharedram, &info->sharedram) ||
576 __put_user (s.bufferram, &info->bufferram) ||
577 __put_user (s.totalswap, &info->totalswap) ||
578 __put_user (s.freeswap, &info->freeswap) ||
579 __put_user (s.procs, &info->procs) ||
580 __put_user (s.totalhigh, &info->totalhigh) ||
581 __put_user (s.freehigh, &info->freehigh) ||
582 __put_user (s.mem_unit, &info->mem_unit))
583 return -EFAULT;
584 return 0;
587 asmlinkage long
588 sys32_sched_rr_get_interval(compat_pid_t pid, struct compat_timespec __user *interval)
590 struct timespec t;
591 int ret;
592 mm_segment_t old_fs = get_fs ();
594 set_fs (KERNEL_DS);
595 ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
596 set_fs (old_fs);
597 if (put_compat_timespec(&t, interval))
598 return -EFAULT;
599 return ret;
602 asmlinkage long
603 sys32_rt_sigpending(compat_sigset_t __user *set, compat_size_t sigsetsize)
605 sigset_t s;
606 compat_sigset_t s32;
607 int ret;
608 mm_segment_t old_fs = get_fs();
610 set_fs (KERNEL_DS);
611 ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
612 set_fs (old_fs);
613 if (!ret) {
614 switch (_NSIG_WORDS) {
615 case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
616 case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
617 case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
618 case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
620 if (copy_to_user (set, &s32, sizeof(compat_sigset_t)))
621 return -EFAULT;
623 return ret;
626 asmlinkage long
627 sys32_rt_sigqueueinfo(int pid, int sig, compat_siginfo_t __user *uinfo)
629 siginfo_t info;
630 int ret;
631 mm_segment_t old_fs = get_fs();
633 if (copy_siginfo_from_user32(&info, uinfo))
634 return -EFAULT;
635 set_fs (KERNEL_DS);
636 ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
637 set_fs (old_fs);
638 return ret;
641 /* These are here just in case some old ia32 binary calls it. */
642 asmlinkage long
643 sys32_pause(void)
645 current->state = TASK_INTERRUPTIBLE;
646 schedule();
647 return -ERESTARTNOHAND;
651 #ifdef CONFIG_SYSCTL
652 struct sysctl_ia32 {
653 unsigned int name;
654 int nlen;
655 unsigned int oldval;
656 unsigned int oldlenp;
657 unsigned int newval;
658 unsigned int newlen;
659 unsigned int __unused[4];
663 asmlinkage long
664 sys32_sysctl(struct sysctl_ia32 __user *args32)
666 struct sysctl_ia32 a32;
667 mm_segment_t old_fs = get_fs ();
668 void __user *oldvalp, *newvalp;
669 size_t oldlen;
670 int __user *namep;
671 long ret;
673 if (copy_from_user(&a32, args32, sizeof (a32)))
674 return -EFAULT;
677 * We need to pre-validate these because we have to disable address checking
678 * before calling do_sysctl() because of OLDLEN but we can't run the risk of the
679 * user specifying bad addresses here. Well, since we're dealing with 32 bit
680 * addresses, we KNOW that access_ok() will always succeed, so this is an
681 * expensive NOP, but so what...
683 namep = compat_ptr(a32.name);
684 oldvalp = compat_ptr(a32.oldval);
685 newvalp = compat_ptr(a32.newval);
687 if ((oldvalp && get_user(oldlen, (int __user *)compat_ptr(a32.oldlenp)))
688 || !access_ok(VERIFY_WRITE, namep, 0)
689 || !access_ok(VERIFY_WRITE, oldvalp, 0)
690 || !access_ok(VERIFY_WRITE, newvalp, 0))
691 return -EFAULT;
693 set_fs(KERNEL_DS);
694 lock_kernel();
695 ret = do_sysctl(namep, a32.nlen, oldvalp, (size_t __user *)&oldlen,
696 newvalp, (size_t) a32.newlen);
697 unlock_kernel();
698 set_fs(old_fs);
700 if (oldvalp && put_user (oldlen, (int __user *)compat_ptr(a32.oldlenp)))
701 return -EFAULT;
703 return ret;
705 #endif
707 /* warning: next two assume little endian */
708 asmlinkage long
709 sys32_pread(unsigned int fd, char __user *ubuf, u32 count, u32 poslo, u32 poshi)
711 return sys_pread64(fd, ubuf, count,
712 ((loff_t)AA(poshi) << 32) | AA(poslo));
715 asmlinkage long
716 sys32_pwrite(unsigned int fd, char __user *ubuf, u32 count, u32 poslo, u32 poshi)
718 return sys_pwrite64(fd, ubuf, count,
719 ((loff_t)AA(poshi) << 32) | AA(poslo));
723 asmlinkage long
724 sys32_personality(unsigned long personality)
726 int ret;
727 if (personality(current->personality) == PER_LINUX32 &&
728 personality == PER_LINUX)
729 personality = PER_LINUX32;
730 ret = sys_personality(personality);
731 if (ret == PER_LINUX32)
732 ret = PER_LINUX;
733 return ret;
736 asmlinkage long
737 sys32_sendfile(int out_fd, int in_fd, compat_off_t __user *offset, s32 count)
739 mm_segment_t old_fs = get_fs();
740 int ret;
741 off_t of;
743 if (offset && get_user(of, offset))
744 return -EFAULT;
746 set_fs(KERNEL_DS);
747 ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
748 count);
749 set_fs(old_fs);
751 if (offset && put_user(of, offset))
752 return -EFAULT;
754 return ret;
757 asmlinkage long sys32_mmap2(unsigned long addr, unsigned long len,
758 unsigned long prot, unsigned long flags,
759 unsigned long fd, unsigned long pgoff)
761 struct mm_struct *mm = current->mm;
762 unsigned long error;
763 struct file * file = NULL;
765 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
766 if (!(flags & MAP_ANONYMOUS)) {
767 file = fget(fd);
768 if (!file)
769 return -EBADF;
772 down_write(&mm->mmap_sem);
773 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
774 up_write(&mm->mmap_sem);
776 if (file)
777 fput(file);
778 return error;
781 asmlinkage long sys32_olduname(struct oldold_utsname __user * name)
783 int error;
785 if (!name)
786 return -EFAULT;
787 if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
788 return -EFAULT;
790 down_read(&uts_sem);
792 error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
793 __put_user(0,name->sysname+__OLD_UTS_LEN);
794 __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
795 __put_user(0,name->nodename+__OLD_UTS_LEN);
796 __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
797 __put_user(0,name->release+__OLD_UTS_LEN);
798 __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
799 __put_user(0,name->version+__OLD_UTS_LEN);
801 char *arch = "x86_64";
802 if (personality(current->personality) == PER_LINUX32)
803 arch = "i686";
805 __copy_to_user(&name->machine,arch,strlen(arch)+1);
808 up_read(&uts_sem);
810 error = error ? -EFAULT : 0;
812 return error;
815 long sys32_uname(struct old_utsname __user * name)
817 int err;
818 if (!name)
819 return -EFAULT;
820 down_read(&uts_sem);
821 err=copy_to_user(name, &system_utsname, sizeof (*name));
822 up_read(&uts_sem);
823 if (personality(current->personality) == PER_LINUX32)
824 err |= copy_to_user(&name->machine, "i686", 5);
825 return err?-EFAULT:0;
828 long sys32_ustat(unsigned dev, struct ustat32 __user *u32p)
830 struct ustat u;
831 mm_segment_t seg;
832 int ret;
834 seg = get_fs();
835 set_fs(KERNEL_DS);
836 ret = sys_ustat(dev, (struct ustat __user *)&u);
837 set_fs(seg);
838 if (ret >= 0) {
839 if (!access_ok(VERIFY_WRITE,u32p,sizeof(struct ustat32)) ||
840 __put_user((__u32) u.f_tfree, &u32p->f_tfree) ||
841 __put_user((__u32) u.f_tinode, &u32p->f_tfree) ||
842 __copy_to_user(&u32p->f_fname, u.f_fname, sizeof(u.f_fname)) ||
843 __copy_to_user(&u32p->f_fpack, u.f_fpack, sizeof(u.f_fpack)))
844 ret = -EFAULT;
846 return ret;
849 asmlinkage long sys32_execve(char __user *name, compat_uptr_t __user *argv,
850 compat_uptr_t __user *envp, struct pt_regs *regs)
852 long error;
853 char * filename;
855 filename = getname(name);
856 error = PTR_ERR(filename);
857 if (IS_ERR(filename))
858 return error;
859 error = compat_do_execve(filename, argv, envp, regs);
860 if (error == 0) {
861 task_lock(current);
862 current->ptrace &= ~PT_DTRACE;
863 task_unlock(current);
865 putname(filename);
866 return error;
869 asmlinkage long sys32_clone(unsigned int clone_flags, unsigned int newsp,
870 struct pt_regs *regs)
872 void __user *parent_tid = (void __user *)regs->rdx;
873 void __user *child_tid = (void __user *)regs->rdi;
874 if (!newsp)
875 newsp = regs->rsp;
876 return do_fork(clone_flags, newsp, regs, 0, parent_tid, child_tid);
880 * Some system calls that need sign extended arguments. This could be done by a generic wrapper.
883 long sys32_lseek (unsigned int fd, int offset, unsigned int whence)
885 return sys_lseek(fd, offset, whence);
888 long sys32_kill(int pid, int sig)
890 return sys_kill(pid, sig);
893 long sys32_fadvise64_64(int fd, __u32 offset_low, __u32 offset_high,
894 __u32 len_low, __u32 len_high, int advice)
896 return sys_fadvise64_64(fd,
897 (((u64)offset_high)<<32) | offset_low,
898 (((u64)len_high)<<32) | len_low,
899 advice);
902 long sys32_vm86_warning(void)
904 struct task_struct *me = current;
905 static char lastcomm[sizeof(me->comm)];
906 if (strncmp(lastcomm, me->comm, sizeof(lastcomm))) {
907 compat_printk(KERN_INFO "%s: vm86 mode not supported on 64 bit kernel\n",
908 me->comm);
909 strncpy(lastcomm, me->comm, sizeof(lastcomm));
911 return -ENOSYS;
914 long sys32_lookup_dcookie(u32 addr_low, u32 addr_high,
915 char __user * buf, size_t len)
917 return sys_lookup_dcookie(((u64)addr_high << 32) | addr_low, buf, len);