blob: 04d80406ce4fed4c1a6ce646253675c65b074269 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sys_ia32.c: Conversion between 32bit and 64bit native syscalls. Based on
3 * sys_sparc32
4 *
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)
13 *
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.
16 *
17 * This file assumes that there is a hole at the end of user address space.
18 *
19 * Some of the functions are LE specific currently. These are hopefully all marked.
20 * This should be fixed.
21 */
22
23#include <linux/config.h>
24#include <linux/kernel.h>
25#include <linux/sched.h>
26#include <linux/fs.h>
27#include <linux/file.h>
28#include <linux/signal.h>
29#include <linux/syscalls.h>
30#include <linux/resource.h>
31#include <linux/times.h>
32#include <linux/utsname.h>
33#include <linux/timex.h>
34#include <linux/smp.h>
35#include <linux/smp_lock.h>
36#include <linux/sem.h>
37#include <linux/msg.h>
38#include <linux/mm.h>
39#include <linux/shm.h>
40#include <linux/slab.h>
41#include <linux/uio.h>
42#include <linux/nfs_fs.h>
43#include <linux/quota.h>
44#include <linux/module.h>
45#include <linux/sunrpc/svc.h>
46#include <linux/nfsd/nfsd.h>
47#include <linux/nfsd/cache.h>
48#include <linux/nfsd/xdr.h>
49#include <linux/nfsd/syscall.h>
50#include <linux/poll.h>
51#include <linux/personality.h>
52#include <linux/stat.h>
53#include <linux/ipc.h>
54#include <linux/rwsem.h>
55#include <linux/binfmts.h>
56#include <linux/init.h>
57#include <linux/aio_abi.h>
58#include <linux/aio.h>
59#include <linux/compat.h>
60#include <linux/vfs.h>
61#include <linux/ptrace.h>
62#include <linux/highuid.h>
63#include <linux/vmalloc.h>
Andrew Morton9e566d82005-07-26 21:41:38 -070064#include <linux/fsnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070065#include <asm/mman.h>
66#include <asm/types.h>
67#include <asm/uaccess.h>
68#include <asm/semaphore.h>
69#include <asm/atomic.h>
70#include <asm/ldt.h>
71
72#include <net/scm.h>
73#include <net/sock.h>
74#include <asm/ia32.h>
75
76#define AA(__x) ((unsigned long)(__x))
77
78int cp_compat_stat(struct kstat *kbuf, struct compat_stat __user *ubuf)
79{
80 typeof(ubuf->st_uid) uid = 0;
81 typeof(ubuf->st_gid) gid = 0;
82 SET_UID(uid, kbuf->uid);
83 SET_GID(gid, kbuf->gid);
84 if (!old_valid_dev(kbuf->dev) || !old_valid_dev(kbuf->rdev))
85 return -EOVERFLOW;
86 if (kbuf->size >= 0x7fffffff)
87 return -EOVERFLOW;
88 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct compat_stat)) ||
89 __put_user (old_encode_dev(kbuf->dev), &ubuf->st_dev) ||
90 __put_user (kbuf->ino, &ubuf->st_ino) ||
91 __put_user (kbuf->mode, &ubuf->st_mode) ||
92 __put_user (kbuf->nlink, &ubuf->st_nlink) ||
93 __put_user (uid, &ubuf->st_uid) ||
94 __put_user (gid, &ubuf->st_gid) ||
95 __put_user (old_encode_dev(kbuf->rdev), &ubuf->st_rdev) ||
96 __put_user (kbuf->size, &ubuf->st_size) ||
97 __put_user (kbuf->atime.tv_sec, &ubuf->st_atime) ||
98 __put_user (kbuf->atime.tv_nsec, &ubuf->st_atime_nsec) ||
99 __put_user (kbuf->mtime.tv_sec, &ubuf->st_mtime) ||
100 __put_user (kbuf->mtime.tv_nsec, &ubuf->st_mtime_nsec) ||
101 __put_user (kbuf->ctime.tv_sec, &ubuf->st_ctime) ||
102 __put_user (kbuf->ctime.tv_nsec, &ubuf->st_ctime_nsec) ||
103 __put_user (kbuf->blksize, &ubuf->st_blksize) ||
104 __put_user (kbuf->blocks, &ubuf->st_blocks))
105 return -EFAULT;
106 return 0;
107}
108
109asmlinkage long
110sys32_truncate64(char __user * filename, unsigned long offset_low, unsigned long offset_high)
111{
112 return sys_truncate(filename, ((loff_t) offset_high << 32) | offset_low);
113}
114
115asmlinkage long
116sys32_ftruncate64(unsigned int fd, unsigned long offset_low, unsigned long offset_high)
117{
118 return sys_ftruncate(fd, ((loff_t) offset_high << 32) | offset_low);
119}
120
121/* Another set for IA32/LFS -- x86_64 struct stat is different due to
122 support for 64bit inode numbers. */
123
124static int
125cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
126{
127 typeof(ubuf->st_uid) uid = 0;
128 typeof(ubuf->st_gid) gid = 0;
129 SET_UID(uid, stat->uid);
130 SET_GID(gid, stat->gid);
131 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
132 __put_user(huge_encode_dev(stat->dev), &ubuf->st_dev) ||
133 __put_user (stat->ino, &ubuf->__st_ino) ||
134 __put_user (stat->ino, &ubuf->st_ino) ||
135 __put_user (stat->mode, &ubuf->st_mode) ||
136 __put_user (stat->nlink, &ubuf->st_nlink) ||
137 __put_user (uid, &ubuf->st_uid) ||
138 __put_user (gid, &ubuf->st_gid) ||
139 __put_user (huge_encode_dev(stat->rdev), &ubuf->st_rdev) ||
140 __put_user (stat->size, &ubuf->st_size) ||
141 __put_user (stat->atime.tv_sec, &ubuf->st_atime) ||
142 __put_user (stat->atime.tv_nsec, &ubuf->st_atime_nsec) ||
143 __put_user (stat->mtime.tv_sec, &ubuf->st_mtime) ||
144 __put_user (stat->mtime.tv_nsec, &ubuf->st_mtime_nsec) ||
145 __put_user (stat->ctime.tv_sec, &ubuf->st_ctime) ||
146 __put_user (stat->ctime.tv_nsec, &ubuf->st_ctime_nsec) ||
147 __put_user (stat->blksize, &ubuf->st_blksize) ||
148 __put_user (stat->blocks, &ubuf->st_blocks))
149 return -EFAULT;
150 return 0;
151}
152
153asmlinkage long
154sys32_stat64(char __user * filename, struct stat64 __user *statbuf)
155{
156 struct kstat stat;
157 int ret = vfs_stat(filename, &stat);
158 if (!ret)
159 ret = cp_stat64(statbuf, &stat);
160 return ret;
161}
162
163asmlinkage long
164sys32_lstat64(char __user * filename, struct stat64 __user *statbuf)
165{
166 struct kstat stat;
167 int ret = vfs_lstat(filename, &stat);
168 if (!ret)
169 ret = cp_stat64(statbuf, &stat);
170 return ret;
171}
172
173asmlinkage long
174sys32_fstat64(unsigned int fd, struct stat64 __user *statbuf)
175{
176 struct kstat stat;
177 int ret = vfs_fstat(fd, &stat);
178 if (!ret)
179 ret = cp_stat64(statbuf, &stat);
180 return ret;
181}
182
183/*
184 * Linux/i386 didn't use to be able to handle more than
185 * 4 system call parameters, so these system calls used a memory
186 * block for parameter passing..
187 */
188
189struct mmap_arg_struct {
190 unsigned int addr;
191 unsigned int len;
192 unsigned int prot;
193 unsigned int flags;
194 unsigned int fd;
195 unsigned int offset;
196};
197
198asmlinkage long
199sys32_mmap(struct mmap_arg_struct __user *arg)
200{
201 struct mmap_arg_struct a;
202 struct file *file = NULL;
203 unsigned long retval;
204 struct mm_struct *mm ;
205
206 if (copy_from_user(&a, arg, sizeof(a)))
207 return -EFAULT;
208
209 if (a.offset & ~PAGE_MASK)
210 return -EINVAL;
211
212 if (!(a.flags & MAP_ANONYMOUS)) {
213 file = fget(a.fd);
214 if (!file)
215 return -EBADF;
216 }
217
218 mm = current->mm;
219 down_write(&mm->mmap_sem);
220 retval = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags, a.offset>>PAGE_SHIFT);
221 if (file)
222 fput(file);
223
224 up_write(&mm->mmap_sem);
225
226 return retval;
227}
228
229asmlinkage long
230sys32_mprotect(unsigned long start, size_t len, unsigned long prot)
231{
232 return sys_mprotect(start,len,prot);
233}
234
235asmlinkage long
236sys32_pipe(int __user *fd)
237{
238 int retval;
239 int fds[2];
240
241 retval = do_pipe(fds);
242 if (retval)
243 goto out;
244 if (copy_to_user(fd, fds, sizeof(fds)))
245 retval = -EFAULT;
246 out:
247 return retval;
248}
249
250asmlinkage long
251sys32_rt_sigaction(int sig, struct sigaction32 __user *act,
252 struct sigaction32 __user *oact, unsigned int sigsetsize)
253{
254 struct k_sigaction new_ka, old_ka;
255 int ret;
256 compat_sigset_t set32;
257
258 /* XXX: Don't preclude handling different sized sigset_t's. */
259 if (sigsetsize != sizeof(compat_sigset_t))
260 return -EINVAL;
261
262 if (act) {
263 compat_uptr_t handler, restorer;
264
265 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
266 __get_user(handler, &act->sa_handler) ||
267 __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
268 __get_user(restorer, &act->sa_restorer)||
269 __copy_from_user(&set32, &act->sa_mask, sizeof(compat_sigset_t)))
270 return -EFAULT;
271 new_ka.sa.sa_handler = compat_ptr(handler);
272 new_ka.sa.sa_restorer = compat_ptr(restorer);
273 /* FIXME: here we rely on _COMPAT_NSIG_WORS to be >= than _NSIG_WORDS << 1 */
274 switch (_NSIG_WORDS) {
275 case 4: new_ka.sa.sa_mask.sig[3] = set32.sig[6]
276 | (((long)set32.sig[7]) << 32);
277 case 3: new_ka.sa.sa_mask.sig[2] = set32.sig[4]
278 | (((long)set32.sig[5]) << 32);
279 case 2: new_ka.sa.sa_mask.sig[1] = set32.sig[2]
280 | (((long)set32.sig[3]) << 32);
281 case 1: new_ka.sa.sa_mask.sig[0] = set32.sig[0]
282 | (((long)set32.sig[1]) << 32);
283 }
284 }
285
286 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
287
288 if (!ret && oact) {
289 /* FIXME: here we rely on _COMPAT_NSIG_WORS to be >= than _NSIG_WORDS << 1 */
290 switch (_NSIG_WORDS) {
291 case 4:
292 set32.sig[7] = (old_ka.sa.sa_mask.sig[3] >> 32);
293 set32.sig[6] = old_ka.sa.sa_mask.sig[3];
294 case 3:
295 set32.sig[5] = (old_ka.sa.sa_mask.sig[2] >> 32);
296 set32.sig[4] = old_ka.sa.sa_mask.sig[2];
297 case 2:
298 set32.sig[3] = (old_ka.sa.sa_mask.sig[1] >> 32);
299 set32.sig[2] = old_ka.sa.sa_mask.sig[1];
300 case 1:
301 set32.sig[1] = (old_ka.sa.sa_mask.sig[0] >> 32);
302 set32.sig[0] = old_ka.sa.sa_mask.sig[0];
303 }
304 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
305 __put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler) ||
306 __put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer) ||
307 __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
308 __copy_to_user(&oact->sa_mask, &set32, sizeof(compat_sigset_t)))
309 return -EFAULT;
310 }
311
312 return ret;
313}
314
315asmlinkage long
316sys32_sigaction (int sig, struct old_sigaction32 __user *act, struct old_sigaction32 __user *oact)
317{
318 struct k_sigaction new_ka, old_ka;
319 int ret;
320
321 if (act) {
322 compat_old_sigset_t mask;
323 compat_uptr_t handler, restorer;
324
325 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
326 __get_user(handler, &act->sa_handler) ||
327 __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
328 __get_user(restorer, &act->sa_restorer) ||
329 __get_user(mask, &act->sa_mask))
330 return -EFAULT;
331
332 new_ka.sa.sa_handler = compat_ptr(handler);
333 new_ka.sa.sa_restorer = compat_ptr(restorer);
334
335 siginitset(&new_ka.sa.sa_mask, mask);
336 }
337
338 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
339
340 if (!ret && oact) {
341 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
342 __put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler) ||
343 __put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer) ||
344 __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
345 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
346 return -EFAULT;
347 }
348
349 return ret;
350}
351
352asmlinkage long
353sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
354 compat_sigset_t __user *oset, unsigned int sigsetsize)
355{
356 sigset_t s;
357 compat_sigset_t s32;
358 int ret;
359 mm_segment_t old_fs = get_fs();
360
361 if (set) {
362 if (copy_from_user (&s32, set, sizeof(compat_sigset_t)))
363 return -EFAULT;
364 switch (_NSIG_WORDS) {
365 case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
366 case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
367 case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
368 case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
369 }
370 }
371 set_fs (KERNEL_DS);
372 ret = sys_rt_sigprocmask(how, set ? &s : NULL, oset ? &s : NULL,
373 sigsetsize);
374 set_fs (old_fs);
375 if (ret) return ret;
376 if (oset) {
377 switch (_NSIG_WORDS) {
378 case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
379 case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
380 case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
381 case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
382 }
383 if (copy_to_user (oset, &s32, sizeof(compat_sigset_t)))
384 return -EFAULT;
385 }
386 return 0;
387}
388
389static inline long
390get_tv32(struct timeval *o, struct compat_timeval __user *i)
391{
392 int err = -EFAULT;
393 if (access_ok(VERIFY_READ, i, sizeof(*i))) {
394 err = __get_user(o->tv_sec, &i->tv_sec);
395 err |= __get_user(o->tv_usec, &i->tv_usec);
396 }
397 return err;
398}
399
400static inline long
401put_tv32(struct compat_timeval __user *o, struct timeval *i)
402{
403 int err = -EFAULT;
404 if (access_ok(VERIFY_WRITE, o, sizeof(*o))) {
405 err = __put_user(i->tv_sec, &o->tv_sec);
406 err |= __put_user(i->tv_usec, &o->tv_usec);
407 }
408 return err;
409}
410
411extern int do_setitimer(int which, struct itimerval *, struct itimerval *);
412
413asmlinkage long
414sys32_alarm(unsigned int seconds)
415{
416 struct itimerval it_new, it_old;
417 unsigned int oldalarm;
418
419 it_new.it_interval.tv_sec = it_new.it_interval.tv_usec = 0;
420 it_new.it_value.tv_sec = seconds;
421 it_new.it_value.tv_usec = 0;
422 do_setitimer(ITIMER_REAL, &it_new, &it_old);
423 oldalarm = it_old.it_value.tv_sec;
424 /* ehhh.. We can't return 0 if we have an alarm pending.. */
425 /* And we'd better return too much than too little anyway */
426 if (it_old.it_value.tv_usec)
427 oldalarm++;
428 return oldalarm;
429}
430
431/* Translations due to time_t size differences. Which affects all
432 sorts of things, like timeval and itimerval. */
433
434extern struct timezone sys_tz;
435
436asmlinkage long
437sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
438{
439 if (tv) {
440 struct timeval ktv;
441 do_gettimeofday(&ktv);
442 if (put_tv32(tv, &ktv))
443 return -EFAULT;
444 }
445 if (tz) {
446 if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
447 return -EFAULT;
448 }
449 return 0;
450}
451
452asmlinkage long
453sys32_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
454{
455 struct timeval ktv;
456 struct timespec kts;
457 struct timezone ktz;
458
459 if (tv) {
460 if (get_tv32(&ktv, tv))
461 return -EFAULT;
462 kts.tv_sec = ktv.tv_sec;
463 kts.tv_nsec = ktv.tv_usec * NSEC_PER_USEC;
464 }
465 if (tz) {
466 if (copy_from_user(&ktz, tz, sizeof(ktz)))
467 return -EFAULT;
468 }
469
470 return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
471}
472
473struct sel_arg_struct {
474 unsigned int n;
475 unsigned int inp;
476 unsigned int outp;
477 unsigned int exp;
478 unsigned int tvp;
479};
480
481asmlinkage long
482sys32_old_select(struct sel_arg_struct __user *arg)
483{
484 struct sel_arg_struct a;
485
486 if (copy_from_user(&a, arg, sizeof(a)))
487 return -EFAULT;
488 return compat_sys_select(a.n, compat_ptr(a.inp), compat_ptr(a.outp),
489 compat_ptr(a.exp), compat_ptr(a.tvp));
490}
491
492extern asmlinkage long
493compat_sys_wait4(compat_pid_t pid, compat_uint_t * stat_addr, int options,
494 struct compat_rusage *ru);
495
496asmlinkage long
497sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr, int options)
498{
499 return compat_sys_wait4(pid, stat_addr, options, NULL);
500}
501
502int sys32_ni_syscall(int call)
503{
504 struct task_struct *me = current;
505 static char lastcomm[sizeof(me->comm)];
506
507 if (strncmp(lastcomm, me->comm, sizeof(lastcomm))) {
508 printk(KERN_INFO "IA32 syscall %d from %s not implemented\n",
509 call, me->comm);
510 strncpy(lastcomm, me->comm, sizeof(lastcomm));
511 }
512 return -ENOSYS;
513}
514
515/* 32-bit timeval and related flotsam. */
516
517asmlinkage long
518sys32_sysfs(int option, u32 arg1, u32 arg2)
519{
520 return sys_sysfs(option, arg1, arg2);
521}
522
523struct sysinfo32 {
524 s32 uptime;
525 u32 loads[3];
526 u32 totalram;
527 u32 freeram;
528 u32 sharedram;
529 u32 bufferram;
530 u32 totalswap;
531 u32 freeswap;
532 unsigned short procs;
533 unsigned short pad;
534 u32 totalhigh;
535 u32 freehigh;
536 u32 mem_unit;
537 char _f[20-2*sizeof(u32)-sizeof(int)];
538};
539
540asmlinkage long
541sys32_sysinfo(struct sysinfo32 __user *info)
542{
543 struct sysinfo s;
544 int ret;
545 mm_segment_t old_fs = get_fs ();
546 int bitcount = 0;
547
548 set_fs (KERNEL_DS);
549 ret = sys_sysinfo(&s);
550 set_fs (old_fs);
551
552 /* Check to see if any memory value is too large for 32-bit and scale
553 * down if needed
554 */
555 if ((s.totalram >> 32) || (s.totalswap >> 32)) {
556 while (s.mem_unit < PAGE_SIZE) {
557 s.mem_unit <<= 1;
558 bitcount++;
559 }
560 s.totalram >>= bitcount;
561 s.freeram >>= bitcount;
562 s.sharedram >>= bitcount;
563 s.bufferram >>= bitcount;
564 s.totalswap >>= bitcount;
565 s.freeswap >>= bitcount;
566 s.totalhigh >>= bitcount;
567 s.freehigh >>= bitcount;
568 }
569
570 if (!access_ok(VERIFY_WRITE, info, sizeof(struct sysinfo32)) ||
571 __put_user (s.uptime, &info->uptime) ||
572 __put_user (s.loads[0], &info->loads[0]) ||
573 __put_user (s.loads[1], &info->loads[1]) ||
574 __put_user (s.loads[2], &info->loads[2]) ||
575 __put_user (s.totalram, &info->totalram) ||
576 __put_user (s.freeram, &info->freeram) ||
577 __put_user (s.sharedram, &info->sharedram) ||
578 __put_user (s.bufferram, &info->bufferram) ||
579 __put_user (s.totalswap, &info->totalswap) ||
580 __put_user (s.freeswap, &info->freeswap) ||
581 __put_user (s.procs, &info->procs) ||
582 __put_user (s.totalhigh, &info->totalhigh) ||
583 __put_user (s.freehigh, &info->freehigh) ||
584 __put_user (s.mem_unit, &info->mem_unit))
585 return -EFAULT;
586 return 0;
587}
588
589asmlinkage long
590sys32_sched_rr_get_interval(compat_pid_t pid, struct compat_timespec __user *interval)
591{
592 struct timespec t;
593 int ret;
594 mm_segment_t old_fs = get_fs ();
595
596 set_fs (KERNEL_DS);
597 ret = sys_sched_rr_get_interval(pid, &t);
598 set_fs (old_fs);
599 if (put_compat_timespec(&t, interval))
600 return -EFAULT;
601 return ret;
602}
603
604asmlinkage long
605sys32_rt_sigpending(compat_sigset_t __user *set, compat_size_t sigsetsize)
606{
607 sigset_t s;
608 compat_sigset_t s32;
609 int ret;
610 mm_segment_t old_fs = get_fs();
611
612 set_fs (KERNEL_DS);
613 ret = sys_rt_sigpending(&s, sigsetsize);
614 set_fs (old_fs);
615 if (!ret) {
616 switch (_NSIG_WORDS) {
617 case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
618 case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
619 case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
620 case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
621 }
622 if (copy_to_user (set, &s32, sizeof(compat_sigset_t)))
623 return -EFAULT;
624 }
625 return ret;
626}
627
628asmlinkage long
629sys32_rt_sigqueueinfo(int pid, int sig, compat_siginfo_t __user *uinfo)
630{
631 siginfo_t info;
632 int ret;
633 mm_segment_t old_fs = get_fs();
634
635 if (copy_siginfo_from_user32(&info, uinfo))
636 return -EFAULT;
637 set_fs (KERNEL_DS);
638 ret = sys_rt_sigqueueinfo(pid, sig, &info);
639 set_fs (old_fs);
640 return ret;
641}
642
643/* These are here just in case some old ia32 binary calls it. */
644asmlinkage long
645sys32_pause(void)
646{
647 current->state = TASK_INTERRUPTIBLE;
648 schedule();
649 return -ERESTARTNOHAND;
650}
651
652
653#ifdef CONFIG_SYSCTL
654struct sysctl_ia32 {
655 unsigned int name;
656 int nlen;
657 unsigned int oldval;
658 unsigned int oldlenp;
659 unsigned int newval;
660 unsigned int newlen;
661 unsigned int __unused[4];
662};
663
664
665asmlinkage long
666sys32_sysctl(struct sysctl_ia32 __user *args32)
667{
668 struct sysctl_ia32 a32;
669 mm_segment_t old_fs = get_fs ();
670 void __user *oldvalp, *newvalp;
671 size_t oldlen;
672 int __user *namep;
673 long ret;
674 extern int do_sysctl(int *name, int nlen, void *oldval, size_t *oldlenp,
675 void *newval, size_t newlen);
676
677
678 if (copy_from_user(&a32, args32, sizeof (a32)))
679 return -EFAULT;
680
681 /*
682 * We need to pre-validate these because we have to disable address checking
683 * before calling do_sysctl() because of OLDLEN but we can't run the risk of the
684 * user specifying bad addresses here. Well, since we're dealing with 32 bit
685 * addresses, we KNOW that access_ok() will always succeed, so this is an
686 * expensive NOP, but so what...
687 */
688 namep = compat_ptr(a32.name);
689 oldvalp = compat_ptr(a32.oldval);
690 newvalp = compat_ptr(a32.newval);
691
692 if ((oldvalp && get_user(oldlen, (int __user *)compat_ptr(a32.oldlenp)))
693 || !access_ok(VERIFY_WRITE, namep, 0)
694 || !access_ok(VERIFY_WRITE, oldvalp, 0)
695 || !access_ok(VERIFY_WRITE, newvalp, 0))
696 return -EFAULT;
697
698 set_fs(KERNEL_DS);
699 lock_kernel();
700 ret = do_sysctl(namep, a32.nlen, oldvalp, &oldlen, newvalp, (size_t) a32.newlen);
701 unlock_kernel();
702 set_fs(old_fs);
703
704 if (oldvalp && put_user (oldlen, (int __user *)compat_ptr(a32.oldlenp)))
705 return -EFAULT;
706
707 return ret;
708}
709#endif
710
711/* warning: next two assume little endian */
712asmlinkage long
713sys32_pread(unsigned int fd, char __user *ubuf, u32 count, u32 poslo, u32 poshi)
714{
715 return sys_pread64(fd, ubuf, count,
716 ((loff_t)AA(poshi) << 32) | AA(poslo));
717}
718
719asmlinkage long
720sys32_pwrite(unsigned int fd, char __user *ubuf, u32 count, u32 poslo, u32 poshi)
721{
722 return sys_pwrite64(fd, ubuf, count,
723 ((loff_t)AA(poshi) << 32) | AA(poslo));
724}
725
726
727asmlinkage long
728sys32_personality(unsigned long personality)
729{
730 int ret;
731 if (personality(current->personality) == PER_LINUX32 &&
732 personality == PER_LINUX)
733 personality = PER_LINUX32;
734 ret = sys_personality(personality);
735 if (ret == PER_LINUX32)
736 ret = PER_LINUX;
737 return ret;
738}
739
740asmlinkage long
741sys32_sendfile(int out_fd, int in_fd, compat_off_t __user *offset, s32 count)
742{
743 mm_segment_t old_fs = get_fs();
744 int ret;
745 off_t of;
746
747 if (offset && get_user(of, offset))
748 return -EFAULT;
749
750 set_fs(KERNEL_DS);
751 ret = sys_sendfile(out_fd, in_fd, offset ? &of : NULL, count);
752 set_fs(old_fs);
753
754 if (!ret && offset && put_user(of, offset))
755 return -EFAULT;
756
757 return ret;
758}
759
760/* Handle adjtimex compatibility. */
761
762struct timex32 {
763 u32 modes;
764 s32 offset, freq, maxerror, esterror;
765 s32 status, constant, precision, tolerance;
766 struct compat_timeval time;
767 s32 tick;
768 s32 ppsfreq, jitter, shift, stabil;
769 s32 jitcnt, calcnt, errcnt, stbcnt;
770 s32 :32; s32 :32; s32 :32; s32 :32;
771 s32 :32; s32 :32; s32 :32; s32 :32;
772 s32 :32; s32 :32; s32 :32; s32 :32;
773};
774
775extern int do_adjtimex(struct timex *);
776
777asmlinkage long
778sys32_adjtimex(struct timex32 __user *utp)
779{
780 struct timex txc;
781 int ret;
782
783 memset(&txc, 0, sizeof(struct timex));
784
785 if (!access_ok(VERIFY_READ, utp, sizeof(struct timex32)) ||
786 __get_user(txc.modes, &utp->modes) ||
787 __get_user(txc.offset, &utp->offset) ||
788 __get_user(txc.freq, &utp->freq) ||
789 __get_user(txc.maxerror, &utp->maxerror) ||
790 __get_user(txc.esterror, &utp->esterror) ||
791 __get_user(txc.status, &utp->status) ||
792 __get_user(txc.constant, &utp->constant) ||
793 __get_user(txc.precision, &utp->precision) ||
794 __get_user(txc.tolerance, &utp->tolerance) ||
795 __get_user(txc.time.tv_sec, &utp->time.tv_sec) ||
796 __get_user(txc.time.tv_usec, &utp->time.tv_usec) ||
797 __get_user(txc.tick, &utp->tick) ||
798 __get_user(txc.ppsfreq, &utp->ppsfreq) ||
799 __get_user(txc.jitter, &utp->jitter) ||
800 __get_user(txc.shift, &utp->shift) ||
801 __get_user(txc.stabil, &utp->stabil) ||
802 __get_user(txc.jitcnt, &utp->jitcnt) ||
803 __get_user(txc.calcnt, &utp->calcnt) ||
804 __get_user(txc.errcnt, &utp->errcnt) ||
805 __get_user(txc.stbcnt, &utp->stbcnt))
806 return -EFAULT;
807
808 ret = do_adjtimex(&txc);
809
810 if (!access_ok(VERIFY_WRITE, utp, sizeof(struct timex32)) ||
811 __put_user(txc.modes, &utp->modes) ||
812 __put_user(txc.offset, &utp->offset) ||
813 __put_user(txc.freq, &utp->freq) ||
814 __put_user(txc.maxerror, &utp->maxerror) ||
815 __put_user(txc.esterror, &utp->esterror) ||
816 __put_user(txc.status, &utp->status) ||
817 __put_user(txc.constant, &utp->constant) ||
818 __put_user(txc.precision, &utp->precision) ||
819 __put_user(txc.tolerance, &utp->tolerance) ||
820 __put_user(txc.time.tv_sec, &utp->time.tv_sec) ||
821 __put_user(txc.time.tv_usec, &utp->time.tv_usec) ||
822 __put_user(txc.tick, &utp->tick) ||
823 __put_user(txc.ppsfreq, &utp->ppsfreq) ||
824 __put_user(txc.jitter, &utp->jitter) ||
825 __put_user(txc.shift, &utp->shift) ||
826 __put_user(txc.stabil, &utp->stabil) ||
827 __put_user(txc.jitcnt, &utp->jitcnt) ||
828 __put_user(txc.calcnt, &utp->calcnt) ||
829 __put_user(txc.errcnt, &utp->errcnt) ||
830 __put_user(txc.stbcnt, &utp->stbcnt))
831 ret = -EFAULT;
832
833 return ret;
834}
835
836asmlinkage long sys32_mmap2(unsigned long addr, unsigned long len,
837 unsigned long prot, unsigned long flags,
838 unsigned long fd, unsigned long pgoff)
839{
840 struct mm_struct *mm = current->mm;
841 unsigned long error;
842 struct file * file = NULL;
843
844 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
845 if (!(flags & MAP_ANONYMOUS)) {
846 file = fget(fd);
847 if (!file)
848 return -EBADF;
849 }
850
851 down_write(&mm->mmap_sem);
852 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
853 up_write(&mm->mmap_sem);
854
855 if (file)
856 fput(file);
857 return error;
858}
859
860asmlinkage long sys32_olduname(struct oldold_utsname __user * name)
861{
862 int error;
863
864 if (!name)
865 return -EFAULT;
866 if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
867 return -EFAULT;
868
869 down_read(&uts_sem);
870
871 error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
872 __put_user(0,name->sysname+__OLD_UTS_LEN);
873 __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
874 __put_user(0,name->nodename+__OLD_UTS_LEN);
875 __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
876 __put_user(0,name->release+__OLD_UTS_LEN);
877 __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
878 __put_user(0,name->version+__OLD_UTS_LEN);
879 {
880 char *arch = "x86_64";
881 if (personality(current->personality) == PER_LINUX32)
882 arch = "i686";
883
884 __copy_to_user(&name->machine,arch,strlen(arch)+1);
885 }
886
887 up_read(&uts_sem);
888
889 error = error ? -EFAULT : 0;
890
891 return error;
892}
893
894long sys32_uname(struct old_utsname __user * name)
895{
896 int err;
897 if (!name)
898 return -EFAULT;
899 down_read(&uts_sem);
900 err=copy_to_user(name, &system_utsname, sizeof (*name));
901 up_read(&uts_sem);
902 if (personality(current->personality) == PER_LINUX32)
903 err |= copy_to_user(&name->machine, "i686", 5);
904 return err?-EFAULT:0;
905}
906
907long sys32_ustat(unsigned dev, struct ustat32 __user *u32p)
908{
909 struct ustat u;
910 mm_segment_t seg;
911 int ret;
912
913 seg = get_fs();
914 set_fs(KERNEL_DS);
915 ret = sys_ustat(dev,&u);
916 set_fs(seg);
917 if (ret >= 0) {
918 if (!access_ok(VERIFY_WRITE,u32p,sizeof(struct ustat32)) ||
919 __put_user((__u32) u.f_tfree, &u32p->f_tfree) ||
920 __put_user((__u32) u.f_tinode, &u32p->f_tfree) ||
921 __copy_to_user(&u32p->f_fname, u.f_fname, sizeof(u.f_fname)) ||
922 __copy_to_user(&u32p->f_fpack, u.f_fpack, sizeof(u.f_fpack)))
923 ret = -EFAULT;
924 }
925 return ret;
926}
927
928asmlinkage long sys32_execve(char __user *name, compat_uptr_t __user *argv,
929 compat_uptr_t __user *envp, struct pt_regs *regs)
930{
931 long error;
932 char * filename;
933
934 filename = getname(name);
935 error = PTR_ERR(filename);
936 if (IS_ERR(filename))
937 return error;
938 error = compat_do_execve(filename, argv, envp, regs);
939 if (error == 0) {
940 task_lock(current);
941 current->ptrace &= ~PT_DTRACE;
942 task_unlock(current);
943 }
944 putname(filename);
945 return error;
946}
947
948asmlinkage long sys32_clone(unsigned int clone_flags, unsigned int newsp,
949 struct pt_regs *regs)
950{
951 void __user *parent_tid = (void __user *)regs->rdx;
952 void __user *child_tid = (void __user *)regs->rdi;
953 if (!newsp)
954 newsp = regs->rsp;
955 return do_fork(clone_flags, newsp, regs, 0, parent_tid, child_tid);
956}
957
958/*
959 * Some system calls that need sign extended arguments. This could be done by a generic wrapper.
960 */
961
962long sys32_lseek (unsigned int fd, int offset, unsigned int whence)
963{
964 return sys_lseek(fd, offset, whence);
965}
966
967long sys32_kill(int pid, int sig)
968{
969 return sys_kill(pid, sig);
970}
971
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972extern asmlinkage long
973sys_timer_create(clockid_t which_clock,
974 struct sigevent __user *timer_event_spec,
975 timer_t __user * created_timer_id);
976
977long
978sys32_timer_create(u32 clock, struct compat_sigevent __user *se32, timer_t __user *timer_id)
979{
980 struct sigevent __user *p = NULL;
981 if (se32) {
982 struct sigevent se;
983 p = compat_alloc_user_space(sizeof(struct sigevent));
984 if (get_compat_sigevent(&se, se32) ||
985 copy_to_user(p, &se, sizeof(se)))
986 return -EFAULT;
987 }
988 return sys_timer_create(clock, p, timer_id);
989}
990
991long sys32_fadvise64_64(int fd, __u32 offset_low, __u32 offset_high,
992 __u32 len_low, __u32 len_high, int advice)
993{
994 return sys_fadvise64_64(fd,
995 (((u64)offset_high)<<32) | offset_low,
996 (((u64)len_high)<<32) | len_low,
997 advice);
998}
999
1000long sys32_vm86_warning(void)
1001{
1002 struct task_struct *me = current;
1003 static char lastcomm[sizeof(me->comm)];
1004 if (strncmp(lastcomm, me->comm, sizeof(lastcomm))) {
1005 printk(KERN_INFO "%s: vm86 mode not supported on 64 bit kernel\n",
1006 me->comm);
1007 strncpy(lastcomm, me->comm, sizeof(lastcomm));
1008 }
1009 return -ENOSYS;
1010}
1011
1012long sys32_lookup_dcookie(u32 addr_low, u32 addr_high,
1013 char __user * buf, size_t len)
1014{
1015 return sys_lookup_dcookie(((u64)addr_high << 32) | addr_low, buf, len);
1016}
1017
1018static int __init ia32_init (void)
1019{
1020 printk("IA32 emulation $Id: sys_ia32.c,v 1.32 2002/03/24 13:02:28 ak Exp $\n");
1021 return 0;
1022}
1023
1024__initcall(ia32_init);
1025
1026extern unsigned long ia32_sys_call_table[];
1027EXPORT_SYMBOL(ia32_sys_call_table);