Merge remote branch 'alsa/fixes' into fix/hda
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / parisc / kernel / sys_parisc32.c
1 /*
2 * sys_parisc32.c: Conversion between 32bit and 64bit native syscalls.
3 *
4 * Copyright (C) 2000-2001 Hewlett Packard Company
5 * Copyright (C) 2000 John Marvin
6 * Copyright (C) 2001 Matthew Wilcox
7 *
8 * These routines maintain argument size conversion between 32bit and 64bit
9 * environment. Based heavily on sys_ia32.c and sys_sparc32.c.
10 */
11
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/smp_lock.h>
24 #include <linux/sem.h>
25 #include <linux/msg.h>
26 #include <linux/shm.h>
27 #include <linux/slab.h>
28 #include <linux/uio.h>
29 #include <linux/nfs_fs.h>
30 #include <linux/ncp_fs.h>
31 #include <linux/sunrpc/svc.h>
32 #include <linux/nfsd/nfsd.h>
33 #include <linux/nfsd/cache.h>
34 #include <linux/nfsd/xdr.h>
35 #include <linux/nfsd/syscall.h>
36 #include <linux/poll.h>
37 #include <linux/personality.h>
38 #include <linux/stat.h>
39 #include <linux/highmem.h>
40 #include <linux/highuid.h>
41 #include <linux/mman.h>
42 #include <linux/binfmts.h>
43 #include <linux/namei.h>
44 #include <linux/vfs.h>
45 #include <linux/ptrace.h>
46 #include <linux/swap.h>
47 #include <linux/syscalls.h>
48
49 #include <asm/types.h>
50 #include <asm/uaccess.h>
51 #include <asm/mmu_context.h>
52
53 #include "sys32.h"
54
55 #undef DEBUG
56
57 #ifdef DEBUG
58 #define DBG(x) printk x
59 #else
60 #define DBG(x)
61 #endif
62
63 /*
64 * sys32_execve() executes a new program.
65 */
66
67 asmlinkage int sys32_execve(struct pt_regs *regs)
68 {
69 int error;
70 char *filename;
71
72 DBG(("sys32_execve(%p) r26 = 0x%lx\n", regs, regs->gr[26]));
73 filename = getname((const char __user *) regs->gr[26]);
74 error = PTR_ERR(filename);
75 if (IS_ERR(filename))
76 goto out;
77 error = compat_do_execve(filename, compat_ptr(regs->gr[25]),
78 compat_ptr(regs->gr[24]), regs);
79 putname(filename);
80 out:
81
82 return error;
83 }
84
85 asmlinkage long sys32_unimplemented(int r26, int r25, int r24, int r23,
86 int r22, int r21, int r20)
87 {
88 printk(KERN_ERR "%s(%d): Unimplemented 32 on 64 syscall #%d!\n",
89 current->comm, current->pid, r20);
90 return -ENOSYS;
91 }
92
93 asmlinkage long sys32_sched_rr_get_interval(pid_t pid,
94 struct compat_timespec __user *interval)
95 {
96 struct timespec t;
97 int ret;
98
99 KERNEL_SYSCALL(ret, sys_sched_rr_get_interval, pid, (struct timespec __user *)&t);
100 if (put_compat_timespec(&t, interval))
101 return -EFAULT;
102 return ret;
103 }
104
105 struct msgbuf32 {
106 int mtype;
107 char mtext[1];
108 };
109
110 asmlinkage long sys32_msgsnd(int msqid,
111 struct msgbuf32 __user *umsgp32,
112 size_t msgsz, int msgflg)
113 {
114 struct msgbuf *mb;
115 struct msgbuf32 mb32;
116 int err;
117
118 if ((mb = kmalloc(msgsz + sizeof *mb + 4, GFP_KERNEL)) == NULL)
119 return -ENOMEM;
120
121 err = get_user(mb32.mtype, &umsgp32->mtype);
122 mb->mtype = mb32.mtype;
123 err |= copy_from_user(mb->mtext, &umsgp32->mtext, msgsz);
124
125 if (err)
126 err = -EFAULT;
127 else
128 KERNEL_SYSCALL(err, sys_msgsnd, msqid, (struct msgbuf __user *)mb, msgsz, msgflg);
129
130 kfree(mb);
131 return err;
132 }
133
134 asmlinkage long sys32_msgrcv(int msqid,
135 struct msgbuf32 __user *umsgp32,
136 size_t msgsz, long msgtyp, int msgflg)
137 {
138 struct msgbuf *mb;
139 struct msgbuf32 mb32;
140 int err, len;
141
142 if ((mb = kmalloc(msgsz + sizeof *mb + 4, GFP_KERNEL)) == NULL)
143 return -ENOMEM;
144
145 KERNEL_SYSCALL(err, sys_msgrcv, msqid, (struct msgbuf __user *)mb, msgsz, msgtyp, msgflg);
146
147 if (err >= 0) {
148 len = err;
149 mb32.mtype = mb->mtype;
150 err = put_user(mb32.mtype, &umsgp32->mtype);
151 err |= copy_to_user(&umsgp32->mtext, mb->mtext, len);
152 if (err)
153 err = -EFAULT;
154 else
155 err = len;
156 }
157
158 kfree(mb);
159 return err;
160 }
161
162 asmlinkage int sys32_sendfile(int out_fd, int in_fd, compat_off_t __user *offset, s32 count)
163 {
164 mm_segment_t old_fs = get_fs();
165 int ret;
166 off_t of;
167
168 if (offset && get_user(of, offset))
169 return -EFAULT;
170
171 set_fs(KERNEL_DS);
172 ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL, count);
173 set_fs(old_fs);
174
175 if (offset && put_user(of, offset))
176 return -EFAULT;
177
178 return ret;
179 }
180
181 asmlinkage int sys32_sendfile64(int out_fd, int in_fd, compat_loff_t __user *offset, s32 count)
182 {
183 mm_segment_t old_fs = get_fs();
184 int ret;
185 loff_t lof;
186
187 if (offset && get_user(lof, offset))
188 return -EFAULT;
189
190 set_fs(KERNEL_DS);
191 ret = sys_sendfile64(out_fd, in_fd, offset ? (loff_t __user *)&lof : NULL, count);
192 set_fs(old_fs);
193
194 if (offset && put_user(lof, offset))
195 return -EFAULT;
196
197 return ret;
198 }
199
200
201 /* lseek() needs a wrapper because 'offset' can be negative, but the top
202 * half of the argument has been zeroed by syscall.S.
203 */
204
205 asmlinkage int sys32_lseek(unsigned int fd, int offset, unsigned int origin)
206 {
207 return sys_lseek(fd, offset, origin);
208 }
209
210 asmlinkage long sys32_semctl(int semid, int semnum, int cmd, union semun arg)
211 {
212 union semun u;
213
214 if (cmd == SETVAL) {
215 /* Ugh. arg is a union of int,ptr,ptr,ptr, so is 8 bytes.
216 * The int should be in the first 4, but our argument
217 * frobbing has left it in the last 4.
218 */
219 u.val = *((int *)&arg + 1);
220 return sys_semctl (semid, semnum, cmd, u);
221 }
222 return sys_semctl (semid, semnum, cmd, arg);
223 }
224
225 long sys32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char __user *buf,
226 size_t len)
227 {
228 return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low,
229 buf, len);
230 }
231
232 asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo,
233 u32 lenhi, u32 lenlo)
234 {
235 return sys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo,
236 ((loff_t)lenhi << 32) | lenlo);
237 }