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 tmp
.st_mode
= stat
->mode
;
81 tmp
.st_nlink
= stat
->nlink
;
82 SET_UID(tmp
.st_uid
, stat
->uid
);
83 SET_GID(tmp
.st_gid
, stat
->gid
);
84 tmp
.st_rdev
= new_encode_dev(stat
->rdev
);
85 tmp
.st_size
= stat
->size
;
86 tmp
.st_atime
= stat
->atime
.tv_sec
;
87 tmp
.st_mtime
= stat
->mtime
.tv_sec
;
88 tmp
.st_ctime
= stat
->ctime
.tv_sec
;
90 tmp
.st_atime_nsec
= stat
->atime
.tv_nsec
;
91 tmp
.st_mtime_nsec
= stat
->mtime
.tv_nsec
;
92 tmp
.st_ctime_nsec
= stat
->ctime
.tv_nsec
;
94 tmp
.st_blocks
= stat
->blocks
;
95 tmp
.st_blksize
= stat
->blksize
;
96 return copy_to_user(statbuf
,&tmp
,sizeof(tmp
)) ? -EFAULT
: 0;
99 asmlinkage
unsigned long
100 sys32_mmap2(unsigned long addr
, unsigned long len
, unsigned long prot
,
101 unsigned long flags
, unsigned long fd
, unsigned long pgoff
)
103 struct file
* file
= NULL
;
107 if (pgoff
& (~PAGE_MASK
>> 12))
109 pgoff
>>= PAGE_SHIFT
-12;
111 if (!(flags
& MAP_ANONYMOUS
)) {
117 flags
&= ~(MAP_EXECUTABLE
| MAP_DENYWRITE
);
119 down_write(¤t
->mm
->mmap_sem
);
120 error
= do_mmap_pgoff(file
, addr
, len
, prot
, flags
, pgoff
);
121 up_write(¤t
->mm
->mmap_sem
);
130 asmlinkage
int sys_truncate64(const char __user
*path
, unsigned int high
,
135 return sys_truncate(path
, ((long) high
<< 32) | low
);
138 asmlinkage
int sys_ftruncate64(unsigned int fd
, unsigned int high
,
143 return sys_ftruncate(fd
, ((long) high
<< 32) | low
);
147 * sys_execve() executes a new program.
149 asmlinkage
int sys32_execve(nabi_no_regargs
struct pt_regs regs
)
154 filename
= getname(compat_ptr(regs
.regs
[4]));
155 error
= PTR_ERR(filename
);
156 if (IS_ERR(filename
))
158 error
= compat_do_execve(filename
, compat_ptr(regs
.regs
[5]),
159 compat_ptr(regs
.regs
[6]), ®s
);
167 sysn32_waitid(int which
, compat_pid_t pid
,
168 siginfo_t __user
*uinfo
, int options
,
169 struct compat_rusage __user
*uru
)
173 mm_segment_t old_fs
= get_fs();
176 if (!access_ok(VERIFY_WRITE
, uinfo
, sizeof(*uinfo
)))
180 ret
= sys_waitid(which
, pid
, uinfo
, options
,
181 uru
? (struct rusage __user
*) &ru
: NULL
);
184 if (__get_user(si_signo
, &uinfo
->si_signo
))
186 if (ret
< 0 || si_signo
== 0)
190 ret
= put_compat_rusage(&ru
, uru
);
210 asmlinkage
int sys32_sysinfo(struct sysinfo32 __user
*info
)
214 mm_segment_t old_fs
= get_fs ();
217 ret
= sys_sysinfo((struct sysinfo __user
*)&s
);
219 err
= put_user (s
.uptime
, &info
->uptime
);
220 err
|= __put_user (s
.loads
[0], &info
->loads
[0]);
221 err
|= __put_user (s
.loads
[1], &info
->loads
[1]);
222 err
|= __put_user (s
.loads
[2], &info
->loads
[2]);
223 err
|= __put_user (s
.totalram
, &info
->totalram
);
224 err
|= __put_user (s
.freeram
, &info
->freeram
);
225 err
|= __put_user (s
.sharedram
, &info
->sharedram
);
226 err
|= __put_user (s
.bufferram
, &info
->bufferram
);
227 err
|= __put_user (s
.totalswap
, &info
->totalswap
);
228 err
|= __put_user (s
.freeswap
, &info
->freeswap
);
229 err
|= __put_user (s
.procs
, &info
->procs
);
230 err
|= __put_user (s
.totalhigh
, &info
->totalhigh
);
231 err
|= __put_user (s
.freehigh
, &info
->freehigh
);
232 err
|= __put_user (s
.mem_unit
, &info
->mem_unit
);
238 #define RLIM_INFINITY32 0x7fffffff
239 #define RESOURCE32(x) ((x > RLIM_INFINITY32) ? RLIM_INFINITY32 : x)
247 asmlinkage
long sys32_truncate64(const char __user
* path
, unsigned long __dummy
,
248 int length_hi
, int length_lo
)
251 asmlinkage
long sys32_truncate64(const char __user
* path
, unsigned long __dummy
,
252 int length_lo
, int length_hi
)
257 length
= ((unsigned long) length_hi
<< 32) | (unsigned int) length_lo
;
259 return sys_truncate(path
, length
);
263 asmlinkage
long sys32_ftruncate64(unsigned int fd
, unsigned long __dummy
,
264 int length_hi
, int length_lo
)
267 asmlinkage
long sys32_ftruncate64(unsigned int fd
, unsigned long __dummy
,
268 int length_lo
, int length_hi
)
273 length
= ((unsigned long) length_hi
<< 32) | (unsigned int) length_lo
;
275 return sys_ftruncate(fd
, length
);
279 get_tv32(struct timeval
*o
, struct compat_timeval __user
*i
)
281 return (!access_ok(VERIFY_READ
, i
, sizeof(*i
)) ||
282 (__get_user(o
->tv_sec
, &i
->tv_sec
) |
283 __get_user(o
->tv_usec
, &i
->tv_usec
)));
287 put_tv32(struct compat_timeval __user
*o
, struct timeval
*i
)
289 return (!access_ok(VERIFY_WRITE
, o
, sizeof(*o
)) ||
290 (__put_user(i
->tv_sec
, &o
->tv_sec
) |
291 __put_user(i
->tv_usec
, &o
->tv_usec
)));
294 extern struct timezone sys_tz
;
297 sys32_gettimeofday(struct compat_timeval __user
*tv
, struct timezone __user
*tz
)
301 do_gettimeofday(&ktv
);
302 if (put_tv32(tv
, &ktv
))
306 if (copy_to_user(tz
, &sys_tz
, sizeof(sys_tz
)))
312 static inline long get_ts32(struct timespec
*o
, struct compat_timeval __user
*i
)
316 if (!access_ok(VERIFY_READ
, i
, sizeof(*i
)))
318 if (__get_user(o
->tv_sec
, &i
->tv_sec
))
320 if (__get_user(usec
, &i
->tv_usec
))
322 o
->tv_nsec
= usec
* 1000;
327 sys32_settimeofday(struct compat_timeval __user
*tv
, struct timezone __user
*tz
)
333 if (get_ts32(&kts
, tv
))
337 if (copy_from_user(&ktz
, tz
, sizeof(ktz
)))
341 return do_sys_settimeofday(tv
? &kts
: NULL
, tz
? &ktz
: NULL
);
344 asmlinkage
int sys32_llseek(unsigned int fd
, unsigned int offset_high
,
345 unsigned int offset_low
, loff_t __user
* result
,
348 return sys_llseek(fd
, offset_high
, offset_low
, result
, origin
);
351 /* From the Single Unix Spec: pread & pwrite act like lseek to pos + op +
352 lseek back to original location. They fail just like lseek does on
353 non-seekable files. */
355 asmlinkage ssize_t
sys32_pread(unsigned int fd
, char __user
* buf
,
356 size_t count
, u32 unused
, u64 a4
, u64 a5
)
358 return sys_pread64(fd
, buf
, count
, merge_64(a4
, a5
));
361 asmlinkage ssize_t
sys32_pwrite(unsigned int fd
, const char __user
* buf
,
362 size_t count
, u32 unused
, u64 a4
, u64 a5
)
364 return sys_pwrite64(fd
, buf
, count
, merge_64(a4
, a5
));
367 asmlinkage
int sys32_sched_rr_get_interval(compat_pid_t pid
,
368 struct compat_timespec __user
*interval
)
372 mm_segment_t old_fs
= get_fs ();
375 ret
= sys_sched_rr_get_interval(pid
, (struct timespec __user
*)&t
);
377 if (put_user (t
.tv_sec
, &interval
->tv_sec
) ||
378 __put_user (t
.tv_nsec
, &interval
->tv_nsec
))
383 struct msgbuf32
{ s32 mtype
; char mtext
[1]; };
396 struct ipc64_perm32
{
404 unsigned short __pad1
;
405 unsigned int __unused1
;
406 unsigned int __unused2
;
410 struct ipc_perm32 sem_perm
; /* permissions .. see ipc.h */
411 compat_time_t sem_otime
; /* last semop time */
412 compat_time_t sem_ctime
; /* last change time */
413 u32 sem_base
; /* ptr to first semaphore in array */
414 u32 sem_pending
; /* pending operations to be processed */
415 u32 sem_pending_last
; /* last pending operation */
416 u32 undo
; /* undo requests on this array */
417 unsigned short sem_nsems
; /* no. of semaphores in array */
420 struct semid64_ds32
{
421 struct ipc64_perm32 sem_perm
;
422 compat_time_t sem_otime
;
423 compat_time_t sem_ctime
;
424 unsigned int sem_nsems
;
425 unsigned int __unused1
;
426 unsigned int __unused2
;
431 struct ipc_perm32 msg_perm
;
434 compat_time_t msg_stime
;
435 compat_time_t msg_rtime
;
436 compat_time_t msg_ctime
;
439 unsigned short msg_cbytes
;
440 unsigned short msg_qnum
;
441 unsigned short msg_qbytes
;
442 compat_ipc_pid_t msg_lspid
;
443 compat_ipc_pid_t msg_lrpid
;
446 struct msqid64_ds32
{
447 struct ipc64_perm32 msg_perm
;
448 compat_time_t msg_stime
;
449 unsigned int __unused1
;
450 compat_time_t msg_rtime
;
451 unsigned int __unused2
;
452 compat_time_t msg_ctime
;
453 unsigned int __unused3
;
454 unsigned int msg_cbytes
;
455 unsigned int msg_qnum
;
456 unsigned int msg_qbytes
;
457 compat_pid_t msg_lspid
;
458 compat_pid_t msg_lrpid
;
459 unsigned int __unused4
;
460 unsigned int __unused5
;
464 struct ipc_perm32 shm_perm
;
466 compat_time_t shm_atime
;
467 compat_time_t shm_dtime
;
468 compat_time_t shm_ctime
;
469 compat_ipc_pid_t shm_cpid
;
470 compat_ipc_pid_t shm_lpid
;
471 unsigned short shm_nattch
;
474 struct shmid64_ds32
{
475 struct ipc64_perm32 shm_perm
;
476 compat_size_t shm_segsz
;
477 compat_time_t shm_atime
;
478 compat_time_t shm_dtime
;
479 compat_time_t shm_ctime
;
480 compat_pid_t shm_cpid
;
481 compat_pid_t shm_lpid
;
482 unsigned int shm_nattch
;
483 unsigned int __unused1
;
484 unsigned int __unused2
;
487 struct ipc_kludge32
{
493 do_sys32_semctl(int first
, int second
, int third
, void __user
*uptr
)
504 if (get_user (pad
, (u32 __user
*)uptr
))
506 if ((third
& ~IPC_64
) == SETVAL
)
507 fourth
.val
= (int)pad
;
509 fourth
.__pad
= (void __user
*)A(pad
);
510 switch (third
& ~IPC_64
) {
522 err
= sys_semctl (first
, second
, third
, fourth
);
527 fourth
.__pad
= (struct semid64_ds __user
*)&s
;
530 err
= sys_semctl(first
, second
, third
| IPC_64
, fourth
);
533 if (third
& IPC_64
) {
534 struct semid64_ds32 __user
*usp64
= (struct semid64_ds32 __user
*) A(pad
);
536 if (!access_ok(VERIFY_WRITE
, usp64
, sizeof(*usp64
))) {
540 err2
= __put_user(s
.sem_perm
.key
, &usp64
->sem_perm
.key
);
541 err2
|= __put_user(s
.sem_perm
.uid
, &usp64
->sem_perm
.uid
);
542 err2
|= __put_user(s
.sem_perm
.gid
, &usp64
->sem_perm
.gid
);
543 err2
|= __put_user(s
.sem_perm
.cuid
, &usp64
->sem_perm
.cuid
);
544 err2
|= __put_user(s
.sem_perm
.cgid
, &usp64
->sem_perm
.cgid
);
545 err2
|= __put_user(s
.sem_perm
.mode
, &usp64
->sem_perm
.mode
);
546 err2
|= __put_user(s
.sem_perm
.seq
, &usp64
->sem_perm
.seq
);
547 err2
|= __put_user(s
.sem_otime
, &usp64
->sem_otime
);
548 err2
|= __put_user(s
.sem_ctime
, &usp64
->sem_ctime
);
549 err2
|= __put_user(s
.sem_nsems
, &usp64
->sem_nsems
);
551 struct semid_ds32 __user
*usp32
= (struct semid_ds32 __user
*) A(pad
);
553 if (!access_ok(VERIFY_WRITE
, usp32
, sizeof(*usp32
))) {
557 err2
= __put_user(s
.sem_perm
.key
, &usp32
->sem_perm
.key
);
558 err2
|= __put_user(s
.sem_perm
.uid
, &usp32
->sem_perm
.uid
);
559 err2
|= __put_user(s
.sem_perm
.gid
, &usp32
->sem_perm
.gid
);
560 err2
|= __put_user(s
.sem_perm
.cuid
, &usp32
->sem_perm
.cuid
);
561 err2
|= __put_user(s
.sem_perm
.cgid
, &usp32
->sem_perm
.cgid
);
562 err2
|= __put_user(s
.sem_perm
.mode
, &usp32
->sem_perm
.mode
);
563 err2
|= __put_user(s
.sem_perm
.seq
, &usp32
->sem_perm
.seq
);
564 err2
|= __put_user(s
.sem_otime
, &usp32
->sem_otime
);
565 err2
|= __put_user(s
.sem_ctime
, &usp32
->sem_ctime
);
566 err2
|= __put_user(s
.sem_nsems
, &usp32
->sem_nsems
);
581 do_sys32_msgsnd (int first
, int second
, int third
, void __user
*uptr
)
583 struct msgbuf32 __user
*up
= (struct msgbuf32 __user
*)uptr
;
590 p
= kmalloc (second
+ sizeof (struct msgbuf
)
594 err
= get_user (p
->mtype
, &up
->mtype
);
597 err
|= __copy_from_user (p
->mtext
, &up
->mtext
, second
);
602 err
= sys_msgsnd (first
, (struct msgbuf __user
*)p
, second
, third
);
611 do_sys32_msgrcv (int first
, int second
, int msgtyp
, int third
,
612 int version
, void __user
*uptr
)
614 struct msgbuf32 __user
*up
;
620 struct ipc_kludge32 __user
*uipck
= (struct ipc_kludge32 __user
*)uptr
;
621 struct ipc_kludge32 ipck
;
627 if (copy_from_user (&ipck
, uipck
, sizeof (struct ipc_kludge32
)))
629 uptr
= (void __user
*)AA(ipck
.msgp
);
630 msgtyp
= ipck
.msgtyp
;
636 p
= kmalloc (second
+ sizeof (struct msgbuf
) + 4, GFP_USER
);
641 err
= sys_msgrcv (first
, (struct msgbuf __user
*)p
, second
+ 4, msgtyp
, third
);
645 up
= (struct msgbuf32 __user
*)uptr
;
646 if (put_user (p
->mtype
, &up
->mtype
) ||
647 __copy_to_user (&up
->mtext
, p
->mtext
, err
))
656 do_sys32_msgctl (int first
, int second
, void __user
*uptr
)
658 int err
= -EINVAL
, err2
;
660 struct msqid_ds32 __user
*up32
= (struct msqid_ds32 __user
*)uptr
;
661 struct msqid64_ds32 __user
*up64
= (struct msqid64_ds32 __user
*)uptr
;
664 switch (second
& ~IPC_64
) {
668 err
= sys_msgctl (first
, second
, (struct msqid_ds __user
*)uptr
);
672 if (second
& IPC_64
) {
673 if (!access_ok(VERIFY_READ
, up64
, sizeof(*up64
))) {
677 err
= __get_user(m
.msg_perm
.uid
, &up64
->msg_perm
.uid
);
678 err
|= __get_user(m
.msg_perm
.gid
, &up64
->msg_perm
.gid
);
679 err
|= __get_user(m
.msg_perm
.mode
, &up64
->msg_perm
.mode
);
680 err
|= __get_user(m
.msg_qbytes
, &up64
->msg_qbytes
);
682 if (!access_ok(VERIFY_READ
, up32
, sizeof(*up32
))) {
686 err
= __get_user(m
.msg_perm
.uid
, &up32
->msg_perm
.uid
);
687 err
|= __get_user(m
.msg_perm
.gid
, &up32
->msg_perm
.gid
);
688 err
|= __get_user(m
.msg_perm
.mode
, &up32
->msg_perm
.mode
);
689 err
|= __get_user(m
.msg_qbytes
, &up32
->msg_qbytes
);
695 err
= sys_msgctl(first
, second
| IPC_64
, (struct msqid_ds __user
*)&m
);
703 err
= sys_msgctl(first
, second
| IPC_64
, (struct msqid_ds __user
*)&m
);
705 if (second
& IPC_64
) {
706 if (!access_ok(VERIFY_WRITE
, up64
, sizeof(*up64
))) {
710 err2
= __put_user(m
.msg_perm
.key
, &up64
->msg_perm
.key
);
711 err2
|= __put_user(m
.msg_perm
.uid
, &up64
->msg_perm
.uid
);
712 err2
|= __put_user(m
.msg_perm
.gid
, &up64
->msg_perm
.gid
);
713 err2
|= __put_user(m
.msg_perm
.cuid
, &up64
->msg_perm
.cuid
);
714 err2
|= __put_user(m
.msg_perm
.cgid
, &up64
->msg_perm
.cgid
);
715 err2
|= __put_user(m
.msg_perm
.mode
, &up64
->msg_perm
.mode
);
716 err2
|= __put_user(m
.msg_perm
.seq
, &up64
->msg_perm
.seq
);
717 err2
|= __put_user(m
.msg_stime
, &up64
->msg_stime
);
718 err2
|= __put_user(m
.msg_rtime
, &up64
->msg_rtime
);
719 err2
|= __put_user(m
.msg_ctime
, &up64
->msg_ctime
);
720 err2
|= __put_user(m
.msg_cbytes
, &up64
->msg_cbytes
);
721 err2
|= __put_user(m
.msg_qnum
, &up64
->msg_qnum
);
722 err2
|= __put_user(m
.msg_qbytes
, &up64
->msg_qbytes
);
723 err2
|= __put_user(m
.msg_lspid
, &up64
->msg_lspid
);
724 err2
|= __put_user(m
.msg_lrpid
, &up64
->msg_lrpid
);
728 if (!access_ok(VERIFY_WRITE
, up32
, sizeof(*up32
))) {
732 err2
= __put_user(m
.msg_perm
.key
, &up32
->msg_perm
.key
);
733 err2
|= __put_user(m
.msg_perm
.uid
, &up32
->msg_perm
.uid
);
734 err2
|= __put_user(m
.msg_perm
.gid
, &up32
->msg_perm
.gid
);
735 err2
|= __put_user(m
.msg_perm
.cuid
, &up32
->msg_perm
.cuid
);
736 err2
|= __put_user(m
.msg_perm
.cgid
, &up32
->msg_perm
.cgid
);
737 err2
|= __put_user(m
.msg_perm
.mode
, &up32
->msg_perm
.mode
);
738 err2
|= __put_user(m
.msg_perm
.seq
, &up32
->msg_perm
.seq
);
739 err2
|= __put_user(m
.msg_stime
, &up32
->msg_stime
);
740 err2
|= __put_user(m
.msg_rtime
, &up32
->msg_rtime
);
741 err2
|= __put_user(m
.msg_ctime
, &up32
->msg_ctime
);
742 err2
|= __put_user(m
.msg_cbytes
, &up32
->msg_cbytes
);
743 err2
|= __put_user(m
.msg_qnum
, &up32
->msg_qnum
);
744 err2
|= __put_user(m
.msg_qbytes
, &up32
->msg_qbytes
);
745 err2
|= __put_user(m
.msg_lspid
, &up32
->msg_lspid
);
746 err2
|= __put_user(m
.msg_lrpid
, &up32
->msg_lrpid
);
757 do_sys32_shmat (int first
, int second
, int third
, int version
, void __user
*uptr
)
760 u32 __user
*uaddr
= (u32 __user
*)A((u32
)third
);
765 err
= do_shmat (first
, uptr
, second
, &raddr
);
768 err
= put_user (raddr
, uaddr
);
774 u32 shm_tot
, shm_rss
, shm_swp
;
775 u32 swap_attempts
, swap_successes
;
779 do_sys32_shmctl (int first
, int second
, void __user
*uptr
)
781 struct shmid64_ds32 __user
*up64
= (struct shmid64_ds32 __user
*)uptr
;
782 struct shmid_ds32 __user
*up32
= (struct shmid_ds32 __user
*)uptr
;
783 struct shm_info32 __user
*uip
= (struct shm_info32 __user
*)uptr
;
784 int err
= -EFAULT
, err2
;
785 struct shmid64_ds s64
;
790 switch (second
& ~IPC_64
) {
792 second
= IPC_INFO
; /* So that we don't have to translate it */
796 err
= sys_shmctl(first
, second
, (struct shmid_ds __user
*)uptr
);
799 if (second
& IPC_64
) {
800 err
= get_user(s
.shm_perm
.uid
, &up64
->shm_perm
.uid
);
801 err
|= get_user(s
.shm_perm
.gid
, &up64
->shm_perm
.gid
);
802 err
|= get_user(s
.shm_perm
.mode
, &up64
->shm_perm
.mode
);
804 err
= get_user(s
.shm_perm
.uid
, &up32
->shm_perm
.uid
);
805 err
|= get_user(s
.shm_perm
.gid
, &up32
->shm_perm
.gid
);
806 err
|= get_user(s
.shm_perm
.mode
, &up32
->shm_perm
.mode
);
812 err
= sys_shmctl(first
, second
& ~IPC_64
, (struct shmid_ds __user
*)&s
);
820 err
= sys_shmctl(first
, second
| IPC_64
, (void __user
*) &s64
);
824 if (second
& IPC_64
) {
825 if (!access_ok(VERIFY_WRITE
, up64
, sizeof(*up64
))) {
829 err2
= __put_user(s64
.shm_perm
.key
, &up64
->shm_perm
.key
);
830 err2
|= __put_user(s64
.shm_perm
.uid
, &up64
->shm_perm
.uid
);
831 err2
|= __put_user(s64
.shm_perm
.gid
, &up64
->shm_perm
.gid
);
832 err2
|= __put_user(s64
.shm_perm
.cuid
, &up64
->shm_perm
.cuid
);
833 err2
|= __put_user(s64
.shm_perm
.cgid
, &up64
->shm_perm
.cgid
);
834 err2
|= __put_user(s64
.shm_perm
.mode
, &up64
->shm_perm
.mode
);
835 err2
|= __put_user(s64
.shm_perm
.seq
, &up64
->shm_perm
.seq
);
836 err2
|= __put_user(s64
.shm_atime
, &up64
->shm_atime
);
837 err2
|= __put_user(s64
.shm_dtime
, &up64
->shm_dtime
);
838 err2
|= __put_user(s64
.shm_ctime
, &up64
->shm_ctime
);
839 err2
|= __put_user(s64
.shm_segsz
, &up64
->shm_segsz
);
840 err2
|= __put_user(s64
.shm_nattch
, &up64
->shm_nattch
);
841 err2
|= __put_user(s64
.shm_cpid
, &up64
->shm_cpid
);
842 err2
|= __put_user(s64
.shm_lpid
, &up64
->shm_lpid
);
844 if (!access_ok(VERIFY_WRITE
, up32
, sizeof(*up32
))) {
848 err2
= __put_user(s64
.shm_perm
.key
, &up32
->shm_perm
.key
);
849 err2
|= __put_user(s64
.shm_perm
.uid
, &up32
->shm_perm
.uid
);
850 err2
|= __put_user(s64
.shm_perm
.gid
, &up32
->shm_perm
.gid
);
851 err2
|= __put_user(s64
.shm_perm
.cuid
, &up32
->shm_perm
.cuid
);
852 err2
|= __put_user(s64
.shm_perm
.cgid
, &up32
->shm_perm
.cgid
);
853 err2
|= __put_user(s64
.shm_perm
.mode
, &up32
->shm_perm
.mode
);
854 err2
|= __put_user(s64
.shm_perm
.seq
, &up32
->shm_perm
.seq
);
855 err2
|= __put_user(s64
.shm_atime
, &up32
->shm_atime
);
856 err2
|= __put_user(s64
.shm_dtime
, &up32
->shm_dtime
);
857 err2
|= __put_user(s64
.shm_ctime
, &up32
->shm_ctime
);
858 err2
|= __put_user(s64
.shm_segsz
, &up32
->shm_segsz
);
859 err2
|= __put_user(s64
.shm_nattch
, &up32
->shm_nattch
);
860 err2
|= __put_user(s64
.shm_cpid
, &up32
->shm_cpid
);
861 err2
|= __put_user(s64
.shm_lpid
, &up32
->shm_lpid
);
870 err
= sys_shmctl(first
, second
, (void __user
*)&si
);
874 err2
= put_user(si
.used_ids
, &uip
->used_ids
);
875 err2
|= __put_user(si
.shm_tot
, &uip
->shm_tot
);
876 err2
|= __put_user(si
.shm_rss
, &uip
->shm_rss
);
877 err2
|= __put_user(si
.shm_swp
, &uip
->shm_swp
);
878 err2
|= __put_user(si
.swap_attempts
, &uip
->swap_attempts
);
879 err2
|= __put_user (si
.swap_successes
, &uip
->swap_successes
);
892 static int sys32_semtimedop(int semid
, struct sembuf __user
*tsems
, int nsems
,
893 const struct compat_timespec __user
*timeout32
)
895 struct compat_timespec t32
;
896 struct timespec __user
*t64
= compat_alloc_user_space(sizeof(*t64
));
898 if (copy_from_user(&t32
, timeout32
, sizeof(t32
)))
901 if (put_user(t32
.tv_sec
, &t64
->tv_sec
) ||
902 put_user(t32
.tv_nsec
, &t64
->tv_nsec
))
905 return sys_semtimedop(semid
, tsems
, nsems
, t64
);
909 sys32_ipc (u32 call
, int first
, int second
, int third
, u32 ptr
, u32 fifth
)
913 version
= call
>> 16; /* hack for backward compatibility */
918 /* struct sembuf is the same on 32 and 64bit :)) */
919 err
= sys_semtimedop (first
, (struct sembuf __user
*)AA(ptr
), second
,
923 err
= sys32_semtimedop (first
, (struct sembuf __user
*)AA(ptr
), second
,
924 (const struct compat_timespec __user
*)AA(fifth
));
927 err
= sys_semget (first
, second
, third
);
930 err
= do_sys32_semctl (first
, second
, third
,
931 (void __user
*)AA(ptr
));
935 err
= do_sys32_msgsnd (first
, second
, third
,
936 (void __user
*)AA(ptr
));
939 err
= do_sys32_msgrcv (first
, second
, fifth
, third
,
940 version
, (void __user
*)AA(ptr
));
943 err
= sys_msgget ((key_t
) first
, second
);
946 err
= do_sys32_msgctl (first
, second
, (void __user
*)AA(ptr
));
950 err
= do_sys32_shmat (first
, second
, third
,
951 version
, (void __user
*)AA(ptr
));
954 err
= sys_shmdt ((char __user
*)A(ptr
));
957 err
= sys_shmget (first
, (unsigned)second
, third
);
960 err
= do_sys32_shmctl (first
, second
, (void __user
*)AA(ptr
));
970 asmlinkage
long sys32_shmat(int shmid
, char __user
*shmaddr
,
971 int shmflg
, int32_t __user
*addr
)
976 err
= do_shmat(shmid
, shmaddr
, shmflg
, &raddr
);
980 return put_user(raddr
, addr
);
987 compat_caddr_t oldval
;
988 compat_caddr_t oldlenp
;
989 compat_caddr_t newval
;
990 compat_size_t newlen
;
991 unsigned int __unused
[4];
996 asmlinkage
long sys32_sysctl(struct sysctl_args32 __user
*args
)
998 struct sysctl_args32 tmp
;
1001 size_t __user
*oldlenp
= NULL
;
1002 unsigned long addr
= (((unsigned long)&args
->__unused
[0]) + 7) & ~7;
1004 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1007 if (tmp
.oldval
&& tmp
.oldlenp
) {
1008 /* Duh, this is ugly and might not work if sysctl_args
1009 is in read-only memory, but do_sysctl does indirectly
1010 a lot of uaccess in both directions and we'd have to
1011 basically copy the whole sysctl.c here, and
1012 glibc's __sysctl uses rw memory for the structure
1014 if (get_user(oldlen
, (u32 __user
*)A(tmp
.oldlenp
)) ||
1015 put_user(oldlen
, (size_t __user
*)addr
))
1017 oldlenp
= (size_t __user
*)addr
;
1021 error
= do_sysctl((int __user
*)A(tmp
.name
), tmp
.nlen
, (void __user
*)A(tmp
.oldval
),
1022 oldlenp
, (void __user
*)A(tmp
.newval
), tmp
.newlen
);
1026 if (get_user(oldlen
, (size_t __user
*)addr
) ||
1027 put_user(oldlen
, (u32 __user
*)A(tmp
.oldlenp
)))
1030 copy_to_user(args
->__unused
, tmp
.__unused
, sizeof(tmp
.__unused
));
1035 #endif /* CONFIG_SYSCTL */
1037 asmlinkage
long sys32_newuname(struct new_utsname __user
* name
)
1041 down_read(&uts_sem
);
1042 if (copy_to_user(name
,&system_utsname
,sizeof *name
))
1046 if (current
->personality
== PER_LINUX32
&& !ret
)
1047 if (copy_to_user(name
->machine
, "mips\0\0\0", 8))
1053 asmlinkage
int sys32_personality(unsigned long personality
)
1056 if (current
->personality
== PER_LINUX32
&& personality
== PER_LINUX
)
1057 personality
= PER_LINUX32
;
1058 ret
= sys_personality(personality
);
1059 if (ret
== PER_LINUX32
)
1064 /* ustat compatibility */
1066 compat_daddr_t f_tfree
;
1067 compat_ino_t f_tinode
;
1072 extern asmlinkage
long sys_ustat(dev_t dev
, struct ustat __user
* ubuf
);
1074 asmlinkage
int sys32_ustat(dev_t dev
, struct ustat32 __user
* ubuf32
)
1078 struct ustat32 tmp32
;
1079 mm_segment_t old_fs
= get_fs();
1082 err
= sys_ustat(dev
, (struct ustat __user
*)&tmp
);
1088 memset(&tmp32
,0,sizeof(struct ustat32
));
1089 tmp32
.f_tfree
= tmp
.f_tfree
;
1090 tmp32
.f_tinode
= tmp
.f_tinode
;
1092 err
= copy_to_user(ubuf32
,&tmp32
,sizeof(struct ustat32
)) ? -EFAULT
: 0;
1098 asmlinkage
int sys32_sendfile(int out_fd
, int in_fd
, compat_off_t __user
*offset
,
1101 mm_segment_t old_fs
= get_fs();
1105 if (offset
&& get_user(of
, offset
))
1109 ret
= sys_sendfile(out_fd
, in_fd
, offset
? (off_t __user
*)&of
: NULL
, count
);
1112 if (offset
&& put_user(of
, offset
))
1118 asmlinkage ssize_t
sys32_readahead(int fd
, u32 pad0
, u64 a2
, u64 a3
,
1121 return sys_readahead(fd
, merge_64(a2
, a3
), count
);
1124 asmlinkage
long sys32_sync_file_range(int fd
, int __pad
,
1125 unsigned long a2
, unsigned long a3
,
1126 unsigned long a4
, unsigned long a5
,
1129 return sys_sync_file_range(fd
,
1130 merge_64(a2
, a3
), merge_64(a4
, a5
),
1134 /* Argument list sizes for sys_socketcall */
1135 #define AL(x) ((x) * sizeof(unsigned int))
1136 static unsigned char socketcall_nargs
[18]={AL(0),AL(3),AL(3),AL(3),AL(2),AL(3),
1137 AL(3),AL(3),AL(4),AL(4),AL(4),AL(6),
1138 AL(6),AL(2),AL(5),AL(5),AL(3),AL(3)};
1142 * System call vectors.
1144 * Argument checking cleaned up. Saved 20% in size.
1145 * This function doesn't need to set the kernel lock because
1146 * it is set by the callees.
1149 asmlinkage
long sys32_socketcall(int call
, unsigned int __user
*args32
)
1155 extern asmlinkage
long sys_socket(int family
, int type
, int protocol
);
1156 extern asmlinkage
long sys_bind(int fd
, struct sockaddr __user
*umyaddr
, int addrlen
);
1157 extern asmlinkage
long sys_connect(int fd
, struct sockaddr __user
*uservaddr
, int addrlen
);
1158 extern asmlinkage
long sys_listen(int fd
, int backlog
);
1159 extern asmlinkage
long sys_accept(int fd
, struct sockaddr __user
*upeer_sockaddr
, int __user
*upeer_addrlen
);
1160 extern asmlinkage
long sys_getsockname(int fd
, struct sockaddr __user
*usockaddr
, int __user
*usockaddr_len
);
1161 extern asmlinkage
long sys_getpeername(int fd
, struct sockaddr __user
*usockaddr
, int __user
*usockaddr_len
);
1162 extern asmlinkage
long sys_socketpair(int family
, int type
, int protocol
, int __user
*usockvec
);
1163 extern asmlinkage
long sys_send(int fd
, void __user
* buff
, size_t len
, unsigned flags
);
1164 extern asmlinkage
long sys_sendto(int fd
, void __user
* buff
, size_t len
, unsigned flags
,
1165 struct sockaddr __user
*addr
, int addr_len
);
1166 extern asmlinkage
long sys_recv(int fd
, void __user
* ubuf
, size_t size
, unsigned flags
);
1167 extern asmlinkage
long sys_recvfrom(int fd
, void __user
* ubuf
, size_t size
, unsigned flags
,
1168 struct sockaddr __user
*addr
, int __user
*addr_len
);
1169 extern asmlinkage
long sys_shutdown(int fd
, int how
);
1170 extern asmlinkage
long sys_setsockopt(int fd
, int level
, int optname
, char __user
*optval
, int optlen
);
1171 extern asmlinkage
long sys_getsockopt(int fd
, int level
, int optname
, char __user
*optval
, int __user
*optlen
);
1172 extern asmlinkage
long sys_sendmsg(int fd
, struct msghdr __user
*msg
, unsigned flags
);
1173 extern asmlinkage
long sys_recvmsg(int fd
, struct msghdr __user
*msg
, unsigned int flags
);
1176 if(call
<1||call
>SYS_RECVMSG
)
1179 /* copy_from_user should be SMP safe. */
1180 if (copy_from_user(a
, args32
, socketcall_nargs
[call
]))
1189 err
= sys_socket(a0
,a1
,a
[2]);
1192 err
= sys_bind(a0
,(struct sockaddr __user
*)A(a1
), a
[2]);
1195 err
= sys_connect(a0
, (struct sockaddr __user
*)A(a1
), a
[2]);
1198 err
= sys_listen(a0
,a1
);
1201 err
= sys_accept(a0
,(struct sockaddr __user
*)A(a1
), (int __user
*)A(a
[2]));
1203 case SYS_GETSOCKNAME
:
1204 err
= sys_getsockname(a0
,(struct sockaddr __user
*)A(a1
), (int __user
*)A(a
[2]));
1206 case SYS_GETPEERNAME
:
1207 err
= sys_getpeername(a0
, (struct sockaddr __user
*)A(a1
), (int __user
*)A(a
[2]));
1209 case SYS_SOCKETPAIR
:
1210 err
= sys_socketpair(a0
,a1
, a
[2], (int __user
*)A(a
[3]));
1213 err
= sys_send(a0
, (void __user
*)A(a1
), a
[2], a
[3]);
1216 err
= sys_sendto(a0
,(void __user
*)A(a1
), a
[2], a
[3],
1217 (struct sockaddr __user
*)A(a
[4]), a
[5]);
1220 err
= sys_recv(a0
, (void __user
*)A(a1
), a
[2], a
[3]);
1223 err
= sys_recvfrom(a0
, (void __user
*)A(a1
), a
[2], a
[3],
1224 (struct sockaddr __user
*)A(a
[4]), (int __user
*)A(a
[5]));
1227 err
= sys_shutdown(a0
,a1
);
1229 case SYS_SETSOCKOPT
:
1230 err
= sys_setsockopt(a0
, a1
, a
[2], (char __user
*)A(a
[3]), a
[4]);
1232 case SYS_GETSOCKOPT
:
1233 err
= sys_getsockopt(a0
, a1
, a
[2], (char __user
*)A(a
[3]), (int __user
*)A(a
[4]));
1236 err
= sys_sendmsg(a0
, (struct msghdr __user
*) A(a1
), a
[2]);
1239 err
= sys_recvmsg(a0
, (struct msghdr __user
*) A(a1
), a
[2]);
1252 u32 payload
[(64 / 4) - 3];
1255 extern asmlinkage
long
1256 sys_timer_create(clockid_t which_clock
,
1257 struct sigevent __user
*timer_event_spec
,
1258 timer_t __user
* created_timer_id
);
1261 sys32_timer_create(u32 clock
, struct sigevent32 __user
*se32
, timer_t __user
*timer_id
)
1263 struct sigevent __user
*p
= NULL
;
1266 p
= compat_alloc_user_space(sizeof(struct sigevent
));
1267 memset(&se
, 0, sizeof(struct sigevent
));
1268 if (get_user(se
.sigev_value
.sival_int
, &se32
->sigev_value
) ||
1269 __get_user(se
.sigev_signo
, &se32
->sigev_signo
) ||
1270 __get_user(se
.sigev_notify
, &se32
->sigev_notify
) ||
1271 __copy_from_user(&se
._sigev_un
._pad
, &se32
->payload
,
1272 sizeof(se32
->payload
)) ||
1273 copy_to_user(p
, &se
, sizeof(se
)))
1276 return sys_timer_create(clock
, p
, timer_id
);
1279 save_static_function(sys32_clone
);
1280 __attribute_used__ noinline
static int
1281 _sys32_clone(nabi_no_regargs
struct pt_regs regs
)
1283 unsigned long clone_flags
;
1284 unsigned long newsp
;
1285 int __user
*parent_tidptr
, *child_tidptr
;
1287 clone_flags
= regs
.regs
[4];
1288 newsp
= regs
.regs
[5];
1290 newsp
= regs
.regs
[29];
1291 parent_tidptr
= (int __user
*) regs
.regs
[6];
1293 /* Use __dummy4 instead of getting it off the stack, so that
1295 child_tidptr
= (int __user
*) __dummy4
;
1296 return do_fork(clone_flags
, newsp
, ®s
, 0,
1297 parent_tidptr
, child_tidptr
);
1300 extern asmlinkage
void sys_set_thread_area(u32 addr
);
1301 asmlinkage
void sys32_set_thread_area(u32 addr
)
1303 sys_set_thread_area(AA(addr
));