Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * sys_ppc32.c: Conversion between 32bit and 64bit native syscalls. | |
3 | * | |
4 | * Copyright (C) 2001 IBM | |
5 | * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz) | |
6 | * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu) | |
7 | * | |
8 | * These routines maintain argument size conversion between 32bit and 64bit | |
9 | * environment. | |
10 | * | |
11 | * This program is free software; you can redistribute it and/or | |
12 | * modify it under the terms of the GNU General Public License | |
13 | * as published by the Free Software Foundation; either version | |
14 | * 2 of the License, or (at your option) any later version. | |
15 | */ | |
16 | ||
17 | #include <linux/config.h> | |
18 | #include <linux/kernel.h> | |
19 | #include <linux/sched.h> | |
20 | #include <linux/fs.h> | |
21 | #include <linux/mm.h> | |
22 | #include <linux/file.h> | |
23 | #include <linux/signal.h> | |
24 | #include <linux/resource.h> | |
25 | #include <linux/times.h> | |
26 | #include <linux/utsname.h> | |
27 | #include <linux/timex.h> | |
28 | #include <linux/smp.h> | |
29 | #include <linux/smp_lock.h> | |
30 | #include <linux/sem.h> | |
31 | #include <linux/msg.h> | |
32 | #include <linux/shm.h> | |
1da177e4 LT |
33 | #include <linux/poll.h> |
34 | #include <linux/personality.h> | |
35 | #include <linux/stat.h> | |
1da177e4 | 36 | #include <linux/mman.h> |
1da177e4 | 37 | #include <linux/in.h> |
1da177e4 LT |
38 | #include <linux/syscalls.h> |
39 | #include <linux/unistd.h> | |
40 | #include <linux/sysctl.h> | |
41 | #include <linux/binfmts.h> | |
1da177e4 LT |
42 | #include <linux/security.h> |
43 | #include <linux/compat.h> | |
44 | #include <linux/ptrace.h> | |
1da177e4 LT |
45 | #include <linux/elf.h> |
46 | ||
1da177e4 LT |
47 | #include <asm/ptrace.h> |
48 | #include <asm/types.h> | |
49 | #include <asm/ipc.h> | |
50 | #include <asm/uaccess.h> | |
51 | #include <asm/unistd.h> | |
52 | #include <asm/semaphore.h> | |
1da177e4 LT |
53 | #include <asm/time.h> |
54 | #include <asm/mmu_context.h> | |
55 | #include <asm/systemcfg.h> | |
d387899f | 56 | #include <asm/ppc-pci.h> |
1da177e4 LT |
57 | |
58 | /* readdir & getdents */ | |
59 | #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de))) | |
60 | #define ROUND_UP(x) (((x)+sizeof(u32)-1) & ~(sizeof(u32)-1)) | |
61 | ||
62 | struct old_linux_dirent32 { | |
63 | u32 d_ino; | |
64 | u32 d_offset; | |
65 | unsigned short d_namlen; | |
66 | char d_name[1]; | |
67 | }; | |
68 | ||
69 | struct readdir_callback32 { | |
70 | struct old_linux_dirent32 __user * dirent; | |
71 | int count; | |
72 | }; | |
73 | ||
74 | static int fillonedir(void * __buf, const char * name, int namlen, | |
75 | off_t offset, ino_t ino, unsigned int d_type) | |
76 | { | |
77 | struct readdir_callback32 * buf = (struct readdir_callback32 *) __buf; | |
78 | struct old_linux_dirent32 __user * dirent; | |
79 | ||
80 | if (buf->count) | |
81 | return -EINVAL; | |
82 | buf->count++; | |
83 | dirent = buf->dirent; | |
84 | put_user(ino, &dirent->d_ino); | |
85 | put_user(offset, &dirent->d_offset); | |
86 | put_user(namlen, &dirent->d_namlen); | |
87 | copy_to_user(dirent->d_name, name, namlen); | |
88 | put_user(0, dirent->d_name + namlen); | |
89 | return 0; | |
90 | } | |
91 | ||
92 | asmlinkage int old32_readdir(unsigned int fd, struct old_linux_dirent32 __user *dirent, unsigned int count) | |
93 | { | |
94 | int error = -EBADF; | |
95 | struct file * file; | |
96 | struct readdir_callback32 buf; | |
97 | ||
98 | file = fget(fd); | |
99 | if (!file) | |
100 | goto out; | |
101 | ||
102 | buf.count = 0; | |
103 | buf.dirent = dirent; | |
104 | ||
105 | error = vfs_readdir(file, (filldir_t)fillonedir, &buf); | |
106 | if (error < 0) | |
107 | goto out_putf; | |
108 | error = buf.count; | |
109 | ||
110 | out_putf: | |
111 | fput(file); | |
112 | out: | |
113 | return error; | |
114 | } | |
115 | ||
116 | struct linux_dirent32 { | |
117 | u32 d_ino; | |
118 | u32 d_off; | |
119 | unsigned short d_reclen; | |
120 | char d_name[1]; | |
121 | }; | |
122 | ||
123 | struct getdents_callback32 { | |
124 | struct linux_dirent32 __user * current_dir; | |
125 | struct linux_dirent32 __user * previous; | |
126 | int count; | |
127 | int error; | |
128 | }; | |
129 | ||
130 | static int filldir(void * __buf, const char * name, int namlen, off_t offset, | |
131 | ino_t ino, unsigned int d_type) | |
132 | { | |
133 | struct linux_dirent32 __user * dirent; | |
134 | struct getdents_callback32 * buf = (struct getdents_callback32 *) __buf; | |
135 | int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 2); | |
136 | ||
137 | buf->error = -EINVAL; /* only used if we fail.. */ | |
138 | if (reclen > buf->count) | |
139 | return -EINVAL; | |
140 | dirent = buf->previous; | |
141 | if (dirent) { | |
142 | if (__put_user(offset, &dirent->d_off)) | |
143 | goto efault; | |
144 | } | |
145 | dirent = buf->current_dir; | |
146 | if (__put_user(ino, &dirent->d_ino)) | |
147 | goto efault; | |
148 | if (__put_user(reclen, &dirent->d_reclen)) | |
149 | goto efault; | |
150 | if (copy_to_user(dirent->d_name, name, namlen)) | |
151 | goto efault; | |
152 | if (__put_user(0, dirent->d_name + namlen)) | |
153 | goto efault; | |
154 | if (__put_user(d_type, (char __user *) dirent + reclen - 1)) | |
155 | goto efault; | |
156 | buf->previous = dirent; | |
157 | dirent = (void __user *)dirent + reclen; | |
158 | buf->current_dir = dirent; | |
159 | buf->count -= reclen; | |
160 | return 0; | |
161 | efault: | |
162 | buf->error = -EFAULT; | |
163 | return -EFAULT; | |
164 | } | |
165 | ||
166 | asmlinkage long sys32_getdents(unsigned int fd, struct linux_dirent32 __user *dirent, | |
167 | unsigned int count) | |
168 | { | |
169 | struct file * file; | |
170 | struct linux_dirent32 __user * lastdirent; | |
171 | struct getdents_callback32 buf; | |
172 | int error; | |
173 | ||
174 | error = -EFAULT; | |
175 | if (!access_ok(VERIFY_WRITE, dirent, count)) | |
176 | goto out; | |
177 | ||
178 | error = -EBADF; | |
179 | file = fget(fd); | |
180 | if (!file) | |
181 | goto out; | |
182 | ||
183 | buf.current_dir = dirent; | |
184 | buf.previous = NULL; | |
185 | buf.count = count; | |
186 | buf.error = 0; | |
187 | ||
188 | error = vfs_readdir(file, (filldir_t)filldir, &buf); | |
189 | if (error < 0) | |
190 | goto out_putf; | |
191 | error = buf.error; | |
192 | lastdirent = buf.previous; | |
193 | if (lastdirent) { | |
194 | if (put_user(file->f_pos, &lastdirent->d_off)) | |
195 | error = -EFAULT; | |
196 | else | |
197 | error = count - buf.count; | |
198 | } | |
199 | ||
200 | out_putf: | |
201 | fput(file); | |
202 | out: | |
203 | return error; | |
204 | } | |
205 | ||
206 | asmlinkage long ppc32_select(u32 n, compat_ulong_t __user *inp, | |
207 | compat_ulong_t __user *outp, compat_ulong_t __user *exp, | |
208 | compat_uptr_t tvp_x) | |
209 | { | |
210 | /* sign extend n */ | |
211 | return compat_sys_select((int)n, inp, outp, exp, compat_ptr(tvp_x)); | |
212 | } | |
213 | ||
214 | int cp_compat_stat(struct kstat *stat, struct compat_stat __user *statbuf) | |
215 | { | |
216 | long err; | |
217 | ||
218 | if (stat->size > MAX_NON_LFS || !new_valid_dev(stat->dev) || | |
219 | !new_valid_dev(stat->rdev)) | |
220 | return -EOVERFLOW; | |
221 | ||
222 | err = access_ok(VERIFY_WRITE, statbuf, sizeof(*statbuf)) ? 0 : -EFAULT; | |
223 | err |= __put_user(new_encode_dev(stat->dev), &statbuf->st_dev); | |
224 | err |= __put_user(stat->ino, &statbuf->st_ino); | |
225 | err |= __put_user(stat->mode, &statbuf->st_mode); | |
226 | err |= __put_user(stat->nlink, &statbuf->st_nlink); | |
227 | err |= __put_user(stat->uid, &statbuf->st_uid); | |
228 | err |= __put_user(stat->gid, &statbuf->st_gid); | |
229 | err |= __put_user(new_encode_dev(stat->rdev), &statbuf->st_rdev); | |
230 | err |= __put_user(stat->size, &statbuf->st_size); | |
231 | err |= __put_user(stat->atime.tv_sec, &statbuf->st_atime); | |
232 | err |= __put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec); | |
233 | err |= __put_user(stat->mtime.tv_sec, &statbuf->st_mtime); | |
234 | err |= __put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec); | |
235 | err |= __put_user(stat->ctime.tv_sec, &statbuf->st_ctime); | |
236 | err |= __put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec); | |
237 | err |= __put_user(stat->blksize, &statbuf->st_blksize); | |
238 | err |= __put_user(stat->blocks, &statbuf->st_blocks); | |
239 | err |= __put_user(0, &statbuf->__unused4[0]); | |
240 | err |= __put_user(0, &statbuf->__unused4[1]); | |
241 | ||
242 | return err; | |
243 | } | |
244 | ||
245 | /* Note: it is necessary to treat option as an unsigned int, | |
246 | * with the corresponding cast to a signed int to insure that the | |
247 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
248 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
249 | */ | |
250 | asmlinkage long sys32_sysfs(u32 option, u32 arg1, u32 arg2) | |
251 | { | |
252 | return sys_sysfs((int)option, arg1, arg2); | |
253 | } | |
254 | ||
255 | /* Handle adjtimex compatibility. */ | |
256 | struct timex32 { | |
257 | u32 modes; | |
258 | s32 offset, freq, maxerror, esterror; | |
259 | s32 status, constant, precision, tolerance; | |
260 | struct compat_timeval time; | |
261 | s32 tick; | |
262 | s32 ppsfreq, jitter, shift, stabil; | |
263 | s32 jitcnt, calcnt, errcnt, stbcnt; | |
264 | s32 :32; s32 :32; s32 :32; s32 :32; | |
265 | s32 :32; s32 :32; s32 :32; s32 :32; | |
266 | s32 :32; s32 :32; s32 :32; s32 :32; | |
267 | }; | |
268 | ||
269 | extern int do_adjtimex(struct timex *); | |
270 | extern void ppc_adjtimex(void); | |
271 | ||
272 | asmlinkage long sys32_adjtimex(struct timex32 __user *utp) | |
273 | { | |
274 | struct timex txc; | |
275 | int ret; | |
276 | ||
277 | memset(&txc, 0, sizeof(struct timex)); | |
278 | ||
279 | if(get_user(txc.modes, &utp->modes) || | |
280 | __get_user(txc.offset, &utp->offset) || | |
281 | __get_user(txc.freq, &utp->freq) || | |
282 | __get_user(txc.maxerror, &utp->maxerror) || | |
283 | __get_user(txc.esterror, &utp->esterror) || | |
284 | __get_user(txc.status, &utp->status) || | |
285 | __get_user(txc.constant, &utp->constant) || | |
286 | __get_user(txc.precision, &utp->precision) || | |
287 | __get_user(txc.tolerance, &utp->tolerance) || | |
288 | __get_user(txc.time.tv_sec, &utp->time.tv_sec) || | |
289 | __get_user(txc.time.tv_usec, &utp->time.tv_usec) || | |
290 | __get_user(txc.tick, &utp->tick) || | |
291 | __get_user(txc.ppsfreq, &utp->ppsfreq) || | |
292 | __get_user(txc.jitter, &utp->jitter) || | |
293 | __get_user(txc.shift, &utp->shift) || | |
294 | __get_user(txc.stabil, &utp->stabil) || | |
295 | __get_user(txc.jitcnt, &utp->jitcnt) || | |
296 | __get_user(txc.calcnt, &utp->calcnt) || | |
297 | __get_user(txc.errcnt, &utp->errcnt) || | |
298 | __get_user(txc.stbcnt, &utp->stbcnt)) | |
299 | return -EFAULT; | |
300 | ||
301 | ret = do_adjtimex(&txc); | |
302 | ||
303 | /* adjust the conversion of TB to time of day to track adjtimex */ | |
304 | ppc_adjtimex(); | |
305 | ||
306 | if(put_user(txc.modes, &utp->modes) || | |
307 | __put_user(txc.offset, &utp->offset) || | |
308 | __put_user(txc.freq, &utp->freq) || | |
309 | __put_user(txc.maxerror, &utp->maxerror) || | |
310 | __put_user(txc.esterror, &utp->esterror) || | |
311 | __put_user(txc.status, &utp->status) || | |
312 | __put_user(txc.constant, &utp->constant) || | |
313 | __put_user(txc.precision, &utp->precision) || | |
314 | __put_user(txc.tolerance, &utp->tolerance) || | |
315 | __put_user(txc.time.tv_sec, &utp->time.tv_sec) || | |
316 | __put_user(txc.time.tv_usec, &utp->time.tv_usec) || | |
317 | __put_user(txc.tick, &utp->tick) || | |
318 | __put_user(txc.ppsfreq, &utp->ppsfreq) || | |
319 | __put_user(txc.jitter, &utp->jitter) || | |
320 | __put_user(txc.shift, &utp->shift) || | |
321 | __put_user(txc.stabil, &utp->stabil) || | |
322 | __put_user(txc.jitcnt, &utp->jitcnt) || | |
323 | __put_user(txc.calcnt, &utp->calcnt) || | |
324 | __put_user(txc.errcnt, &utp->errcnt) || | |
325 | __put_user(txc.stbcnt, &utp->stbcnt)) | |
326 | ret = -EFAULT; | |
327 | ||
328 | return ret; | |
329 | } | |
330 | ||
1da177e4 LT |
331 | asmlinkage long sys32_pause(void) |
332 | { | |
333 | current->state = TASK_INTERRUPTIBLE; | |
334 | schedule(); | |
335 | ||
336 | return -ERESTARTNOHAND; | |
337 | } | |
338 | ||
1da177e4 LT |
339 | static inline long get_ts32(struct timespec *o, struct compat_timeval __user *i) |
340 | { | |
341 | long usec; | |
342 | ||
343 | if (!access_ok(VERIFY_READ, i, sizeof(*i))) | |
344 | return -EFAULT; | |
345 | if (__get_user(o->tv_sec, &i->tv_sec)) | |
346 | return -EFAULT; | |
347 | if (__get_user(usec, &i->tv_usec)) | |
348 | return -EFAULT; | |
349 | o->tv_nsec = usec * 1000; | |
350 | return 0; | |
351 | } | |
352 | ||
353 | static inline long put_tv32(struct compat_timeval __user *o, struct timeval *i) | |
354 | { | |
355 | return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) || | |
356 | (__put_user(i->tv_sec, &o->tv_sec) | | |
357 | __put_user(i->tv_usec, &o->tv_usec))); | |
358 | } | |
359 | ||
360 | struct sysinfo32 { | |
361 | s32 uptime; | |
362 | u32 loads[3]; | |
363 | u32 totalram; | |
364 | u32 freeram; | |
365 | u32 sharedram; | |
366 | u32 bufferram; | |
367 | u32 totalswap; | |
368 | u32 freeswap; | |
369 | unsigned short procs; | |
370 | unsigned short pad; | |
371 | u32 totalhigh; | |
372 | u32 freehigh; | |
373 | u32 mem_unit; | |
374 | char _f[20-2*sizeof(int)-sizeof(int)]; | |
375 | }; | |
376 | ||
377 | asmlinkage long sys32_sysinfo(struct sysinfo32 __user *info) | |
378 | { | |
379 | struct sysinfo s; | |
380 | int ret, err; | |
381 | int bitcount=0; | |
382 | mm_segment_t old_fs = get_fs (); | |
383 | ||
384 | /* The __user cast is valid due to set_fs() */ | |
385 | set_fs (KERNEL_DS); | |
386 | ret = sys_sysinfo((struct sysinfo __user *)&s); | |
387 | set_fs (old_fs); | |
388 | ||
389 | /* Check to see if any memory value is too large for 32-bit and | |
390 | * scale down if needed. | |
391 | */ | |
392 | if ((s.totalram >> 32) || (s.totalswap >> 32)) { | |
393 | while (s.mem_unit < PAGE_SIZE) { | |
394 | s.mem_unit <<= 1; | |
395 | bitcount++; | |
396 | } | |
397 | s.totalram >>=bitcount; | |
398 | s.freeram >>= bitcount; | |
399 | s.sharedram >>= bitcount; | |
400 | s.bufferram >>= bitcount; | |
401 | s.totalswap >>= bitcount; | |
402 | s.freeswap >>= bitcount; | |
403 | s.totalhigh >>= bitcount; | |
404 | s.freehigh >>= bitcount; | |
405 | } | |
406 | ||
407 | err = put_user (s.uptime, &info->uptime); | |
408 | err |= __put_user (s.loads[0], &info->loads[0]); | |
409 | err |= __put_user (s.loads[1], &info->loads[1]); | |
410 | err |= __put_user (s.loads[2], &info->loads[2]); | |
411 | err |= __put_user (s.totalram, &info->totalram); | |
412 | err |= __put_user (s.freeram, &info->freeram); | |
413 | err |= __put_user (s.sharedram, &info->sharedram); | |
414 | err |= __put_user (s.bufferram, &info->bufferram); | |
415 | err |= __put_user (s.totalswap, &info->totalswap); | |
416 | err |= __put_user (s.freeswap, &info->freeswap); | |
417 | err |= __put_user (s.procs, &info->procs); | |
418 | err |= __put_user (s.totalhigh, &info->totalhigh); | |
419 | err |= __put_user (s.freehigh, &info->freehigh); | |
420 | err |= __put_user (s.mem_unit, &info->mem_unit); | |
421 | if (err) | |
422 | return -EFAULT; | |
423 | ||
424 | return ret; | |
425 | } | |
426 | ||
427 | ||
428 | ||
429 | ||
430 | /* Translations due to time_t size differences. Which affects all | |
431 | sorts of things, like timeval and itimerval. */ | |
432 | extern struct timezone sys_tz; | |
433 | ||
434 | asmlinkage long sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz) | |
435 | { | |
436 | if (tv) { | |
437 | struct timeval ktv; | |
438 | do_gettimeofday(&ktv); | |
439 | if (put_tv32(tv, &ktv)) | |
440 | return -EFAULT; | |
441 | } | |
442 | if (tz) { | |
443 | if (copy_to_user(tz, &sys_tz, sizeof(sys_tz))) | |
444 | return -EFAULT; | |
445 | } | |
446 | ||
447 | return 0; | |
448 | } | |
449 | ||
450 | ||
451 | ||
452 | asmlinkage long sys32_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz) | |
453 | { | |
454 | struct timespec kts; | |
455 | struct timezone ktz; | |
456 | ||
457 | if (tv) { | |
458 | if (get_ts32(&kts, tv)) | |
459 | return -EFAULT; | |
460 | } | |
461 | if (tz) { | |
462 | if (copy_from_user(&ktz, tz, sizeof(ktz))) | |
463 | return -EFAULT; | |
464 | } | |
465 | ||
466 | return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL); | |
467 | } | |
468 | ||
469 | #ifdef CONFIG_SYSVIPC | |
470 | long sys32_ipc(u32 call, u32 first, u32 second, u32 third, compat_uptr_t ptr, | |
471 | u32 fifth) | |
472 | { | |
473 | int version; | |
474 | ||
475 | version = call >> 16; /* hack for backward compatibility */ | |
476 | call &= 0xffff; | |
477 | ||
478 | switch (call) { | |
479 | ||
480 | case SEMTIMEDOP: | |
481 | if (fifth) | |
482 | /* sign extend semid */ | |
483 | return compat_sys_semtimedop((int)first, | |
484 | compat_ptr(ptr), second, | |
485 | compat_ptr(fifth)); | |
486 | /* else fall through for normal semop() */ | |
487 | case SEMOP: | |
488 | /* struct sembuf is the same on 32 and 64bit :)) */ | |
489 | /* sign extend semid */ | |
490 | return sys_semtimedop((int)first, compat_ptr(ptr), second, | |
491 | NULL); | |
492 | case SEMGET: | |
493 | /* sign extend key, nsems */ | |
494 | return sys_semget((int)first, (int)second, third); | |
495 | case SEMCTL: | |
496 | /* sign extend semid, semnum */ | |
497 | return compat_sys_semctl((int)first, (int)second, third, | |
498 | compat_ptr(ptr)); | |
499 | ||
500 | case MSGSND: | |
501 | /* sign extend msqid */ | |
502 | return compat_sys_msgsnd((int)first, (int)second, third, | |
503 | compat_ptr(ptr)); | |
504 | case MSGRCV: | |
505 | /* sign extend msqid, msgtyp */ | |
506 | return compat_sys_msgrcv((int)first, second, (int)fifth, | |
507 | third, version, compat_ptr(ptr)); | |
508 | case MSGGET: | |
509 | /* sign extend key */ | |
510 | return sys_msgget((int)first, second); | |
511 | case MSGCTL: | |
512 | /* sign extend msqid */ | |
513 | return compat_sys_msgctl((int)first, second, compat_ptr(ptr)); | |
514 | ||
515 | case SHMAT: | |
516 | /* sign extend shmid */ | |
517 | return compat_sys_shmat((int)first, second, third, version, | |
518 | compat_ptr(ptr)); | |
519 | case SHMDT: | |
520 | return sys_shmdt(compat_ptr(ptr)); | |
521 | case SHMGET: | |
522 | /* sign extend key_t */ | |
523 | return sys_shmget((int)first, second, third); | |
524 | case SHMCTL: | |
525 | /* sign extend shmid */ | |
526 | return compat_sys_shmctl((int)first, second, compat_ptr(ptr)); | |
527 | ||
528 | default: | |
529 | return -ENOSYS; | |
530 | } | |
531 | ||
532 | return -ENOSYS; | |
533 | } | |
534 | #endif | |
535 | ||
536 | /* Note: it is necessary to treat out_fd and in_fd as unsigned ints, | |
537 | * with the corresponding cast to a signed int to insure that the | |
538 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
539 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
540 | */ | |
541 | asmlinkage long sys32_sendfile(u32 out_fd, u32 in_fd, compat_off_t __user * offset, u32 count) | |
542 | { | |
543 | mm_segment_t old_fs = get_fs(); | |
544 | int ret; | |
545 | off_t of; | |
546 | off_t __user *up; | |
547 | ||
548 | if (offset && get_user(of, offset)) | |
549 | return -EFAULT; | |
550 | ||
551 | /* The __user pointer cast is valid because of the set_fs() */ | |
552 | set_fs(KERNEL_DS); | |
553 | up = offset ? (off_t __user *) &of : NULL; | |
554 | ret = sys_sendfile((int)out_fd, (int)in_fd, up, count); | |
555 | set_fs(old_fs); | |
556 | ||
557 | if (offset && put_user(of, offset)) | |
558 | return -EFAULT; | |
559 | ||
560 | return ret; | |
561 | } | |
562 | ||
563 | asmlinkage int sys32_sendfile64(int out_fd, int in_fd, compat_loff_t __user *offset, s32 count) | |
564 | { | |
565 | mm_segment_t old_fs = get_fs(); | |
566 | int ret; | |
567 | loff_t lof; | |
568 | loff_t __user *up; | |
569 | ||
570 | if (offset && get_user(lof, offset)) | |
571 | return -EFAULT; | |
572 | ||
573 | /* The __user pointer cast is valid because of the set_fs() */ | |
574 | set_fs(KERNEL_DS); | |
575 | up = offset ? (loff_t __user *) &lof : NULL; | |
576 | ret = sys_sendfile64(out_fd, in_fd, up, count); | |
577 | set_fs(old_fs); | |
578 | ||
579 | if (offset && put_user(lof, offset)) | |
580 | return -EFAULT; | |
581 | ||
582 | return ret; | |
583 | } | |
584 | ||
585 | long sys32_execve(unsigned long a0, unsigned long a1, unsigned long a2, | |
586 | unsigned long a3, unsigned long a4, unsigned long a5, | |
587 | struct pt_regs *regs) | |
588 | { | |
589 | int error; | |
590 | char * filename; | |
591 | ||
592 | filename = getname((char __user *) a0); | |
593 | error = PTR_ERR(filename); | |
594 | if (IS_ERR(filename)) | |
595 | goto out; | |
596 | flush_fp_to_thread(current); | |
597 | flush_altivec_to_thread(current); | |
598 | ||
599 | error = compat_do_execve(filename, compat_ptr(a1), compat_ptr(a2), regs); | |
600 | ||
601 | if (error == 0) { | |
602 | task_lock(current); | |
603 | current->ptrace &= ~PT_DTRACE; | |
604 | task_unlock(current); | |
605 | } | |
606 | putname(filename); | |
607 | ||
608 | out: | |
609 | return error; | |
610 | } | |
611 | ||
1da177e4 LT |
612 | /* Note: it is necessary to treat option as an unsigned int, |
613 | * with the corresponding cast to a signed int to insure that the | |
614 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
615 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
616 | */ | |
617 | asmlinkage long sys32_prctl(u32 option, u32 arg2, u32 arg3, u32 arg4, u32 arg5) | |
618 | { | |
619 | return sys_prctl((int)option, | |
620 | (unsigned long) arg2, | |
621 | (unsigned long) arg3, | |
622 | (unsigned long) arg4, | |
623 | (unsigned long) arg5); | |
624 | } | |
625 | ||
626 | /* Note: it is necessary to treat pid as an unsigned int, | |
627 | * with the corresponding cast to a signed int to insure that the | |
628 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
629 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
630 | */ | |
631 | asmlinkage long sys32_sched_rr_get_interval(u32 pid, struct compat_timespec __user *interval) | |
632 | { | |
633 | struct timespec t; | |
634 | int ret; | |
635 | mm_segment_t old_fs = get_fs (); | |
636 | ||
637 | /* The __user pointer cast is valid because of the set_fs() */ | |
638 | set_fs (KERNEL_DS); | |
639 | ret = sys_sched_rr_get_interval((int)pid, (struct timespec __user *) &t); | |
640 | set_fs (old_fs); | |
641 | if (put_compat_timespec(&t, interval)) | |
642 | return -EFAULT; | |
643 | return ret; | |
644 | } | |
645 | ||
646 | asmlinkage int sys32_pciconfig_read(u32 bus, u32 dfn, u32 off, u32 len, u32 ubuf) | |
647 | { | |
648 | return sys_pciconfig_read((unsigned long) bus, | |
649 | (unsigned long) dfn, | |
650 | (unsigned long) off, | |
651 | (unsigned long) len, | |
652 | compat_ptr(ubuf)); | |
653 | } | |
654 | ||
655 | asmlinkage int sys32_pciconfig_write(u32 bus, u32 dfn, u32 off, u32 len, u32 ubuf) | |
656 | { | |
657 | return sys_pciconfig_write((unsigned long) bus, | |
658 | (unsigned long) dfn, | |
659 | (unsigned long) off, | |
660 | (unsigned long) len, | |
661 | compat_ptr(ubuf)); | |
662 | } | |
663 | ||
1da177e4 LT |
664 | asmlinkage int sys32_pciconfig_iobase(u32 which, u32 in_bus, u32 in_devfn) |
665 | { | |
b2ad7b5e | 666 | return sys_pciconfig_iobase(which, in_bus, in_devfn); |
1da177e4 LT |
667 | } |
668 | ||
669 | ||
1da177e4 LT |
670 | /* Note: it is necessary to treat mode as an unsigned int, |
671 | * with the corresponding cast to a signed int to insure that the | |
672 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
673 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
674 | */ | |
675 | asmlinkage long sys32_access(const char __user * filename, u32 mode) | |
676 | { | |
677 | return sys_access(filename, (int)mode); | |
678 | } | |
679 | ||
680 | ||
681 | /* Note: it is necessary to treat mode as an unsigned int, | |
682 | * with the corresponding cast to a signed int to insure that the | |
683 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
684 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
685 | */ | |
686 | asmlinkage long sys32_creat(const char __user * pathname, u32 mode) | |
687 | { | |
688 | return sys_creat(pathname, (int)mode); | |
689 | } | |
690 | ||
691 | ||
692 | /* Note: it is necessary to treat pid and options as unsigned ints, | |
693 | * with the corresponding cast to a signed int to insure that the | |
694 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
695 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
696 | */ | |
697 | asmlinkage long sys32_waitpid(u32 pid, unsigned int __user * stat_addr, u32 options) | |
698 | { | |
699 | return sys_waitpid((int)pid, stat_addr, (int)options); | |
700 | } | |
701 | ||
702 | ||
703 | /* Note: it is necessary to treat gidsetsize as an unsigned int, | |
704 | * with the corresponding cast to a signed int to insure that the | |
705 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
706 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
707 | */ | |
708 | asmlinkage long sys32_getgroups(u32 gidsetsize, gid_t __user *grouplist) | |
709 | { | |
710 | return sys_getgroups((int)gidsetsize, grouplist); | |
711 | } | |
712 | ||
713 | ||
714 | /* Note: it is necessary to treat pid as an unsigned int, | |
715 | * with the corresponding cast to a signed int to insure that the | |
716 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
717 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
718 | */ | |
719 | asmlinkage long sys32_getpgid(u32 pid) | |
720 | { | |
721 | return sys_getpgid((int)pid); | |
722 | } | |
723 | ||
724 | ||
1da177e4 LT |
725 | |
726 | /* Note: it is necessary to treat pid as an unsigned int, | |
727 | * with the corresponding cast to a signed int to insure that the | |
728 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
729 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
730 | */ | |
731 | asmlinkage long sys32_getsid(u32 pid) | |
732 | { | |
733 | return sys_getsid((int)pid); | |
734 | } | |
735 | ||
736 | ||
737 | /* Note: it is necessary to treat pid and sig as unsigned ints, | |
738 | * with the corresponding cast to a signed int to insure that the | |
739 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
740 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
741 | */ | |
742 | asmlinkage long sys32_kill(u32 pid, u32 sig) | |
743 | { | |
744 | return sys_kill((int)pid, (int)sig); | |
745 | } | |
746 | ||
747 | ||
748 | /* Note: it is necessary to treat mode as an unsigned int, | |
749 | * with the corresponding cast to a signed int to insure that the | |
750 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
751 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
752 | */ | |
753 | asmlinkage long sys32_mkdir(const char __user * pathname, u32 mode) | |
754 | { | |
755 | return sys_mkdir(pathname, (int)mode); | |
756 | } | |
757 | ||
758 | long sys32_nice(u32 increment) | |
759 | { | |
760 | /* sign extend increment */ | |
761 | return sys_nice((int)increment); | |
762 | } | |
763 | ||
764 | off_t ppc32_lseek(unsigned int fd, u32 offset, unsigned int origin) | |
765 | { | |
766 | /* sign extend n */ | |
767 | return sys_lseek(fd, (int)offset, origin); | |
768 | } | |
769 | ||
1da177e4 LT |
770 | /* Note: it is necessary to treat bufsiz as an unsigned int, |
771 | * with the corresponding cast to a signed int to insure that the | |
772 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
773 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
774 | */ | |
775 | asmlinkage long sys32_readlink(const char __user * path, char __user * buf, u32 bufsiz) | |
776 | { | |
777 | return sys_readlink(path, buf, (int)bufsiz); | |
778 | } | |
779 | ||
780 | /* Note: it is necessary to treat option as an unsigned int, | |
781 | * with the corresponding cast to a signed int to insure that the | |
782 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
783 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
784 | */ | |
785 | asmlinkage long sys32_sched_get_priority_max(u32 policy) | |
786 | { | |
787 | return sys_sched_get_priority_max((int)policy); | |
788 | } | |
789 | ||
790 | ||
791 | /* Note: it is necessary to treat policy as an unsigned int, | |
792 | * with the corresponding cast to a signed int to insure that the | |
793 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
794 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
795 | */ | |
796 | asmlinkage long sys32_sched_get_priority_min(u32 policy) | |
797 | { | |
798 | return sys_sched_get_priority_min((int)policy); | |
799 | } | |
800 | ||
801 | ||
802 | /* Note: it is necessary to treat pid as an unsigned int, | |
803 | * with the corresponding cast to a signed int to insure that the | |
804 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
805 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
806 | */ | |
807 | asmlinkage long sys32_sched_getparam(u32 pid, struct sched_param __user *param) | |
808 | { | |
809 | return sys_sched_getparam((int)pid, param); | |
810 | } | |
811 | ||
812 | ||
813 | /* Note: it is necessary to treat pid as an unsigned int, | |
814 | * with the corresponding cast to a signed int to insure that the | |
815 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
816 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
817 | */ | |
818 | asmlinkage long sys32_sched_getscheduler(u32 pid) | |
819 | { | |
820 | return sys_sched_getscheduler((int)pid); | |
821 | } | |
822 | ||
823 | ||
824 | /* Note: it is necessary to treat pid as an unsigned int, | |
825 | * with the corresponding cast to a signed int to insure that the | |
826 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
827 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
828 | */ | |
829 | asmlinkage long sys32_sched_setparam(u32 pid, struct sched_param __user *param) | |
830 | { | |
831 | return sys_sched_setparam((int)pid, param); | |
832 | } | |
833 | ||
834 | ||
835 | /* Note: it is necessary to treat pid and policy as unsigned ints, | |
836 | * with the corresponding cast to a signed int to insure that the | |
837 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
838 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
839 | */ | |
840 | asmlinkage long sys32_sched_setscheduler(u32 pid, u32 policy, struct sched_param __user *param) | |
841 | { | |
842 | return sys_sched_setscheduler((int)pid, (int)policy, param); | |
843 | } | |
844 | ||
845 | ||
846 | /* Note: it is necessary to treat len as an unsigned int, | |
847 | * with the corresponding cast to a signed int to insure that the | |
848 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
849 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
850 | */ | |
851 | asmlinkage long sys32_setdomainname(char __user *name, u32 len) | |
852 | { | |
853 | return sys_setdomainname(name, (int)len); | |
854 | } | |
855 | ||
856 | ||
857 | /* Note: it is necessary to treat gidsetsize as an unsigned int, | |
858 | * with the corresponding cast to a signed int to insure that the | |
859 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
860 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
861 | */ | |
862 | asmlinkage long sys32_setgroups(u32 gidsetsize, gid_t __user *grouplist) | |
863 | { | |
864 | return sys_setgroups((int)gidsetsize, grouplist); | |
865 | } | |
866 | ||
867 | ||
868 | asmlinkage long sys32_sethostname(char __user *name, u32 len) | |
869 | { | |
870 | /* sign extend len */ | |
871 | return sys_sethostname(name, (int)len); | |
872 | } | |
873 | ||
874 | ||
875 | /* Note: it is necessary to treat pid and pgid as unsigned ints, | |
876 | * with the corresponding cast to a signed int to insure that the | |
877 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
878 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
879 | */ | |
880 | asmlinkage long sys32_setpgid(u32 pid, u32 pgid) | |
881 | { | |
882 | return sys_setpgid((int)pid, (int)pgid); | |
883 | } | |
884 | ||
79c2cc7b AB |
885 | long sys32_getpriority(u32 which, u32 who) |
886 | { | |
887 | /* sign extend which and who */ | |
888 | return sys_getpriority((int)which, (int)who); | |
889 | } | |
1da177e4 LT |
890 | |
891 | long sys32_setpriority(u32 which, u32 who, u32 niceval) | |
892 | { | |
893 | /* sign extend which, who and niceval */ | |
894 | return sys_setpriority((int)which, (int)who, (int)niceval); | |
895 | } | |
896 | ||
79c2cc7b AB |
897 | long sys32_ioprio_get(u32 which, u32 who) |
898 | { | |
899 | /* sign extend which and who */ | |
900 | return sys_ioprio_get((int)which, (int)who); | |
901 | } | |
902 | ||
903 | long sys32_ioprio_set(u32 which, u32 who, u32 ioprio) | |
904 | { | |
905 | /* sign extend which, who and ioprio */ | |
906 | return sys_ioprio_set((int)which, (int)who, (int)ioprio); | |
907 | } | |
908 | ||
1da177e4 LT |
909 | /* Note: it is necessary to treat newmask as an unsigned int, |
910 | * with the corresponding cast to a signed int to insure that the | |
911 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
912 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
913 | */ | |
914 | asmlinkage long sys32_ssetmask(u32 newmask) | |
915 | { | |
916 | return sys_ssetmask((int) newmask); | |
917 | } | |
918 | ||
919 | asmlinkage long sys32_syslog(u32 type, char __user * buf, u32 len) | |
920 | { | |
921 | /* sign extend len */ | |
922 | return sys_syslog(type, buf, (int)len); | |
923 | } | |
924 | ||
925 | ||
926 | /* Note: it is necessary to treat mask as an unsigned int, | |
927 | * with the corresponding cast to a signed int to insure that the | |
928 | * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) | |
929 | * and the register representation of a signed int (msr in 64-bit mode) is performed. | |
930 | */ | |
931 | asmlinkage long sys32_umask(u32 mask) | |
932 | { | |
933 | return sys_umask((int)mask); | |
934 | } | |
935 | ||
936 | #ifdef CONFIG_SYSCTL | |
937 | struct __sysctl_args32 { | |
938 | u32 name; | |
939 | int nlen; | |
940 | u32 oldval; | |
941 | u32 oldlenp; | |
942 | u32 newval; | |
943 | u32 newlen; | |
944 | u32 __unused[4]; | |
945 | }; | |
946 | ||
947 | asmlinkage long sys32_sysctl(struct __sysctl_args32 __user *args) | |
948 | { | |
949 | struct __sysctl_args32 tmp; | |
950 | int error; | |
951 | size_t oldlen; | |
952 | size_t __user *oldlenp = NULL; | |
953 | unsigned long addr = (((unsigned long)&args->__unused[0]) + 7) & ~7; | |
954 | ||
955 | if (copy_from_user(&tmp, args, sizeof(tmp))) | |
956 | return -EFAULT; | |
957 | ||
958 | if (tmp.oldval && tmp.oldlenp) { | |
959 | /* Duh, this is ugly and might not work if sysctl_args | |
960 | is in read-only memory, but do_sysctl does indirectly | |
961 | a lot of uaccess in both directions and we'd have to | |
962 | basically copy the whole sysctl.c here, and | |
963 | glibc's __sysctl uses rw memory for the structure | |
964 | anyway. */ | |
965 | oldlenp = (size_t __user *)addr; | |
966 | if (get_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)) || | |
967 | put_user(oldlen, oldlenp)) | |
968 | return -EFAULT; | |
969 | } | |
970 | ||
971 | lock_kernel(); | |
972 | error = do_sysctl(compat_ptr(tmp.name), tmp.nlen, | |
973 | compat_ptr(tmp.oldval), oldlenp, | |
974 | compat_ptr(tmp.newval), tmp.newlen); | |
975 | unlock_kernel(); | |
976 | if (oldlenp) { | |
977 | if (!error) { | |
978 | if (get_user(oldlen, oldlenp) || | |
979 | put_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp))) | |
980 | error = -EFAULT; | |
981 | } | |
982 | copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused)); | |
983 | } | |
984 | return error; | |
985 | } | |
986 | #endif | |
987 | ||
ce10d979 PM |
988 | asmlinkage int sys32_uname(struct old_utsname __user * name) |
989 | { | |
990 | int err = 0; | |
991 | ||
992 | down_read(&uts_sem); | |
993 | if (copy_to_user(name, &system_utsname, sizeof(*name))) | |
994 | err = -EFAULT; | |
995 | up_read(&uts_sem); | |
996 | if (!err && personality(current->personality) == PER_LINUX32) { | |
997 | /* change "ppc64" to "ppc" */ | |
998 | if (__put_user(0, name->machine + 3) | |
999 | || __put_user(0, name->machine + 4)) | |
1000 | err = -EFAULT; | |
1001 | } | |
1002 | return err; | |
1003 | } | |
1004 | ||
1da177e4 LT |
1005 | asmlinkage int sys32_olduname(struct oldold_utsname __user * name) |
1006 | { | |
1007 | int error; | |
ce10d979 | 1008 | |
1da177e4 LT |
1009 | if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname))) |
1010 | return -EFAULT; | |
1011 | ||
1012 | down_read(&uts_sem); | |
1013 | error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN); | |
ce10d979 PM |
1014 | error |= __put_user(0,name->sysname+__OLD_UTS_LEN); |
1015 | error |= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN); | |
1016 | error |= __put_user(0,name->nodename+__OLD_UTS_LEN); | |
1017 | error |= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN); | |
1018 | error |= __put_user(0,name->release+__OLD_UTS_LEN); | |
1019 | error |= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN); | |
1020 | error |= __put_user(0,name->version+__OLD_UTS_LEN); | |
1021 | error |= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN); | |
1022 | error |= __put_user(0,name->machine+__OLD_UTS_LEN); | |
1023 | if (personality(current->personality) == PER_LINUX32) { | |
1024 | /* change "ppc64" to "ppc" */ | |
1025 | error |= __put_user(0, name->machine + 3); | |
1026 | error |= __put_user(0, name->machine + 4); | |
1027 | } | |
1028 | ||
1da177e4 LT |
1029 | up_read(&uts_sem); |
1030 | ||
1031 | error = error ? -EFAULT : 0; | |
1032 | ||
1033 | return error; | |
1034 | } | |
1035 | ||
1036 | unsigned long sys32_mmap2(unsigned long addr, size_t len, | |
1037 | unsigned long prot, unsigned long flags, | |
1038 | unsigned long fd, unsigned long pgoff) | |
1039 | { | |
1040 | /* This should remain 12 even if PAGE_SIZE changes */ | |
1041 | return sys_mmap(addr, len, prot, flags, fd, pgoff << 12); | |
1042 | } | |
1043 | ||
1044 | int get_compat_timeval(struct timeval *tv, struct compat_timeval __user *ctv) | |
1045 | { | |
1046 | return (!access_ok(VERIFY_READ, ctv, sizeof(*ctv)) || | |
1047 | __get_user(tv->tv_sec, &ctv->tv_sec) || | |
1048 | __get_user(tv->tv_usec, &ctv->tv_usec)) ? -EFAULT : 0; | |
1049 | } | |
1050 | ||
1051 | asmlinkage long sys32_utimes(char __user *filename, struct compat_timeval __user *tvs) | |
1052 | { | |
1053 | struct timeval ktvs[2], *ptr; | |
1054 | ||
1055 | ptr = NULL; | |
1056 | if (tvs) { | |
1057 | if (get_compat_timeval(&ktvs[0], &tvs[0]) || | |
1058 | get_compat_timeval(&ktvs[1], &tvs[1])) | |
1059 | return -EFAULT; | |
1060 | ptr = ktvs; | |
1061 | } | |
1062 | ||
1063 | return do_utimes(filename, ptr); | |
1064 | } | |
1065 | ||
1066 | long sys32_tgkill(u32 tgid, u32 pid, int sig) | |
1067 | { | |
1068 | /* sign extend tgid, pid */ | |
1069 | return sys_tgkill((int)tgid, (int)pid, sig); | |
1070 | } | |
1071 | ||
1072 | /* | |
1073 | * long long munging: | |
1074 | * The 32 bit ABI passes long longs in an odd even register pair. | |
1075 | */ | |
1076 | ||
1077 | compat_ssize_t sys32_pread64(unsigned int fd, char __user *ubuf, compat_size_t count, | |
1078 | u32 reg6, u32 poshi, u32 poslo) | |
1079 | { | |
1080 | return sys_pread64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo); | |
1081 | } | |
1082 | ||
1083 | compat_ssize_t sys32_pwrite64(unsigned int fd, char __user *ubuf, compat_size_t count, | |
1084 | u32 reg6, u32 poshi, u32 poslo) | |
1085 | { | |
1086 | return sys_pwrite64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo); | |
1087 | } | |
1088 | ||
1089 | compat_ssize_t sys32_readahead(int fd, u32 r4, u32 offhi, u32 offlo, u32 count) | |
1090 | { | |
1091 | return sys_readahead(fd, ((loff_t)offhi << 32) | offlo, count); | |
1092 | } | |
1093 | ||
1094 | asmlinkage int sys32_truncate64(const char __user * path, u32 reg4, | |
1095 | unsigned long high, unsigned long low) | |
1096 | { | |
1097 | return sys_truncate(path, (high << 32) | low); | |
1098 | } | |
1099 | ||
1100 | asmlinkage int sys32_ftruncate64(unsigned int fd, u32 reg4, unsigned long high, | |
1101 | unsigned long low) | |
1102 | { | |
1103 | return sys_ftruncate(fd, (high << 32) | low); | |
1104 | } | |
1105 | ||
1106 | long ppc32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char __user *buf, | |
1107 | size_t len) | |
1108 | { | |
1109 | return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low, | |
1110 | buf, len); | |
1111 | } | |
1112 | ||
1113 | long ppc32_fadvise64(int fd, u32 unused, u32 offset_high, u32 offset_low, | |
1114 | size_t len, int advice) | |
1115 | { | |
1116 | return sys_fadvise64(fd, (u64)offset_high << 32 | offset_low, len, | |
1117 | advice); | |
1118 | } | |
1119 | ||
1120 | long ppc32_fadvise64_64(int fd, int advice, u32 offset_high, u32 offset_low, | |
1121 | u32 len_high, u32 len_low) | |
1122 | { | |
1123 | return sys_fadvise64(fd, (u64)offset_high << 32 | offset_low, | |
1124 | (u64)len_high << 32 | len_low, advice); | |
1125 | } | |
1126 | ||
1da177e4 LT |
1127 | long ppc32_timer_create(clockid_t clock, |
1128 | struct compat_sigevent __user *ev32, | |
1129 | timer_t __user *timer_id) | |
1130 | { | |
1131 | sigevent_t event; | |
1132 | timer_t t; | |
1133 | long err; | |
1134 | mm_segment_t savefs; | |
1135 | ||
1136 | if (ev32 == NULL) | |
1137 | return sys_timer_create(clock, NULL, timer_id); | |
1138 | ||
1139 | if (get_compat_sigevent(&event, ev32)) | |
1140 | return -EFAULT; | |
1141 | ||
1142 | if (!access_ok(VERIFY_WRITE, timer_id, sizeof(timer_t))) | |
1143 | return -EFAULT; | |
1144 | ||
1145 | savefs = get_fs(); | |
1146 | set_fs(KERNEL_DS); | |
1147 | /* The __user pointer casts are valid due to the set_fs() */ | |
1148 | err = sys_timer_create(clock, | |
1149 | (sigevent_t __user *) &event, | |
1150 | (timer_t __user *) &t); | |
1151 | set_fs(savefs); | |
1152 | ||
1153 | if (err == 0) | |
1154 | err = __put_user(t, timer_id); | |
1155 | ||
1156 | return err; | |
1157 | } | |
1158 | ||
1159 | asmlinkage long sys32_add_key(const char __user *_type, | |
1160 | const char __user *_description, | |
1161 | const void __user *_payload, | |
1162 | u32 plen, | |
1163 | u32 ringid) | |
1164 | { | |
1165 | return sys_add_key(_type, _description, _payload, plen, ringid); | |
1166 | } | |
1167 | ||
1168 | asmlinkage long sys32_request_key(const char __user *_type, | |
1169 | const char __user *_description, | |
1170 | const char __user *_callout_info, | |
1171 | u32 destringid) | |
1172 | { | |
1173 | return sys_request_key(_type, _description, _callout_info, destringid); | |
1174 | } | |
1175 |