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/compiler.h>
10 #include <linux/errno.h>
11 #include <linux/file.h>
12 #include <linux/smp_lock.h>
13 #include <linux/highuid.h>
14 #include <linux/dirent.h>
15 #include <linux/resource.h>
16 #include <linux/highmem.h>
17 #include <linux/time.h>
18 #include <linux/times.h>
19 #include <linux/poll.h>
20 #include <linux/slab.h>
21 #include <linux/skbuff.h>
22 #include <linux/filter.h>
23 #include <linux/shm.h>
24 #include <linux/sem.h>
25 #include <linux/msg.h>
26 #include <linux/icmpv6.h>
27 #include <linux/syscalls.h>
28 #include <linux/sysctl.h>
29 #include <linux/utime.h>
30 #include <linux/utsname.h>
31 #include <linux/personality.h>
32 #include <linux/dnotify.h>
33 #include <linux/module.h>
34 #include <linux/binfmts.h>
35 #include <linux/security.h>
36 #include <linux/compat.h>
37 #include <linux/vfs.h>
44 #include <asm/uaccess.h>
45 #include <asm/mmu_context.h>
48 /* Use this to get at 32-bit user passed pointers. */
49 /* A() macro should be used for places where you e.g.
50 have some internal variable u32 and just want to get
51 rid of a compiler warning. AA() has to be used in
52 places where you want to convert a function argument
53 to 32bit pointer or when you e.g. access pt_regs
54 structure and want to consider 32bit registers only.
56 #define A(__x) ((unsigned long)(__x))
57 #define AA(__x) ((unsigned long)((int)__x))
60 #define merge_64(r1,r2) ((((r1) & 0xffffffffUL) << 32) + ((r2) & 0xffffffffUL))
63 #define merge_64(r1,r2) ((((r2) & 0xffffffffUL) << 32) + ((r1) & 0xffffffffUL))
67 * Revalidate the inode. This is required for proper NFS attribute caching.
70 int cp_compat_stat(struct kstat
*stat
, struct compat_stat __user
*statbuf
)
72 struct compat_stat tmp
;
74 if (!new_valid_dev(stat
->dev
) || !new_valid_dev(stat
->rdev
))
77 memset(&tmp
, 0, sizeof(tmp
));
78 tmp
.st_dev
= new_encode_dev(stat
->dev
);
79 tmp
.st_ino
= stat
->ino
;
80 if (sizeof(tmp
.st_ino
) < sizeof(stat
->ino
) && 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
)
360 return sys_pread64(fd
, buf
, count
, merge_64(a4
, a5
));
363 asmlinkage ssize_t
sys32_pwrite(unsigned int fd
, const char __user
* buf
,
364 size_t count
, u32 unused
, u64 a4
, u64 a5
)
366 return sys_pwrite64(fd
, buf
, count
, merge_64(a4
, a5
));
369 asmlinkage
int sys32_sched_rr_get_interval(compat_pid_t pid
,
370 struct compat_timespec __user
*interval
)
374 mm_segment_t old_fs
= get_fs ();
377 ret
= sys_sched_rr_get_interval(pid
, (struct timespec __user
*)&t
);
379 if (put_user (t
.tv_sec
, &interval
->tv_sec
) ||
380 __put_user (t
.tv_nsec
, &interval
->tv_nsec
))
385 struct msgbuf32
{ s32 mtype
; char mtext
[1]; };
398 struct ipc64_perm32
{
406 unsigned short __pad1
;
407 unsigned int __unused1
;
408 unsigned int __unused2
;
412 struct ipc_perm32 sem_perm
; /* permissions .. see ipc.h */
413 compat_time_t sem_otime
; /* last semop time */
414 compat_time_t sem_ctime
; /* last change time */
415 u32 sem_base
; /* ptr to first semaphore in array */
416 u32 sem_pending
; /* pending operations to be processed */
417 u32 sem_pending_last
; /* last pending operation */
418 u32 undo
; /* undo requests on this array */
419 unsigned short sem_nsems
; /* no. of semaphores in array */
422 struct semid64_ds32
{
423 struct ipc64_perm32 sem_perm
;
424 compat_time_t sem_otime
;
425 compat_time_t sem_ctime
;
426 unsigned int sem_nsems
;
427 unsigned int __unused1
;
428 unsigned int __unused2
;
433 struct ipc_perm32 msg_perm
;
436 compat_time_t msg_stime
;
437 compat_time_t msg_rtime
;
438 compat_time_t msg_ctime
;
441 unsigned short msg_cbytes
;
442 unsigned short msg_qnum
;
443 unsigned short msg_qbytes
;
444 compat_ipc_pid_t msg_lspid
;
445 compat_ipc_pid_t msg_lrpid
;
448 struct msqid64_ds32
{
449 struct ipc64_perm32 msg_perm
;
450 compat_time_t msg_stime
;
451 unsigned int __unused1
;
452 compat_time_t msg_rtime
;
453 unsigned int __unused2
;
454 compat_time_t msg_ctime
;
455 unsigned int __unused3
;
456 unsigned int msg_cbytes
;
457 unsigned int msg_qnum
;
458 unsigned int msg_qbytes
;
459 compat_pid_t msg_lspid
;
460 compat_pid_t msg_lrpid
;
461 unsigned int __unused4
;
462 unsigned int __unused5
;
466 struct ipc_perm32 shm_perm
;
468 compat_time_t shm_atime
;
469 compat_time_t shm_dtime
;
470 compat_time_t shm_ctime
;
471 compat_ipc_pid_t shm_cpid
;
472 compat_ipc_pid_t shm_lpid
;
473 unsigned short shm_nattch
;
476 struct shmid64_ds32
{
477 struct ipc64_perm32 shm_perm
;
478 compat_size_t shm_segsz
;
479 compat_time_t shm_atime
;
480 compat_time_t shm_dtime
;
481 compat_time_t shm_ctime
;
482 compat_pid_t shm_cpid
;
483 compat_pid_t shm_lpid
;
484 unsigned int shm_nattch
;
485 unsigned int __unused1
;
486 unsigned int __unused2
;
489 struct ipc_kludge32
{
495 do_sys32_semctl(int first
, int second
, int third
, void __user
*uptr
)
506 if (get_user (pad
, (u32 __user
*)uptr
))
508 if ((third
& ~IPC_64
) == SETVAL
)
509 fourth
.val
= (int)pad
;
511 fourth
.__pad
= (void __user
*)A(pad
);
512 switch (third
& ~IPC_64
) {
524 err
= sys_semctl (first
, second
, third
, fourth
);
529 fourth
.__pad
= (struct semid64_ds __user
*)&s
;
532 err
= sys_semctl(first
, second
, third
| IPC_64
, fourth
);
535 if (third
& IPC_64
) {
536 struct semid64_ds32 __user
*usp64
= (struct semid64_ds32 __user
*) A(pad
);
538 if (!access_ok(VERIFY_WRITE
, usp64
, sizeof(*usp64
))) {
542 err2
= __put_user(s
.sem_perm
.key
, &usp64
->sem_perm
.key
);
543 err2
|= __put_user(s
.sem_perm
.uid
, &usp64
->sem_perm
.uid
);
544 err2
|= __put_user(s
.sem_perm
.gid
, &usp64
->sem_perm
.gid
);
545 err2
|= __put_user(s
.sem_perm
.cuid
, &usp64
->sem_perm
.cuid
);
546 err2
|= __put_user(s
.sem_perm
.cgid
, &usp64
->sem_perm
.cgid
);
547 err2
|= __put_user(s
.sem_perm
.mode
, &usp64
->sem_perm
.mode
);
548 err2
|= __put_user(s
.sem_perm
.seq
, &usp64
->sem_perm
.seq
);
549 err2
|= __put_user(s
.sem_otime
, &usp64
->sem_otime
);
550 err2
|= __put_user(s
.sem_ctime
, &usp64
->sem_ctime
);
551 err2
|= __put_user(s
.sem_nsems
, &usp64
->sem_nsems
);
553 struct semid_ds32 __user
*usp32
= (struct semid_ds32 __user
*) A(pad
);
555 if (!access_ok(VERIFY_WRITE
, usp32
, sizeof(*usp32
))) {
559 err2
= __put_user(s
.sem_perm
.key
, &usp32
->sem_perm
.key
);
560 err2
|= __put_user(s
.sem_perm
.uid
, &usp32
->sem_perm
.uid
);
561 err2
|= __put_user(s
.sem_perm
.gid
, &usp32
->sem_perm
.gid
);
562 err2
|= __put_user(s
.sem_perm
.cuid
, &usp32
->sem_perm
.cuid
);
563 err2
|= __put_user(s
.sem_perm
.cgid
, &usp32
->sem_perm
.cgid
);
564 err2
|= __put_user(s
.sem_perm
.mode
, &usp32
->sem_perm
.mode
);
565 err2
|= __put_user(s
.sem_perm
.seq
, &usp32
->sem_perm
.seq
);
566 err2
|= __put_user(s
.sem_otime
, &usp32
->sem_otime
);
567 err2
|= __put_user(s
.sem_ctime
, &usp32
->sem_ctime
);
568 err2
|= __put_user(s
.sem_nsems
, &usp32
->sem_nsems
);
583 do_sys32_msgsnd (int first
, int second
, int third
, void __user
*uptr
)
585 struct msgbuf32 __user
*up
= (struct msgbuf32 __user
*)uptr
;
592 p
= kmalloc (second
+ sizeof (struct msgbuf
)
596 err
= get_user (p
->mtype
, &up
->mtype
);
599 err
|= __copy_from_user (p
->mtext
, &up
->mtext
, second
);
604 err
= sys_msgsnd (first
, (struct msgbuf __user
*)p
, second
, third
);
613 do_sys32_msgrcv (int first
, int second
, int msgtyp
, int third
,
614 int version
, void __user
*uptr
)
616 struct msgbuf32 __user
*up
;
622 struct ipc_kludge32 __user
*uipck
= (struct ipc_kludge32 __user
*)uptr
;
623 struct ipc_kludge32 ipck
;
629 if (copy_from_user (&ipck
, uipck
, sizeof (struct ipc_kludge32
)))
631 uptr
= (void __user
*)AA(ipck
.msgp
);
632 msgtyp
= ipck
.msgtyp
;
638 p
= kmalloc (second
+ sizeof (struct msgbuf
) + 4, GFP_USER
);
643 err
= sys_msgrcv (first
, (struct msgbuf __user
*)p
, second
+ 4, msgtyp
, third
);
647 up
= (struct msgbuf32 __user
*)uptr
;
648 if (put_user (p
->mtype
, &up
->mtype
) ||
649 __copy_to_user (&up
->mtext
, p
->mtext
, err
))
658 do_sys32_msgctl (int first
, int second
, void __user
*uptr
)
660 int err
= -EINVAL
, err2
;
662 struct msqid_ds32 __user
*up32
= (struct msqid_ds32 __user
*)uptr
;
663 struct msqid64_ds32 __user
*up64
= (struct msqid64_ds32 __user
*)uptr
;
666 switch (second
& ~IPC_64
) {
670 err
= sys_msgctl (first
, second
, (struct msqid_ds __user
*)uptr
);
674 if (second
& IPC_64
) {
675 if (!access_ok(VERIFY_READ
, up64
, sizeof(*up64
))) {
679 err
= __get_user(m
.msg_perm
.uid
, &up64
->msg_perm
.uid
);
680 err
|= __get_user(m
.msg_perm
.gid
, &up64
->msg_perm
.gid
);
681 err
|= __get_user(m
.msg_perm
.mode
, &up64
->msg_perm
.mode
);
682 err
|= __get_user(m
.msg_qbytes
, &up64
->msg_qbytes
);
684 if (!access_ok(VERIFY_READ
, up32
, sizeof(*up32
))) {
688 err
= __get_user(m
.msg_perm
.uid
, &up32
->msg_perm
.uid
);
689 err
|= __get_user(m
.msg_perm
.gid
, &up32
->msg_perm
.gid
);
690 err
|= __get_user(m
.msg_perm
.mode
, &up32
->msg_perm
.mode
);
691 err
|= __get_user(m
.msg_qbytes
, &up32
->msg_qbytes
);
697 err
= sys_msgctl(first
, second
| IPC_64
, (struct msqid_ds __user
*)&m
);
705 err
= sys_msgctl(first
, second
| IPC_64
, (struct msqid_ds __user
*)&m
);
707 if (second
& IPC_64
) {
708 if (!access_ok(VERIFY_WRITE
, up64
, sizeof(*up64
))) {
712 err2
= __put_user(m
.msg_perm
.key
, &up64
->msg_perm
.key
);
713 err2
|= __put_user(m
.msg_perm
.uid
, &up64
->msg_perm
.uid
);
714 err2
|= __put_user(m
.msg_perm
.gid
, &up64
->msg_perm
.gid
);
715 err2
|= __put_user(m
.msg_perm
.cuid
, &up64
->msg_perm
.cuid
);
716 err2
|= __put_user(m
.msg_perm
.cgid
, &up64
->msg_perm
.cgid
);
717 err2
|= __put_user(m
.msg_perm
.mode
, &up64
->msg_perm
.mode
);
718 err2
|= __put_user(m
.msg_perm
.seq
, &up64
->msg_perm
.seq
);
719 err2
|= __put_user(m
.msg_stime
, &up64
->msg_stime
);
720 err2
|= __put_user(m
.msg_rtime
, &up64
->msg_rtime
);
721 err2
|= __put_user(m
.msg_ctime
, &up64
->msg_ctime
);
722 err2
|= __put_user(m
.msg_cbytes
, &up64
->msg_cbytes
);
723 err2
|= __put_user(m
.msg_qnum
, &up64
->msg_qnum
);
724 err2
|= __put_user(m
.msg_qbytes
, &up64
->msg_qbytes
);
725 err2
|= __put_user(m
.msg_lspid
, &up64
->msg_lspid
);
726 err2
|= __put_user(m
.msg_lrpid
, &up64
->msg_lrpid
);
730 if (!access_ok(VERIFY_WRITE
, up32
, sizeof(*up32
))) {
734 err2
= __put_user(m
.msg_perm
.key
, &up32
->msg_perm
.key
);
735 err2
|= __put_user(m
.msg_perm
.uid
, &up32
->msg_perm
.uid
);
736 err2
|= __put_user(m
.msg_perm
.gid
, &up32
->msg_perm
.gid
);
737 err2
|= __put_user(m
.msg_perm
.cuid
, &up32
->msg_perm
.cuid
);
738 err2
|= __put_user(m
.msg_perm
.cgid
, &up32
->msg_perm
.cgid
);
739 err2
|= __put_user(m
.msg_perm
.mode
, &up32
->msg_perm
.mode
);
740 err2
|= __put_user(m
.msg_perm
.seq
, &up32
->msg_perm
.seq
);
741 err2
|= __put_user(m
.msg_stime
, &up32
->msg_stime
);
742 err2
|= __put_user(m
.msg_rtime
, &up32
->msg_rtime
);
743 err2
|= __put_user(m
.msg_ctime
, &up32
->msg_ctime
);
744 err2
|= __put_user(m
.msg_cbytes
, &up32
->msg_cbytes
);
745 err2
|= __put_user(m
.msg_qnum
, &up32
->msg_qnum
);
746 err2
|= __put_user(m
.msg_qbytes
, &up32
->msg_qbytes
);
747 err2
|= __put_user(m
.msg_lspid
, &up32
->msg_lspid
);
748 err2
|= __put_user(m
.msg_lrpid
, &up32
->msg_lrpid
);
759 do_sys32_shmat (int first
, int second
, int third
, int version
, void __user
*uptr
)
762 u32 __user
*uaddr
= (u32 __user
*)A((u32
)third
);
767 err
= do_shmat (first
, uptr
, second
, &raddr
);
770 err
= put_user (raddr
, uaddr
);
776 u32 shm_tot
, shm_rss
, shm_swp
;
777 u32 swap_attempts
, swap_successes
;
781 do_sys32_shmctl (int first
, int second
, void __user
*uptr
)
783 struct shmid64_ds32 __user
*up64
= (struct shmid64_ds32 __user
*)uptr
;
784 struct shmid_ds32 __user
*up32
= (struct shmid_ds32 __user
*)uptr
;
785 struct shm_info32 __user
*uip
= (struct shm_info32 __user
*)uptr
;
786 int err
= -EFAULT
, err2
;
787 struct shmid64_ds s64
;
792 switch (second
& ~IPC_64
) {
794 second
= IPC_INFO
; /* So that we don't have to translate it */
798 err
= sys_shmctl(first
, second
, (struct shmid_ds __user
*)uptr
);
801 if (second
& IPC_64
) {
802 err
= get_user(s
.shm_perm
.uid
, &up64
->shm_perm
.uid
);
803 err
|= get_user(s
.shm_perm
.gid
, &up64
->shm_perm
.gid
);
804 err
|= get_user(s
.shm_perm
.mode
, &up64
->shm_perm
.mode
);
806 err
= get_user(s
.shm_perm
.uid
, &up32
->shm_perm
.uid
);
807 err
|= get_user(s
.shm_perm
.gid
, &up32
->shm_perm
.gid
);
808 err
|= get_user(s
.shm_perm
.mode
, &up32
->shm_perm
.mode
);
814 err
= sys_shmctl(first
, second
& ~IPC_64
, (struct shmid_ds __user
*)&s
);
822 err
= sys_shmctl(first
, second
| IPC_64
, (void __user
*) &s64
);
826 if (second
& IPC_64
) {
827 if (!access_ok(VERIFY_WRITE
, up64
, sizeof(*up64
))) {
831 err2
= __put_user(s64
.shm_perm
.key
, &up64
->shm_perm
.key
);
832 err2
|= __put_user(s64
.shm_perm
.uid
, &up64
->shm_perm
.uid
);
833 err2
|= __put_user(s64
.shm_perm
.gid
, &up64
->shm_perm
.gid
);
834 err2
|= __put_user(s64
.shm_perm
.cuid
, &up64
->shm_perm
.cuid
);
835 err2
|= __put_user(s64
.shm_perm
.cgid
, &up64
->shm_perm
.cgid
);
836 err2
|= __put_user(s64
.shm_perm
.mode
, &up64
->shm_perm
.mode
);
837 err2
|= __put_user(s64
.shm_perm
.seq
, &up64
->shm_perm
.seq
);
838 err2
|= __put_user(s64
.shm_atime
, &up64
->shm_atime
);
839 err2
|= __put_user(s64
.shm_dtime
, &up64
->shm_dtime
);
840 err2
|= __put_user(s64
.shm_ctime
, &up64
->shm_ctime
);
841 err2
|= __put_user(s64
.shm_segsz
, &up64
->shm_segsz
);
842 err2
|= __put_user(s64
.shm_nattch
, &up64
->shm_nattch
);
843 err2
|= __put_user(s64
.shm_cpid
, &up64
->shm_cpid
);
844 err2
|= __put_user(s64
.shm_lpid
, &up64
->shm_lpid
);
846 if (!access_ok(VERIFY_WRITE
, up32
, sizeof(*up32
))) {
850 err2
= __put_user(s64
.shm_perm
.key
, &up32
->shm_perm
.key
);
851 err2
|= __put_user(s64
.shm_perm
.uid
, &up32
->shm_perm
.uid
);
852 err2
|= __put_user(s64
.shm_perm
.gid
, &up32
->shm_perm
.gid
);
853 err2
|= __put_user(s64
.shm_perm
.cuid
, &up32
->shm_perm
.cuid
);
854 err2
|= __put_user(s64
.shm_perm
.cgid
, &up32
->shm_perm
.cgid
);
855 err2
|= __put_user(s64
.shm_perm
.mode
, &up32
->shm_perm
.mode
);
856 err2
|= __put_user(s64
.shm_perm
.seq
, &up32
->shm_perm
.seq
);
857 err2
|= __put_user(s64
.shm_atime
, &up32
->shm_atime
);
858 err2
|= __put_user(s64
.shm_dtime
, &up32
->shm_dtime
);
859 err2
|= __put_user(s64
.shm_ctime
, &up32
->shm_ctime
);
860 err2
|= __put_user(s64
.shm_segsz
, &up32
->shm_segsz
);
861 err2
|= __put_user(s64
.shm_nattch
, &up32
->shm_nattch
);
862 err2
|= __put_user(s64
.shm_cpid
, &up32
->shm_cpid
);
863 err2
|= __put_user(s64
.shm_lpid
, &up32
->shm_lpid
);
872 err
= sys_shmctl(first
, second
, (void __user
*)&si
);
876 err2
= put_user(si
.used_ids
, &uip
->used_ids
);
877 err2
|= __put_user(si
.shm_tot
, &uip
->shm_tot
);
878 err2
|= __put_user(si
.shm_rss
, &uip
->shm_rss
);
879 err2
|= __put_user(si
.shm_swp
, &uip
->shm_swp
);
880 err2
|= __put_user(si
.swap_attempts
, &uip
->swap_attempts
);
881 err2
|= __put_user (si
.swap_successes
, &uip
->swap_successes
);
894 static int sys32_semtimedop(int semid
, struct sembuf __user
*tsems
, int nsems
,
895 const struct compat_timespec __user
*timeout32
)
897 struct compat_timespec t32
;
898 struct timespec __user
*t64
= compat_alloc_user_space(sizeof(*t64
));
900 if (copy_from_user(&t32
, timeout32
, sizeof(t32
)))
903 if (put_user(t32
.tv_sec
, &t64
->tv_sec
) ||
904 put_user(t32
.tv_nsec
, &t64
->tv_nsec
))
907 return sys_semtimedop(semid
, tsems
, nsems
, t64
);
911 sys32_ipc (u32 call
, int first
, int second
, int third
, u32 ptr
, u32 fifth
)
915 version
= call
>> 16; /* hack for backward compatibility */
920 /* struct sembuf is the same on 32 and 64bit :)) */
921 err
= sys_semtimedop (first
, (struct sembuf __user
*)AA(ptr
), second
,
925 err
= sys32_semtimedop (first
, (struct sembuf __user
*)AA(ptr
), second
,
926 (const struct compat_timespec __user
*)AA(fifth
));
929 err
= sys_semget (first
, second
, third
);
932 err
= do_sys32_semctl (first
, second
, third
,
933 (void __user
*)AA(ptr
));
937 err
= do_sys32_msgsnd (first
, second
, third
,
938 (void __user
*)AA(ptr
));
941 err
= do_sys32_msgrcv (first
, second
, fifth
, third
,
942 version
, (void __user
*)AA(ptr
));
945 err
= sys_msgget ((key_t
) first
, second
);
948 err
= do_sys32_msgctl (first
, second
, (void __user
*)AA(ptr
));
952 err
= do_sys32_shmat (first
, second
, third
,
953 version
, (void __user
*)AA(ptr
));
956 err
= sys_shmdt ((char __user
*)A(ptr
));
959 err
= sys_shmget (first
, (unsigned)second
, third
);
962 err
= do_sys32_shmctl (first
, second
, (void __user
*)AA(ptr
));
972 asmlinkage
long sys32_shmat(int shmid
, char __user
*shmaddr
,
973 int shmflg
, int32_t __user
*addr
)
978 err
= do_shmat(shmid
, shmaddr
, shmflg
, &raddr
);
982 return put_user(raddr
, addr
);
989 compat_caddr_t oldval
;
990 compat_caddr_t oldlenp
;
991 compat_caddr_t newval
;
992 compat_size_t newlen
;
993 unsigned int __unused
[4];
996 #ifdef CONFIG_SYSCTL_SYSCALL
998 asmlinkage
long sys32_sysctl(struct sysctl_args32 __user
*args
)
1000 struct sysctl_args32 tmp
;
1003 size_t __user
*oldlenp
= NULL
;
1004 unsigned long addr
= (((unsigned long)&args
->__unused
[0]) + 7) & ~7;
1006 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1009 if (tmp
.oldval
&& tmp
.oldlenp
) {
1010 /* Duh, this is ugly and might not work if sysctl_args
1011 is in read-only memory, but do_sysctl does indirectly
1012 a lot of uaccess in both directions and we'd have to
1013 basically copy the whole sysctl.c here, and
1014 glibc's __sysctl uses rw memory for the structure
1016 if (get_user(oldlen
, (u32 __user
*)A(tmp
.oldlenp
)) ||
1017 put_user(oldlen
, (size_t __user
*)addr
))
1019 oldlenp
= (size_t __user
*)addr
;
1023 error
= do_sysctl((int __user
*)A(tmp
.name
), tmp
.nlen
, (void __user
*)A(tmp
.oldval
),
1024 oldlenp
, (void __user
*)A(tmp
.newval
), tmp
.newlen
);
1028 if (get_user(oldlen
, (size_t __user
*)addr
) ||
1029 put_user(oldlen
, (u32 __user
*)A(tmp
.oldlenp
)))
1032 copy_to_user(args
->__unused
, tmp
.__unused
, sizeof(tmp
.__unused
));
1037 #endif /* CONFIG_SYSCTL_SYSCALL */
1039 asmlinkage
long sys32_newuname(struct new_utsname __user
* name
)
1043 down_read(&uts_sem
);
1044 if (copy_to_user(name
, utsname(), sizeof *name
))
1048 if (current
->personality
== PER_LINUX32
&& !ret
)
1049 if (copy_to_user(name
->machine
, "mips\0\0\0", 8))
1055 asmlinkage
int sys32_personality(unsigned long personality
)
1058 personality
&= 0xffffffff;
1059 if (personality(current
->personality
) == PER_LINUX32
&&
1060 personality
== PER_LINUX
)
1061 personality
= PER_LINUX32
;
1062 ret
= sys_personality(personality
);
1063 if (ret
== PER_LINUX32
)
1068 /* ustat compatibility */
1070 compat_daddr_t f_tfree
;
1071 compat_ino_t f_tinode
;
1076 extern asmlinkage
long sys_ustat(dev_t dev
, struct ustat __user
* ubuf
);
1078 asmlinkage
int sys32_ustat(dev_t dev
, struct ustat32 __user
* ubuf32
)
1082 struct ustat32 tmp32
;
1083 mm_segment_t old_fs
= get_fs();
1086 err
= sys_ustat(dev
, (struct ustat __user
*)&tmp
);
1092 memset(&tmp32
,0,sizeof(struct ustat32
));
1093 tmp32
.f_tfree
= tmp
.f_tfree
;
1094 tmp32
.f_tinode
= tmp
.f_tinode
;
1096 err
= copy_to_user(ubuf32
,&tmp32
,sizeof(struct ustat32
)) ? -EFAULT
: 0;
1102 asmlinkage
int sys32_sendfile(int out_fd
, int in_fd
, compat_off_t __user
*offset
,
1105 mm_segment_t old_fs
= get_fs();
1109 if (offset
&& get_user(of
, offset
))
1113 ret
= sys_sendfile(out_fd
, in_fd
, offset
? (off_t __user
*)&of
: NULL
, count
);
1116 if (offset
&& put_user(of
, offset
))
1122 asmlinkage ssize_t
sys32_readahead(int fd
, u32 pad0
, u64 a2
, u64 a3
,
1125 return sys_readahead(fd
, merge_64(a2
, a3
), count
);
1128 asmlinkage
long sys32_sync_file_range(int fd
, int __pad
,
1129 unsigned long a2
, unsigned long a3
,
1130 unsigned long a4
, unsigned long a5
,
1133 return sys_sync_file_range(fd
,
1134 merge_64(a2
, a3
), merge_64(a4
, a5
),
1138 /* Argument list sizes for sys_socketcall */
1139 #define AL(x) ((x) * sizeof(unsigned int))
1140 static unsigned char socketcall_nargs
[18]={AL(0),AL(3),AL(3),AL(3),AL(2),AL(3),
1141 AL(3),AL(3),AL(4),AL(4),AL(4),AL(6),
1142 AL(6),AL(2),AL(5),AL(5),AL(3),AL(3)};
1146 * System call vectors.
1148 * Argument checking cleaned up. Saved 20% in size.
1149 * This function doesn't need to set the kernel lock because
1150 * it is set by the callees.
1153 asmlinkage
long sys32_socketcall(int call
, unsigned int __user
*args32
)
1159 extern asmlinkage
long sys_socket(int family
, int type
, int protocol
);
1160 extern asmlinkage
long sys_bind(int fd
, struct sockaddr __user
*umyaddr
, int addrlen
);
1161 extern asmlinkage
long sys_connect(int fd
, struct sockaddr __user
*uservaddr
, int addrlen
);
1162 extern asmlinkage
long sys_listen(int fd
, int backlog
);
1163 extern asmlinkage
long sys_accept(int fd
, struct sockaddr __user
*upeer_sockaddr
, int __user
*upeer_addrlen
);
1164 extern asmlinkage
long sys_getsockname(int fd
, struct sockaddr __user
*usockaddr
, int __user
*usockaddr_len
);
1165 extern asmlinkage
long sys_getpeername(int fd
, struct sockaddr __user
*usockaddr
, int __user
*usockaddr_len
);
1166 extern asmlinkage
long sys_socketpair(int family
, int type
, int protocol
, int __user
*usockvec
);
1167 extern asmlinkage
long sys_send(int fd
, void __user
* buff
, size_t len
, unsigned flags
);
1168 extern asmlinkage
long sys_sendto(int fd
, void __user
* buff
, size_t len
, unsigned flags
,
1169 struct sockaddr __user
*addr
, int addr_len
);
1170 extern asmlinkage
long sys_recv(int fd
, void __user
* ubuf
, size_t size
, unsigned flags
);
1171 extern asmlinkage
long sys_recvfrom(int fd
, void __user
* ubuf
, size_t size
, unsigned flags
,
1172 struct sockaddr __user
*addr
, int __user
*addr_len
);
1173 extern asmlinkage
long sys_shutdown(int fd
, int how
);
1174 extern asmlinkage
long sys_setsockopt(int fd
, int level
, int optname
, char __user
*optval
, int optlen
);
1175 extern asmlinkage
long sys_getsockopt(int fd
, int level
, int optname
, char __user
*optval
, int __user
*optlen
);
1176 extern asmlinkage
long sys_sendmsg(int fd
, struct msghdr __user
*msg
, unsigned flags
);
1177 extern asmlinkage
long sys_recvmsg(int fd
, struct msghdr __user
*msg
, unsigned int flags
);
1180 if(call
<1||call
>SYS_RECVMSG
)
1183 /* copy_from_user should be SMP safe. */
1184 if (copy_from_user(a
, args32
, socketcall_nargs
[call
]))
1193 err
= sys_socket(a0
,a1
,a
[2]);
1196 err
= sys_bind(a0
,(struct sockaddr __user
*)A(a1
), a
[2]);
1199 err
= sys_connect(a0
, (struct sockaddr __user
*)A(a1
), a
[2]);
1202 err
= sys_listen(a0
,a1
);
1205 err
= sys_accept(a0
,(struct sockaddr __user
*)A(a1
), (int __user
*)A(a
[2]));
1207 case SYS_GETSOCKNAME
:
1208 err
= sys_getsockname(a0
,(struct sockaddr __user
*)A(a1
), (int __user
*)A(a
[2]));
1210 case SYS_GETPEERNAME
:
1211 err
= sys_getpeername(a0
, (struct sockaddr __user
*)A(a1
), (int __user
*)A(a
[2]));
1213 case SYS_SOCKETPAIR
:
1214 err
= sys_socketpair(a0
,a1
, a
[2], (int __user
*)A(a
[3]));
1217 err
= sys_send(a0
, (void __user
*)A(a1
), a
[2], a
[3]);
1220 err
= sys_sendto(a0
,(void __user
*)A(a1
), a
[2], a
[3],
1221 (struct sockaddr __user
*)A(a
[4]), a
[5]);
1224 err
= sys_recv(a0
, (void __user
*)A(a1
), a
[2], a
[3]);
1227 err
= sys_recvfrom(a0
, (void __user
*)A(a1
), a
[2], a
[3],
1228 (struct sockaddr __user
*)A(a
[4]), (int __user
*)A(a
[5]));
1231 err
= sys_shutdown(a0
,a1
);
1233 case SYS_SETSOCKOPT
:
1234 err
= sys_setsockopt(a0
, a1
, a
[2], (char __user
*)A(a
[3]), a
[4]);
1236 case SYS_GETSOCKOPT
:
1237 err
= sys_getsockopt(a0
, a1
, a
[2], (char __user
*)A(a
[3]), (int __user
*)A(a
[4]));
1240 err
= sys_sendmsg(a0
, (struct msghdr __user
*) A(a1
), a
[2]);
1243 err
= sys_recvmsg(a0
, (struct msghdr __user
*) A(a1
), a
[2]);
1256 u32 payload
[(64 / 4) - 3];
1259 extern asmlinkage
long
1260 sys_timer_create(clockid_t which_clock
,
1261 struct sigevent __user
*timer_event_spec
,
1262 timer_t __user
* created_timer_id
);
1265 sys32_timer_create(u32 clock
, struct sigevent32 __user
*se32
, timer_t __user
*timer_id
)
1267 struct sigevent __user
*p
= NULL
;
1270 p
= compat_alloc_user_space(sizeof(struct sigevent
));
1271 memset(&se
, 0, sizeof(struct sigevent
));
1272 if (get_user(se
.sigev_value
.sival_int
, &se32
->sigev_value
) ||
1273 __get_user(se
.sigev_signo
, &se32
->sigev_signo
) ||
1274 __get_user(se
.sigev_notify
, &se32
->sigev_notify
) ||
1275 __copy_from_user(&se
._sigev_un
._pad
, &se32
->payload
,
1276 sizeof(se32
->payload
)) ||
1277 copy_to_user(p
, &se
, sizeof(se
)))
1280 return sys_timer_create(clock
, p
, timer_id
);
1283 save_static_function(sys32_clone
);
1284 __attribute_used__ noinline
static int
1285 _sys32_clone(nabi_no_regargs
struct pt_regs regs
)
1287 unsigned long clone_flags
;
1288 unsigned long newsp
;
1289 int __user
*parent_tidptr
, *child_tidptr
;
1291 clone_flags
= regs
.regs
[4];
1292 newsp
= regs
.regs
[5];
1294 newsp
= regs
.regs
[29];
1295 parent_tidptr
= (int __user
*) regs
.regs
[6];
1297 /* Use __dummy4 instead of getting it off the stack, so that
1299 child_tidptr
= (int __user
*) __dummy4
;
1300 return do_fork(clone_flags
, newsp
, ®s
, 0,
1301 parent_tidptr
, child_tidptr
);