blob: ee30557629dc0c4252c545724fb6af1a81102ac7 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/smp.h>
34#include <linux/smp_lock.h>
35#include <linux/sem.h>
36#include <linux/msg.h>
37#include <linux/mm.h>
38#include <linux/shm.h>
39#include <linux/slab.h>
40#include <linux/uio.h>
41#include <linux/nfs_fs.h>
42#include <linux/quota.h>
43#include <linux/module.h>
44#include <linux/sunrpc/svc.h>
45#include <linux/nfsd/nfsd.h>
46#include <linux/nfsd/cache.h>
47#include <linux/nfsd/xdr.h>
48#include <linux/nfsd/syscall.h>
49#include <linux/poll.h>
50#include <linux/personality.h>
51#include <linux/stat.h>
52#include <linux/ipc.h>
53#include <linux/rwsem.h>
54#include <linux/binfmts.h>
55#include <linux/init.h>
56#include <linux/aio_abi.h>
57#include <linux/aio.h>
58#include <linux/compat.h>
59#include <linux/vfs.h>
60#include <linux/ptrace.h>
61#include <linux/highuid.h>
62#include <linux/vmalloc.h>
Andrew Morton9e566d82005-07-26 21:41:38 -070063#include <linux/fsnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070064#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>
70
71#include <net/scm.h>
72#include <net/sock.h>
73#include <asm/ia32.h>
74
75#define AA(__x) ((unsigned long)(__x))
76
77int cp_compat_stat(struct kstat *kbuf, struct compat_stat __user *ubuf)
78{
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;
106}
107
108asmlinkage long
109sys32_truncate64(char __user * filename, unsigned long offset_low, unsigned long offset_high)
110{
111 return sys_truncate(filename, ((loff_t) offset_high << 32) | offset_low);
112}
113
114asmlinkage long
115sys32_ftruncate64(unsigned int fd, unsigned long offset_low, unsigned long offset_high)
116{
117 return sys_ftruncate(fd, ((loff_t) offset_high << 32) | offset_low);
118}
119
120/* Another set for IA32/LFS -- x86_64 struct stat is different due to
121 support for 64bit inode numbers. */
122
123static int
124cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
125{
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;
150}
151
152asmlinkage long
153sys32_stat64(char __user * filename, struct stat64 __user *statbuf)
154{
155 struct kstat stat;
156 int ret = vfs_stat(filename, &stat);
157 if (!ret)
158 ret = cp_stat64(statbuf, &stat);
159 return ret;
160}
161
162asmlinkage long
163sys32_lstat64(char __user * filename, struct stat64 __user *statbuf)
164{
165 struct kstat stat;
166 int ret = vfs_lstat(filename, &stat);
167 if (!ret)
168 ret = cp_stat64(statbuf, &stat);
169 return ret;
170}
171
172asmlinkage long
173sys32_fstat64(unsigned int fd, struct stat64 __user *statbuf)
174{
175 struct kstat stat;
176 int ret = vfs_fstat(fd, &stat);
177 if (!ret)
178 ret = cp_stat64(statbuf, &stat);
179 return ret;
180}
181
Ulrich Dreppercff2b762006-02-11 17:55:47 -0800182asmlinkage long
183sys32_fstatat(unsigned int dfd, char __user *filename,
184 struct stat64 __user* statbuf, int flag)
185{
186 struct kstat stat;
187 int error = -EINVAL;
188
189 if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
190 goto out;
191
192 if (flag & AT_SYMLINK_NOFOLLOW)
193 error = vfs_lstat_fd(dfd, filename, &stat);
194 else
195 error = vfs_stat_fd(dfd, filename, &stat);
196
197 if (!error)
198 error = cp_stat64(statbuf, &stat);
199
200out:
201 return error;
202}
203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204/*
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..
208 */
209
210struct 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;
217};
218
219asmlinkage long
220sys32_mmap(struct mmap_arg_struct __user *arg)
221{
222 struct mmap_arg_struct a;
223 struct file *file = NULL;
224 unsigned long retval;
225 struct mm_struct *mm ;
226
227 if (copy_from_user(&a, arg, sizeof(a)))
228 return -EFAULT;
229
230 if (a.offset & ~PAGE_MASK)
231 return -EINVAL;
232
233 if (!(a.flags & MAP_ANONYMOUS)) {
234 file = fget(a.fd);
235 if (!file)
236 return -EBADF;
237 }
238
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);
244
245 up_write(&mm->mmap_sem);
246
247 return retval;
248}
249
250asmlinkage long
251sys32_mprotect(unsigned long start, size_t len, unsigned long prot)
252{
253 return sys_mprotect(start,len,prot);
254}
255
256asmlinkage long
257sys32_pipe(int __user *fd)
258{
259 int retval;
260 int fds[2];
261
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;
269}
270
271asmlinkage long
272sys32_rt_sigaction(int sig, struct sigaction32 __user *act,
273 struct sigaction32 __user *oact, unsigned int sigsetsize)
274{
275 struct k_sigaction new_ka, old_ka;
276 int ret;
277 compat_sigset_t set32;
278
279 /* XXX: Don't preclude handling different sized sigset_t's. */
280 if (sigsetsize != sizeof(compat_sigset_t))
281 return -EINVAL;
282
283 if (act) {
284 compat_uptr_t handler, restorer;
285
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);
304 }
305 }
306
307 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
308
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];
324 }
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;
331 }
332
333 return ret;
334}
335
336asmlinkage long
337sys32_sigaction (int sig, struct old_sigaction32 __user *act, struct old_sigaction32 __user *oact)
338{
339 struct k_sigaction new_ka, old_ka;
340 int ret;
341
342 if (act) {
343 compat_old_sigset_t mask;
344 compat_uptr_t handler, restorer;
345
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;
352
353 new_ka.sa.sa_handler = compat_ptr(handler);
354 new_ka.sa.sa_restorer = compat_ptr(restorer);
355
356 siginitset(&new_ka.sa.sa_mask, mask);
357 }
358
359 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
360
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;
368 }
369
370 return ret;
371}
372
373asmlinkage long
374sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
375 compat_sigset_t __user *oset, unsigned int sigsetsize)
376{
377 sigset_t s;
378 compat_sigset_t s32;
379 int ret;
380 mm_segment_t old_fs = get_fs();
381
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);
390 }
391 }
392 set_fs (KERNEL_DS);
393 ret = sys_rt_sigprocmask(how, set ? &s : NULL, oset ? &s : NULL,
394 sigsetsize);
395 set_fs (old_fs);
396 if (ret) return ret;
397 if (oset) {
398 switch (_NSIG_WORDS) {
399 case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
400 case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
401 case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
402 case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
403 }
404 if (copy_to_user (oset, &s32, sizeof(compat_sigset_t)))
405 return -EFAULT;
406 }
407 return 0;
408}
409
410static inline long
411get_tv32(struct timeval *o, struct compat_timeval __user *i)
412{
413 int err = -EFAULT;
414 if (access_ok(VERIFY_READ, i, sizeof(*i))) {
415 err = __get_user(o->tv_sec, &i->tv_sec);
416 err |= __get_user(o->tv_usec, &i->tv_usec);
417 }
418 return err;
419}
420
421static inline long
422put_tv32(struct compat_timeval __user *o, struct timeval *i)
423{
424 int err = -EFAULT;
425 if (access_ok(VERIFY_WRITE, o, sizeof(*o))) {
426 err = __put_user(i->tv_sec, &o->tv_sec);
427 err |= __put_user(i->tv_usec, &o->tv_usec);
428 }
429 return err;
430}
431
Thomas Gleixnerc08b8a42006-03-25 03:06:33 -0800432extern unsigned int alarm_setitimer(unsigned int seconds);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
434asmlinkage long
435sys32_alarm(unsigned int seconds)
436{
Thomas Gleixnerc08b8a42006-03-25 03:06:33 -0800437 return alarm_setitimer(seconds);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438}
439
440/* Translations due to time_t size differences. Which affects all
441 sorts of things, like timeval and itimerval. */
442
443extern struct timezone sys_tz;
444
445asmlinkage long
446sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
447{
448 if (tv) {
449 struct timeval ktv;
450 do_gettimeofday(&ktv);
451 if (put_tv32(tv, &ktv))
452 return -EFAULT;
453 }
454 if (tz) {
455 if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
456 return -EFAULT;
457 }
458 return 0;
459}
460
461asmlinkage long
462sys32_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
463{
464 struct timeval ktv;
465 struct timespec kts;
466 struct timezone ktz;
467
468 if (tv) {
469 if (get_tv32(&ktv, tv))
470 return -EFAULT;
471 kts.tv_sec = ktv.tv_sec;
472 kts.tv_nsec = ktv.tv_usec * NSEC_PER_USEC;
473 }
474 if (tz) {
475 if (copy_from_user(&ktz, tz, sizeof(ktz)))
476 return -EFAULT;
477 }
478
479 return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
480}
481
482struct sel_arg_struct {
483 unsigned int n;
484 unsigned int inp;
485 unsigned int outp;
486 unsigned int exp;
487 unsigned int tvp;
488};
489
490asmlinkage long
491sys32_old_select(struct sel_arg_struct __user *arg)
492{
493 struct sel_arg_struct a;
494
495 if (copy_from_user(&a, arg, sizeof(a)))
496 return -EFAULT;
497 return compat_sys_select(a.n, compat_ptr(a.inp), compat_ptr(a.outp),
498 compat_ptr(a.exp), compat_ptr(a.tvp));
499}
500
501extern asmlinkage long
502compat_sys_wait4(compat_pid_t pid, compat_uint_t * stat_addr, int options,
503 struct compat_rusage *ru);
504
505asmlinkage long
506sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr, int options)
507{
508 return compat_sys_wait4(pid, stat_addr, options, NULL);
509}
510
511int sys32_ni_syscall(int call)
512{
513 struct task_struct *me = current;
514 static char lastcomm[sizeof(me->comm)];
515
516 if (strncmp(lastcomm, me->comm, sizeof(lastcomm))) {
Andi Kleenbebfa102006-06-26 13:56:52 +0200517 compat_printk(KERN_INFO "IA32 syscall %d from %s not implemented\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 call, me->comm);
519 strncpy(lastcomm, me->comm, sizeof(lastcomm));
520 }
521 return -ENOSYS;
522}
523
524/* 32-bit timeval and related flotsam. */
525
526asmlinkage long
527sys32_sysfs(int option, u32 arg1, u32 arg2)
528{
529 return sys_sysfs(option, arg1, arg2);
530}
531
532struct sysinfo32 {
533 s32 uptime;
534 u32 loads[3];
535 u32 totalram;
536 u32 freeram;
537 u32 sharedram;
538 u32 bufferram;
539 u32 totalswap;
540 u32 freeswap;
541 unsigned short procs;
542 unsigned short pad;
543 u32 totalhigh;
544 u32 freehigh;
545 u32 mem_unit;
546 char _f[20-2*sizeof(u32)-sizeof(int)];
547};
548
549asmlinkage long
550sys32_sysinfo(struct sysinfo32 __user *info)
551{
552 struct sysinfo s;
553 int ret;
554 mm_segment_t old_fs = get_fs ();
555 int bitcount = 0;
556
557 set_fs (KERNEL_DS);
558 ret = sys_sysinfo(&s);
559 set_fs (old_fs);
560
561 /* Check to see if any memory value is too large for 32-bit and scale
562 * down if needed
563 */
564 if ((s.totalram >> 32) || (s.totalswap >> 32)) {
565 while (s.mem_unit < PAGE_SIZE) {
566 s.mem_unit <<= 1;
567 bitcount++;
568 }
569 s.totalram >>= bitcount;
570 s.freeram >>= bitcount;
571 s.sharedram >>= bitcount;
572 s.bufferram >>= bitcount;
573 s.totalswap >>= bitcount;
574 s.freeswap >>= bitcount;
575 s.totalhigh >>= bitcount;
576 s.freehigh >>= bitcount;
577 }
578
579 if (!access_ok(VERIFY_WRITE, info, sizeof(struct sysinfo32)) ||
580 __put_user (s.uptime, &info->uptime) ||
581 __put_user (s.loads[0], &info->loads[0]) ||
582 __put_user (s.loads[1], &info->loads[1]) ||
583 __put_user (s.loads[2], &info->loads[2]) ||
584 __put_user (s.totalram, &info->totalram) ||
585 __put_user (s.freeram, &info->freeram) ||
586 __put_user (s.sharedram, &info->sharedram) ||
587 __put_user (s.bufferram, &info->bufferram) ||
588 __put_user (s.totalswap, &info->totalswap) ||
589 __put_user (s.freeswap, &info->freeswap) ||
590 __put_user (s.procs, &info->procs) ||
591 __put_user (s.totalhigh, &info->totalhigh) ||
592 __put_user (s.freehigh, &info->freehigh) ||
593 __put_user (s.mem_unit, &info->mem_unit))
594 return -EFAULT;
595 return 0;
596}
597
598asmlinkage long
599sys32_sched_rr_get_interval(compat_pid_t pid, struct compat_timespec __user *interval)
600{
601 struct timespec t;
602 int ret;
603 mm_segment_t old_fs = get_fs ();
604
605 set_fs (KERNEL_DS);
606 ret = sys_sched_rr_get_interval(pid, &t);
607 set_fs (old_fs);
608 if (put_compat_timespec(&t, interval))
609 return -EFAULT;
610 return ret;
611}
612
613asmlinkage long
614sys32_rt_sigpending(compat_sigset_t __user *set, compat_size_t sigsetsize)
615{
616 sigset_t s;
617 compat_sigset_t s32;
618 int ret;
619 mm_segment_t old_fs = get_fs();
620
621 set_fs (KERNEL_DS);
622 ret = sys_rt_sigpending(&s, sigsetsize);
623 set_fs (old_fs);
624 if (!ret) {
625 switch (_NSIG_WORDS) {
626 case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
627 case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
628 case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
629 case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
630 }
631 if (copy_to_user (set, &s32, sizeof(compat_sigset_t)))
632 return -EFAULT;
633 }
634 return ret;
635}
636
637asmlinkage long
638sys32_rt_sigqueueinfo(int pid, int sig, compat_siginfo_t __user *uinfo)
639{
640 siginfo_t info;
641 int ret;
642 mm_segment_t old_fs = get_fs();
643
644 if (copy_siginfo_from_user32(&info, uinfo))
645 return -EFAULT;
646 set_fs (KERNEL_DS);
647 ret = sys_rt_sigqueueinfo(pid, sig, &info);
648 set_fs (old_fs);
649 return ret;
650}
651
652/* These are here just in case some old ia32 binary calls it. */
653asmlinkage long
654sys32_pause(void)
655{
656 current->state = TASK_INTERRUPTIBLE;
657 schedule();
658 return -ERESTARTNOHAND;
659}
660
661
662#ifdef CONFIG_SYSCTL
663struct sysctl_ia32 {
664 unsigned int name;
665 int nlen;
666 unsigned int oldval;
667 unsigned int oldlenp;
668 unsigned int newval;
669 unsigned int newlen;
670 unsigned int __unused[4];
671};
672
673
674asmlinkage long
675sys32_sysctl(struct sysctl_ia32 __user *args32)
676{
677 struct sysctl_ia32 a32;
678 mm_segment_t old_fs = get_fs ();
679 void __user *oldvalp, *newvalp;
680 size_t oldlen;
681 int __user *namep;
682 long ret;
683 extern int do_sysctl(int *name, int nlen, void *oldval, size_t *oldlenp,
684 void *newval, size_t newlen);
685
686
687 if (copy_from_user(&a32, args32, sizeof (a32)))
688 return -EFAULT;
689
690 /*
691 * We need to pre-validate these because we have to disable address checking
692 * before calling do_sysctl() because of OLDLEN but we can't run the risk of the
693 * user specifying bad addresses here. Well, since we're dealing with 32 bit
694 * addresses, we KNOW that access_ok() will always succeed, so this is an
695 * expensive NOP, but so what...
696 */
697 namep = compat_ptr(a32.name);
698 oldvalp = compat_ptr(a32.oldval);
699 newvalp = compat_ptr(a32.newval);
700
701 if ((oldvalp && get_user(oldlen, (int __user *)compat_ptr(a32.oldlenp)))
702 || !access_ok(VERIFY_WRITE, namep, 0)
703 || !access_ok(VERIFY_WRITE, oldvalp, 0)
704 || !access_ok(VERIFY_WRITE, newvalp, 0))
705 return -EFAULT;
706
707 set_fs(KERNEL_DS);
708 lock_kernel();
709 ret = do_sysctl(namep, a32.nlen, oldvalp, &oldlen, newvalp, (size_t) a32.newlen);
710 unlock_kernel();
711 set_fs(old_fs);
712
713 if (oldvalp && put_user (oldlen, (int __user *)compat_ptr(a32.oldlenp)))
714 return -EFAULT;
715
716 return ret;
717}
718#endif
719
720/* warning: next two assume little endian */
721asmlinkage long
722sys32_pread(unsigned int fd, char __user *ubuf, u32 count, u32 poslo, u32 poshi)
723{
724 return sys_pread64(fd, ubuf, count,
725 ((loff_t)AA(poshi) << 32) | AA(poslo));
726}
727
728asmlinkage long
729sys32_pwrite(unsigned int fd, char __user *ubuf, u32 count, u32 poslo, u32 poshi)
730{
731 return sys_pwrite64(fd, ubuf, count,
732 ((loff_t)AA(poshi) << 32) | AA(poslo));
733}
734
735
736asmlinkage long
737sys32_personality(unsigned long personality)
738{
739 int ret;
740 if (personality(current->personality) == PER_LINUX32 &&
741 personality == PER_LINUX)
742 personality = PER_LINUX32;
743 ret = sys_personality(personality);
744 if (ret == PER_LINUX32)
745 ret = PER_LINUX;
746 return ret;
747}
748
749asmlinkage long
750sys32_sendfile(int out_fd, int in_fd, compat_off_t __user *offset, s32 count)
751{
752 mm_segment_t old_fs = get_fs();
753 int ret;
754 off_t of;
755
756 if (offset && get_user(of, offset))
757 return -EFAULT;
758
759 set_fs(KERNEL_DS);
760 ret = sys_sendfile(out_fd, in_fd, offset ? &of : NULL, count);
761 set_fs(old_fs);
762
Tsuneo.Yoshioka@f-secure.com83b942b2005-09-12 18:49:24 +0200763 if (offset && put_user(of, offset))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 return -EFAULT;
765
766 return ret;
767}
768
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769asmlinkage long sys32_mmap2(unsigned long addr, unsigned long len,
770 unsigned long prot, unsigned long flags,
771 unsigned long fd, unsigned long pgoff)
772{
773 struct mm_struct *mm = current->mm;
774 unsigned long error;
775 struct file * file = NULL;
776
777 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
778 if (!(flags & MAP_ANONYMOUS)) {
779 file = fget(fd);
780 if (!file)
781 return -EBADF;
782 }
783
784 down_write(&mm->mmap_sem);
785 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
786 up_write(&mm->mmap_sem);
787
788 if (file)
789 fput(file);
790 return error;
791}
792
793asmlinkage long sys32_olduname(struct oldold_utsname __user * name)
794{
795 int error;
796
797 if (!name)
798 return -EFAULT;
799 if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
800 return -EFAULT;
801
802 down_read(&uts_sem);
803
804 error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
805 __put_user(0,name->sysname+__OLD_UTS_LEN);
806 __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
807 __put_user(0,name->nodename+__OLD_UTS_LEN);
808 __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
809 __put_user(0,name->release+__OLD_UTS_LEN);
810 __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
811 __put_user(0,name->version+__OLD_UTS_LEN);
812 {
813 char *arch = "x86_64";
814 if (personality(current->personality) == PER_LINUX32)
815 arch = "i686";
816
817 __copy_to_user(&name->machine,arch,strlen(arch)+1);
818 }
819
820 up_read(&uts_sem);
821
822 error = error ? -EFAULT : 0;
823
824 return error;
825}
826
827long sys32_uname(struct old_utsname __user * name)
828{
829 int err;
830 if (!name)
831 return -EFAULT;
832 down_read(&uts_sem);
833 err=copy_to_user(name, &system_utsname, sizeof (*name));
834 up_read(&uts_sem);
835 if (personality(current->personality) == PER_LINUX32)
836 err |= copy_to_user(&name->machine, "i686", 5);
837 return err?-EFAULT:0;
838}
839
840long sys32_ustat(unsigned dev, struct ustat32 __user *u32p)
841{
842 struct ustat u;
843 mm_segment_t seg;
844 int ret;
845
846 seg = get_fs();
847 set_fs(KERNEL_DS);
848 ret = sys_ustat(dev,&u);
849 set_fs(seg);
850 if (ret >= 0) {
851 if (!access_ok(VERIFY_WRITE,u32p,sizeof(struct ustat32)) ||
852 __put_user((__u32) u.f_tfree, &u32p->f_tfree) ||
853 __put_user((__u32) u.f_tinode, &u32p->f_tfree) ||
854 __copy_to_user(&u32p->f_fname, u.f_fname, sizeof(u.f_fname)) ||
855 __copy_to_user(&u32p->f_fpack, u.f_fpack, sizeof(u.f_fpack)))
856 ret = -EFAULT;
857 }
858 return ret;
859}
860
861asmlinkage long sys32_execve(char __user *name, compat_uptr_t __user *argv,
862 compat_uptr_t __user *envp, struct pt_regs *regs)
863{
864 long error;
865 char * filename;
866
867 filename = getname(name);
868 error = PTR_ERR(filename);
869 if (IS_ERR(filename))
870 return error;
871 error = compat_do_execve(filename, argv, envp, regs);
872 if (error == 0) {
873 task_lock(current);
874 current->ptrace &= ~PT_DTRACE;
875 task_unlock(current);
876 }
877 putname(filename);
878 return error;
879}
880
881asmlinkage long sys32_clone(unsigned int clone_flags, unsigned int newsp,
882 struct pt_regs *regs)
883{
884 void __user *parent_tid = (void __user *)regs->rdx;
885 void __user *child_tid = (void __user *)regs->rdi;
886 if (!newsp)
887 newsp = regs->rsp;
888 return do_fork(clone_flags, newsp, regs, 0, parent_tid, child_tid);
889}
890
891/*
892 * Some system calls that need sign extended arguments. This could be done by a generic wrapper.
893 */
894
895long sys32_lseek (unsigned int fd, int offset, unsigned int whence)
896{
897 return sys_lseek(fd, offset, whence);
898}
899
900long sys32_kill(int pid, int sig)
901{
902 return sys_kill(pid, sig);
903}
904
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905long sys32_fadvise64_64(int fd, __u32 offset_low, __u32 offset_high,
906 __u32 len_low, __u32 len_high, int advice)
907{
908 return sys_fadvise64_64(fd,
909 (((u64)offset_high)<<32) | offset_low,
910 (((u64)len_high)<<32) | len_low,
911 advice);
912}
913
914long sys32_vm86_warning(void)
915{
916 struct task_struct *me = current;
917 static char lastcomm[sizeof(me->comm)];
918 if (strncmp(lastcomm, me->comm, sizeof(lastcomm))) {
Andi Kleenbebfa102006-06-26 13:56:52 +0200919 compat_printk(KERN_INFO "%s: vm86 mode not supported on 64 bit kernel\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 me->comm);
921 strncpy(lastcomm, me->comm, sizeof(lastcomm));
922 }
923 return -ENOSYS;
924}
925
926long sys32_lookup_dcookie(u32 addr_low, u32 addr_high,
927 char __user * buf, size_t len)
928{
929 return sys_lookup_dcookie(((u64)addr_high << 32) | addr_low, buf, len);
930}
931
932static int __init ia32_init (void)
933{
934 printk("IA32 emulation $Id: sys_ia32.c,v 1.32 2002/03/24 13:02:28 ak Exp $\n");
935 return 0;
936}
937
938__initcall(ia32_init);
939
940extern unsigned long ia32_sys_call_table[];
941EXPORT_SYMBOL(ia32_sys_call_table);