sys_ppc32.c 25 KB

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