2 * sys_parisc32.c: Conversion between 32bit and 64bit native syscalls.
4 * Copyright (C) 2000-2001 Hewlett Packard Company
5 * Copyright (C) 2000 John Marvin
6 * Copyright (C) 2001 Matthew Wilcox
8 * These routines maintain argument size conversion between 32bit and 64bit
9 * environment. Based heavily on sys_ia32.c and sys_sparc32.c.
12 #include <linux/compat.h>
13 #include <linux/kernel.h>
14 #include <linux/sched.h>
17 #include <linux/file.h>
18 #include <linux/signal.h>
19 #include <linux/resource.h>
20 #include <linux/times.h>
21 #include <linux/utsname.h>
22 #include <linux/time.h>
23 #include <linux/smp.h>
24 #include <linux/smp_lock.h>
25 #include <linux/sem.h>
26 #include <linux/msg.h>
27 #include <linux/shm.h>
28 #include <linux/slab.h>
29 #include <linux/uio.h>
30 #include <linux/nfs_fs.h>
31 #include <linux/ncp_fs.h>
32 #include <linux/sunrpc/svc.h>
33 #include <linux/nfsd/nfsd.h>
34 #include <linux/nfsd/cache.h>
35 #include <linux/nfsd/xdr.h>
36 #include <linux/nfsd/syscall.h>
37 #include <linux/poll.h>
38 #include <linux/personality.h>
39 #include <linux/stat.h>
40 #include <linux/highmem.h>
41 #include <linux/highuid.h>
42 #include <linux/mman.h>
43 #include <linux/binfmts.h>
44 #include <linux/namei.h>
45 #include <linux/vfs.h>
46 #include <linux/ptrace.h>
47 #include <linux/swap.h>
48 #include <linux/syscalls.h>
50 #include <asm/types.h>
51 #include <asm/uaccess.h>
52 #include <asm/mmu_context.h>
59 #define DBG(x) printk x
65 * sys32_execve() executes a new program.
68 asmlinkage
int sys32_execve(struct pt_regs
*regs
)
73 DBG(("sys32_execve(%p) r26 = 0x%lx\n", regs
, regs
->gr
[26]));
74 filename
= getname((const char __user
*) regs
->gr
[26]);
75 error
= PTR_ERR(filename
);
78 error
= compat_do_execve(filename
, compat_ptr(regs
->gr
[25]),
79 compat_ptr(regs
->gr
[24]), regs
);
82 current
->ptrace
&= ~PT_DTRACE
;
91 asmlinkage
long sys32_unimplemented(int r26
, int r25
, int r24
, int r23
,
92 int r22
, int r21
, int r20
)
94 printk(KERN_ERR
"%s(%d): Unimplemented 32 on 64 syscall #%d!\n",
95 current
->comm
, current
->pid
, r20
);
101 struct __sysctl_args32
{
111 asmlinkage
long sys32_sysctl(struct __sysctl_args32 __user
*args
)
113 #ifndef CONFIG_SYSCTL_SYSCALL
116 struct __sysctl_args32 tmp
;
118 unsigned int oldlen32
;
119 size_t oldlen
, __user
*oldlenp
= NULL
;
120 unsigned long addr
= (((long __force
)&args
->__unused
[0]) + 7) & ~7;
122 DBG(("sysctl32(%p)\n", args
));
124 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
127 if (tmp
.oldval
&& tmp
.oldlenp
) {
128 /* Duh, this is ugly and might not work if sysctl_args
129 is in read-only memory, but do_sysctl does indirectly
130 a lot of uaccess in both directions and we'd have to
131 basically copy the whole sysctl.c here, and
132 glibc's __sysctl uses rw memory for the structure
134 /* a possibly better hack than this, which will avoid the
135 * problem if the struct is read only, is to push the
136 * 'oldlen' value out to the user's stack instead. -PB
138 if (get_user(oldlen32
, (u32
*)(u64
)tmp
.oldlenp
))
141 if (put_user(oldlen
, (size_t *)addr
))
143 oldlenp
= (size_t *)addr
;
147 error
= do_sysctl((int __user
*)(u64
)tmp
.name
, tmp
.nlen
,
148 (void __user
*)(u64
)tmp
.oldval
, oldlenp
,
149 (void __user
*)(u64
)tmp
.newval
, tmp
.newlen
);
153 if (get_user(oldlen
, (size_t *)addr
)) {
157 if (put_user(oldlen32
, (u32
*)(u64
)tmp
.oldlenp
))
161 if (copy_to_user(args
->__unused
, tmp
.__unused
, sizeof(tmp
.__unused
)))
168 #endif /* CONFIG_SYSCTL */
170 asmlinkage
long sys32_sched_rr_get_interval(pid_t pid
,
171 struct compat_timespec __user
*interval
)
176 KERNEL_SYSCALL(ret
, sys_sched_rr_get_interval
, pid
, (struct timespec __user
*)&t
);
177 if (put_compat_timespec(&t
, interval
))
182 /*** copied from mips64 ***/
184 * Ooo, nasty. We need here to frob 32-bit unsigned longs to
185 * 64-bit unsigned longs.
189 get_fd_set32(unsigned long n
, u32
*ufdset
, unsigned long *fdset
)
191 n
= (n
+ 8*sizeof(u32
) - 1) / (8*sizeof(u32
));
195 if (!access_ok(VERIFY_WRITE
, ufdset
, n
*sizeof(u32
)))
202 __get_user(l
, ufdset
);
203 __get_user(h
, ufdset
+1);
205 *fdset
++ = h
<< 32 | l
;
209 __get_user(*fdset
, ufdset
);
211 /* Tricky, must clear full unsigned long in the
212 * kernel fdset at the end, this makes sure that
215 memset(fdset
, 0, ((n
+ 1) & ~1)*sizeof(u32
));
221 set_fd_set32(unsigned long n
, u32
*ufdset
, unsigned long *fdset
)
224 n
= (n
+ 8*sizeof(u32
) - 1) / (8*sizeof(u32
));
235 __put_user(l
, ufdset
);
236 __put_user(h
, ufdset
+1);
241 __put_user(*fdset
, ufdset
);
249 asmlinkage
long sys32_msgsnd(int msqid
,
250 struct msgbuf32 __user
*umsgp32
,
251 size_t msgsz
, int msgflg
)
254 struct msgbuf32 mb32
;
257 if ((mb
= kmalloc(msgsz
+ sizeof *mb
+ 4, GFP_KERNEL
)) == NULL
)
260 err
= get_user(mb32
.mtype
, &umsgp32
->mtype
);
261 mb
->mtype
= mb32
.mtype
;
262 err
|= copy_from_user(mb
->mtext
, &umsgp32
->mtext
, msgsz
);
267 KERNEL_SYSCALL(err
, sys_msgsnd
, msqid
, (struct msgbuf __user
*)mb
, msgsz
, msgflg
);
273 asmlinkage
long sys32_msgrcv(int msqid
,
274 struct msgbuf32 __user
*umsgp32
,
275 size_t msgsz
, long msgtyp
, int msgflg
)
278 struct msgbuf32 mb32
;
281 if ((mb
= kmalloc(msgsz
+ sizeof *mb
+ 4, GFP_KERNEL
)) == NULL
)
284 KERNEL_SYSCALL(err
, sys_msgrcv
, msqid
, (struct msgbuf __user
*)mb
, msgsz
, msgtyp
, msgflg
);
288 mb32
.mtype
= mb
->mtype
;
289 err
= put_user(mb32
.mtype
, &umsgp32
->mtype
);
290 err
|= copy_to_user(&umsgp32
->mtext
, mb
->mtext
, len
);
301 asmlinkage
int sys32_sendfile(int out_fd
, int in_fd
, compat_off_t __user
*offset
, s32 count
)
303 mm_segment_t old_fs
= get_fs();
307 if (offset
&& get_user(of
, offset
))
311 ret
= sys_sendfile(out_fd
, in_fd
, offset
? (off_t __user
*)&of
: NULL
, count
);
314 if (offset
&& put_user(of
, offset
))
320 asmlinkage
int sys32_sendfile64(int out_fd
, int in_fd
, compat_loff_t __user
*offset
, s32 count
)
322 mm_segment_t old_fs
= get_fs();
326 if (offset
&& get_user(lof
, offset
))
330 ret
= sys_sendfile64(out_fd
, in_fd
, offset
? (loff_t __user
*)&lof
: NULL
, count
);
333 if (offset
&& put_user(lof
, offset
))
340 /* lseek() needs a wrapper because 'offset' can be negative, but the top
341 * half of the argument has been zeroed by syscall.S.
344 asmlinkage
int sys32_lseek(unsigned int fd
, int offset
, unsigned int origin
)
346 return sys_lseek(fd
, offset
, origin
);
349 asmlinkage
long sys32_semctl(int semid
, int semnum
, int cmd
, union semun arg
)
354 /* Ugh. arg is a union of int,ptr,ptr,ptr, so is 8 bytes.
355 * The int should be in the first 4, but our argument
356 * frobbing has left it in the last 4.
358 u
.val
= *((int *)&arg
+ 1);
359 return sys_semctl (semid
, semnum
, cmd
, u
);
361 return sys_semctl (semid
, semnum
, cmd
, arg
);
364 long sys32_lookup_dcookie(u32 cookie_high
, u32 cookie_low
, char __user
*buf
,
367 return sys_lookup_dcookie((u64
)cookie_high
<< 32 | cookie_low
,
371 asmlinkage
long compat_sys_fallocate(int fd
, int mode
, u32 offhi
, u32 offlo
,
372 u32 lenhi
, u32 lenlo
)
374 return sys_fallocate(fd
, mode
, ((loff_t
)offhi
<< 32) | offlo
,
375 ((loff_t
)lenhi
<< 32) | lenlo
);