sys_ppc32.c 24 KB

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