sys_ppc32.c 22 KB

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