2 * Conversion between 32-bit and 64-bit native system calls.
4 * Copyright (C) 2000 Silicon Graphics, Inc.
5 * Written by Ulf Carlsson (ulfc@engr.sgi.com)
6 * sys32_execve from ia64/ia32 code, Feb 2000, Kanoj Sarcar (kanoj@sgi.com)
8 #include <linux/config.h>
9 #include <linux/compiler.h>
11 #include <linux/errno.h>
12 #include <linux/file.h>
13 #include <linux/smp_lock.h>
14 #include <linux/highuid.h>
15 #include <linux/dirent.h>
16 #include <linux/resource.h>
17 #include <linux/highmem.h>
18 #include <linux/time.h>
19 #include <linux/times.h>
20 #include <linux/poll.h>
21 #include <linux/slab.h>
22 #include <linux/skbuff.h>
23 #include <linux/filter.h>
24 #include <linux/shm.h>
25 #include <linux/sem.h>
26 #include <linux/msg.h>
27 #include <linux/icmpv6.h>
28 #include <linux/syscalls.h>
29 #include <linux/sysctl.h>
30 #include <linux/utime.h>
31 #include <linux/utsname.h>
32 #include <linux/personality.h>
33 #include <linux/timex.h>
34 #include <linux/dnotify.h>
35 #include <linux/module.h>
36 #include <linux/binfmts.h>
37 #include <linux/security.h>
38 #include <linux/compat.h>
39 #include <linux/vfs.h>
46 #include <asm/uaccess.h>
47 #include <asm/mmu_context.h>
50 /* Use this to get at 32-bit user passed pointers. */
51 /* A() macro should be used for places where you e.g.
52 have some internal variable u32 and just want to get
53 rid of a compiler warning. AA() has to be used in
54 places where you want to convert a function argument
55 to 32bit pointer or when you e.g. access pt_regs
56 structure and want to consider 32bit registers only.
58 #define A(__x) ((unsigned long)(__x))
59 #define AA(__x) ((unsigned long)((int)__x))
62 #define merge_64(r1,r2) ((((r1) & 0xffffffffUL) << 32) + ((r2) & 0xffffffffUL))
65 #define merge_64(r1,r2) ((((r2) & 0xffffffffUL) << 32) + ((r1) & 0xffffffffUL))
69 * Revalidate the inode. This is required for proper NFS attribute caching.
72 int cp_compat_stat(struct kstat
*stat
, struct compat_stat __user
*statbuf
)
74 struct compat_stat tmp
;
76 if (!new_valid_dev(stat
->dev
) || !new_valid_dev(stat
->rdev
))
79 memset(&tmp
, 0, sizeof(tmp
));
80 tmp
.st_dev
= new_encode_dev(stat
->dev
);
81 tmp
.st_ino
= stat
->ino
;
82 tmp
.st_mode
= stat
->mode
;
83 tmp
.st_nlink
= stat
->nlink
;
84 SET_UID(tmp
.st_uid
, stat
->uid
);
85 SET_GID(tmp
.st_gid
, stat
->gid
);
86 tmp
.st_rdev
= new_encode_dev(stat
->rdev
);
87 tmp
.st_size
= stat
->size
;
88 tmp
.st_atime
= stat
->atime
.tv_sec
;
89 tmp
.st_mtime
= stat
->mtime
.tv_sec
;
90 tmp
.st_ctime
= stat
->ctime
.tv_sec
;
92 tmp
.st_atime_nsec
= stat
->atime
.tv_nsec
;
93 tmp
.st_mtime_nsec
= stat
->mtime
.tv_nsec
;
94 tmp
.st_ctime_nsec
= stat
->ctime
.tv_nsec
;
96 tmp
.st_blocks
= stat
->blocks
;
97 tmp
.st_blksize
= stat
->blksize
;
98 return copy_to_user(statbuf
,&tmp
,sizeof(tmp
)) ? -EFAULT
: 0;
101 asmlinkage
unsigned long
102 sys32_mmap2(unsigned long addr
, unsigned long len
, unsigned long prot
,
103 unsigned long flags
, unsigned long fd
, unsigned long pgoff
)
105 struct file
* file
= NULL
;
109 if (pgoff
& (~PAGE_MASK
>> 12))
111 pgoff
>>= PAGE_SHIFT
-12;
113 if (!(flags
& MAP_ANONYMOUS
)) {
119 flags
&= ~(MAP_EXECUTABLE
| MAP_DENYWRITE
);
121 down_write(¤t
->mm
->mmap_sem
);
122 error
= do_mmap_pgoff(file
, addr
, len
, prot
, flags
, pgoff
);
123 up_write(¤t
->mm
->mmap_sem
);
132 asmlinkage
int sys_truncate64(const char __user
*path
, unsigned int high
,
137 return sys_truncate(path
, ((long) high
<< 32) | low
);
140 asmlinkage
int sys_ftruncate64(unsigned int fd
, unsigned int high
,
145 return sys_ftruncate(fd
, ((long) high
<< 32) | low
);
149 * sys_execve() executes a new program.
151 asmlinkage
int sys32_execve(nabi_no_regargs
struct pt_regs regs
)
156 filename
= getname(compat_ptr(regs
.regs
[4]));
157 error
= PTR_ERR(filename
);
158 if (IS_ERR(filename
))
160 error
= compat_do_execve(filename
, compat_ptr(regs
.regs
[5]),
161 compat_ptr(regs
.regs
[6]), ®s
);
169 sysn32_waitid(int which
, compat_pid_t pid
,
170 siginfo_t __user
*uinfo
, int options
,
171 struct compat_rusage __user
*uru
)
175 mm_segment_t old_fs
= get_fs();
178 if (!access_ok(VERIFY_WRITE
, uinfo
, sizeof(*uinfo
)))
182 ret
= sys_waitid(which
, pid
, uinfo
, options
,
183 uru
? (struct rusage __user
*) &ru
: NULL
);
186 if (__get_user(si_signo
, &uinfo
->si_signo
))
188 if (ret
< 0 || si_signo
== 0)
192 ret
= put_compat_rusage(&ru
, uru
);
212 asmlinkage
int sys32_sysinfo(struct sysinfo32 __user
*info
)
216 mm_segment_t old_fs
= get_fs ();
219 ret
= sys_sysinfo((struct sysinfo __user
*)&s
);
221 err
= put_user (s
.uptime
, &info
->uptime
);
222 err
|= __put_user (s
.loads
[0], &info
->loads
[0]);
223 err
|= __put_user (s
.loads
[1], &info
->loads
[1]);
224 err
|= __put_user (s
.loads
[2], &info
->loads
[2]);
225 err
|= __put_user (s
.totalram
, &info
->totalram
);
226 err
|= __put_user (s
.freeram
, &info
->freeram
);
227 err
|= __put_user (s
.sharedram
, &info
->sharedram
);
228 err
|= __put_user (s
.bufferram
, &info
->bufferram
);
229 err
|= __put_user (s
.totalswap
, &info
->totalswap
);
230 err
|= __put_user (s
.freeswap
, &info
->freeswap
);
231 err
|= __put_user (s
.procs
, &info
->procs
);
232 err
|= __put_user (s
.totalhigh
, &info
->totalhigh
);
233 err
|= __put_user (s
.freehigh
, &info
->freehigh
);
234 err
|= __put_user (s
.mem_unit
, &info
->mem_unit
);
240 #define RLIM_INFINITY32 0x7fffffff
241 #define RESOURCE32(x) ((x > RLIM_INFINITY32) ? RLIM_INFINITY32 : x)
249 asmlinkage
long sys32_truncate64(const char __user
* path
, unsigned long __dummy
,
250 int length_hi
, int length_lo
)
253 asmlinkage
long sys32_truncate64(const char __user
* path
, unsigned long __dummy
,
254 int length_lo
, int length_hi
)
259 length
= ((unsigned long) length_hi
<< 32) | (unsigned int) length_lo
;
261 return sys_truncate(path
, length
);
265 asmlinkage
long sys32_ftruncate64(unsigned int fd
, unsigned long __dummy
,
266 int length_hi
, int length_lo
)
269 asmlinkage
long sys32_ftruncate64(unsigned int fd
, unsigned long __dummy
,
270 int length_lo
, int length_hi
)
275 length
= ((unsigned long) length_hi
<< 32) | (unsigned int) length_lo
;
277 return sys_ftruncate(fd
, length
);
281 get_tv32(struct timeval
*o
, struct compat_timeval __user
*i
)
283 return (!access_ok(VERIFY_READ
, i
, sizeof(*i
)) ||
284 (__get_user(o
->tv_sec
, &i
->tv_sec
) |
285 __get_user(o
->tv_usec
, &i
->tv_usec
)));
289 put_tv32(struct compat_timeval __user
*o
, struct timeval
*i
)
291 return (!access_ok(VERIFY_WRITE
, o
, sizeof(*o
)) ||
292 (__put_user(i
->tv_sec
, &o
->tv_sec
) |
293 __put_user(i
->tv_usec
, &o
->tv_usec
)));
296 extern struct timezone sys_tz
;
299 sys32_gettimeofday(struct compat_timeval __user
*tv
, struct timezone __user
*tz
)
303 do_gettimeofday(&ktv
);
304 if (put_tv32(tv
, &ktv
))
308 if (copy_to_user(tz
, &sys_tz
, sizeof(sys_tz
)))
314 static inline long get_ts32(struct timespec
*o
, struct compat_timeval __user
*i
)
318 if (!access_ok(VERIFY_READ
, i
, sizeof(*i
)))
320 if (__get_user(o
->tv_sec
, &i
->tv_sec
))
322 if (__get_user(usec
, &i
->tv_usec
))
324 o
->tv_nsec
= usec
* 1000;
329 sys32_settimeofday(struct compat_timeval __user
*tv
, struct timezone __user
*tz
)
335 if (get_ts32(&kts
, tv
))
339 if (copy_from_user(&ktz
, tz
, sizeof(ktz
)))
343 return do_sys_settimeofday(tv
? &kts
: NULL
, tz
? &ktz
: NULL
);
346 asmlinkage
int sys32_llseek(unsigned int fd
, unsigned int offset_high
,
347 unsigned int offset_low
, loff_t __user
* result
,
350 return sys_llseek(fd
, offset_high
, offset_low
, result
, origin
);
353 /* From the Single Unix Spec: pread & pwrite act like lseek to pos + op +
354 lseek back to original location. They fail just like lseek does on
355 non-seekable files. */
357 asmlinkage ssize_t
sys32_pread(unsigned int fd
, char __user
* buf
,
358 size_t count
, u32 unused
, u64 a4
, u64 a5
)
362 ssize_t (*read
)(struct file
*, char __user
*, size_t, loff_t
*);
369 if (!(file
->f_mode
& FMODE_READ
))
371 pos
= merge_64(a4
, a5
);
372 ret
= rw_verify_area(READ
, file
, &pos
, count
);
376 if (!file
->f_op
|| !(read
= file
->f_op
->read
))
381 if (!(file
->f_mode
& FMODE_PREAD
))
383 ret
= read(file
, buf
, count
, &pos
);
385 dnotify_parent(file
->f_dentry
, DN_ACCESS
);
392 asmlinkage ssize_t
sys32_pwrite(unsigned int fd
, const char __user
* buf
,
393 size_t count
, u32 unused
, u64 a4
, u64 a5
)
397 ssize_t (*write
)(struct file
*, const char __user
*, size_t, loff_t
*);
404 if (!(file
->f_mode
& FMODE_WRITE
))
406 pos
= merge_64(a4
, a5
);
407 ret
= rw_verify_area(WRITE
, file
, &pos
, count
);
411 if (!file
->f_op
|| !(write
= file
->f_op
->write
))
417 if (!(file
->f_mode
& FMODE_PWRITE
))
420 ret
= write(file
, buf
, count
, &pos
);
422 dnotify_parent(file
->f_dentry
, DN_MODIFY
);
429 asmlinkage
int sys32_sched_rr_get_interval(compat_pid_t pid
,
430 struct compat_timespec __user
*interval
)
434 mm_segment_t old_fs
= get_fs ();
437 ret
= sys_sched_rr_get_interval(pid
, (struct timespec __user
*)&t
);
439 if (put_user (t
.tv_sec
, &interval
->tv_sec
) ||
440 __put_user (t
.tv_nsec
, &interval
->tv_nsec
))
445 struct msgbuf32
{ s32 mtype
; char mtext
[1]; };
458 struct ipc64_perm32
{
466 unsigned short __pad1
;
467 unsigned int __unused1
;
468 unsigned int __unused2
;
472 struct ipc_perm32 sem_perm
; /* permissions .. see ipc.h */
473 compat_time_t sem_otime
; /* last semop time */
474 compat_time_t sem_ctime
; /* last change time */
475 u32 sem_base
; /* ptr to first semaphore in array */
476 u32 sem_pending
; /* pending operations to be processed */
477 u32 sem_pending_last
; /* last pending operation */
478 u32 undo
; /* undo requests on this array */
479 unsigned short sem_nsems
; /* no. of semaphores in array */
482 struct semid64_ds32
{
483 struct ipc64_perm32 sem_perm
;
484 compat_time_t sem_otime
;
485 compat_time_t sem_ctime
;
486 unsigned int sem_nsems
;
487 unsigned int __unused1
;
488 unsigned int __unused2
;
493 struct ipc_perm32 msg_perm
;
496 compat_time_t msg_stime
;
497 compat_time_t msg_rtime
;
498 compat_time_t msg_ctime
;
501 unsigned short msg_cbytes
;
502 unsigned short msg_qnum
;
503 unsigned short msg_qbytes
;
504 compat_ipc_pid_t msg_lspid
;
505 compat_ipc_pid_t msg_lrpid
;
508 struct msqid64_ds32
{
509 struct ipc64_perm32 msg_perm
;
510 compat_time_t msg_stime
;
511 unsigned int __unused1
;
512 compat_time_t msg_rtime
;
513 unsigned int __unused2
;
514 compat_time_t msg_ctime
;
515 unsigned int __unused3
;
516 unsigned int msg_cbytes
;
517 unsigned int msg_qnum
;
518 unsigned int msg_qbytes
;
519 compat_pid_t msg_lspid
;
520 compat_pid_t msg_lrpid
;
521 unsigned int __unused4
;
522 unsigned int __unused5
;
526 struct ipc_perm32 shm_perm
;
528 compat_time_t shm_atime
;
529 compat_time_t shm_dtime
;
530 compat_time_t shm_ctime
;
531 compat_ipc_pid_t shm_cpid
;
532 compat_ipc_pid_t shm_lpid
;
533 unsigned short shm_nattch
;
536 struct shmid64_ds32
{
537 struct ipc64_perm32 shm_perm
;
538 compat_size_t shm_segsz
;
539 compat_time_t shm_atime
;
540 compat_time_t shm_dtime
;
541 compat_time_t shm_ctime
;
542 compat_pid_t shm_cpid
;
543 compat_pid_t shm_lpid
;
544 unsigned int shm_nattch
;
545 unsigned int __unused1
;
546 unsigned int __unused2
;
549 struct ipc_kludge32
{
555 do_sys32_semctl(int first
, int second
, int third
, void __user
*uptr
)
566 if (get_user (pad
, (u32 __user
*)uptr
))
568 if ((third
& ~IPC_64
) == SETVAL
)
569 fourth
.val
= (int)pad
;
571 fourth
.__pad
= (void __user
*)A(pad
);
572 switch (third
& ~IPC_64
) {
584 err
= sys_semctl (first
, second
, third
, fourth
);
589 fourth
.__pad
= (struct semid64_ds __user
*)&s
;
592 err
= sys_semctl(first
, second
, third
| IPC_64
, fourth
);
595 if (third
& IPC_64
) {
596 struct semid64_ds32 __user
*usp64
= (struct semid64_ds32 __user
*) A(pad
);
598 if (!access_ok(VERIFY_WRITE
, usp64
, sizeof(*usp64
))) {
602 err2
= __put_user(s
.sem_perm
.key
, &usp64
->sem_perm
.key
);
603 err2
|= __put_user(s
.sem_perm
.uid
, &usp64
->sem_perm
.uid
);
604 err2
|= __put_user(s
.sem_perm
.gid
, &usp64
->sem_perm
.gid
);
605 err2
|= __put_user(s
.sem_perm
.cuid
, &usp64
->sem_perm
.cuid
);
606 err2
|= __put_user(s
.sem_perm
.cgid
, &usp64
->sem_perm
.cgid
);
607 err2
|= __put_user(s
.sem_perm
.mode
, &usp64
->sem_perm
.mode
);
608 err2
|= __put_user(s
.sem_perm
.seq
, &usp64
->sem_perm
.seq
);
609 err2
|= __put_user(s
.sem_otime
, &usp64
->sem_otime
);
610 err2
|= __put_user(s
.sem_ctime
, &usp64
->sem_ctime
);
611 err2
|= __put_user(s
.sem_nsems
, &usp64
->sem_nsems
);
613 struct semid_ds32 __user
*usp32
= (struct semid_ds32 __user
*) A(pad
);
615 if (!access_ok(VERIFY_WRITE
, usp32
, sizeof(*usp32
))) {
619 err2
= __put_user(s
.sem_perm
.key
, &usp32
->sem_perm
.key
);
620 err2
|= __put_user(s
.sem_perm
.uid
, &usp32
->sem_perm
.uid
);
621 err2
|= __put_user(s
.sem_perm
.gid
, &usp32
->sem_perm
.gid
);
622 err2
|= __put_user(s
.sem_perm
.cuid
, &usp32
->sem_perm
.cuid
);
623 err2
|= __put_user(s
.sem_perm
.cgid
, &usp32
->sem_perm
.cgid
);
624 err2
|= __put_user(s
.sem_perm
.mode
, &usp32
->sem_perm
.mode
);
625 err2
|= __put_user(s
.sem_perm
.seq
, &usp32
->sem_perm
.seq
);
626 err2
|= __put_user(s
.sem_otime
, &usp32
->sem_otime
);
627 err2
|= __put_user(s
.sem_ctime
, &usp32
->sem_ctime
);
628 err2
|= __put_user(s
.sem_nsems
, &usp32
->sem_nsems
);
643 do_sys32_msgsnd (int first
, int second
, int third
, void __user
*uptr
)
645 struct msgbuf32 __user
*up
= (struct msgbuf32 __user
*)uptr
;
652 p
= kmalloc (second
+ sizeof (struct msgbuf
)
656 err
= get_user (p
->mtype
, &up
->mtype
);
659 err
|= __copy_from_user (p
->mtext
, &up
->mtext
, second
);
664 err
= sys_msgsnd (first
, (struct msgbuf __user
*)p
, second
, third
);
673 do_sys32_msgrcv (int first
, int second
, int msgtyp
, int third
,
674 int version
, void __user
*uptr
)
676 struct msgbuf32 __user
*up
;
682 struct ipc_kludge32 __user
*uipck
= (struct ipc_kludge32 __user
*)uptr
;
683 struct ipc_kludge32 ipck
;
689 if (copy_from_user (&ipck
, uipck
, sizeof (struct ipc_kludge32
)))
691 uptr
= (void __user
*)AA(ipck
.msgp
);
692 msgtyp
= ipck
.msgtyp
;
698 p
= kmalloc (second
+ sizeof (struct msgbuf
) + 4, GFP_USER
);
703 err
= sys_msgrcv (first
, (struct msgbuf __user
*)p
, second
+ 4, msgtyp
, third
);
707 up
= (struct msgbuf32 __user
*)uptr
;
708 if (put_user (p
->mtype
, &up
->mtype
) ||
709 __copy_to_user (&up
->mtext
, p
->mtext
, err
))
718 do_sys32_msgctl (int first
, int second
, void __user
*uptr
)
720 int err
= -EINVAL
, err2
;
722 struct msqid_ds32 __user
*up32
= (struct msqid_ds32 __user
*)uptr
;
723 struct msqid64_ds32 __user
*up64
= (struct msqid64_ds32 __user
*)uptr
;
726 switch (second
& ~IPC_64
) {
730 err
= sys_msgctl (first
, second
, (struct msqid_ds __user
*)uptr
);
734 if (second
& IPC_64
) {
735 if (!access_ok(VERIFY_READ
, up64
, sizeof(*up64
))) {
739 err
= __get_user(m
.msg_perm
.uid
, &up64
->msg_perm
.uid
);
740 err
|= __get_user(m
.msg_perm
.gid
, &up64
->msg_perm
.gid
);
741 err
|= __get_user(m
.msg_perm
.mode
, &up64
->msg_perm
.mode
);
742 err
|= __get_user(m
.msg_qbytes
, &up64
->msg_qbytes
);
744 if (!access_ok(VERIFY_READ
, up32
, sizeof(*up32
))) {
748 err
= __get_user(m
.msg_perm
.uid
, &up32
->msg_perm
.uid
);
749 err
|= __get_user(m
.msg_perm
.gid
, &up32
->msg_perm
.gid
);
750 err
|= __get_user(m
.msg_perm
.mode
, &up32
->msg_perm
.mode
);
751 err
|= __get_user(m
.msg_qbytes
, &up32
->msg_qbytes
);
757 err
= sys_msgctl(first
, second
| IPC_64
, (struct msqid_ds __user
*)&m
);
765 err
= sys_msgctl(first
, second
| IPC_64
, (struct msqid_ds __user
*)&m
);
767 if (second
& IPC_64
) {
768 if (!access_ok(VERIFY_WRITE
, up64
, sizeof(*up64
))) {
772 err2
= __put_user(m
.msg_perm
.key
, &up64
->msg_perm
.key
);
773 err2
|= __put_user(m
.msg_perm
.uid
, &up64
->msg_perm
.uid
);
774 err2
|= __put_user(m
.msg_perm
.gid
, &up64
->msg_perm
.gid
);
775 err2
|= __put_user(m
.msg_perm
.cuid
, &up64
->msg_perm
.cuid
);
776 err2
|= __put_user(m
.msg_perm
.cgid
, &up64
->msg_perm
.cgid
);
777 err2
|= __put_user(m
.msg_perm
.mode
, &up64
->msg_perm
.mode
);
778 err2
|= __put_user(m
.msg_perm
.seq
, &up64
->msg_perm
.seq
);
779 err2
|= __put_user(m
.msg_stime
, &up64
->msg_stime
);
780 err2
|= __put_user(m
.msg_rtime
, &up64
->msg_rtime
);
781 err2
|= __put_user(m
.msg_ctime
, &up64
->msg_ctime
);
782 err2
|= __put_user(m
.msg_cbytes
, &up64
->msg_cbytes
);
783 err2
|= __put_user(m
.msg_qnum
, &up64
->msg_qnum
);
784 err2
|= __put_user(m
.msg_qbytes
, &up64
->msg_qbytes
);
785 err2
|= __put_user(m
.msg_lspid
, &up64
->msg_lspid
);
786 err2
|= __put_user(m
.msg_lrpid
, &up64
->msg_lrpid
);
790 if (!access_ok(VERIFY_WRITE
, up32
, sizeof(*up32
))) {
794 err2
= __put_user(m
.msg_perm
.key
, &up32
->msg_perm
.key
);
795 err2
|= __put_user(m
.msg_perm
.uid
, &up32
->msg_perm
.uid
);
796 err2
|= __put_user(m
.msg_perm
.gid
, &up32
->msg_perm
.gid
);
797 err2
|= __put_user(m
.msg_perm
.cuid
, &up32
->msg_perm
.cuid
);
798 err2
|= __put_user(m
.msg_perm
.cgid
, &up32
->msg_perm
.cgid
);
799 err2
|= __put_user(m
.msg_perm
.mode
, &up32
->msg_perm
.mode
);
800 err2
|= __put_user(m
.msg_perm
.seq
, &up32
->msg_perm
.seq
);
801 err2
|= __put_user(m
.msg_stime
, &up32
->msg_stime
);
802 err2
|= __put_user(m
.msg_rtime
, &up32
->msg_rtime
);
803 err2
|= __put_user(m
.msg_ctime
, &up32
->msg_ctime
);
804 err2
|= __put_user(m
.msg_cbytes
, &up32
->msg_cbytes
);
805 err2
|= __put_user(m
.msg_qnum
, &up32
->msg_qnum
);
806 err2
|= __put_user(m
.msg_qbytes
, &up32
->msg_qbytes
);
807 err2
|= __put_user(m
.msg_lspid
, &up32
->msg_lspid
);
808 err2
|= __put_user(m
.msg_lrpid
, &up32
->msg_lrpid
);
819 do_sys32_shmat (int first
, int second
, int third
, int version
, void __user
*uptr
)
822 u32 __user
*uaddr
= (u32 __user
*)A((u32
)third
);
827 err
= do_shmat (first
, uptr
, second
, &raddr
);
830 err
= put_user (raddr
, uaddr
);
836 u32 shm_tot
, shm_rss
, shm_swp
;
837 u32 swap_attempts
, swap_successes
;
841 do_sys32_shmctl (int first
, int second
, void __user
*uptr
)
843 struct shmid64_ds32 __user
*up64
= (struct shmid64_ds32 __user
*)uptr
;
844 struct shmid_ds32 __user
*up32
= (struct shmid_ds32 __user
*)uptr
;
845 struct shm_info32 __user
*uip
= (struct shm_info32 __user
*)uptr
;
846 int err
= -EFAULT
, err2
;
847 struct shmid64_ds s64
;
852 switch (second
& ~IPC_64
) {
854 second
= IPC_INFO
; /* So that we don't have to translate it */
858 err
= sys_shmctl(first
, second
, (struct shmid_ds __user
*)uptr
);
861 if (second
& IPC_64
) {
862 err
= get_user(s
.shm_perm
.uid
, &up64
->shm_perm
.uid
);
863 err
|= get_user(s
.shm_perm
.gid
, &up64
->shm_perm
.gid
);
864 err
|= get_user(s
.shm_perm
.mode
, &up64
->shm_perm
.mode
);
866 err
= get_user(s
.shm_perm
.uid
, &up32
->shm_perm
.uid
);
867 err
|= get_user(s
.shm_perm
.gid
, &up32
->shm_perm
.gid
);
868 err
|= get_user(s
.shm_perm
.mode
, &up32
->shm_perm
.mode
);
874 err
= sys_shmctl(first
, second
& ~IPC_64
, (struct shmid_ds __user
*)&s
);
882 err
= sys_shmctl(first
, second
| IPC_64
, (void __user
*) &s64
);
886 if (second
& IPC_64
) {
887 if (!access_ok(VERIFY_WRITE
, up64
, sizeof(*up64
))) {
891 err2
= __put_user(s64
.shm_perm
.key
, &up64
->shm_perm
.key
);
892 err2
|= __put_user(s64
.shm_perm
.uid
, &up64
->shm_perm
.uid
);
893 err2
|= __put_user(s64
.shm_perm
.gid
, &up64
->shm_perm
.gid
);
894 err2
|= __put_user(s64
.shm_perm
.cuid
, &up64
->shm_perm
.cuid
);
895 err2
|= __put_user(s64
.shm_perm
.cgid
, &up64
->shm_perm
.cgid
);
896 err2
|= __put_user(s64
.shm_perm
.mode
, &up64
->shm_perm
.mode
);
897 err2
|= __put_user(s64
.shm_perm
.seq
, &up64
->shm_perm
.seq
);
898 err2
|= __put_user(s64
.shm_atime
, &up64
->shm_atime
);
899 err2
|= __put_user(s64
.shm_dtime
, &up64
->shm_dtime
);
900 err2
|= __put_user(s64
.shm_ctime
, &up64
->shm_ctime
);
901 err2
|= __put_user(s64
.shm_segsz
, &up64
->shm_segsz
);
902 err2
|= __put_user(s64
.shm_nattch
, &up64
->shm_nattch
);
903 err2
|= __put_user(s64
.shm_cpid
, &up64
->shm_cpid
);
904 err2
|= __put_user(s64
.shm_lpid
, &up64
->shm_lpid
);
906 if (!access_ok(VERIFY_WRITE
, up32
, sizeof(*up32
))) {
910 err2
= __put_user(s64
.shm_perm
.key
, &up32
->shm_perm
.key
);
911 err2
|= __put_user(s64
.shm_perm
.uid
, &up32
->shm_perm
.uid
);
912 err2
|= __put_user(s64
.shm_perm
.gid
, &up32
->shm_perm
.gid
);
913 err2
|= __put_user(s64
.shm_perm
.cuid
, &up32
->shm_perm
.cuid
);
914 err2
|= __put_user(s64
.shm_perm
.cgid
, &up32
->shm_perm
.cgid
);
915 err2
|= __put_user(s64
.shm_perm
.mode
, &up32
->shm_perm
.mode
);
916 err2
|= __put_user(s64
.shm_perm
.seq
, &up32
->shm_perm
.seq
);
917 err2
|= __put_user(s64
.shm_atime
, &up32
->shm_atime
);
918 err2
|= __put_user(s64
.shm_dtime
, &up32
->shm_dtime
);
919 err2
|= __put_user(s64
.shm_ctime
, &up32
->shm_ctime
);
920 err2
|= __put_user(s64
.shm_segsz
, &up32
->shm_segsz
);
921 err2
|= __put_user(s64
.shm_nattch
, &up32
->shm_nattch
);
922 err2
|= __put_user(s64
.shm_cpid
, &up32
->shm_cpid
);
923 err2
|= __put_user(s64
.shm_lpid
, &up32
->shm_lpid
);
932 err
= sys_shmctl(first
, second
, (void __user
*)&si
);
936 err2
= put_user(si
.used_ids
, &uip
->used_ids
);
937 err2
|= __put_user(si
.shm_tot
, &uip
->shm_tot
);
938 err2
|= __put_user(si
.shm_rss
, &uip
->shm_rss
);
939 err2
|= __put_user(si
.shm_swp
, &uip
->shm_swp
);
940 err2
|= __put_user(si
.swap_attempts
, &uip
->swap_attempts
);
941 err2
|= __put_user (si
.swap_successes
, &uip
->swap_successes
);
954 static int sys32_semtimedop(int semid
, struct sembuf __user
*tsems
, int nsems
,
955 const struct compat_timespec __user
*timeout32
)
957 struct compat_timespec t32
;
958 struct timespec __user
*t64
= compat_alloc_user_space(sizeof(*t64
));
960 if (copy_from_user(&t32
, timeout32
, sizeof(t32
)))
963 if (put_user(t32
.tv_sec
, &t64
->tv_sec
) ||
964 put_user(t32
.tv_nsec
, &t64
->tv_nsec
))
967 return sys_semtimedop(semid
, tsems
, nsems
, t64
);
971 sys32_ipc (u32 call
, int first
, int second
, int third
, u32 ptr
, u32 fifth
)
975 version
= call
>> 16; /* hack for backward compatibility */
980 /* struct sembuf is the same on 32 and 64bit :)) */
981 err
= sys_semtimedop (first
, (struct sembuf __user
*)AA(ptr
), second
,
985 err
= sys32_semtimedop (first
, (struct sembuf __user
*)AA(ptr
), second
,
986 (const struct compat_timespec __user
*)AA(fifth
));
989 err
= sys_semget (first
, second
, third
);
992 err
= do_sys32_semctl (first
, second
, third
,
993 (void __user
*)AA(ptr
));
997 err
= do_sys32_msgsnd (first
, second
, third
,
998 (void __user
*)AA(ptr
));
1001 err
= do_sys32_msgrcv (first
, second
, fifth
, third
,
1002 version
, (void __user
*)AA(ptr
));
1005 err
= sys_msgget ((key_t
) first
, second
);
1008 err
= do_sys32_msgctl (first
, second
, (void __user
*)AA(ptr
));
1012 err
= do_sys32_shmat (first
, second
, third
,
1013 version
, (void __user
*)AA(ptr
));
1016 err
= sys_shmdt ((char __user
*)A(ptr
));
1019 err
= sys_shmget (first
, (unsigned)second
, third
);
1022 err
= do_sys32_shmctl (first
, second
, (void __user
*)AA(ptr
));
1032 asmlinkage
long sys32_shmat(int shmid
, char __user
*shmaddr
,
1033 int shmflg
, int32_t __user
*addr
)
1035 unsigned long raddr
;
1038 err
= do_shmat(shmid
, shmaddr
, shmflg
, &raddr
);
1042 return put_user(raddr
, addr
);
1045 struct sysctl_args32
1047 compat_caddr_t name
;
1049 compat_caddr_t oldval
;
1050 compat_caddr_t oldlenp
;
1051 compat_caddr_t newval
;
1052 compat_size_t newlen
;
1053 unsigned int __unused
[4];
1056 #ifdef CONFIG_SYSCTL
1058 asmlinkage
long sys32_sysctl(struct sysctl_args32 __user
*args
)
1060 struct sysctl_args32 tmp
;
1063 size_t __user
*oldlenp
= NULL
;
1064 unsigned long addr
= (((unsigned long)&args
->__unused
[0]) + 7) & ~7;
1066 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1069 if (tmp
.oldval
&& tmp
.oldlenp
) {
1070 /* Duh, this is ugly and might not work if sysctl_args
1071 is in read-only memory, but do_sysctl does indirectly
1072 a lot of uaccess in both directions and we'd have to
1073 basically copy the whole sysctl.c here, and
1074 glibc's __sysctl uses rw memory for the structure
1076 if (get_user(oldlen
, (u32 __user
*)A(tmp
.oldlenp
)) ||
1077 put_user(oldlen
, (size_t __user
*)addr
))
1079 oldlenp
= (size_t __user
*)addr
;
1083 error
= do_sysctl((int __user
*)A(tmp
.name
), tmp
.nlen
, (void __user
*)A(tmp
.oldval
),
1084 oldlenp
, (void __user
*)A(tmp
.newval
), tmp
.newlen
);
1088 if (get_user(oldlen
, (size_t __user
*)addr
) ||
1089 put_user(oldlen
, (u32 __user
*)A(tmp
.oldlenp
)))
1092 copy_to_user(args
->__unused
, tmp
.__unused
, sizeof(tmp
.__unused
));
1097 #endif /* CONFIG_SYSCTL */
1099 asmlinkage
long sys32_newuname(struct new_utsname __user
* name
)
1103 down_read(&uts_sem
);
1104 if (copy_to_user(name
,&system_utsname
,sizeof *name
))
1108 if (current
->personality
== PER_LINUX32
&& !ret
)
1109 if (copy_to_user(name
->machine
, "mips\0\0\0", 8))
1115 asmlinkage
int sys32_personality(unsigned long personality
)
1118 if (current
->personality
== PER_LINUX32
&& personality
== PER_LINUX
)
1119 personality
= PER_LINUX32
;
1120 ret
= sys_personality(personality
);
1121 if (ret
== PER_LINUX32
)
1126 /* ustat compatibility */
1128 compat_daddr_t f_tfree
;
1129 compat_ino_t f_tinode
;
1134 extern asmlinkage
long sys_ustat(dev_t dev
, struct ustat __user
* ubuf
);
1136 asmlinkage
int sys32_ustat(dev_t dev
, struct ustat32 __user
* ubuf32
)
1140 struct ustat32 tmp32
;
1141 mm_segment_t old_fs
= get_fs();
1144 err
= sys_ustat(dev
, (struct ustat __user
*)&tmp
);
1150 memset(&tmp32
,0,sizeof(struct ustat32
));
1151 tmp32
.f_tfree
= tmp
.f_tfree
;
1152 tmp32
.f_tinode
= tmp
.f_tinode
;
1154 err
= copy_to_user(ubuf32
,&tmp32
,sizeof(struct ustat32
)) ? -EFAULT
: 0;
1160 /* Handle adjtimex compatibility. */
1164 s32 offset
, freq
, maxerror
, esterror
;
1165 s32 status
, constant
, precision
, tolerance
;
1166 struct compat_timeval time
;
1168 s32 ppsfreq
, jitter
, shift
, stabil
;
1169 s32 jitcnt
, calcnt
, errcnt
, stbcnt
;
1170 s32
:32; s32
:32; s32
:32; s32
:32;
1171 s32
:32; s32
:32; s32
:32; s32
:32;
1172 s32
:32; s32
:32; s32
:32; s32
:32;
1175 extern int do_adjtimex(struct timex
*);
1177 asmlinkage
int sys32_adjtimex(struct timex32 __user
*utp
)
1182 memset(&txc
, 0, sizeof(struct timex
));
1184 if (get_user(txc
.modes
, &utp
->modes
) ||
1185 __get_user(txc
.offset
, &utp
->offset
) ||
1186 __get_user(txc
.freq
, &utp
->freq
) ||
1187 __get_user(txc
.maxerror
, &utp
->maxerror
) ||
1188 __get_user(txc
.esterror
, &utp
->esterror
) ||
1189 __get_user(txc
.status
, &utp
->status
) ||
1190 __get_user(txc
.constant
, &utp
->constant
) ||
1191 __get_user(txc
.precision
, &utp
->precision
) ||
1192 __get_user(txc
.tolerance
, &utp
->tolerance
) ||
1193 __get_user(txc
.time
.tv_sec
, &utp
->time
.tv_sec
) ||
1194 __get_user(txc
.time
.tv_usec
, &utp
->time
.tv_usec
) ||
1195 __get_user(txc
.tick
, &utp
->tick
) ||
1196 __get_user(txc
.ppsfreq
, &utp
->ppsfreq
) ||
1197 __get_user(txc
.jitter
, &utp
->jitter
) ||
1198 __get_user(txc
.shift
, &utp
->shift
) ||
1199 __get_user(txc
.stabil
, &utp
->stabil
) ||
1200 __get_user(txc
.jitcnt
, &utp
->jitcnt
) ||
1201 __get_user(txc
.calcnt
, &utp
->calcnt
) ||
1202 __get_user(txc
.errcnt
, &utp
->errcnt
) ||
1203 __get_user(txc
.stbcnt
, &utp
->stbcnt
))
1206 ret
= do_adjtimex(&txc
);
1208 if (put_user(txc
.modes
, &utp
->modes
) ||
1209 __put_user(txc
.offset
, &utp
->offset
) ||
1210 __put_user(txc
.freq
, &utp
->freq
) ||
1211 __put_user(txc
.maxerror
, &utp
->maxerror
) ||
1212 __put_user(txc
.esterror
, &utp
->esterror
) ||
1213 __put_user(txc
.status
, &utp
->status
) ||
1214 __put_user(txc
.constant
, &utp
->constant
) ||
1215 __put_user(txc
.precision
, &utp
->precision
) ||
1216 __put_user(txc
.tolerance
, &utp
->tolerance
) ||
1217 __put_user(txc
.time
.tv_sec
, &utp
->time
.tv_sec
) ||
1218 __put_user(txc
.time
.tv_usec
, &utp
->time
.tv_usec
) ||
1219 __put_user(txc
.tick
, &utp
->tick
) ||
1220 __put_user(txc
.ppsfreq
, &utp
->ppsfreq
) ||
1221 __put_user(txc
.jitter
, &utp
->jitter
) ||
1222 __put_user(txc
.shift
, &utp
->shift
) ||
1223 __put_user(txc
.stabil
, &utp
->stabil
) ||
1224 __put_user(txc
.jitcnt
, &utp
->jitcnt
) ||
1225 __put_user(txc
.calcnt
, &utp
->calcnt
) ||
1226 __put_user(txc
.errcnt
, &utp
->errcnt
) ||
1227 __put_user(txc
.stbcnt
, &utp
->stbcnt
))
1233 asmlinkage
int sys32_sendfile(int out_fd
, int in_fd
, compat_off_t __user
*offset
,
1236 mm_segment_t old_fs
= get_fs();
1240 if (offset
&& get_user(of
, offset
))
1244 ret
= sys_sendfile(out_fd
, in_fd
, offset
? (off_t __user
*)&of
: NULL
, count
);
1247 if (offset
&& put_user(of
, offset
))
1253 asmlinkage ssize_t
sys32_readahead(int fd
, u32 pad0
, u64 a2
, u64 a3
,
1256 return sys_readahead(fd
, merge_64(a2
, a3
), count
);
1259 /* Argument list sizes for sys_socketcall */
1260 #define AL(x) ((x) * sizeof(unsigned int))
1261 static unsigned char socketcall_nargs
[18]={AL(0),AL(3),AL(3),AL(3),AL(2),AL(3),
1262 AL(3),AL(3),AL(4),AL(4),AL(4),AL(6),
1263 AL(6),AL(2),AL(5),AL(5),AL(3),AL(3)};
1267 * System call vectors.
1269 * Argument checking cleaned up. Saved 20% in size.
1270 * This function doesn't need to set the kernel lock because
1271 * it is set by the callees.
1274 asmlinkage
long sys32_socketcall(int call
, unsigned int __user
*args32
)
1280 extern asmlinkage
long sys_socket(int family
, int type
, int protocol
);
1281 extern asmlinkage
long sys_bind(int fd
, struct sockaddr __user
*umyaddr
, int addrlen
);
1282 extern asmlinkage
long sys_connect(int fd
, struct sockaddr __user
*uservaddr
, int addrlen
);
1283 extern asmlinkage
long sys_listen(int fd
, int backlog
);
1284 extern asmlinkage
long sys_accept(int fd
, struct sockaddr __user
*upeer_sockaddr
, int __user
*upeer_addrlen
);
1285 extern asmlinkage
long sys_getsockname(int fd
, struct sockaddr __user
*usockaddr
, int __user
*usockaddr_len
);
1286 extern asmlinkage
long sys_getpeername(int fd
, struct sockaddr __user
*usockaddr
, int __user
*usockaddr_len
);
1287 extern asmlinkage
long sys_socketpair(int family
, int type
, int protocol
, int __user
*usockvec
);
1288 extern asmlinkage
long sys_send(int fd
, void __user
* buff
, size_t len
, unsigned flags
);
1289 extern asmlinkage
long sys_sendto(int fd
, void __user
* buff
, size_t len
, unsigned flags
,
1290 struct sockaddr __user
*addr
, int addr_len
);
1291 extern asmlinkage
long sys_recv(int fd
, void __user
* ubuf
, size_t size
, unsigned flags
);
1292 extern asmlinkage
long sys_recvfrom(int fd
, void __user
* ubuf
, size_t size
, unsigned flags
,
1293 struct sockaddr __user
*addr
, int __user
*addr_len
);
1294 extern asmlinkage
long sys_shutdown(int fd
, int how
);
1295 extern asmlinkage
long sys_setsockopt(int fd
, int level
, int optname
, char __user
*optval
, int optlen
);
1296 extern asmlinkage
long sys_getsockopt(int fd
, int level
, int optname
, char __user
*optval
, int __user
*optlen
);
1297 extern asmlinkage
long sys_sendmsg(int fd
, struct msghdr __user
*msg
, unsigned flags
);
1298 extern asmlinkage
long sys_recvmsg(int fd
, struct msghdr __user
*msg
, unsigned int flags
);
1301 if(call
<1||call
>SYS_RECVMSG
)
1304 /* copy_from_user should be SMP safe. */
1305 if (copy_from_user(a
, args32
, socketcall_nargs
[call
]))
1314 err
= sys_socket(a0
,a1
,a
[2]);
1317 err
= sys_bind(a0
,(struct sockaddr __user
*)A(a1
), a
[2]);
1320 err
= sys_connect(a0
, (struct sockaddr __user
*)A(a1
), a
[2]);
1323 err
= sys_listen(a0
,a1
);
1326 err
= sys_accept(a0
,(struct sockaddr __user
*)A(a1
), (int __user
*)A(a
[2]));
1328 case SYS_GETSOCKNAME
:
1329 err
= sys_getsockname(a0
,(struct sockaddr __user
*)A(a1
), (int __user
*)A(a
[2]));
1331 case SYS_GETPEERNAME
:
1332 err
= sys_getpeername(a0
, (struct sockaddr __user
*)A(a1
), (int __user
*)A(a
[2]));
1334 case SYS_SOCKETPAIR
:
1335 err
= sys_socketpair(a0
,a1
, a
[2], (int __user
*)A(a
[3]));
1338 err
= sys_send(a0
, (void __user
*)A(a1
), a
[2], a
[3]);
1341 err
= sys_sendto(a0
,(void __user
*)A(a1
), a
[2], a
[3],
1342 (struct sockaddr __user
*)A(a
[4]), a
[5]);
1345 err
= sys_recv(a0
, (void __user
*)A(a1
), a
[2], a
[3]);
1348 err
= sys_recvfrom(a0
, (void __user
*)A(a1
), a
[2], a
[3],
1349 (struct sockaddr __user
*)A(a
[4]), (int __user
*)A(a
[5]));
1352 err
= sys_shutdown(a0
,a1
);
1354 case SYS_SETSOCKOPT
:
1355 err
= sys_setsockopt(a0
, a1
, a
[2], (char __user
*)A(a
[3]), a
[4]);
1357 case SYS_GETSOCKOPT
:
1358 err
= sys_getsockopt(a0
, a1
, a
[2], (char __user
*)A(a
[3]), (int __user
*)A(a
[4]));
1361 err
= sys_sendmsg(a0
, (struct msghdr __user
*) A(a1
), a
[2]);
1364 err
= sys_recvmsg(a0
, (struct msghdr __user
*) A(a1
), a
[2]);
1377 u32 payload
[(64 / 4) - 3];
1380 extern asmlinkage
long
1381 sys_timer_create(clockid_t which_clock
,
1382 struct sigevent __user
*timer_event_spec
,
1383 timer_t __user
* created_timer_id
);
1386 sys32_timer_create(u32 clock
, struct sigevent32 __user
*se32
, timer_t __user
*timer_id
)
1388 struct sigevent __user
*p
= NULL
;
1391 p
= compat_alloc_user_space(sizeof(struct sigevent
));
1392 memset(&se
, 0, sizeof(struct sigevent
));
1393 if (get_user(se
.sigev_value
.sival_int
, &se32
->sigev_value
) ||
1394 __get_user(se
.sigev_signo
, &se32
->sigev_signo
) ||
1395 __get_user(se
.sigev_notify
, &se32
->sigev_notify
) ||
1396 __copy_from_user(&se
._sigev_un
._pad
, &se32
->payload
,
1397 sizeof(se32
->payload
)) ||
1398 copy_to_user(p
, &se
, sizeof(se
)))
1401 return sys_timer_create(clock
, p
, timer_id
);
1404 save_static_function(sys32_clone
);
1405 __attribute_used__ noinline
static int
1406 _sys32_clone(nabi_no_regargs
struct pt_regs regs
)
1408 unsigned long clone_flags
;
1409 unsigned long newsp
;
1410 int __user
*parent_tidptr
, *child_tidptr
;
1412 clone_flags
= regs
.regs
[4];
1413 newsp
= regs
.regs
[5];
1415 newsp
= regs
.regs
[29];
1416 parent_tidptr
= (int __user
*) regs
.regs
[6];
1418 /* Use __dummy4 instead of getting it off the stack, so that
1420 child_tidptr
= (int __user
*) __dummy4
;
1421 return do_fork(clone_flags
, newsp
, ®s
, 0,
1422 parent_tidptr
, child_tidptr
);
1425 extern asmlinkage
void sys_set_thread_area(u32 addr
);
1426 asmlinkage
void sys32_set_thread_area(u32 addr
)
1428 sys_set_thread_area(AA(addr
));