sys_ppc32.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  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. #include <linux/config.h>
  17. #include <linux/kernel.h>
  18. #include <linux/sched.h>
  19. #include <linux/fs.h>
  20. #include <linux/mm.h>
  21. #include <linux/file.h>
  22. #include <linux/signal.h>
  23. #include <linux/resource.h>
  24. #include <linux/times.h>
  25. #include <linux/utsname.h>
  26. #include <linux/smp.h>
  27. #include <linux/smp_lock.h>
  28. #include <linux/sem.h>
  29. #include <linux/msg.h>
  30. #include <linux/shm.h>
  31. #include <linux/poll.h>
  32. #include <linux/personality.h>
  33. #include <linux/stat.h>
  34. #include <linux/mman.h>
  35. #include <linux/in.h>
  36. #include <linux/syscalls.h>
  37. #include <linux/unistd.h>
  38. #include <linux/sysctl.h>
  39. #include <linux/binfmts.h>
  40. #include <linux/security.h>
  41. #include <linux/compat.h>
  42. #include <linux/ptrace.h>
  43. #include <linux/elf.h>
  44. #include <asm/ptrace.h>
  45. #include <asm/types.h>
  46. #include <asm/ipc.h>
  47. #include <asm/uaccess.h>
  48. #include <asm/unistd.h>
  49. #include <asm/semaphore.h>
  50. #include <asm/time.h>
  51. #include <asm/mmu_context.h>
  52. #include <asm/ppc-pci.h>
  53. /* readdir & getdents */
  54. #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
  55. #define ROUND_UP(x) (((x)+sizeof(u32)-1) & ~(sizeof(u32)-1))
  56. struct old_linux_dirent32 {
  57. u32 d_ino;
  58. u32 d_offset;
  59. unsigned short d_namlen;
  60. char d_name[1];
  61. };
  62. struct readdir_callback32 {
  63. struct old_linux_dirent32 __user * dirent;
  64. int count;
  65. };
  66. static int fillonedir(void * __buf, const char * name, int namlen,
  67. off_t offset, ino_t ino, unsigned int d_type)
  68. {
  69. struct readdir_callback32 * buf = (struct readdir_callback32 *) __buf;
  70. struct old_linux_dirent32 __user * dirent;
  71. if (buf->count)
  72. return -EINVAL;
  73. buf->count++;
  74. dirent = buf->dirent;
  75. put_user(ino, &dirent->d_ino);
  76. put_user(offset, &dirent->d_offset);
  77. put_user(namlen, &dirent->d_namlen);
  78. copy_to_user(dirent->d_name, name, namlen);
  79. put_user(0, dirent->d_name + namlen);
  80. return 0;
  81. }
  82. asmlinkage int old32_readdir(unsigned int fd, struct old_linux_dirent32 __user *dirent, unsigned int count)
  83. {
  84. int error = -EBADF;
  85. struct file * file;
  86. struct readdir_callback32 buf;
  87. file = fget(fd);
  88. if (!file)
  89. goto out;
  90. buf.count = 0;
  91. buf.dirent = dirent;
  92. error = vfs_readdir(file, (filldir_t)fillonedir, &buf);
  93. if (error < 0)
  94. goto out_putf;
  95. error = buf.count;
  96. out_putf:
  97. fput(file);
  98. out:
  99. return error;
  100. }
  101. asmlinkage long ppc32_select(u32 n, compat_ulong_t __user *inp,
  102. compat_ulong_t __user *outp, compat_ulong_t __user *exp,
  103. compat_uptr_t tvp_x)
  104. {
  105. /* sign extend n */
  106. return compat_sys_select((int)n, inp, outp, exp, compat_ptr(tvp_x));
  107. }
  108. int cp_compat_stat(struct kstat *stat, struct compat_stat __user *statbuf)
  109. {
  110. long err;
  111. if (stat->size > MAX_NON_LFS || !new_valid_dev(stat->dev) ||
  112. !new_valid_dev(stat->rdev))
  113. return -EOVERFLOW;
  114. err = access_ok(VERIFY_WRITE, statbuf, sizeof(*statbuf)) ? 0 : -EFAULT;
  115. err |= __put_user(new_encode_dev(stat->dev), &statbuf->st_dev);
  116. err |= __put_user(stat->ino, &statbuf->st_ino);
  117. err |= __put_user(stat->mode, &statbuf->st_mode);
  118. err |= __put_user(stat->nlink, &statbuf->st_nlink);
  119. err |= __put_user(stat->uid, &statbuf->st_uid);
  120. err |= __put_user(stat->gid, &statbuf->st_gid);
  121. err |= __put_user(new_encode_dev(stat->rdev), &statbuf->st_rdev);
  122. err |= __put_user(stat->size, &statbuf->st_size);
  123. err |= __put_user(stat->atime.tv_sec, &statbuf->st_atime);
  124. err |= __put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);
  125. err |= __put_user(stat->mtime.tv_sec, &statbuf->st_mtime);
  126. err |= __put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);
  127. err |= __put_user(stat->ctime.tv_sec, &statbuf->st_ctime);
  128. err |= __put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);
  129. err |= __put_user(stat->blksize, &statbuf->st_blksize);
  130. err |= __put_user(stat->blocks, &statbuf->st_blocks);
  131. err |= __put_user(0, &statbuf->__unused4[0]);
  132. err |= __put_user(0, &statbuf->__unused4[1]);
  133. return err;
  134. }
  135. /* Note: it is necessary to treat option as an unsigned int,
  136. * with the corresponding cast to a signed int to insure that the
  137. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  138. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  139. */
  140. asmlinkage long compat_sys_sysfs(u32 option, u32 arg1, u32 arg2)
  141. {
  142. return sys_sysfs((int)option, arg1, arg2);
  143. }
  144. asmlinkage long compat_sys_pause(void)
  145. {
  146. current->state = TASK_INTERRUPTIBLE;
  147. schedule();
  148. return -ERESTARTNOHAND;
  149. }
  150. static inline long get_ts32(struct timespec *o, struct compat_timeval __user *i)
  151. {
  152. long usec;
  153. if (!access_ok(VERIFY_READ, i, sizeof(*i)))
  154. return -EFAULT;
  155. if (__get_user(o->tv_sec, &i->tv_sec))
  156. return -EFAULT;
  157. if (__get_user(usec, &i->tv_usec))
  158. return -EFAULT;
  159. o->tv_nsec = usec * 1000;
  160. return 0;
  161. }
  162. static inline long put_tv32(struct compat_timeval __user *o, struct timeval *i)
  163. {
  164. return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
  165. (__put_user(i->tv_sec, &o->tv_sec) |
  166. __put_user(i->tv_usec, &o->tv_usec)));
  167. }
  168. struct sysinfo32 {
  169. s32 uptime;
  170. u32 loads[3];
  171. u32 totalram;
  172. u32 freeram;
  173. u32 sharedram;
  174. u32 bufferram;
  175. u32 totalswap;
  176. u32 freeswap;
  177. unsigned short procs;
  178. unsigned short pad;
  179. u32 totalhigh;
  180. u32 freehigh;
  181. u32 mem_unit;
  182. char _f[20-2*sizeof(int)-sizeof(int)];
  183. };
  184. asmlinkage long compat_sys_sysinfo(struct sysinfo32 __user *info)
  185. {
  186. struct sysinfo s;
  187. int ret, err;
  188. int bitcount=0;
  189. mm_segment_t old_fs = get_fs ();
  190. /* The __user cast is valid due to set_fs() */
  191. set_fs (KERNEL_DS);
  192. ret = sys_sysinfo((struct sysinfo __user *)&s);
  193. set_fs (old_fs);
  194. /* Check to see if any memory value is too large for 32-bit and
  195. * scale down if needed.
  196. */
  197. if ((s.totalram >> 32) || (s.totalswap >> 32)) {
  198. while (s.mem_unit < PAGE_SIZE) {
  199. s.mem_unit <<= 1;
  200. bitcount++;
  201. }
  202. s.totalram >>=bitcount;
  203. s.freeram >>= bitcount;
  204. s.sharedram >>= bitcount;
  205. s.bufferram >>= bitcount;
  206. s.totalswap >>= bitcount;
  207. s.freeswap >>= bitcount;
  208. s.totalhigh >>= bitcount;
  209. s.freehigh >>= bitcount;
  210. }
  211. err = put_user (s.uptime, &info->uptime);
  212. err |= __put_user (s.loads[0], &info->loads[0]);
  213. err |= __put_user (s.loads[1], &info->loads[1]);
  214. err |= __put_user (s.loads[2], &info->loads[2]);
  215. err |= __put_user (s.totalram, &info->totalram);
  216. err |= __put_user (s.freeram, &info->freeram);
  217. err |= __put_user (s.sharedram, &info->sharedram);
  218. err |= __put_user (s.bufferram, &info->bufferram);
  219. err |= __put_user (s.totalswap, &info->totalswap);
  220. err |= __put_user (s.freeswap, &info->freeswap);
  221. err |= __put_user (s.procs, &info->procs);
  222. err |= __put_user (s.totalhigh, &info->totalhigh);
  223. err |= __put_user (s.freehigh, &info->freehigh);
  224. err |= __put_user (s.mem_unit, &info->mem_unit);
  225. if (err)
  226. return -EFAULT;
  227. return ret;
  228. }
  229. /* Translations due to time_t size differences. Which affects all
  230. sorts of things, like timeval and itimerval. */
  231. extern struct timezone sys_tz;
  232. asmlinkage long compat_sys_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
  233. {
  234. if (tv) {
  235. struct timeval ktv;
  236. do_gettimeofday(&ktv);
  237. if (put_tv32(tv, &ktv))
  238. return -EFAULT;
  239. }
  240. if (tz) {
  241. if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
  242. return -EFAULT;
  243. }
  244. return 0;
  245. }
  246. asmlinkage long compat_sys_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
  247. {
  248. struct timespec kts;
  249. struct timezone ktz;
  250. if (tv) {
  251. if (get_ts32(&kts, tv))
  252. return -EFAULT;
  253. }
  254. if (tz) {
  255. if (copy_from_user(&ktz, tz, sizeof(ktz)))
  256. return -EFAULT;
  257. }
  258. return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
  259. }
  260. #ifdef CONFIG_SYSVIPC
  261. long compat_sys_ipc(u32 call, u32 first, u32 second, u32 third, compat_uptr_t ptr,
  262. u32 fifth)
  263. {
  264. int version;
  265. version = call >> 16; /* hack for backward compatibility */
  266. call &= 0xffff;
  267. switch (call) {
  268. case SEMTIMEDOP:
  269. if (fifth)
  270. /* sign extend semid */
  271. return compat_sys_semtimedop((int)first,
  272. compat_ptr(ptr), second,
  273. compat_ptr(fifth));
  274. /* else fall through for normal semop() */
  275. case SEMOP:
  276. /* struct sembuf is the same on 32 and 64bit :)) */
  277. /* sign extend semid */
  278. return sys_semtimedop((int)first, compat_ptr(ptr), second,
  279. NULL);
  280. case SEMGET:
  281. /* sign extend key, nsems */
  282. return sys_semget((int)first, (int)second, third);
  283. case SEMCTL:
  284. /* sign extend semid, semnum */
  285. return compat_sys_semctl((int)first, (int)second, third,
  286. compat_ptr(ptr));
  287. case MSGSND:
  288. /* sign extend msqid */
  289. return compat_sys_msgsnd((int)first, (int)second, third,
  290. compat_ptr(ptr));
  291. case MSGRCV:
  292. /* sign extend msqid, msgtyp */
  293. return compat_sys_msgrcv((int)first, second, (int)fifth,
  294. third, version, compat_ptr(ptr));
  295. case MSGGET:
  296. /* sign extend key */
  297. return sys_msgget((int)first, second);
  298. case MSGCTL:
  299. /* sign extend msqid */
  300. return compat_sys_msgctl((int)first, second, compat_ptr(ptr));
  301. case SHMAT:
  302. /* sign extend shmid */
  303. return compat_sys_shmat((int)first, second, third, version,
  304. compat_ptr(ptr));
  305. case SHMDT:
  306. return sys_shmdt(compat_ptr(ptr));
  307. case SHMGET:
  308. /* sign extend key_t */
  309. return sys_shmget((int)first, second, third);
  310. case SHMCTL:
  311. /* sign extend shmid */
  312. return compat_sys_shmctl((int)first, second, compat_ptr(ptr));
  313. default:
  314. return -ENOSYS;
  315. }
  316. return -ENOSYS;
  317. }
  318. #endif
  319. /* Note: it is necessary to treat out_fd and in_fd as unsigned ints,
  320. * with the corresponding cast to a signed int to insure that the
  321. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  322. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  323. */
  324. asmlinkage long compat_sys_sendfile(u32 out_fd, u32 in_fd, compat_off_t __user * offset, u32 count)
  325. {
  326. mm_segment_t old_fs = get_fs();
  327. int ret;
  328. off_t of;
  329. off_t __user *up;
  330. if (offset && get_user(of, offset))
  331. return -EFAULT;
  332. /* The __user pointer cast is valid because of the set_fs() */
  333. set_fs(KERNEL_DS);
  334. up = offset ? (off_t __user *) &of : NULL;
  335. ret = sys_sendfile((int)out_fd, (int)in_fd, up, count);
  336. set_fs(old_fs);
  337. if (offset && put_user(of, offset))
  338. return -EFAULT;
  339. return ret;
  340. }
  341. asmlinkage int compat_sys_sendfile64(int out_fd, int in_fd, compat_loff_t __user *offset, s32 count)
  342. {
  343. mm_segment_t old_fs = get_fs();
  344. int ret;
  345. loff_t lof;
  346. loff_t __user *up;
  347. if (offset && get_user(lof, offset))
  348. return -EFAULT;
  349. /* The __user pointer cast is valid because of the set_fs() */
  350. set_fs(KERNEL_DS);
  351. up = offset ? (loff_t __user *) &lof : NULL;
  352. ret = sys_sendfile64(out_fd, in_fd, up, count);
  353. set_fs(old_fs);
  354. if (offset && put_user(lof, offset))
  355. return -EFAULT;
  356. return ret;
  357. }
  358. long compat_sys_execve(unsigned long a0, unsigned long a1, unsigned long a2,
  359. unsigned long a3, unsigned long a4, unsigned long a5,
  360. struct pt_regs *regs)
  361. {
  362. int error;
  363. char * filename;
  364. filename = getname((char __user *) a0);
  365. error = PTR_ERR(filename);
  366. if (IS_ERR(filename))
  367. goto out;
  368. flush_fp_to_thread(current);
  369. flush_altivec_to_thread(current);
  370. error = compat_do_execve(filename, compat_ptr(a1), compat_ptr(a2), regs);
  371. if (error == 0) {
  372. task_lock(current);
  373. current->ptrace &= ~PT_DTRACE;
  374. task_unlock(current);
  375. }
  376. putname(filename);
  377. out:
  378. return error;
  379. }
  380. /* Note: it is necessary to treat option as an unsigned int,
  381. * with the corresponding cast to a signed int to insure that the
  382. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  383. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  384. */
  385. asmlinkage long compat_sys_prctl(u32 option, u32 arg2, u32 arg3, u32 arg4, u32 arg5)
  386. {
  387. return sys_prctl((int)option,
  388. (unsigned long) arg2,
  389. (unsigned long) arg3,
  390. (unsigned long) arg4,
  391. (unsigned long) arg5);
  392. }
  393. /* Note: it is necessary to treat pid as an unsigned int,
  394. * with the corresponding cast to a signed int to insure that the
  395. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  396. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  397. */
  398. asmlinkage long compat_sys_sched_rr_get_interval(u32 pid, struct compat_timespec __user *interval)
  399. {
  400. struct timespec t;
  401. int ret;
  402. mm_segment_t old_fs = get_fs ();
  403. /* The __user pointer cast is valid because of the set_fs() */
  404. set_fs (KERNEL_DS);
  405. ret = sys_sched_rr_get_interval((int)pid, (struct timespec __user *) &t);
  406. set_fs (old_fs);
  407. if (put_compat_timespec(&t, interval))
  408. return -EFAULT;
  409. return ret;
  410. }
  411. /* Note: it is necessary to treat mode as an unsigned int,
  412. * with the corresponding cast to a signed int to insure that the
  413. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  414. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  415. */
  416. asmlinkage long compat_sys_access(const char __user * filename, u32 mode)
  417. {
  418. return sys_access(filename, (int)mode);
  419. }
  420. /* Note: it is necessary to treat mode as an unsigned int,
  421. * with the corresponding cast to a signed int to insure that the
  422. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  423. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  424. */
  425. asmlinkage long compat_sys_creat(const char __user * pathname, u32 mode)
  426. {
  427. return sys_creat(pathname, (int)mode);
  428. }
  429. /* Note: it is necessary to treat pid and options as unsigned ints,
  430. * with the corresponding cast to a signed int to insure that the
  431. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  432. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  433. */
  434. asmlinkage long compat_sys_waitpid(u32 pid, unsigned int __user * stat_addr, u32 options)
  435. {
  436. return sys_waitpid((int)pid, stat_addr, (int)options);
  437. }
  438. /* Note: it is necessary to treat gidsetsize as an unsigned int,
  439. * with the corresponding cast to a signed int to insure that the
  440. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  441. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  442. */
  443. asmlinkage long compat_sys_getgroups(u32 gidsetsize, gid_t __user *grouplist)
  444. {
  445. return sys_getgroups((int)gidsetsize, grouplist);
  446. }
  447. /* Note: it is necessary to treat pid as an unsigned int,
  448. * with the corresponding cast to a signed int to insure that the
  449. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  450. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  451. */
  452. asmlinkage long compat_sys_getpgid(u32 pid)
  453. {
  454. return sys_getpgid((int)pid);
  455. }
  456. /* Note: it is necessary to treat pid as an unsigned int,
  457. * with the corresponding cast to a signed int to insure that the
  458. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  459. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  460. */
  461. asmlinkage long compat_sys_getsid(u32 pid)
  462. {
  463. return sys_getsid((int)pid);
  464. }
  465. /* Note: it is necessary to treat pid and sig as unsigned ints,
  466. * with the corresponding cast to a signed int to insure that the
  467. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  468. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  469. */
  470. asmlinkage long compat_sys_kill(u32 pid, u32 sig)
  471. {
  472. return sys_kill((int)pid, (int)sig);
  473. }
  474. /* Note: it is necessary to treat mode as an unsigned int,
  475. * with the corresponding cast to a signed int to insure that the
  476. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  477. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  478. */
  479. asmlinkage long compat_sys_mkdir(const char __user * pathname, u32 mode)
  480. {
  481. return sys_mkdir(pathname, (int)mode);
  482. }
  483. long compat_sys_nice(u32 increment)
  484. {
  485. /* sign extend increment */
  486. return sys_nice((int)increment);
  487. }
  488. off_t ppc32_lseek(unsigned int fd, u32 offset, unsigned int origin)
  489. {
  490. /* sign extend n */
  491. return sys_lseek(fd, (int)offset, origin);
  492. }
  493. /* Note: it is necessary to treat bufsiz as an unsigned int,
  494. * with the corresponding cast to a signed int to insure that the
  495. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  496. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  497. */
  498. asmlinkage long compat_sys_readlink(const char __user * path, char __user * buf, u32 bufsiz)
  499. {
  500. return sys_readlink(path, buf, (int)bufsiz);
  501. }
  502. /* Note: it is necessary to treat option as an unsigned int,
  503. * with the corresponding cast to a signed int to insure that the
  504. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  505. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  506. */
  507. asmlinkage long compat_sys_sched_get_priority_max(u32 policy)
  508. {
  509. return sys_sched_get_priority_max((int)policy);
  510. }
  511. /* Note: it is necessary to treat policy as an unsigned int,
  512. * with the corresponding cast to a signed int to insure that the
  513. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  514. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  515. */
  516. asmlinkage long compat_sys_sched_get_priority_min(u32 policy)
  517. {
  518. return sys_sched_get_priority_min((int)policy);
  519. }
  520. /* Note: it is necessary to treat pid as an unsigned int,
  521. * with the corresponding cast to a signed int to insure that the
  522. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  523. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  524. */
  525. asmlinkage long compat_sys_sched_getparam(u32 pid, struct sched_param __user *param)
  526. {
  527. return sys_sched_getparam((int)pid, param);
  528. }
  529. /* Note: it is necessary to treat pid as an unsigned int,
  530. * with the corresponding cast to a signed int to insure that the
  531. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  532. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  533. */
  534. asmlinkage long compat_sys_sched_getscheduler(u32 pid)
  535. {
  536. return sys_sched_getscheduler((int)pid);
  537. }
  538. /* Note: it is necessary to treat pid as an unsigned int,
  539. * with the corresponding cast to a signed int to insure that the
  540. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  541. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  542. */
  543. asmlinkage long compat_sys_sched_setparam(u32 pid, struct sched_param __user *param)
  544. {
  545. return sys_sched_setparam((int)pid, param);
  546. }
  547. /* Note: it is necessary to treat pid and policy as unsigned ints,
  548. * with the corresponding cast to a signed int to insure that the
  549. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  550. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  551. */
  552. asmlinkage long compat_sys_sched_setscheduler(u32 pid, u32 policy, struct sched_param __user *param)
  553. {
  554. return sys_sched_setscheduler((int)pid, (int)policy, param);
  555. }
  556. /* Note: it is necessary to treat len as an unsigned int,
  557. * with the corresponding cast to a signed int to insure that the
  558. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  559. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  560. */
  561. asmlinkage long compat_sys_setdomainname(char __user *name, u32 len)
  562. {
  563. return sys_setdomainname(name, (int)len);
  564. }
  565. /* Note: it is necessary to treat gidsetsize as an unsigned int,
  566. * with the corresponding cast to a signed int to insure that the
  567. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  568. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  569. */
  570. asmlinkage long compat_sys_setgroups(u32 gidsetsize, gid_t __user *grouplist)
  571. {
  572. return sys_setgroups((int)gidsetsize, grouplist);
  573. }
  574. asmlinkage long compat_sys_sethostname(char __user *name, u32 len)
  575. {
  576. /* sign extend len */
  577. return sys_sethostname(name, (int)len);
  578. }
  579. /* Note: it is necessary to treat pid and pgid as unsigned ints,
  580. * with the corresponding cast to a signed int to insure that the
  581. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  582. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  583. */
  584. asmlinkage long compat_sys_setpgid(u32 pid, u32 pgid)
  585. {
  586. return sys_setpgid((int)pid, (int)pgid);
  587. }
  588. long compat_sys_getpriority(u32 which, u32 who)
  589. {
  590. /* sign extend which and who */
  591. return sys_getpriority((int)which, (int)who);
  592. }
  593. long compat_sys_setpriority(u32 which, u32 who, u32 niceval)
  594. {
  595. /* sign extend which, who and niceval */
  596. return sys_setpriority((int)which, (int)who, (int)niceval);
  597. }
  598. long compat_sys_ioprio_get(u32 which, u32 who)
  599. {
  600. /* sign extend which and who */
  601. return sys_ioprio_get((int)which, (int)who);
  602. }
  603. long compat_sys_ioprio_set(u32 which, u32 who, u32 ioprio)
  604. {
  605. /* sign extend which, who and ioprio */
  606. return sys_ioprio_set((int)which, (int)who, (int)ioprio);
  607. }
  608. /* Note: it is necessary to treat newmask as an unsigned int,
  609. * with the corresponding cast to a signed int to insure that the
  610. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  611. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  612. */
  613. asmlinkage long compat_sys_ssetmask(u32 newmask)
  614. {
  615. return sys_ssetmask((int) newmask);
  616. }
  617. asmlinkage long compat_sys_syslog(u32 type, char __user * buf, u32 len)
  618. {
  619. /* sign extend len */
  620. return sys_syslog(type, buf, (int)len);
  621. }
  622. /* Note: it is necessary to treat mask as an unsigned int,
  623. * with the corresponding cast to a signed int to insure that the
  624. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  625. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  626. */
  627. asmlinkage long compat_sys_umask(u32 mask)
  628. {
  629. return sys_umask((int)mask);
  630. }
  631. #ifdef CONFIG_SYSCTL
  632. struct __sysctl_args32 {
  633. u32 name;
  634. int nlen;
  635. u32 oldval;
  636. u32 oldlenp;
  637. u32 newval;
  638. u32 newlen;
  639. u32 __unused[4];
  640. };
  641. asmlinkage long compat_sys_sysctl(struct __sysctl_args32 __user *args)
  642. {
  643. struct __sysctl_args32 tmp;
  644. int error;
  645. size_t oldlen;
  646. size_t __user *oldlenp = NULL;
  647. unsigned long addr = (((unsigned long)&args->__unused[0]) + 7) & ~7;
  648. if (copy_from_user(&tmp, args, sizeof(tmp)))
  649. return -EFAULT;
  650. if (tmp.oldval && tmp.oldlenp) {
  651. /* Duh, this is ugly and might not work if sysctl_args
  652. is in read-only memory, but do_sysctl does indirectly
  653. a lot of uaccess in both directions and we'd have to
  654. basically copy the whole sysctl.c here, and
  655. glibc's __sysctl uses rw memory for the structure
  656. anyway. */
  657. oldlenp = (size_t __user *)addr;
  658. if (get_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)) ||
  659. put_user(oldlen, oldlenp))
  660. return -EFAULT;
  661. }
  662. lock_kernel();
  663. error = do_sysctl(compat_ptr(tmp.name), tmp.nlen,
  664. compat_ptr(tmp.oldval), oldlenp,
  665. compat_ptr(tmp.newval), tmp.newlen);
  666. unlock_kernel();
  667. if (oldlenp) {
  668. if (!error) {
  669. if (get_user(oldlen, oldlenp) ||
  670. put_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)))
  671. error = -EFAULT;
  672. }
  673. copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused));
  674. }
  675. return error;
  676. }
  677. #endif
  678. unsigned long compat_sys_mmap2(unsigned long addr, size_t len,
  679. unsigned long prot, unsigned long flags,
  680. unsigned long fd, unsigned long pgoff)
  681. {
  682. /* This should remain 12 even if PAGE_SIZE changes */
  683. return sys_mmap(addr, len, prot, flags, fd, pgoff << 12);
  684. }
  685. long compat_sys_tgkill(u32 tgid, u32 pid, int sig)
  686. {
  687. /* sign extend tgid, pid */
  688. return sys_tgkill((int)tgid, (int)pid, sig);
  689. }
  690. /*
  691. * long long munging:
  692. * The 32 bit ABI passes long longs in an odd even register pair.
  693. */
  694. compat_ssize_t compat_sys_pread64(unsigned int fd, char __user *ubuf, compat_size_t count,
  695. u32 reg6, u32 poshi, u32 poslo)
  696. {
  697. return sys_pread64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
  698. }
  699. compat_ssize_t compat_sys_pwrite64(unsigned int fd, char __user *ubuf, compat_size_t count,
  700. u32 reg6, u32 poshi, u32 poslo)
  701. {
  702. return sys_pwrite64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
  703. }
  704. compat_ssize_t compat_sys_readahead(int fd, u32 r4, u32 offhi, u32 offlo, u32 count)
  705. {
  706. return sys_readahead(fd, ((loff_t)offhi << 32) | offlo, count);
  707. }
  708. asmlinkage int compat_sys_truncate64(const char __user * path, u32 reg4,
  709. unsigned long high, unsigned long low)
  710. {
  711. return sys_truncate(path, (high << 32) | low);
  712. }
  713. asmlinkage int compat_sys_ftruncate64(unsigned int fd, u32 reg4, unsigned long high,
  714. unsigned long low)
  715. {
  716. return sys_ftruncate(fd, (high << 32) | low);
  717. }
  718. long ppc32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char __user *buf,
  719. size_t len)
  720. {
  721. return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low,
  722. buf, len);
  723. }
  724. long ppc32_fadvise64(int fd, u32 unused, u32 offset_high, u32 offset_low,
  725. size_t len, int advice)
  726. {
  727. return sys_fadvise64(fd, (u64)offset_high << 32 | offset_low, len,
  728. advice);
  729. }
  730. asmlinkage long compat_sys_add_key(const char __user *_type,
  731. const char __user *_description,
  732. const void __user *_payload,
  733. u32 plen,
  734. u32 ringid)
  735. {
  736. return sys_add_key(_type, _description, _payload, plen, ringid);
  737. }
  738. asmlinkage long compat_sys_request_key(const char __user *_type,
  739. const char __user *_description,
  740. const char __user *_callout_info,
  741. u32 destringid)
  742. {
  743. return sys_request_key(_type, _description, _callout_info, destringid);
  744. }