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