blob: 1cacf61f9c91eb27ca3730510df3b35b449493e1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/poll.h>
34#include <linux/personality.h>
35#include <linux/stat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/mman.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/in.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <linux/syscalls.h>
39#include <linux/unistd.h>
40#include <linux/sysctl.h>
41#include <linux/binfmts.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/security.h>
43#include <linux/compat.h>
44#include <linux/ptrace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/elf.h>
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#include <asm/time.h>
54#include <asm/mmu_context.h>
55#include <asm/systemcfg.h>
Stephen Rothwelld3878992005-09-28 02:50:25 +100056#include <asm/ppc-pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
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
62struct old_linux_dirent32 {
63 u32 d_ino;
64 u32 d_offset;
65 unsigned short d_namlen;
66 char d_name[1];
67};
68
69struct readdir_callback32 {
70 struct old_linux_dirent32 __user * dirent;
71 int count;
72};
73
74static 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
92asmlinkage 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
110out_putf:
111 fput(file);
112out:
113 return error;
114}
115
116struct linux_dirent32 {
117 u32 d_ino;
118 u32 d_off;
119 unsigned short d_reclen;
120 char d_name[1];
121};
122
123struct getdents_callback32 {
124 struct linux_dirent32 __user * current_dir;
125 struct linux_dirent32 __user * previous;
126 int count;
127 int error;
128};
129
130static 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;
161efault:
162 buf->error = -EFAULT;
163 return -EFAULT;
164}
165
166asmlinkage 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
200out_putf:
201 fput(file);
202out:
203 return error;
204}
205
206asmlinkage 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
214int 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 */
250asmlinkage long sys32_sysfs(u32 option, u32 arg1, u32 arg2)
251{
252 return sys_sysfs((int)option, arg1, arg2);
253}
254
255/* Handle adjtimex compatibility. */
256struct 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
269extern int do_adjtimex(struct timex *);
270extern void ppc_adjtimex(void);
271
272asmlinkage 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331asmlinkage long sys32_pause(void)
332{
333 current->state = TASK_INTERRUPTIBLE;
334 schedule();
335
336 return -ERESTARTNOHAND;
337}
338
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339static 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
353static 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
360struct 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
377asmlinkage 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. */
432extern struct timezone sys_tz;
433
434asmlinkage 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
452asmlinkage 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
470long 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 */
541asmlinkage 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
563asmlinkage 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
585long 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
608out:
609 return error;
610}
611
612/* Set up a thread for executing a new program. */
613void start_thread32(struct pt_regs* regs, unsigned long nip, unsigned long sp)
614{
615 set_fs(USER_DS);
616
617 /*
618 * If we exec out of a kernel thread then thread.regs will not be
619 * set. Do it now.
620 */
621 if (!current->thread.regs) {
622 unsigned long childregs = (unsigned long)current->thread_info +
623 THREAD_SIZE;
624 childregs -= sizeof(struct pt_regs);
625 current->thread.regs = (struct pt_regs *)childregs;
626 }
627
628 /*
629 * ELF_PLAT_INIT already clears all registers but it also sets r2.
630 * So just clear r2 here.
631 */
632 regs->gpr[2] = 0;
633
634 regs->nip = nip;
635 regs->gpr[1] = sp;
636 regs->msr = MSR_USER32;
637#ifndef CONFIG_SMP
638 if (last_task_used_math == current)
639 last_task_used_math = 0;
640#endif /* CONFIG_SMP */
641 current->thread.fpscr = 0;
642 memset(current->thread.fpr, 0, sizeof(current->thread.fpr));
643#ifdef CONFIG_ALTIVEC
644#ifndef CONFIG_SMP
645 if (last_task_used_altivec == current)
646 last_task_used_altivec = 0;
647#endif /* CONFIG_SMP */
648 memset(current->thread.vr, 0, sizeof(current->thread.vr));
649 current->thread.vscr.u[0] = 0;
650 current->thread.vscr.u[1] = 0;
651 current->thread.vscr.u[2] = 0;
652 current->thread.vscr.u[3] = 0x00010000; /* Java mode disabled */
653 current->thread.vrsave = 0;
654 current->thread.used_vr = 0;
655#endif /* CONFIG_ALTIVEC */
656}
657
658/* Note: it is necessary to treat option as an unsigned int,
659 * with the corresponding cast to a signed int to insure that the
660 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
661 * and the register representation of a signed int (msr in 64-bit mode) is performed.
662 */
663asmlinkage long sys32_prctl(u32 option, u32 arg2, u32 arg3, u32 arg4, u32 arg5)
664{
665 return sys_prctl((int)option,
666 (unsigned long) arg2,
667 (unsigned long) arg3,
668 (unsigned long) arg4,
669 (unsigned long) arg5);
670}
671
672/* Note: it is necessary to treat pid as an unsigned int,
673 * with the corresponding cast to a signed int to insure that the
674 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
675 * and the register representation of a signed int (msr in 64-bit mode) is performed.
676 */
677asmlinkage long sys32_sched_rr_get_interval(u32 pid, struct compat_timespec __user *interval)
678{
679 struct timespec t;
680 int ret;
681 mm_segment_t old_fs = get_fs ();
682
683 /* The __user pointer cast is valid because of the set_fs() */
684 set_fs (KERNEL_DS);
685 ret = sys_sched_rr_get_interval((int)pid, (struct timespec __user *) &t);
686 set_fs (old_fs);
687 if (put_compat_timespec(&t, interval))
688 return -EFAULT;
689 return ret;
690}
691
692asmlinkage int sys32_pciconfig_read(u32 bus, u32 dfn, u32 off, u32 len, u32 ubuf)
693{
694 return sys_pciconfig_read((unsigned long) bus,
695 (unsigned long) dfn,
696 (unsigned long) off,
697 (unsigned long) len,
698 compat_ptr(ubuf));
699}
700
701asmlinkage int sys32_pciconfig_write(u32 bus, u32 dfn, u32 off, u32 len, u32 ubuf)
702{
703 return sys_pciconfig_write((unsigned long) bus,
704 (unsigned long) dfn,
705 (unsigned long) off,
706 (unsigned long) len,
707 compat_ptr(ubuf));
708}
709
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710asmlinkage int sys32_pciconfig_iobase(u32 which, u32 in_bus, u32 in_devfn)
711{
Paul Mackerrasb2ad7b52005-09-09 23:02:36 +1000712 return sys_pciconfig_iobase(which, in_bus, in_devfn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713}
714
715
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716/* Note: it is necessary to treat mode as an unsigned int,
717 * with the corresponding cast to a signed int to insure that the
718 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
719 * and the register representation of a signed int (msr in 64-bit mode) is performed.
720 */
721asmlinkage long sys32_access(const char __user * filename, u32 mode)
722{
723 return sys_access(filename, (int)mode);
724}
725
726
727/* Note: it is necessary to treat mode as an unsigned int,
728 * with the corresponding cast to a signed int to insure that the
729 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
730 * and the register representation of a signed int (msr in 64-bit mode) is performed.
731 */
732asmlinkage long sys32_creat(const char __user * pathname, u32 mode)
733{
734 return sys_creat(pathname, (int)mode);
735}
736
737
738/* Note: it is necessary to treat pid and options as unsigned ints,
739 * with the corresponding cast to a signed int to insure that the
740 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
741 * and the register representation of a signed int (msr in 64-bit mode) is performed.
742 */
743asmlinkage long sys32_waitpid(u32 pid, unsigned int __user * stat_addr, u32 options)
744{
745 return sys_waitpid((int)pid, stat_addr, (int)options);
746}
747
748
749/* Note: it is necessary to treat gidsetsize as an unsigned int,
750 * with the corresponding cast to a signed int to insure that the
751 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
752 * and the register representation of a signed int (msr in 64-bit mode) is performed.
753 */
754asmlinkage long sys32_getgroups(u32 gidsetsize, gid_t __user *grouplist)
755{
756 return sys_getgroups((int)gidsetsize, grouplist);
757}
758
759
760/* Note: it is necessary to treat pid as an unsigned int,
761 * with the corresponding cast to a signed int to insure that the
762 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
763 * and the register representation of a signed int (msr in 64-bit mode) is performed.
764 */
765asmlinkage long sys32_getpgid(u32 pid)
766{
767 return sys_getpgid((int)pid);
768}
769
770
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
772/* Note: it is necessary to treat pid as an unsigned int,
773 * with the corresponding cast to a signed int to insure that the
774 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
775 * and the register representation of a signed int (msr in 64-bit mode) is performed.
776 */
777asmlinkage long sys32_getsid(u32 pid)
778{
779 return sys_getsid((int)pid);
780}
781
782
783/* Note: it is necessary to treat pid and sig as unsigned ints,
784 * with the corresponding cast to a signed int to insure that the
785 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
786 * and the register representation of a signed int (msr in 64-bit mode) is performed.
787 */
788asmlinkage long sys32_kill(u32 pid, u32 sig)
789{
790 return sys_kill((int)pid, (int)sig);
791}
792
793
794/* Note: it is necessary to treat mode as an unsigned int,
795 * with the corresponding cast to a signed int to insure that the
796 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
797 * and the register representation of a signed int (msr in 64-bit mode) is performed.
798 */
799asmlinkage long sys32_mkdir(const char __user * pathname, u32 mode)
800{
801 return sys_mkdir(pathname, (int)mode);
802}
803
804long sys32_nice(u32 increment)
805{
806 /* sign extend increment */
807 return sys_nice((int)increment);
808}
809
810off_t ppc32_lseek(unsigned int fd, u32 offset, unsigned int origin)
811{
812 /* sign extend n */
813 return sys_lseek(fd, (int)offset, origin);
814}
815
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816/* Note: it is necessary to treat bufsiz as an unsigned int,
817 * with the corresponding cast to a signed int to insure that the
818 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
819 * and the register representation of a signed int (msr in 64-bit mode) is performed.
820 */
821asmlinkage long sys32_readlink(const char __user * path, char __user * buf, u32 bufsiz)
822{
823 return sys_readlink(path, buf, (int)bufsiz);
824}
825
826/* Note: it is necessary to treat option as an unsigned int,
827 * with the corresponding cast to a signed int to insure that the
828 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
829 * and the register representation of a signed int (msr in 64-bit mode) is performed.
830 */
831asmlinkage long sys32_sched_get_priority_max(u32 policy)
832{
833 return sys_sched_get_priority_max((int)policy);
834}
835
836
837/* Note: it is necessary to treat policy as an unsigned int,
838 * with the corresponding cast to a signed int to insure that the
839 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
840 * and the register representation of a signed int (msr in 64-bit mode) is performed.
841 */
842asmlinkage long sys32_sched_get_priority_min(u32 policy)
843{
844 return sys_sched_get_priority_min((int)policy);
845}
846
847
848/* Note: it is necessary to treat pid as an unsigned int,
849 * with the corresponding cast to a signed int to insure that the
850 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
851 * and the register representation of a signed int (msr in 64-bit mode) is performed.
852 */
853asmlinkage long sys32_sched_getparam(u32 pid, struct sched_param __user *param)
854{
855 return sys_sched_getparam((int)pid, param);
856}
857
858
859/* Note: it is necessary to treat pid as an unsigned int,
860 * with the corresponding cast to a signed int to insure that the
861 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
862 * and the register representation of a signed int (msr in 64-bit mode) is performed.
863 */
864asmlinkage long sys32_sched_getscheduler(u32 pid)
865{
866 return sys_sched_getscheduler((int)pid);
867}
868
869
870/* Note: it is necessary to treat pid as an unsigned int,
871 * with the corresponding cast to a signed int to insure that the
872 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
873 * and the register representation of a signed int (msr in 64-bit mode) is performed.
874 */
875asmlinkage long sys32_sched_setparam(u32 pid, struct sched_param __user *param)
876{
877 return sys_sched_setparam((int)pid, param);
878}
879
880
881/* Note: it is necessary to treat pid and policy as unsigned ints,
882 * with the corresponding cast to a signed int to insure that the
883 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
884 * and the register representation of a signed int (msr in 64-bit mode) is performed.
885 */
886asmlinkage long sys32_sched_setscheduler(u32 pid, u32 policy, struct sched_param __user *param)
887{
888 return sys_sched_setscheduler((int)pid, (int)policy, param);
889}
890
891
892/* Note: it is necessary to treat len as an unsigned int,
893 * with the corresponding cast to a signed int to insure that the
894 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
895 * and the register representation of a signed int (msr in 64-bit mode) is performed.
896 */
897asmlinkage long sys32_setdomainname(char __user *name, u32 len)
898{
899 return sys_setdomainname(name, (int)len);
900}
901
902
903/* Note: it is necessary to treat gidsetsize as an unsigned int,
904 * with the corresponding cast to a signed int to insure that the
905 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
906 * and the register representation of a signed int (msr in 64-bit mode) is performed.
907 */
908asmlinkage long sys32_setgroups(u32 gidsetsize, gid_t __user *grouplist)
909{
910 return sys_setgroups((int)gidsetsize, grouplist);
911}
912
913
914asmlinkage long sys32_sethostname(char __user *name, u32 len)
915{
916 /* sign extend len */
917 return sys_sethostname(name, (int)len);
918}
919
920
921/* Note: it is necessary to treat pid and pgid as unsigned ints,
922 * with the corresponding cast to a signed int to insure that the
923 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
924 * and the register representation of a signed int (msr in 64-bit mode) is performed.
925 */
926asmlinkage long sys32_setpgid(u32 pid, u32 pgid)
927{
928 return sys_setpgid((int)pid, (int)pgid);
929}
930
Anton Blanchard79c2cc72005-07-07 17:56:15 -0700931long sys32_getpriority(u32 which, u32 who)
932{
933 /* sign extend which and who */
934 return sys_getpriority((int)which, (int)who);
935}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936
937long sys32_setpriority(u32 which, u32 who, u32 niceval)
938{
939 /* sign extend which, who and niceval */
940 return sys_setpriority((int)which, (int)who, (int)niceval);
941}
942
Anton Blanchard79c2cc72005-07-07 17:56:15 -0700943long sys32_ioprio_get(u32 which, u32 who)
944{
945 /* sign extend which and who */
946 return sys_ioprio_get((int)which, (int)who);
947}
948
949long sys32_ioprio_set(u32 which, u32 who, u32 ioprio)
950{
951 /* sign extend which, who and ioprio */
952 return sys_ioprio_set((int)which, (int)who, (int)ioprio);
953}
954
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955/* Note: it is necessary to treat newmask as an unsigned int,
956 * with the corresponding cast to a signed int to insure that the
957 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
958 * and the register representation of a signed int (msr in 64-bit mode) is performed.
959 */
960asmlinkage long sys32_ssetmask(u32 newmask)
961{
962 return sys_ssetmask((int) newmask);
963}
964
965asmlinkage long sys32_syslog(u32 type, char __user * buf, u32 len)
966{
967 /* sign extend len */
968 return sys_syslog(type, buf, (int)len);
969}
970
971
972/* Note: it is necessary to treat mask as an unsigned int,
973 * with the corresponding cast to a signed int to insure that the
974 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
975 * and the register representation of a signed int (msr in 64-bit mode) is performed.
976 */
977asmlinkage long sys32_umask(u32 mask)
978{
979 return sys_umask((int)mask);
980}
981
982#ifdef CONFIG_SYSCTL
983struct __sysctl_args32 {
984 u32 name;
985 int nlen;
986 u32 oldval;
987 u32 oldlenp;
988 u32 newval;
989 u32 newlen;
990 u32 __unused[4];
991};
992
993asmlinkage long sys32_sysctl(struct __sysctl_args32 __user *args)
994{
995 struct __sysctl_args32 tmp;
996 int error;
997 size_t oldlen;
998 size_t __user *oldlenp = NULL;
999 unsigned long addr = (((unsigned long)&args->__unused[0]) + 7) & ~7;
1000
1001 if (copy_from_user(&tmp, args, sizeof(tmp)))
1002 return -EFAULT;
1003
1004 if (tmp.oldval && tmp.oldlenp) {
1005 /* Duh, this is ugly and might not work if sysctl_args
1006 is in read-only memory, but do_sysctl does indirectly
1007 a lot of uaccess in both directions and we'd have to
1008 basically copy the whole sysctl.c here, and
1009 glibc's __sysctl uses rw memory for the structure
1010 anyway. */
1011 oldlenp = (size_t __user *)addr;
1012 if (get_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)) ||
1013 put_user(oldlen, oldlenp))
1014 return -EFAULT;
1015 }
1016
1017 lock_kernel();
1018 error = do_sysctl(compat_ptr(tmp.name), tmp.nlen,
1019 compat_ptr(tmp.oldval), oldlenp,
1020 compat_ptr(tmp.newval), tmp.newlen);
1021 unlock_kernel();
1022 if (oldlenp) {
1023 if (!error) {
1024 if (get_user(oldlen, oldlenp) ||
1025 put_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)))
1026 error = -EFAULT;
1027 }
1028 copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused));
1029 }
1030 return error;
1031}
1032#endif
1033
Paul Mackerrasce10d972005-06-08 21:59:15 +10001034asmlinkage int sys32_uname(struct old_utsname __user * name)
1035{
1036 int err = 0;
1037
1038 down_read(&uts_sem);
1039 if (copy_to_user(name, &system_utsname, sizeof(*name)))
1040 err = -EFAULT;
1041 up_read(&uts_sem);
1042 if (!err && personality(current->personality) == PER_LINUX32) {
1043 /* change "ppc64" to "ppc" */
1044 if (__put_user(0, name->machine + 3)
1045 || __put_user(0, name->machine + 4))
1046 err = -EFAULT;
1047 }
1048 return err;
1049}
1050
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051asmlinkage int sys32_olduname(struct oldold_utsname __user * name)
1052{
1053 int error;
Paul Mackerrasce10d972005-06-08 21:59:15 +10001054
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
1056 return -EFAULT;
1057
1058 down_read(&uts_sem);
1059 error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
Paul Mackerrasce10d972005-06-08 21:59:15 +10001060 error |= __put_user(0,name->sysname+__OLD_UTS_LEN);
1061 error |= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
1062 error |= __put_user(0,name->nodename+__OLD_UTS_LEN);
1063 error |= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
1064 error |= __put_user(0,name->release+__OLD_UTS_LEN);
1065 error |= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
1066 error |= __put_user(0,name->version+__OLD_UTS_LEN);
1067 error |= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN);
1068 error |= __put_user(0,name->machine+__OLD_UTS_LEN);
1069 if (personality(current->personality) == PER_LINUX32) {
1070 /* change "ppc64" to "ppc" */
1071 error |= __put_user(0, name->machine + 3);
1072 error |= __put_user(0, name->machine + 4);
1073 }
1074
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 up_read(&uts_sem);
1076
1077 error = error ? -EFAULT : 0;
1078
1079 return error;
1080}
1081
1082unsigned long sys32_mmap2(unsigned long addr, size_t len,
1083 unsigned long prot, unsigned long flags,
1084 unsigned long fd, unsigned long pgoff)
1085{
1086 /* This should remain 12 even if PAGE_SIZE changes */
1087 return sys_mmap(addr, len, prot, flags, fd, pgoff << 12);
1088}
1089
1090int get_compat_timeval(struct timeval *tv, struct compat_timeval __user *ctv)
1091{
1092 return (!access_ok(VERIFY_READ, ctv, sizeof(*ctv)) ||
1093 __get_user(tv->tv_sec, &ctv->tv_sec) ||
1094 __get_user(tv->tv_usec, &ctv->tv_usec)) ? -EFAULT : 0;
1095}
1096
1097asmlinkage long sys32_utimes(char __user *filename, struct compat_timeval __user *tvs)
1098{
1099 struct timeval ktvs[2], *ptr;
1100
1101 ptr = NULL;
1102 if (tvs) {
1103 if (get_compat_timeval(&ktvs[0], &tvs[0]) ||
1104 get_compat_timeval(&ktvs[1], &tvs[1]))
1105 return -EFAULT;
1106 ptr = ktvs;
1107 }
1108
1109 return do_utimes(filename, ptr);
1110}
1111
1112long sys32_tgkill(u32 tgid, u32 pid, int sig)
1113{
1114 /* sign extend tgid, pid */
1115 return sys_tgkill((int)tgid, (int)pid, sig);
1116}
1117
1118/*
1119 * long long munging:
1120 * The 32 bit ABI passes long longs in an odd even register pair.
1121 */
1122
1123compat_ssize_t sys32_pread64(unsigned int fd, char __user *ubuf, compat_size_t count,
1124 u32 reg6, u32 poshi, u32 poslo)
1125{
1126 return sys_pread64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
1127}
1128
1129compat_ssize_t sys32_pwrite64(unsigned int fd, char __user *ubuf, compat_size_t count,
1130 u32 reg6, u32 poshi, u32 poslo)
1131{
1132 return sys_pwrite64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
1133}
1134
1135compat_ssize_t sys32_readahead(int fd, u32 r4, u32 offhi, u32 offlo, u32 count)
1136{
1137 return sys_readahead(fd, ((loff_t)offhi << 32) | offlo, count);
1138}
1139
1140asmlinkage int sys32_truncate64(const char __user * path, u32 reg4,
1141 unsigned long high, unsigned long low)
1142{
1143 return sys_truncate(path, (high << 32) | low);
1144}
1145
1146asmlinkage int sys32_ftruncate64(unsigned int fd, u32 reg4, unsigned long high,
1147 unsigned long low)
1148{
1149 return sys_ftruncate(fd, (high << 32) | low);
1150}
1151
1152long ppc32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char __user *buf,
1153 size_t len)
1154{
1155 return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low,
1156 buf, len);
1157}
1158
1159long ppc32_fadvise64(int fd, u32 unused, u32 offset_high, u32 offset_low,
1160 size_t len, int advice)
1161{
1162 return sys_fadvise64(fd, (u64)offset_high << 32 | offset_low, len,
1163 advice);
1164}
1165
1166long ppc32_fadvise64_64(int fd, int advice, u32 offset_high, u32 offset_low,
1167 u32 len_high, u32 len_low)
1168{
1169 return sys_fadvise64(fd, (u64)offset_high << 32 | offset_low,
1170 (u64)len_high << 32 | len_low, advice);
1171}
1172
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173long ppc32_timer_create(clockid_t clock,
1174 struct compat_sigevent __user *ev32,
1175 timer_t __user *timer_id)
1176{
1177 sigevent_t event;
1178 timer_t t;
1179 long err;
1180 mm_segment_t savefs;
1181
1182 if (ev32 == NULL)
1183 return sys_timer_create(clock, NULL, timer_id);
1184
1185 if (get_compat_sigevent(&event, ev32))
1186 return -EFAULT;
1187
1188 if (!access_ok(VERIFY_WRITE, timer_id, sizeof(timer_t)))
1189 return -EFAULT;
1190
1191 savefs = get_fs();
1192 set_fs(KERNEL_DS);
1193 /* The __user pointer casts are valid due to the set_fs() */
1194 err = sys_timer_create(clock,
1195 (sigevent_t __user *) &event,
1196 (timer_t __user *) &t);
1197 set_fs(savefs);
1198
1199 if (err == 0)
1200 err = __put_user(t, timer_id);
1201
1202 return err;
1203}
1204
1205asmlinkage long sys32_add_key(const char __user *_type,
1206 const char __user *_description,
1207 const void __user *_payload,
1208 u32 plen,
1209 u32 ringid)
1210{
1211 return sys_add_key(_type, _description, _payload, plen, ringid);
1212}
1213
1214asmlinkage long sys32_request_key(const char __user *_type,
1215 const char __user *_description,
1216 const char __user *_callout_info,
1217 u32 destringid)
1218{
1219 return sys_request_key(_type, _description, _callout_info, destringid);
1220}
1221