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> 33 #include <linux/poll.h> 34 #include <linux/personality.h> 35 #include <linux/stat.h> 36 #include <linux/mman.h> 37 #include <linux/in.h> 38 #include <linux/syscalls.h> 39 #include <linux/unistd.h> 40 #include <linux/sysctl.h> 41 #include <linux/binfmts.h> 42 #include <linux/security.h> 43 #include <linux/compat.h> 44 #include <linux/ptrace.h> 45 #include <linux/elf.h> 46 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> 53 #include <asm/time.h> 54 #include <asm/mmu_context.h> 55 #include <asm/systemcfg.h> 56 #include <asm/ppc-pci.h> 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 asmlinkage long ppc32_select(u32 n, compat_ulong_t __user *inp, 117 compat_ulong_t __user *outp, compat_ulong_t __user *exp, 118 compat_uptr_t tvp_x) 119 { 120 /* sign extend n */ 121 return compat_sys_select((int)n, inp, outp, exp, compat_ptr(tvp_x)); 122 } 123 124 int cp_compat_stat(struct kstat *stat, struct compat_stat __user *statbuf) 125 { 126 long err; 127 128 if (stat->size > MAX_NON_LFS || !new_valid_dev(stat->dev) || 129 !new_valid_dev(stat->rdev)) 130 return -EOVERFLOW; 131 132 err = access_ok(VERIFY_WRITE, statbuf, sizeof(*statbuf)) ? 0 : -EFAULT; 133 err |= __put_user(new_encode_dev(stat->dev), &statbuf->st_dev); 134 err |= __put_user(stat->ino, &statbuf->st_ino); 135 err |= __put_user(stat->mode, &statbuf->st_mode); 136 err |= __put_user(stat->nlink, &statbuf->st_nlink); 137 err |= __put_user(stat->uid, &statbuf->st_uid); 138 err |= __put_user(stat->gid, &statbuf->st_gid); 139 err |= __put_user(new_encode_dev(stat->rdev), &statbuf->st_rdev); 140 err |= __put_user(stat->size, &statbuf->st_size); 141 err |= __put_user(stat->atime.tv_sec, &statbuf->st_atime); 142 err |= __put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec); 143 err |= __put_user(stat->mtime.tv_sec, &statbuf->st_mtime); 144 err |= __put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec); 145 err |= __put_user(stat->ctime.tv_sec, &statbuf->st_ctime); 146 err |= __put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec); 147 err |= __put_user(stat->blksize, &statbuf->st_blksize); 148 err |= __put_user(stat->blocks, &statbuf->st_blocks); 149 err |= __put_user(0, &statbuf->__unused4[0]); 150 err |= __put_user(0, &statbuf->__unused4[1]); 151 152 return err; 153 } 154 155 /* Note: it is necessary to treat option as an unsigned int, 156 * with the corresponding cast to a signed int to insure that the 157 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) 158 * and the register representation of a signed int (msr in 64-bit mode) is performed. 159 */ 160 asmlinkage long compat_sys_sysfs(u32 option, u32 arg1, u32 arg2) 161 { 162 return sys_sysfs((int)option, arg1, arg2); 163 } 164 165 /* Handle adjtimex compatibility. */ 166 struct timex32 { 167 u32 modes; 168 s32 offset, freq, maxerror, esterror; 169 s32 status, constant, precision, tolerance; 170 struct compat_timeval time; 171 s32 tick; 172 s32 ppsfreq, jitter, shift, stabil; 173 s32 jitcnt, calcnt, errcnt, stbcnt; 174 s32 :32; s32 :32; s32 :32; s32 :32; 175 s32 :32; s32 :32; s32 :32; s32 :32; 176 s32 :32; s32 :32; s32 :32; s32 :32; 177 }; 178 179 extern int do_adjtimex(struct timex *); 180 extern void ppc_adjtimex(void); 181 182 asmlinkage long compat_sys_adjtimex(struct timex32 __user *utp) 183 { 184 struct timex txc; 185 int ret; 186 187 memset(&txc, 0, sizeof(struct timex)); 188 189 if(get_user(txc.modes, &utp->modes) || 190 __get_user(txc.offset, &utp->offset) || 191 __get_user(txc.freq, &utp->freq) || 192 __get_user(txc.maxerror, &utp->maxerror) || 193 __get_user(txc.esterror, &utp->esterror) || 194 __get_user(txc.status, &utp->status) || 195 __get_user(txc.constant, &utp->constant) || 196 __get_user(txc.precision, &utp->precision) || 197 __get_user(txc.tolerance, &utp->tolerance) || 198 __get_user(txc.time.tv_sec, &utp->time.tv_sec) || 199 __get_user(txc.time.tv_usec, &utp->time.tv_usec) || 200 __get_user(txc.tick, &utp->tick) || 201 __get_user(txc.ppsfreq, &utp->ppsfreq) || 202 __get_user(txc.jitter, &utp->jitter) || 203 __get_user(txc.shift, &utp->shift) || 204 __get_user(txc.stabil, &utp->stabil) || 205 __get_user(txc.jitcnt, &utp->jitcnt) || 206 __get_user(txc.calcnt, &utp->calcnt) || 207 __get_user(txc.errcnt, &utp->errcnt) || 208 __get_user(txc.stbcnt, &utp->stbcnt)) 209 return -EFAULT; 210 211 ret = do_adjtimex(&txc); 212 213 /* adjust the conversion of TB to time of day to track adjtimex */ 214 ppc_adjtimex(); 215 216 if(put_user(txc.modes, &utp->modes) || 217 __put_user(txc.offset, &utp->offset) || 218 __put_user(txc.freq, &utp->freq) || 219 __put_user(txc.maxerror, &utp->maxerror) || 220 __put_user(txc.esterror, &utp->esterror) || 221 __put_user(txc.status, &utp->status) || 222 __put_user(txc.constant, &utp->constant) || 223 __put_user(txc.precision, &utp->precision) || 224 __put_user(txc.tolerance, &utp->tolerance) || 225 __put_user(txc.time.tv_sec, &utp->time.tv_sec) || 226 __put_user(txc.time.tv_usec, &utp->time.tv_usec) || 227 __put_user(txc.tick, &utp->tick) || 228 __put_user(txc.ppsfreq, &utp->ppsfreq) || 229 __put_user(txc.jitter, &utp->jitter) || 230 __put_user(txc.shift, &utp->shift) || 231 __put_user(txc.stabil, &utp->stabil) || 232 __put_user(txc.jitcnt, &utp->jitcnt) || 233 __put_user(txc.calcnt, &utp->calcnt) || 234 __put_user(txc.errcnt, &utp->errcnt) || 235 __put_user(txc.stbcnt, &utp->stbcnt)) 236 ret = -EFAULT; 237 238 return ret; 239 } 240 241 asmlinkage long compat_sys_pause(void) 242 { 243 current->state = TASK_INTERRUPTIBLE; 244 schedule(); 245 246 return -ERESTARTNOHAND; 247 } 248 249 static inline long get_ts32(struct timespec *o, struct compat_timeval __user *i) 250 { 251 long usec; 252 253 if (!access_ok(VERIFY_READ, i, sizeof(*i))) 254 return -EFAULT; 255 if (__get_user(o->tv_sec, &i->tv_sec)) 256 return -EFAULT; 257 if (__get_user(usec, &i->tv_usec)) 258 return -EFAULT; 259 o->tv_nsec = usec * 1000; 260 return 0; 261 } 262 263 static inline long put_tv32(struct compat_timeval __user *o, struct timeval *i) 264 { 265 return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) || 266 (__put_user(i->tv_sec, &o->tv_sec) | 267 __put_user(i->tv_usec, &o->tv_usec))); 268 } 269 270 struct sysinfo32 { 271 s32 uptime; 272 u32 loads[3]; 273 u32 totalram; 274 u32 freeram; 275 u32 sharedram; 276 u32 bufferram; 277 u32 totalswap; 278 u32 freeswap; 279 unsigned short procs; 280 unsigned short pad; 281 u32 totalhigh; 282 u32 freehigh; 283 u32 mem_unit; 284 char _f[20-2*sizeof(int)-sizeof(int)]; 285 }; 286 287 asmlinkage long compat_sys_sysinfo(struct sysinfo32 __user *info) 288 { 289 struct sysinfo s; 290 int ret, err; 291 int bitcount=0; 292 mm_segment_t old_fs = get_fs (); 293 294 /* The __user cast is valid due to set_fs() */ 295 set_fs (KERNEL_DS); 296 ret = sys_sysinfo((struct sysinfo __user *)&s); 297 set_fs (old_fs); 298 299 /* Check to see if any memory value is too large for 32-bit and 300 * scale down if needed. 301 */ 302 if ((s.totalram >> 32) || (s.totalswap >> 32)) { 303 while (s.mem_unit < PAGE_SIZE) { 304 s.mem_unit <<= 1; 305 bitcount++; 306 } 307 s.totalram >>=bitcount; 308 s.freeram >>= bitcount; 309 s.sharedram >>= bitcount; 310 s.bufferram >>= bitcount; 311 s.totalswap >>= bitcount; 312 s.freeswap >>= bitcount; 313 s.totalhigh >>= bitcount; 314 s.freehigh >>= bitcount; 315 } 316 317 err = put_user (s.uptime, &info->uptime); 318 err |= __put_user (s.loads[0], &info->loads[0]); 319 err |= __put_user (s.loads[1], &info->loads[1]); 320 err |= __put_user (s.loads[2], &info->loads[2]); 321 err |= __put_user (s.totalram, &info->totalram); 322 err |= __put_user (s.freeram, &info->freeram); 323 err |= __put_user (s.sharedram, &info->sharedram); 324 err |= __put_user (s.bufferram, &info->bufferram); 325 err |= __put_user (s.totalswap, &info->totalswap); 326 err |= __put_user (s.freeswap, &info->freeswap); 327 err |= __put_user (s.procs, &info->procs); 328 err |= __put_user (s.totalhigh, &info->totalhigh); 329 err |= __put_user (s.freehigh, &info->freehigh); 330 err |= __put_user (s.mem_unit, &info->mem_unit); 331 if (err) 332 return -EFAULT; 333 334 return ret; 335 } 336 337 338 339 340 /* Translations due to time_t size differences. Which affects all 341 sorts of things, like timeval and itimerval. */ 342 extern struct timezone sys_tz; 343 344 asmlinkage long compat_sys_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz) 345 { 346 if (tv) { 347 struct timeval ktv; 348 do_gettimeofday(&ktv); 349 if (put_tv32(tv, &ktv)) 350 return -EFAULT; 351 } 352 if (tz) { 353 if (copy_to_user(tz, &sys_tz, sizeof(sys_tz))) 354 return -EFAULT; 355 } 356 357 return 0; 358 } 359 360 361 362 asmlinkage long compat_sys_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz) 363 { 364 struct timespec kts; 365 struct timezone ktz; 366 367 if (tv) { 368 if (get_ts32(&kts, tv)) 369 return -EFAULT; 370 } 371 if (tz) { 372 if (copy_from_user(&ktz, tz, sizeof(ktz))) 373 return -EFAULT; 374 } 375 376 return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL); 377 } 378 379 #ifdef CONFIG_SYSVIPC 380 long compat_sys_ipc(u32 call, u32 first, u32 second, u32 third, compat_uptr_t ptr, 381 u32 fifth) 382 { 383 int version; 384 385 version = call >> 16; /* hack for backward compatibility */ 386 call &= 0xffff; 387 388 switch (call) { 389 390 case SEMTIMEDOP: 391 if (fifth) 392 /* sign extend semid */ 393 return compat_sys_semtimedop((int)first, 394 compat_ptr(ptr), second, 395 compat_ptr(fifth)); 396 /* else fall through for normal semop() */ 397 case SEMOP: 398 /* struct sembuf is the same on 32 and 64bit :)) */ 399 /* sign extend semid */ 400 return sys_semtimedop((int)first, compat_ptr(ptr), second, 401 NULL); 402 case SEMGET: 403 /* sign extend key, nsems */ 404 return sys_semget((int)first, (int)second, third); 405 case SEMCTL: 406 /* sign extend semid, semnum */ 407 return compat_sys_semctl((int)first, (int)second, third, 408 compat_ptr(ptr)); 409 410 case MSGSND: 411 /* sign extend msqid */ 412 return compat_sys_msgsnd((int)first, (int)second, third, 413 compat_ptr(ptr)); 414 case MSGRCV: 415 /* sign extend msqid, msgtyp */ 416 return compat_sys_msgrcv((int)first, second, (int)fifth, 417 third, version, compat_ptr(ptr)); 418 case MSGGET: 419 /* sign extend key */ 420 return sys_msgget((int)first, second); 421 case MSGCTL: 422 /* sign extend msqid */ 423 return compat_sys_msgctl((int)first, second, compat_ptr(ptr)); 424 425 case SHMAT: 426 /* sign extend shmid */ 427 return compat_sys_shmat((int)first, second, third, version, 428 compat_ptr(ptr)); 429 case SHMDT: 430 return sys_shmdt(compat_ptr(ptr)); 431 case SHMGET: 432 /* sign extend key_t */ 433 return sys_shmget((int)first, second, third); 434 case SHMCTL: 435 /* sign extend shmid */ 436 return compat_sys_shmctl((int)first, second, compat_ptr(ptr)); 437 438 default: 439 return -ENOSYS; 440 } 441 442 return -ENOSYS; 443 } 444 #endif 445 446 /* Note: it is necessary to treat out_fd and in_fd as unsigned ints, 447 * with the corresponding cast to a signed int to insure that the 448 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) 449 * and the register representation of a signed int (msr in 64-bit mode) is performed. 450 */ 451 asmlinkage long compat_sys_sendfile(u32 out_fd, u32 in_fd, compat_off_t __user * offset, u32 count) 452 { 453 mm_segment_t old_fs = get_fs(); 454 int ret; 455 off_t of; 456 off_t __user *up; 457 458 if (offset && get_user(of, offset)) 459 return -EFAULT; 460 461 /* The __user pointer cast is valid because of the set_fs() */ 462 set_fs(KERNEL_DS); 463 up = offset ? (off_t __user *) &of : NULL; 464 ret = sys_sendfile((int)out_fd, (int)in_fd, up, count); 465 set_fs(old_fs); 466 467 if (offset && put_user(of, offset)) 468 return -EFAULT; 469 470 return ret; 471 } 472 473 asmlinkage int compat_sys_sendfile64(int out_fd, int in_fd, compat_loff_t __user *offset, s32 count) 474 { 475 mm_segment_t old_fs = get_fs(); 476 int ret; 477 loff_t lof; 478 loff_t __user *up; 479 480 if (offset && get_user(lof, offset)) 481 return -EFAULT; 482 483 /* The __user pointer cast is valid because of the set_fs() */ 484 set_fs(KERNEL_DS); 485 up = offset ? (loff_t __user *) &lof : NULL; 486 ret = sys_sendfile64(out_fd, in_fd, up, count); 487 set_fs(old_fs); 488 489 if (offset && put_user(lof, offset)) 490 return -EFAULT; 491 492 return ret; 493 } 494 495 long compat_sys_execve(unsigned long a0, unsigned long a1, unsigned long a2, 496 unsigned long a3, unsigned long a4, unsigned long a5, 497 struct pt_regs *regs) 498 { 499 int error; 500 char * filename; 501 502 filename = getname((char __user *) a0); 503 error = PTR_ERR(filename); 504 if (IS_ERR(filename)) 505 goto out; 506 flush_fp_to_thread(current); 507 flush_altivec_to_thread(current); 508 509 error = compat_do_execve(filename, compat_ptr(a1), compat_ptr(a2), regs); 510 511 if (error == 0) { 512 task_lock(current); 513 current->ptrace &= ~PT_DTRACE; 514 task_unlock(current); 515 } 516 putname(filename); 517 518 out: 519 return error; 520 } 521 522 /* Note: it is necessary to treat option as an unsigned int, 523 * with the corresponding cast to a signed int to insure that the 524 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) 525 * and the register representation of a signed int (msr in 64-bit mode) is performed. 526 */ 527 asmlinkage long compat_sys_prctl(u32 option, u32 arg2, u32 arg3, u32 arg4, u32 arg5) 528 { 529 return sys_prctl((int)option, 530 (unsigned long) arg2, 531 (unsigned long) arg3, 532 (unsigned long) arg4, 533 (unsigned long) arg5); 534 } 535 536 /* Note: it is necessary to treat pid as an unsigned int, 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 compat_sys_sched_rr_get_interval(u32 pid, struct compat_timespec __user *interval) 542 { 543 struct timespec t; 544 int ret; 545 mm_segment_t old_fs = get_fs (); 546 547 /* The __user pointer cast is valid because of the set_fs() */ 548 set_fs (KERNEL_DS); 549 ret = sys_sched_rr_get_interval((int)pid, (struct timespec __user *) &t); 550 set_fs (old_fs); 551 if (put_compat_timespec(&t, interval)) 552 return -EFAULT; 553 return ret; 554 } 555 556 asmlinkage int compat_sys_pciconfig_read(u32 bus, u32 dfn, u32 off, u32 len, u32 ubuf) 557 { 558 return sys_pciconfig_read((unsigned long) bus, 559 (unsigned long) dfn, 560 (unsigned long) off, 561 (unsigned long) len, 562 compat_ptr(ubuf)); 563 } 564 565 asmlinkage int compat_sys_pciconfig_write(u32 bus, u32 dfn, u32 off, u32 len, u32 ubuf) 566 { 567 return sys_pciconfig_write((unsigned long) bus, 568 (unsigned long) dfn, 569 (unsigned long) off, 570 (unsigned long) len, 571 compat_ptr(ubuf)); 572 } 573 574 asmlinkage int compat_sys_pciconfig_iobase(u32 which, u32 in_bus, u32 in_devfn) 575 { 576 return sys_pciconfig_iobase(which, in_bus, in_devfn); 577 } 578 579 580 /* Note: it is necessary to treat mode as an unsigned int, 581 * with the corresponding cast to a signed int to insure that the 582 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) 583 * and the register representation of a signed int (msr in 64-bit mode) is performed. 584 */ 585 asmlinkage long compat_sys_access(const char __user * filename, u32 mode) 586 { 587 return sys_access(filename, (int)mode); 588 } 589 590 591 /* Note: it is necessary to treat mode as an unsigned int, 592 * with the corresponding cast to a signed int to insure that the 593 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) 594 * and the register representation of a signed int (msr in 64-bit mode) is performed. 595 */ 596 asmlinkage long compat_sys_creat(const char __user * pathname, u32 mode) 597 { 598 return sys_creat(pathname, (int)mode); 599 } 600 601 602 /* Note: it is necessary to treat pid and options as unsigned ints, 603 * with the corresponding cast to a signed int to insure that the 604 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) 605 * and the register representation of a signed int (msr in 64-bit mode) is performed. 606 */ 607 asmlinkage long compat_sys_waitpid(u32 pid, unsigned int __user * stat_addr, u32 options) 608 { 609 return sys_waitpid((int)pid, stat_addr, (int)options); 610 } 611 612 613 /* Note: it is necessary to treat gidsetsize as an unsigned int, 614 * with the corresponding cast to a signed int to insure that the 615 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) 616 * and the register representation of a signed int (msr in 64-bit mode) is performed. 617 */ 618 asmlinkage long compat_sys_getgroups(u32 gidsetsize, gid_t __user *grouplist) 619 { 620 return sys_getgroups((int)gidsetsize, grouplist); 621 } 622 623 624 /* Note: it is necessary to treat pid as an unsigned int, 625 * with the corresponding cast to a signed int to insure that the 626 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) 627 * and the register representation of a signed int (msr in 64-bit mode) is performed. 628 */ 629 asmlinkage long compat_sys_getpgid(u32 pid) 630 { 631 return sys_getpgid((int)pid); 632 } 633 634 635 636 /* Note: it is necessary to treat pid as an unsigned int, 637 * with the corresponding cast to a signed int to insure that the 638 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) 639 * and the register representation of a signed int (msr in 64-bit mode) is performed. 640 */ 641 asmlinkage long compat_sys_getsid(u32 pid) 642 { 643 return sys_getsid((int)pid); 644 } 645 646 647 /* Note: it is necessary to treat pid and sig as unsigned ints, 648 * with the corresponding cast to a signed int to insure that the 649 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) 650 * and the register representation of a signed int (msr in 64-bit mode) is performed. 651 */ 652 asmlinkage long compat_sys_kill(u32 pid, u32 sig) 653 { 654 return sys_kill((int)pid, (int)sig); 655 } 656 657 658 /* Note: it is necessary to treat mode 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 */ 663 asmlinkage long compat_sys_mkdir(const char __user * pathname, u32 mode) 664 { 665 return sys_mkdir(pathname, (int)mode); 666 } 667 668 long compat_sys_nice(u32 increment) 669 { 670 /* sign extend increment */ 671 return sys_nice((int)increment); 672 } 673 674 off_t ppc32_lseek(unsigned int fd, u32 offset, unsigned int origin) 675 { 676 /* sign extend n */ 677 return sys_lseek(fd, (int)offset, origin); 678 } 679 680 /* Note: it is necessary to treat bufsiz as an unsigned int, 681 * with the corresponding cast to a signed int to insure that the 682 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) 683 * and the register representation of a signed int (msr in 64-bit mode) is performed. 684 */ 685 asmlinkage long compat_sys_readlink(const char __user * path, char __user * buf, u32 bufsiz) 686 { 687 return sys_readlink(path, buf, (int)bufsiz); 688 } 689 690 /* Note: it is necessary to treat option as an unsigned int, 691 * with the corresponding cast to a signed int to insure that the 692 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) 693 * and the register representation of a signed int (msr in 64-bit mode) is performed. 694 */ 695 asmlinkage long compat_sys_sched_get_priority_max(u32 policy) 696 { 697 return sys_sched_get_priority_max((int)policy); 698 } 699 700 701 /* Note: it is necessary to treat policy as an unsigned int, 702 * with the corresponding cast to a signed int to insure that the 703 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) 704 * and the register representation of a signed int (msr in 64-bit mode) is performed. 705 */ 706 asmlinkage long compat_sys_sched_get_priority_min(u32 policy) 707 { 708 return sys_sched_get_priority_min((int)policy); 709 } 710 711 712 /* Note: it is necessary to treat pid as an unsigned int, 713 * with the corresponding cast to a signed int to insure that the 714 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) 715 * and the register representation of a signed int (msr in 64-bit mode) is performed. 716 */ 717 asmlinkage long compat_sys_sched_getparam(u32 pid, struct sched_param __user *param) 718 { 719 return sys_sched_getparam((int)pid, param); 720 } 721 722 723 /* Note: it is necessary to treat pid as an unsigned int, 724 * with the corresponding cast to a signed int to insure that the 725 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) 726 * and the register representation of a signed int (msr in 64-bit mode) is performed. 727 */ 728 asmlinkage long compat_sys_sched_getscheduler(u32 pid) 729 { 730 return sys_sched_getscheduler((int)pid); 731 } 732 733 734 /* Note: it is necessary to treat pid as an unsigned int, 735 * with the corresponding cast to a signed int to insure that the 736 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) 737 * and the register representation of a signed int (msr in 64-bit mode) is performed. 738 */ 739 asmlinkage long compat_sys_sched_setparam(u32 pid, struct sched_param __user *param) 740 { 741 return sys_sched_setparam((int)pid, param); 742 } 743 744 745 /* Note: it is necessary to treat pid and policy as unsigned ints, 746 * with the corresponding cast to a signed int to insure that the 747 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) 748 * and the register representation of a signed int (msr in 64-bit mode) is performed. 749 */ 750 asmlinkage long compat_sys_sched_setscheduler(u32 pid, u32 policy, struct sched_param __user *param) 751 { 752 return sys_sched_setscheduler((int)pid, (int)policy, param); 753 } 754 755 756 /* Note: it is necessary to treat len as an unsigned int, 757 * with the corresponding cast to a signed int to insure that the 758 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) 759 * and the register representation of a signed int (msr in 64-bit mode) is performed. 760 */ 761 asmlinkage long compat_sys_setdomainname(char __user *name, u32 len) 762 { 763 return sys_setdomainname(name, (int)len); 764 } 765 766 767 /* Note: it is necessary to treat gidsetsize as an unsigned int, 768 * with the corresponding cast to a signed int to insure that the 769 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) 770 * and the register representation of a signed int (msr in 64-bit mode) is performed. 771 */ 772 asmlinkage long compat_sys_setgroups(u32 gidsetsize, gid_t __user *grouplist) 773 { 774 return sys_setgroups((int)gidsetsize, grouplist); 775 } 776 777 778 asmlinkage long compat_sys_sethostname(char __user *name, u32 len) 779 { 780 /* sign extend len */ 781 return sys_sethostname(name, (int)len); 782 } 783 784 785 /* Note: it is necessary to treat pid and pgid as unsigned ints, 786 * with the corresponding cast to a signed int to insure that the 787 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) 788 * and the register representation of a signed int (msr in 64-bit mode) is performed. 789 */ 790 asmlinkage long compat_sys_setpgid(u32 pid, u32 pgid) 791 { 792 return sys_setpgid((int)pid, (int)pgid); 793 } 794 795 long compat_sys_getpriority(u32 which, u32 who) 796 { 797 /* sign extend which and who */ 798 return sys_getpriority((int)which, (int)who); 799 } 800 801 long compat_sys_setpriority(u32 which, u32 who, u32 niceval) 802 { 803 /* sign extend which, who and niceval */ 804 return sys_setpriority((int)which, (int)who, (int)niceval); 805 } 806 807 long compat_sys_ioprio_get(u32 which, u32 who) 808 { 809 /* sign extend which and who */ 810 return sys_ioprio_get((int)which, (int)who); 811 } 812 813 long compat_sys_ioprio_set(u32 which, u32 who, u32 ioprio) 814 { 815 /* sign extend which, who and ioprio */ 816 return sys_ioprio_set((int)which, (int)who, (int)ioprio); 817 } 818 819 /* Note: it is necessary to treat newmask as an unsigned int, 820 * with the corresponding cast to a signed int to insure that the 821 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) 822 * and the register representation of a signed int (msr in 64-bit mode) is performed. 823 */ 824 asmlinkage long compat_sys_ssetmask(u32 newmask) 825 { 826 return sys_ssetmask((int) newmask); 827 } 828 829 asmlinkage long compat_sys_syslog(u32 type, char __user * buf, u32 len) 830 { 831 /* sign extend len */ 832 return sys_syslog(type, buf, (int)len); 833 } 834 835 836 /* Note: it is necessary to treat mask as an unsigned int, 837 * with the corresponding cast to a signed int to insure that the 838 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode) 839 * and the register representation of a signed int (msr in 64-bit mode) is performed. 840 */ 841 asmlinkage long compat_sys_umask(u32 mask) 842 { 843 return sys_umask((int)mask); 844 } 845 846 #ifdef CONFIG_SYSCTL 847 struct __sysctl_args32 { 848 u32 name; 849 int nlen; 850 u32 oldval; 851 u32 oldlenp; 852 u32 newval; 853 u32 newlen; 854 u32 __unused[4]; 855 }; 856 857 asmlinkage long compat_sys_sysctl(struct __sysctl_args32 __user *args) 858 { 859 struct __sysctl_args32 tmp; 860 int error; 861 size_t oldlen; 862 size_t __user *oldlenp = NULL; 863 unsigned long addr = (((unsigned long)&args->__unused[0]) + 7) & ~7; 864 865 if (copy_from_user(&tmp, args, sizeof(tmp))) 866 return -EFAULT; 867 868 if (tmp.oldval && tmp.oldlenp) { 869 /* Duh, this is ugly and might not work if sysctl_args 870 is in read-only memory, but do_sysctl does indirectly 871 a lot of uaccess in both directions and we'd have to 872 basically copy the whole sysctl.c here, and 873 glibc's __sysctl uses rw memory for the structure 874 anyway. */ 875 oldlenp = (size_t __user *)addr; 876 if (get_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)) || 877 put_user(oldlen, oldlenp)) 878 return -EFAULT; 879 } 880 881 lock_kernel(); 882 error = do_sysctl(compat_ptr(tmp.name), tmp.nlen, 883 compat_ptr(tmp.oldval), oldlenp, 884 compat_ptr(tmp.newval), tmp.newlen); 885 unlock_kernel(); 886 if (oldlenp) { 887 if (!error) { 888 if (get_user(oldlen, oldlenp) || 889 put_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp))) 890 error = -EFAULT; 891 } 892 copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused)); 893 } 894 return error; 895 } 896 #endif 897 898 unsigned long compat_sys_mmap2(unsigned long addr, size_t len, 899 unsigned long prot, unsigned long flags, 900 unsigned long fd, unsigned long pgoff) 901 { 902 /* This should remain 12 even if PAGE_SIZE changes */ 903 return sys_mmap(addr, len, prot, flags, fd, pgoff << 12); 904 } 905 906 long compat_sys_tgkill(u32 tgid, u32 pid, int sig) 907 { 908 /* sign extend tgid, pid */ 909 return sys_tgkill((int)tgid, (int)pid, sig); 910 } 911 912 /* 913 * long long munging: 914 * The 32 bit ABI passes long longs in an odd even register pair. 915 */ 916 917 compat_ssize_t compat_sys_pread64(unsigned int fd, char __user *ubuf, compat_size_t count, 918 u32 reg6, u32 poshi, u32 poslo) 919 { 920 return sys_pread64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo); 921 } 922 923 compat_ssize_t compat_sys_pwrite64(unsigned int fd, char __user *ubuf, compat_size_t count, 924 u32 reg6, u32 poshi, u32 poslo) 925 { 926 return sys_pwrite64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo); 927 } 928 929 compat_ssize_t compat_sys_readahead(int fd, u32 r4, u32 offhi, u32 offlo, u32 count) 930 { 931 return sys_readahead(fd, ((loff_t)offhi << 32) | offlo, count); 932 } 933 934 asmlinkage int compat_sys_truncate64(const char __user * path, u32 reg4, 935 unsigned long high, unsigned long low) 936 { 937 return sys_truncate(path, (high << 32) | low); 938 } 939 940 asmlinkage int compat_sys_ftruncate64(unsigned int fd, u32 reg4, unsigned long high, 941 unsigned long low) 942 { 943 return sys_ftruncate(fd, (high << 32) | low); 944 } 945 946 long ppc32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char __user *buf, 947 size_t len) 948 { 949 return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low, 950 buf, len); 951 } 952 953 long ppc32_fadvise64(int fd, u32 unused, u32 offset_high, u32 offset_low, 954 size_t len, int advice) 955 { 956 return sys_fadvise64(fd, (u64)offset_high << 32 | offset_low, len, 957 advice); 958 } 959 960 long ppc32_timer_create(clockid_t clock, 961 struct compat_sigevent __user *ev32, 962 timer_t __user *timer_id) 963 { 964 sigevent_t event; 965 timer_t t; 966 long err; 967 mm_segment_t savefs; 968 969 if (ev32 == NULL) 970 return sys_timer_create(clock, NULL, timer_id); 971 972 if (get_compat_sigevent(&event, ev32)) 973 return -EFAULT; 974 975 if (!access_ok(VERIFY_WRITE, timer_id, sizeof(timer_t))) 976 return -EFAULT; 977 978 savefs = get_fs(); 979 set_fs(KERNEL_DS); 980 /* The __user pointer casts are valid due to the set_fs() */ 981 err = sys_timer_create(clock, 982 (sigevent_t __user *) &event, 983 (timer_t __user *) &t); 984 set_fs(savefs); 985 986 if (err == 0) 987 err = __put_user(t, timer_id); 988 989 return err; 990 } 991 992 asmlinkage long compat_sys_add_key(const char __user *_type, 993 const char __user *_description, 994 const void __user *_payload, 995 u32 plen, 996 u32 ringid) 997 { 998 return sys_add_key(_type, _description, _payload, plen, ringid); 999 } 1000 1001 asmlinkage long compat_sys_request_key(const char __user *_type, 1002 const char __user *_description, 1003 const char __user *_callout_info, 1004 u32 destringid) 1005 { 1006 return sys_request_key(_type, _description, _callout_info, destringid); 1007 } 1008 1009