7cede7a9e0dc4831cf80349ce2a049b88cf8cab8
[deliverable/linux.git] / arch / x86 / ia32 / sys_ia32.c
1 /*
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
20 * hopefully all marked. This should be fixed.
21 */
22
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/times.h>
30 #include <linux/utsname.h>
31 #include <linux/smp_lock.h>
32 #include <linux/mm.h>
33 #include <linux/uio.h>
34 #include <linux/poll.h>
35 #include <linux/personality.h>
36 #include <linux/stat.h>
37 #include <linux/rwsem.h>
38 #include <linux/compat.h>
39 #include <linux/vfs.h>
40 #include <linux/ptrace.h>
41 #include <linux/highuid.h>
42 #include <linux/sysctl.h>
43 #include <asm/mman.h>
44 #include <asm/types.h>
45 #include <asm/uaccess.h>
46 #include <asm/semaphore.h>
47 #include <asm/atomic.h>
48 #include <asm/ia32.h>
49 #include <asm/vgtod.h>
50
51 #define AA(__x) ((unsigned long)(__x))
52
53 int cp_compat_stat(struct kstat *kbuf, struct compat_stat __user *ubuf)
54 {
55 compat_ino_t ino;
56
57 typeof(ubuf->st_uid) uid = 0;
58 typeof(ubuf->st_gid) gid = 0;
59 SET_UID(uid, kbuf->uid);
60 SET_GID(gid, kbuf->gid);
61 if (!old_valid_dev(kbuf->dev) || !old_valid_dev(kbuf->rdev))
62 return -EOVERFLOW;
63 if (kbuf->size >= 0x7fffffff)
64 return -EOVERFLOW;
65 ino = kbuf->ino;
66 if (sizeof(ino) < sizeof(kbuf->ino) && ino != kbuf->ino)
67 return -EOVERFLOW;
68 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct compat_stat)) ||
69 __put_user(old_encode_dev(kbuf->dev), &ubuf->st_dev) ||
70 __put_user(ino, &ubuf->st_ino) ||
71 __put_user(kbuf->mode, &ubuf->st_mode) ||
72 __put_user(kbuf->nlink, &ubuf->st_nlink) ||
73 __put_user(uid, &ubuf->st_uid) ||
74 __put_user(gid, &ubuf->st_gid) ||
75 __put_user(old_encode_dev(kbuf->rdev), &ubuf->st_rdev) ||
76 __put_user(kbuf->size, &ubuf->st_size) ||
77 __put_user(kbuf->atime.tv_sec, &ubuf->st_atime) ||
78 __put_user(kbuf->atime.tv_nsec, &ubuf->st_atime_nsec) ||
79 __put_user(kbuf->mtime.tv_sec, &ubuf->st_mtime) ||
80 __put_user(kbuf->mtime.tv_nsec, &ubuf->st_mtime_nsec) ||
81 __put_user(kbuf->ctime.tv_sec, &ubuf->st_ctime) ||
82 __put_user(kbuf->ctime.tv_nsec, &ubuf->st_ctime_nsec) ||
83 __put_user(kbuf->blksize, &ubuf->st_blksize) ||
84 __put_user(kbuf->blocks, &ubuf->st_blocks))
85 return -EFAULT;
86 return 0;
87 }
88
89 asmlinkage long sys32_truncate64(char __user *filename,
90 unsigned long offset_low,
91 unsigned long offset_high)
92 {
93 return sys_truncate(filename, ((loff_t) offset_high << 32) | offset_low);
94 }
95
96 asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
97 unsigned long offset_high)
98 {
99 return sys_ftruncate(fd, ((loff_t) offset_high << 32) | offset_low);
100 }
101
102 /*
103 * Another set for IA32/LFS -- x86_64 struct stat is different due to
104 * support for 64bit inode numbers.
105 */
106 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
107 {
108 typeof(ubuf->st_uid) uid = 0;
109 typeof(ubuf->st_gid) gid = 0;
110 SET_UID(uid, stat->uid);
111 SET_GID(gid, stat->gid);
112 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
113 __put_user(huge_encode_dev(stat->dev), &ubuf->st_dev) ||
114 __put_user(stat->ino, &ubuf->__st_ino) ||
115 __put_user(stat->ino, &ubuf->st_ino) ||
116 __put_user(stat->mode, &ubuf->st_mode) ||
117 __put_user(stat->nlink, &ubuf->st_nlink) ||
118 __put_user(uid, &ubuf->st_uid) ||
119 __put_user(gid, &ubuf->st_gid) ||
120 __put_user(huge_encode_dev(stat->rdev), &ubuf->st_rdev) ||
121 __put_user(stat->size, &ubuf->st_size) ||
122 __put_user(stat->atime.tv_sec, &ubuf->st_atime) ||
123 __put_user(stat->atime.tv_nsec, &ubuf->st_atime_nsec) ||
124 __put_user(stat->mtime.tv_sec, &ubuf->st_mtime) ||
125 __put_user(stat->mtime.tv_nsec, &ubuf->st_mtime_nsec) ||
126 __put_user(stat->ctime.tv_sec, &ubuf->st_ctime) ||
127 __put_user(stat->ctime.tv_nsec, &ubuf->st_ctime_nsec) ||
128 __put_user(stat->blksize, &ubuf->st_blksize) ||
129 __put_user(stat->blocks, &ubuf->st_blocks))
130 return -EFAULT;
131 return 0;
132 }
133
134 asmlinkage long sys32_stat64(char __user *filename,
135 struct stat64 __user *statbuf)
136 {
137 struct kstat stat;
138 int ret = vfs_stat(filename, &stat);
139
140 if (!ret)
141 ret = cp_stat64(statbuf, &stat);
142 return ret;
143 }
144
145 asmlinkage long sys32_lstat64(char __user *filename,
146 struct stat64 __user *statbuf)
147 {
148 struct kstat stat;
149 int ret = vfs_lstat(filename, &stat);
150 if (!ret)
151 ret = cp_stat64(statbuf, &stat);
152 return ret;
153 }
154
155 asmlinkage long sys32_fstat64(unsigned int fd, struct stat64 __user *statbuf)
156 {
157 struct kstat stat;
158 int ret = vfs_fstat(fd, &stat);
159 if (!ret)
160 ret = cp_stat64(statbuf, &stat);
161 return ret;
162 }
163
164 asmlinkage long sys32_fstatat(unsigned int dfd, char __user *filename,
165 struct stat64 __user *statbuf, int flag)
166 {
167 struct kstat stat;
168 int error = -EINVAL;
169
170 if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
171 goto out;
172
173 if (flag & AT_SYMLINK_NOFOLLOW)
174 error = vfs_lstat_fd(dfd, filename, &stat);
175 else
176 error = vfs_stat_fd(dfd, filename, &stat);
177
178 if (!error)
179 error = cp_stat64(statbuf, &stat);
180
181 out:
182 return error;
183 }
184
185 /*
186 * Linux/i386 didn't use to be able to handle more than
187 * 4 system call parameters, so these system calls used a memory
188 * block for parameter passing..
189 */
190
191 struct mmap_arg_struct {
192 unsigned int addr;
193 unsigned int len;
194 unsigned int prot;
195 unsigned int flags;
196 unsigned int fd;
197 unsigned int offset;
198 };
199
200 asmlinkage long sys32_mmap(struct mmap_arg_struct __user *arg)
201 {
202 struct mmap_arg_struct a;
203 struct file *file = NULL;
204 unsigned long retval;
205 struct mm_struct *mm ;
206
207 if (copy_from_user(&a, arg, sizeof(a)))
208 return -EFAULT;
209
210 if (a.offset & ~PAGE_MASK)
211 return -EINVAL;
212
213 if (!(a.flags & MAP_ANONYMOUS)) {
214 file = fget(a.fd);
215 if (!file)
216 return -EBADF;
217 }
218
219 mm = current->mm;
220 down_write(&mm->mmap_sem);
221 retval = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags,
222 a.offset>>PAGE_SHIFT);
223 if (file)
224 fput(file);
225
226 up_write(&mm->mmap_sem);
227
228 return retval;
229 }
230
231 asmlinkage long sys32_mprotect(unsigned long start, size_t len,
232 unsigned long prot)
233 {
234 return sys_mprotect(start, len, prot);
235 }
236
237 asmlinkage long sys32_pipe(int __user *fd)
238 {
239 int retval;
240 int fds[2];
241
242 retval = do_pipe(fds);
243 if (retval)
244 goto out;
245 if (copy_to_user(fd, fds, sizeof(fds)))
246 retval = -EFAULT;
247 out:
248 return retval;
249 }
250
251 asmlinkage long sys32_rt_sigaction(int sig, struct sigaction32 __user *act,
252 struct sigaction32 __user *oact,
253 unsigned int sigsetsize)
254 {
255 struct k_sigaction new_ka, old_ka;
256 int ret;
257 compat_sigset_t set32;
258
259 /* XXX: Don't preclude handling different sized sigset_t's. */
260 if (sigsetsize != sizeof(compat_sigset_t))
261 return -EINVAL;
262
263 if (act) {
264 compat_uptr_t handler, restorer;
265
266 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
267 __get_user(handler, &act->sa_handler) ||
268 __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
269 __get_user(restorer, &act->sa_restorer) ||
270 __copy_from_user(&set32, &act->sa_mask,
271 sizeof(compat_sigset_t)))
272 return -EFAULT;
273 new_ka.sa.sa_handler = compat_ptr(handler);
274 new_ka.sa.sa_restorer = compat_ptr(restorer);
275
276 /*
277 * FIXME: here we rely on _COMPAT_NSIG_WORS to be >=
278 * than _NSIG_WORDS << 1
279 */
280 switch (_NSIG_WORDS) {
281 case 4: new_ka.sa.sa_mask.sig[3] = set32.sig[6]
282 | (((long)set32.sig[7]) << 32);
283 case 3: new_ka.sa.sa_mask.sig[2] = set32.sig[4]
284 | (((long)set32.sig[5]) << 32);
285 case 2: new_ka.sa.sa_mask.sig[1] = set32.sig[2]
286 | (((long)set32.sig[3]) << 32);
287 case 1: new_ka.sa.sa_mask.sig[0] = set32.sig[0]
288 | (((long)set32.sig[1]) << 32);
289 }
290 }
291
292 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
293
294 if (!ret && oact) {
295 /*
296 * FIXME: here we rely on _COMPAT_NSIG_WORS to be >=
297 * than _NSIG_WORDS << 1
298 */
299 switch (_NSIG_WORDS) {
300 case 4:
301 set32.sig[7] = (old_ka.sa.sa_mask.sig[3] >> 32);
302 set32.sig[6] = old_ka.sa.sa_mask.sig[3];
303 case 3:
304 set32.sig[5] = (old_ka.sa.sa_mask.sig[2] >> 32);
305 set32.sig[4] = old_ka.sa.sa_mask.sig[2];
306 case 2:
307 set32.sig[3] = (old_ka.sa.sa_mask.sig[1] >> 32);
308 set32.sig[2] = old_ka.sa.sa_mask.sig[1];
309 case 1:
310 set32.sig[1] = (old_ka.sa.sa_mask.sig[0] >> 32);
311 set32.sig[0] = old_ka.sa.sa_mask.sig[0];
312 }
313 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
314 __put_user(ptr_to_compat(old_ka.sa.sa_handler),
315 &oact->sa_handler) ||
316 __put_user(ptr_to_compat(old_ka.sa.sa_restorer),
317 &oact->sa_restorer) ||
318 __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
319 __copy_to_user(&oact->sa_mask, &set32,
320 sizeof(compat_sigset_t)))
321 return -EFAULT;
322 }
323
324 return ret;
325 }
326
327 asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
328 struct old_sigaction32 __user *oact)
329 {
330 struct k_sigaction new_ka, old_ka;
331 int ret;
332
333 if (act) {
334 compat_old_sigset_t mask;
335 compat_uptr_t handler, restorer;
336
337 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
338 __get_user(handler, &act->sa_handler) ||
339 __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
340 __get_user(restorer, &act->sa_restorer) ||
341 __get_user(mask, &act->sa_mask))
342 return -EFAULT;
343
344 new_ka.sa.sa_handler = compat_ptr(handler);
345 new_ka.sa.sa_restorer = compat_ptr(restorer);
346
347 siginitset(&new_ka.sa.sa_mask, mask);
348 }
349
350 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
351
352 if (!ret && oact) {
353 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
354 __put_user(ptr_to_compat(old_ka.sa.sa_handler),
355 &oact->sa_handler) ||
356 __put_user(ptr_to_compat(old_ka.sa.sa_restorer),
357 &oact->sa_restorer) ||
358 __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
359 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
360 return -EFAULT;
361 }
362
363 return ret;
364 }
365
366 asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
367 compat_sigset_t __user *oset,
368 unsigned int sigsetsize)
369 {
370 sigset_t s;
371 compat_sigset_t s32;
372 int ret;
373 mm_segment_t old_fs = get_fs();
374
375 if (set) {
376 if (copy_from_user(&s32, set, sizeof(compat_sigset_t)))
377 return -EFAULT;
378 switch (_NSIG_WORDS) {
379 case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
380 case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
381 case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
382 case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
383 }
384 }
385 set_fs(KERNEL_DS);
386 ret = sys_rt_sigprocmask(how,
387 set ? (sigset_t __user *)&s : NULL,
388 oset ? (sigset_t __user *)&s : NULL,
389 sigsetsize);
390 set_fs(old_fs);
391 if (ret)
392 return ret;
393 if (oset) {
394 switch (_NSIG_WORDS) {
395 case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
396 case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
397 case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
398 case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
399 }
400 if (copy_to_user(oset, &s32, sizeof(compat_sigset_t)))
401 return -EFAULT;
402 }
403 return 0;
404 }
405
406 static inline long get_tv32(struct timeval *o, struct compat_timeval __user *i)
407 {
408 int err = -EFAULT;
409
410 if (access_ok(VERIFY_READ, i, sizeof(*i))) {
411 err = __get_user(o->tv_sec, &i->tv_sec);
412 err |= __get_user(o->tv_usec, &i->tv_usec);
413 }
414 return err;
415 }
416
417 static inline long put_tv32(struct compat_timeval __user *o, struct timeval *i)
418 {
419 int err = -EFAULT;
420
421 if (access_ok(VERIFY_WRITE, o, sizeof(*o))) {
422 err = __put_user(i->tv_sec, &o->tv_sec);
423 err |= __put_user(i->tv_usec, &o->tv_usec);
424 }
425 return err;
426 }
427
428 asmlinkage long sys32_alarm(unsigned int seconds)
429 {
430 return alarm_setitimer(seconds);
431 }
432
433 /*
434 * Translations due to time_t size differences. Which affects all
435 * sorts of things, like timeval and itimerval.
436 */
437 asmlinkage long sys32_gettimeofday(struct compat_timeval __user *tv,
438 struct timezone __user *tz)
439 {
440 if (tv) {
441 struct timeval ktv;
442
443 do_gettimeofday(&ktv);
444 if (put_tv32(tv, &ktv))
445 return -EFAULT;
446 }
447 if (tz) {
448 if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
449 return -EFAULT;
450 }
451 return 0;
452 }
453
454 asmlinkage long sys32_settimeofday(struct compat_timeval __user *tv,
455 struct timezone __user *tz)
456 {
457 struct timeval ktv;
458 struct timespec kts;
459 struct timezone ktz;
460
461 if (tv) {
462 if (get_tv32(&ktv, tv))
463 return -EFAULT;
464 kts.tv_sec = ktv.tv_sec;
465 kts.tv_nsec = ktv.tv_usec * NSEC_PER_USEC;
466 }
467 if (tz) {
468 if (copy_from_user(&ktz, tz, sizeof(ktz)))
469 return -EFAULT;
470 }
471
472 return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
473 }
474
475 struct sel_arg_struct {
476 unsigned int n;
477 unsigned int inp;
478 unsigned int outp;
479 unsigned int exp;
480 unsigned int tvp;
481 };
482
483 asmlinkage long sys32_old_select(struct sel_arg_struct __user *arg)
484 {
485 struct sel_arg_struct a;
486
487 if (copy_from_user(&a, arg, sizeof(a)))
488 return -EFAULT;
489 return compat_sys_select(a.n, compat_ptr(a.inp), compat_ptr(a.outp),
490 compat_ptr(a.exp), compat_ptr(a.tvp));
491 }
492
493 asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
494 int options)
495 {
496 return compat_sys_wait4(pid, stat_addr, options, NULL);
497 }
498
499 /* 32-bit timeval and related flotsam. */
500
501 asmlinkage long sys32_sysfs(int option, u32 arg1, u32 arg2)
502 {
503 return sys_sysfs(option, arg1, arg2);
504 }
505
506 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
507 struct compat_timespec __user *interval)
508 {
509 struct timespec t;
510 int ret;
511 mm_segment_t old_fs = get_fs();
512
513 set_fs(KERNEL_DS);
514 ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
515 set_fs(old_fs);
516 if (put_compat_timespec(&t, interval))
517 return -EFAULT;
518 return ret;
519 }
520
521 asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
522 compat_size_t sigsetsize)
523 {
524 sigset_t s;
525 compat_sigset_t s32;
526 int ret;
527 mm_segment_t old_fs = get_fs();
528
529 set_fs(KERNEL_DS);
530 ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
531 set_fs(old_fs);
532 if (!ret) {
533 switch (_NSIG_WORDS) {
534 case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
535 case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
536 case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
537 case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
538 }
539 if (copy_to_user(set, &s32, sizeof(compat_sigset_t)))
540 return -EFAULT;
541 }
542 return ret;
543 }
544
545 asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
546 compat_siginfo_t __user *uinfo)
547 {
548 siginfo_t info;
549 int ret;
550 mm_segment_t old_fs = get_fs();
551
552 if (copy_siginfo_from_user32(&info, uinfo))
553 return -EFAULT;
554 set_fs(KERNEL_DS);
555 ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
556 set_fs(old_fs);
557 return ret;
558 }
559
560 /* These are here just in case some old ia32 binary calls it. */
561 asmlinkage long sys32_pause(void)
562 {
563 current->state = TASK_INTERRUPTIBLE;
564 schedule();
565 return -ERESTARTNOHAND;
566 }
567
568
569 #ifdef CONFIG_SYSCTL_SYSCALL
570 struct sysctl_ia32 {
571 unsigned int name;
572 int nlen;
573 unsigned int oldval;
574 unsigned int oldlenp;
575 unsigned int newval;
576 unsigned int newlen;
577 unsigned int __unused[4];
578 };
579
580
581 asmlinkage long sys32_sysctl(struct sysctl_ia32 __user *args32)
582 {
583 struct sysctl_ia32 a32;
584 mm_segment_t old_fs = get_fs();
585 void __user *oldvalp, *newvalp;
586 size_t oldlen;
587 int __user *namep;
588 long ret;
589
590 if (copy_from_user(&a32, args32, sizeof(a32)))
591 return -EFAULT;
592
593 /*
594 * We need to pre-validate these because we have to disable
595 * address checking before calling do_sysctl() because of
596 * OLDLEN but we can't run the risk of the user specifying bad
597 * addresses here. Well, since we're dealing with 32 bit
598 * addresses, we KNOW that access_ok() will always succeed, so
599 * this is an expensive NOP, but so what...
600 */
601 namep = compat_ptr(a32.name);
602 oldvalp = compat_ptr(a32.oldval);
603 newvalp = compat_ptr(a32.newval);
604
605 if ((oldvalp && get_user(oldlen, (int __user *)compat_ptr(a32.oldlenp)))
606 || !access_ok(VERIFY_WRITE, namep, 0)
607 || !access_ok(VERIFY_WRITE, oldvalp, 0)
608 || !access_ok(VERIFY_WRITE, newvalp, 0))
609 return -EFAULT;
610
611 set_fs(KERNEL_DS);
612 lock_kernel();
613 ret = do_sysctl(namep, a32.nlen, oldvalp, (size_t __user *)&oldlen,
614 newvalp, (size_t) a32.newlen);
615 unlock_kernel();
616 set_fs(old_fs);
617
618 if (oldvalp && put_user(oldlen, (int __user *)compat_ptr(a32.oldlenp)))
619 return -EFAULT;
620
621 return ret;
622 }
623 #endif
624
625 /* warning: next two assume little endian */
626 asmlinkage long sys32_pread(unsigned int fd, char __user *ubuf, u32 count,
627 u32 poslo, u32 poshi)
628 {
629 return sys_pread64(fd, ubuf, count,
630 ((loff_t)AA(poshi) << 32) | AA(poslo));
631 }
632
633 asmlinkage long sys32_pwrite(unsigned int fd, char __user *ubuf, u32 count,
634 u32 poslo, u32 poshi)
635 {
636 return sys_pwrite64(fd, ubuf, count,
637 ((loff_t)AA(poshi) << 32) | AA(poslo));
638 }
639
640
641 asmlinkage long sys32_personality(unsigned long personality)
642 {
643 int ret;
644
645 if (personality(current->personality) == PER_LINUX32 &&
646 personality == PER_LINUX)
647 personality = PER_LINUX32;
648 ret = sys_personality(personality);
649 if (ret == PER_LINUX32)
650 ret = PER_LINUX;
651 return ret;
652 }
653
654 asmlinkage long sys32_sendfile(int out_fd, int in_fd,
655 compat_off_t __user *offset, s32 count)
656 {
657 mm_segment_t old_fs = get_fs();
658 int ret;
659 off_t of;
660
661 if (offset && get_user(of, offset))
662 return -EFAULT;
663
664 set_fs(KERNEL_DS);
665 ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
666 count);
667 set_fs(old_fs);
668
669 if (offset && put_user(of, offset))
670 return -EFAULT;
671 return ret;
672 }
673
674 asmlinkage long sys32_mmap2(unsigned long addr, unsigned long len,
675 unsigned long prot, unsigned long flags,
676 unsigned long fd, unsigned long pgoff)
677 {
678 struct mm_struct *mm = current->mm;
679 unsigned long error;
680 struct file *file = NULL;
681
682 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
683 if (!(flags & MAP_ANONYMOUS)) {
684 file = fget(fd);
685 if (!file)
686 return -EBADF;
687 }
688
689 down_write(&mm->mmap_sem);
690 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
691 up_write(&mm->mmap_sem);
692
693 if (file)
694 fput(file);
695 return error;
696 }
697
698 asmlinkage long sys32_olduname(struct oldold_utsname __user *name)
699 {
700 char *arch = "x86_64";
701 int err;
702
703 if (!name)
704 return -EFAULT;
705 if (!access_ok(VERIFY_WRITE, name, sizeof(struct oldold_utsname)))
706 return -EFAULT;
707
708 down_read(&uts_sem);
709
710 err = __copy_to_user(&name->sysname, &utsname()->sysname,
711 __OLD_UTS_LEN);
712 err |= __put_user(0, name->sysname+__OLD_UTS_LEN);
713 err |= __copy_to_user(&name->nodename, &utsname()->nodename,
714 __OLD_UTS_LEN);
715 err |= __put_user(0, name->nodename+__OLD_UTS_LEN);
716 err |= __copy_to_user(&name->release, &utsname()->release,
717 __OLD_UTS_LEN);
718 err |= __put_user(0, name->release+__OLD_UTS_LEN);
719 err |= __copy_to_user(&name->version, &utsname()->version,
720 __OLD_UTS_LEN);
721 err |= __put_user(0, name->version+__OLD_UTS_LEN);
722
723 if (personality(current->personality) == PER_LINUX32)
724 arch = "i686";
725
726 err |= __copy_to_user(&name->machine, arch, strlen(arch) + 1);
727
728 up_read(&uts_sem);
729
730 err = err ? -EFAULT : 0;
731
732 return err;
733 }
734
735 long sys32_uname(struct old_utsname __user *name)
736 {
737 int err;
738
739 if (!name)
740 return -EFAULT;
741 down_read(&uts_sem);
742 err = copy_to_user(name, utsname(), sizeof(*name));
743 up_read(&uts_sem);
744 if (personality(current->personality) == PER_LINUX32)
745 err |= copy_to_user(&name->machine, "i686", 5);
746
747 return err ? -EFAULT : 0;
748 }
749
750 long sys32_ustat(unsigned dev, struct ustat32 __user *u32p)
751 {
752 struct ustat u;
753 mm_segment_t seg;
754 int ret;
755
756 seg = get_fs();
757 set_fs(KERNEL_DS);
758 ret = sys_ustat(dev, (struct ustat __user *)&u);
759 set_fs(seg);
760 if (ret < 0)
761 return ret;
762
763 if (!access_ok(VERIFY_WRITE, u32p, sizeof(struct ustat32)) ||
764 __put_user((__u32) u.f_tfree, &u32p->f_tfree) ||
765 __put_user((__u32) u.f_tinode, &u32p->f_tfree) ||
766 __copy_to_user(&u32p->f_fname, u.f_fname, sizeof(u.f_fname)) ||
767 __copy_to_user(&u32p->f_fpack, u.f_fpack, sizeof(u.f_fpack)))
768 ret = -EFAULT;
769 return ret;
770 }
771
772 asmlinkage long sys32_execve(char __user *name, compat_uptr_t __user *argv,
773 compat_uptr_t __user *envp, struct pt_regs *regs)
774 {
775 long error;
776 char *filename;
777
778 filename = getname(name);
779 error = PTR_ERR(filename);
780 if (IS_ERR(filename))
781 return error;
782 error = compat_do_execve(filename, argv, envp, regs);
783 putname(filename);
784 return error;
785 }
786
787 asmlinkage long sys32_clone(unsigned int clone_flags, unsigned int newsp,
788 struct pt_regs *regs)
789 {
790 void __user *parent_tid = (void __user *)regs->dx;
791 void __user *child_tid = (void __user *)regs->di;
792
793 if (!newsp)
794 newsp = regs->sp;
795 return do_fork(clone_flags, newsp, regs, 0, parent_tid, child_tid);
796 }
797
798 /*
799 * Some system calls that need sign extended arguments. This could be
800 * done by a generic wrapper.
801 */
802 long sys32_lseek(unsigned int fd, int offset, unsigned int whence)
803 {
804 return sys_lseek(fd, offset, whence);
805 }
806
807 long sys32_kill(int pid, int sig)
808 {
809 return sys_kill(pid, sig);
810 }
811
812 long sys32_fadvise64_64(int fd, __u32 offset_low, __u32 offset_high,
813 __u32 len_low, __u32 len_high, int advice)
814 {
815 return sys_fadvise64_64(fd,
816 (((u64)offset_high)<<32) | offset_low,
817 (((u64)len_high)<<32) | len_low,
818 advice);
819 }
820
821 long sys32_vm86_warning(void)
822 {
823 struct task_struct *me = current;
824 static char lastcomm[sizeof(me->comm)];
825
826 if (strncmp(lastcomm, me->comm, sizeof(lastcomm))) {
827 compat_printk(KERN_INFO
828 "%s: vm86 mode not supported on 64 bit kernel\n",
829 me->comm);
830 strncpy(lastcomm, me->comm, sizeof(lastcomm));
831 }
832 return -ENOSYS;
833 }
834
835 long sys32_lookup_dcookie(u32 addr_low, u32 addr_high,
836 char __user *buf, size_t len)
837 {
838 return sys_lookup_dcookie(((u64)addr_high << 32) | addr_low, buf, len);
839 }
840
841 asmlinkage ssize_t sys32_readahead(int fd, unsigned off_lo, unsigned off_hi,
842 size_t count)
843 {
844 return sys_readahead(fd, ((u64)off_hi << 32) | off_lo, count);
845 }
846
847 asmlinkage long sys32_sync_file_range(int fd, unsigned off_low, unsigned off_hi,
848 unsigned n_low, unsigned n_hi, int flags)
849 {
850 return sys_sync_file_range(fd,
851 ((u64)off_hi << 32) | off_low,
852 ((u64)n_hi << 32) | n_low, flags);
853 }
854
855 asmlinkage long sys32_fadvise64(int fd, unsigned offset_lo, unsigned offset_hi,
856 size_t len, int advice)
857 {
858 return sys_fadvise64_64(fd, ((u64)offset_hi << 32) | offset_lo,
859 len, advice);
860 }
861
862 asmlinkage long sys32_fallocate(int fd, int mode, unsigned offset_lo,
863 unsigned offset_hi, unsigned len_lo,
864 unsigned len_hi)
865 {
866 return sys_fallocate(fd, mode, ((u64)offset_hi << 32) | offset_lo,
867 ((u64)len_hi << 32) | len_lo);
868 }
This page took 0.047063 seconds and 4 git commands to generate.