Linux 3.8-rc7
[cris-mirror.git] / arch / parisc / kernel / sys_parisc32.c
blob9cfdaa19ab63314da7e04e0958eaadda0fadde9a
1 /*
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>
15 #include <linux/fs.h>
16 #include <linux/mm.h>
17 #include <linux/file.h>
18 #include <linux/signal.h>
19 #include <linux/resource.h>
20 #include <linux/times.h>
21 #include <linux/time.h>
22 #include <linux/smp.h>
23 #include <linux/sem.h>
24 #include <linux/msg.h>
25 #include <linux/shm.h>
26 #include <linux/slab.h>
27 #include <linux/uio.h>
28 #include <linux/ncp_fs.h>
29 #include <linux/poll.h>
30 #include <linux/personality.h>
31 #include <linux/stat.h>
32 #include <linux/highmem.h>
33 #include <linux/highuid.h>
34 #include <linux/mman.h>
35 #include <linux/binfmts.h>
36 #include <linux/namei.h>
37 #include <linux/vfs.h>
38 #include <linux/ptrace.h>
39 #include <linux/swap.h>
40 #include <linux/syscalls.h>
42 #include <asm/types.h>
43 #include <asm/uaccess.h>
44 #include <asm/mmu_context.h>
46 #include "sys32.h"
48 #undef DEBUG
50 #ifdef DEBUG
51 #define DBG(x) printk x
52 #else
53 #define DBG(x)
54 #endif
56 asmlinkage long sys32_unimplemented(int r26, int r25, int r24, int r23,
57 int r22, int r21, int r20)
59 printk(KERN_ERR "%s(%d): Unimplemented 32 on 64 syscall #%d!\n",
60 current->comm, current->pid, r20);
61 return -ENOSYS;
64 asmlinkage long sys32_sched_rr_get_interval(pid_t pid,
65 struct compat_timespec __user *interval)
67 struct timespec t;
68 int ret;
70 KERNEL_SYSCALL(ret, sys_sched_rr_get_interval, pid, (struct timespec __user *)&t);
71 if (put_compat_timespec(&t, interval))
72 return -EFAULT;
73 return ret;
76 struct msgbuf32 {
77 int mtype;
78 char mtext[1];
81 asmlinkage long sys32_msgsnd(int msqid,
82 struct msgbuf32 __user *umsgp32,
83 size_t msgsz, int msgflg)
85 struct msgbuf *mb;
86 struct msgbuf32 mb32;
87 int err;
89 if ((mb = kmalloc(msgsz + sizeof *mb + 4, GFP_KERNEL)) == NULL)
90 return -ENOMEM;
92 err = get_user(mb32.mtype, &umsgp32->mtype);
93 mb->mtype = mb32.mtype;
94 err |= copy_from_user(mb->mtext, &umsgp32->mtext, msgsz);
96 if (err)
97 err = -EFAULT;
98 else
99 KERNEL_SYSCALL(err, sys_msgsnd, msqid, (struct msgbuf __user *)mb, msgsz, msgflg);
101 kfree(mb);
102 return err;
105 asmlinkage long sys32_msgrcv(int msqid,
106 struct msgbuf32 __user *umsgp32,
107 size_t msgsz, long msgtyp, int msgflg)
109 struct msgbuf *mb;
110 struct msgbuf32 mb32;
111 int err, len;
113 if ((mb = kmalloc(msgsz + sizeof *mb + 4, GFP_KERNEL)) == NULL)
114 return -ENOMEM;
116 KERNEL_SYSCALL(err, sys_msgrcv, msqid, (struct msgbuf __user *)mb, msgsz, msgtyp, msgflg);
118 if (err >= 0) {
119 len = err;
120 mb32.mtype = mb->mtype;
121 err = put_user(mb32.mtype, &umsgp32->mtype);
122 err |= copy_to_user(&umsgp32->mtext, mb->mtext, len);
123 if (err)
124 err = -EFAULT;
125 else
126 err = len;
129 kfree(mb);
130 return err;
133 asmlinkage int sys32_sendfile(int out_fd, int in_fd, compat_off_t __user *offset, s32 count)
135 mm_segment_t old_fs = get_fs();
136 int ret;
137 off_t of;
139 if (offset && get_user(of, offset))
140 return -EFAULT;
142 set_fs(KERNEL_DS);
143 ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL, count);
144 set_fs(old_fs);
146 if (offset && put_user(of, offset))
147 return -EFAULT;
149 return ret;
152 asmlinkage int sys32_sendfile64(int out_fd, int in_fd, compat_loff_t __user *offset, s32 count)
154 mm_segment_t old_fs = get_fs();
155 int ret;
156 loff_t lof;
158 if (offset && get_user(lof, offset))
159 return -EFAULT;
161 set_fs(KERNEL_DS);
162 ret = sys_sendfile64(out_fd, in_fd, offset ? (loff_t __user *)&lof : NULL, count);
163 set_fs(old_fs);
165 if (offset && put_user(lof, offset))
166 return -EFAULT;
168 return ret;
172 /* lseek() needs a wrapper because 'offset' can be negative, but the top
173 * half of the argument has been zeroed by syscall.S.
176 asmlinkage int sys32_lseek(unsigned int fd, int offset, unsigned int origin)
178 return sys_lseek(fd, offset, origin);
181 asmlinkage long sys32_semctl(int semid, int semnum, int cmd, union semun arg)
183 union semun u;
185 if (cmd == SETVAL) {
186 /* Ugh. arg is a union of int,ptr,ptr,ptr, so is 8 bytes.
187 * The int should be in the first 4, but our argument
188 * frobbing has left it in the last 4.
190 u.val = *((int *)&arg + 1);
191 return sys_semctl (semid, semnum, cmd, u);
193 return sys_semctl (semid, semnum, cmd, arg);
196 long sys32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char __user *buf,
197 size_t len)
199 return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low,
200 buf, len);
203 asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo,
204 u32 lenhi, u32 lenlo)
206 return sys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo,
207 ((loff_t)lenhi << 32) | lenlo);
210 asmlinkage long compat_sys_fanotify_mark(int fan_fd, int flags, u32 mask_hi,
211 u32 mask_lo, int fd,
212 const char __user *pathname)
214 return sys_fanotify_mark(fan_fd, flags, ((u64)mask_hi << 32) | mask_lo,
215 fd, pathname);