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