sys_ppc32.c 25 KB

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