sys_ppc32.c 28 KB

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