sys_ppc32.c 26 KB

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