sys_ppc32.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008
  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/systemcfg.h>
  54. #include <asm/ppc-pci.h>
  55. /* readdir & getdents */
  56. #define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
  57. #define ROUND_UP(x) (((x)+sizeof(u32)-1) & ~(sizeof(u32)-1))
  58. struct old_linux_dirent32 {
  59. u32 d_ino;
  60. u32 d_offset;
  61. unsigned short d_namlen;
  62. char d_name[1];
  63. };
  64. struct readdir_callback32 {
  65. struct old_linux_dirent32 __user * dirent;
  66. int count;
  67. };
  68. static int fillonedir(void * __buf, const char * name, int namlen,
  69. off_t offset, ino_t ino, unsigned int d_type)
  70. {
  71. struct readdir_callback32 * buf = (struct readdir_callback32 *) __buf;
  72. struct old_linux_dirent32 __user * dirent;
  73. if (buf->count)
  74. return -EINVAL;
  75. buf->count++;
  76. dirent = buf->dirent;
  77. put_user(ino, &dirent->d_ino);
  78. put_user(offset, &dirent->d_offset);
  79. put_user(namlen, &dirent->d_namlen);
  80. copy_to_user(dirent->d_name, name, namlen);
  81. put_user(0, dirent->d_name + namlen);
  82. return 0;
  83. }
  84. asmlinkage int old32_readdir(unsigned int fd, struct old_linux_dirent32 __user *dirent, unsigned int count)
  85. {
  86. int error = -EBADF;
  87. struct file * file;
  88. struct readdir_callback32 buf;
  89. file = fget(fd);
  90. if (!file)
  91. goto out;
  92. buf.count = 0;
  93. buf.dirent = dirent;
  94. error = vfs_readdir(file, (filldir_t)fillonedir, &buf);
  95. if (error < 0)
  96. goto out_putf;
  97. error = buf.count;
  98. out_putf:
  99. fput(file);
  100. out:
  101. return error;
  102. }
  103. asmlinkage long ppc32_select(u32 n, compat_ulong_t __user *inp,
  104. compat_ulong_t __user *outp, compat_ulong_t __user *exp,
  105. compat_uptr_t tvp_x)
  106. {
  107. /* sign extend n */
  108. return compat_sys_select((int)n, inp, outp, exp, compat_ptr(tvp_x));
  109. }
  110. int cp_compat_stat(struct kstat *stat, struct compat_stat __user *statbuf)
  111. {
  112. long err;
  113. if (stat->size > MAX_NON_LFS || !new_valid_dev(stat->dev) ||
  114. !new_valid_dev(stat->rdev))
  115. return -EOVERFLOW;
  116. err = access_ok(VERIFY_WRITE, statbuf, sizeof(*statbuf)) ? 0 : -EFAULT;
  117. err |= __put_user(new_encode_dev(stat->dev), &statbuf->st_dev);
  118. err |= __put_user(stat->ino, &statbuf->st_ino);
  119. err |= __put_user(stat->mode, &statbuf->st_mode);
  120. err |= __put_user(stat->nlink, &statbuf->st_nlink);
  121. err |= __put_user(stat->uid, &statbuf->st_uid);
  122. err |= __put_user(stat->gid, &statbuf->st_gid);
  123. err |= __put_user(new_encode_dev(stat->rdev), &statbuf->st_rdev);
  124. err |= __put_user(stat->size, &statbuf->st_size);
  125. err |= __put_user(stat->atime.tv_sec, &statbuf->st_atime);
  126. err |= __put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);
  127. err |= __put_user(stat->mtime.tv_sec, &statbuf->st_mtime);
  128. err |= __put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);
  129. err |= __put_user(stat->ctime.tv_sec, &statbuf->st_ctime);
  130. err |= __put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);
  131. err |= __put_user(stat->blksize, &statbuf->st_blksize);
  132. err |= __put_user(stat->blocks, &statbuf->st_blocks);
  133. err |= __put_user(0, &statbuf->__unused4[0]);
  134. err |= __put_user(0, &statbuf->__unused4[1]);
  135. return err;
  136. }
  137. /* Note: it is necessary to treat option as an unsigned int,
  138. * with the corresponding cast to a signed int to insure that the
  139. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  140. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  141. */
  142. asmlinkage long compat_sys_sysfs(u32 option, u32 arg1, u32 arg2)
  143. {
  144. return sys_sysfs((int)option, arg1, arg2);
  145. }
  146. /* Handle adjtimex compatibility. */
  147. struct timex32 {
  148. u32 modes;
  149. s32 offset, freq, maxerror, esterror;
  150. s32 status, constant, precision, tolerance;
  151. struct compat_timeval time;
  152. s32 tick;
  153. s32 ppsfreq, jitter, shift, stabil;
  154. s32 jitcnt, calcnt, errcnt, stbcnt;
  155. s32 :32; s32 :32; s32 :32; s32 :32;
  156. s32 :32; s32 :32; s32 :32; s32 :32;
  157. s32 :32; s32 :32; s32 :32; s32 :32;
  158. };
  159. extern int do_adjtimex(struct timex *);
  160. extern void ppc_adjtimex(void);
  161. asmlinkage long compat_sys_adjtimex(struct timex32 __user *utp)
  162. {
  163. struct timex txc;
  164. int ret;
  165. memset(&txc, 0, sizeof(struct timex));
  166. if(get_user(txc.modes, &utp->modes) ||
  167. __get_user(txc.offset, &utp->offset) ||
  168. __get_user(txc.freq, &utp->freq) ||
  169. __get_user(txc.maxerror, &utp->maxerror) ||
  170. __get_user(txc.esterror, &utp->esterror) ||
  171. __get_user(txc.status, &utp->status) ||
  172. __get_user(txc.constant, &utp->constant) ||
  173. __get_user(txc.precision, &utp->precision) ||
  174. __get_user(txc.tolerance, &utp->tolerance) ||
  175. __get_user(txc.time.tv_sec, &utp->time.tv_sec) ||
  176. __get_user(txc.time.tv_usec, &utp->time.tv_usec) ||
  177. __get_user(txc.tick, &utp->tick) ||
  178. __get_user(txc.ppsfreq, &utp->ppsfreq) ||
  179. __get_user(txc.jitter, &utp->jitter) ||
  180. __get_user(txc.shift, &utp->shift) ||
  181. __get_user(txc.stabil, &utp->stabil) ||
  182. __get_user(txc.jitcnt, &utp->jitcnt) ||
  183. __get_user(txc.calcnt, &utp->calcnt) ||
  184. __get_user(txc.errcnt, &utp->errcnt) ||
  185. __get_user(txc.stbcnt, &utp->stbcnt))
  186. return -EFAULT;
  187. ret = do_adjtimex(&txc);
  188. /* adjust the conversion of TB to time of day to track adjtimex */
  189. ppc_adjtimex();
  190. if(put_user(txc.modes, &utp->modes) ||
  191. __put_user(txc.offset, &utp->offset) ||
  192. __put_user(txc.freq, &utp->freq) ||
  193. __put_user(txc.maxerror, &utp->maxerror) ||
  194. __put_user(txc.esterror, &utp->esterror) ||
  195. __put_user(txc.status, &utp->status) ||
  196. __put_user(txc.constant, &utp->constant) ||
  197. __put_user(txc.precision, &utp->precision) ||
  198. __put_user(txc.tolerance, &utp->tolerance) ||
  199. __put_user(txc.time.tv_sec, &utp->time.tv_sec) ||
  200. __put_user(txc.time.tv_usec, &utp->time.tv_usec) ||
  201. __put_user(txc.tick, &utp->tick) ||
  202. __put_user(txc.ppsfreq, &utp->ppsfreq) ||
  203. __put_user(txc.jitter, &utp->jitter) ||
  204. __put_user(txc.shift, &utp->shift) ||
  205. __put_user(txc.stabil, &utp->stabil) ||
  206. __put_user(txc.jitcnt, &utp->jitcnt) ||
  207. __put_user(txc.calcnt, &utp->calcnt) ||
  208. __put_user(txc.errcnt, &utp->errcnt) ||
  209. __put_user(txc.stbcnt, &utp->stbcnt))
  210. ret = -EFAULT;
  211. return ret;
  212. }
  213. asmlinkage long compat_sys_pause(void)
  214. {
  215. current->state = TASK_INTERRUPTIBLE;
  216. schedule();
  217. return -ERESTARTNOHAND;
  218. }
  219. static inline long get_ts32(struct timespec *o, struct compat_timeval __user *i)
  220. {
  221. long usec;
  222. if (!access_ok(VERIFY_READ, i, sizeof(*i)))
  223. return -EFAULT;
  224. if (__get_user(o->tv_sec, &i->tv_sec))
  225. return -EFAULT;
  226. if (__get_user(usec, &i->tv_usec))
  227. return -EFAULT;
  228. o->tv_nsec = usec * 1000;
  229. return 0;
  230. }
  231. static inline long put_tv32(struct compat_timeval __user *o, struct timeval *i)
  232. {
  233. return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
  234. (__put_user(i->tv_sec, &o->tv_sec) |
  235. __put_user(i->tv_usec, &o->tv_usec)));
  236. }
  237. struct sysinfo32 {
  238. s32 uptime;
  239. u32 loads[3];
  240. u32 totalram;
  241. u32 freeram;
  242. u32 sharedram;
  243. u32 bufferram;
  244. u32 totalswap;
  245. u32 freeswap;
  246. unsigned short procs;
  247. unsigned short pad;
  248. u32 totalhigh;
  249. u32 freehigh;
  250. u32 mem_unit;
  251. char _f[20-2*sizeof(int)-sizeof(int)];
  252. };
  253. asmlinkage long compat_sys_sysinfo(struct sysinfo32 __user *info)
  254. {
  255. struct sysinfo s;
  256. int ret, err;
  257. int bitcount=0;
  258. mm_segment_t old_fs = get_fs ();
  259. /* The __user cast is valid due to set_fs() */
  260. set_fs (KERNEL_DS);
  261. ret = sys_sysinfo((struct sysinfo __user *)&s);
  262. set_fs (old_fs);
  263. /* Check to see if any memory value is too large for 32-bit and
  264. * scale down if needed.
  265. */
  266. if ((s.totalram >> 32) || (s.totalswap >> 32)) {
  267. while (s.mem_unit < PAGE_SIZE) {
  268. s.mem_unit <<= 1;
  269. bitcount++;
  270. }
  271. s.totalram >>=bitcount;
  272. s.freeram >>= bitcount;
  273. s.sharedram >>= bitcount;
  274. s.bufferram >>= bitcount;
  275. s.totalswap >>= bitcount;
  276. s.freeswap >>= bitcount;
  277. s.totalhigh >>= bitcount;
  278. s.freehigh >>= bitcount;
  279. }
  280. err = put_user (s.uptime, &info->uptime);
  281. err |= __put_user (s.loads[0], &info->loads[0]);
  282. err |= __put_user (s.loads[1], &info->loads[1]);
  283. err |= __put_user (s.loads[2], &info->loads[2]);
  284. err |= __put_user (s.totalram, &info->totalram);
  285. err |= __put_user (s.freeram, &info->freeram);
  286. err |= __put_user (s.sharedram, &info->sharedram);
  287. err |= __put_user (s.bufferram, &info->bufferram);
  288. err |= __put_user (s.totalswap, &info->totalswap);
  289. err |= __put_user (s.freeswap, &info->freeswap);
  290. err |= __put_user (s.procs, &info->procs);
  291. err |= __put_user (s.totalhigh, &info->totalhigh);
  292. err |= __put_user (s.freehigh, &info->freehigh);
  293. err |= __put_user (s.mem_unit, &info->mem_unit);
  294. if (err)
  295. return -EFAULT;
  296. return ret;
  297. }
  298. /* Translations due to time_t size differences. Which affects all
  299. sorts of things, like timeval and itimerval. */
  300. extern struct timezone sys_tz;
  301. asmlinkage long compat_sys_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
  302. {
  303. if (tv) {
  304. struct timeval ktv;
  305. do_gettimeofday(&ktv);
  306. if (put_tv32(tv, &ktv))
  307. return -EFAULT;
  308. }
  309. if (tz) {
  310. if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
  311. return -EFAULT;
  312. }
  313. return 0;
  314. }
  315. asmlinkage long compat_sys_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
  316. {
  317. struct timespec kts;
  318. struct timezone ktz;
  319. if (tv) {
  320. if (get_ts32(&kts, tv))
  321. return -EFAULT;
  322. }
  323. if (tz) {
  324. if (copy_from_user(&ktz, tz, sizeof(ktz)))
  325. return -EFAULT;
  326. }
  327. return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
  328. }
  329. #ifdef CONFIG_SYSVIPC
  330. long compat_sys_ipc(u32 call, u32 first, u32 second, u32 third, compat_uptr_t ptr,
  331. u32 fifth)
  332. {
  333. int version;
  334. version = call >> 16; /* hack for backward compatibility */
  335. call &= 0xffff;
  336. switch (call) {
  337. case SEMTIMEDOP:
  338. if (fifth)
  339. /* sign extend semid */
  340. return compat_sys_semtimedop((int)first,
  341. compat_ptr(ptr), second,
  342. compat_ptr(fifth));
  343. /* else fall through for normal semop() */
  344. case SEMOP:
  345. /* struct sembuf is the same on 32 and 64bit :)) */
  346. /* sign extend semid */
  347. return sys_semtimedop((int)first, compat_ptr(ptr), second,
  348. NULL);
  349. case SEMGET:
  350. /* sign extend key, nsems */
  351. return sys_semget((int)first, (int)second, third);
  352. case SEMCTL:
  353. /* sign extend semid, semnum */
  354. return compat_sys_semctl((int)first, (int)second, third,
  355. compat_ptr(ptr));
  356. case MSGSND:
  357. /* sign extend msqid */
  358. return compat_sys_msgsnd((int)first, (int)second, third,
  359. compat_ptr(ptr));
  360. case MSGRCV:
  361. /* sign extend msqid, msgtyp */
  362. return compat_sys_msgrcv((int)first, second, (int)fifth,
  363. third, version, compat_ptr(ptr));
  364. case MSGGET:
  365. /* sign extend key */
  366. return sys_msgget((int)first, second);
  367. case MSGCTL:
  368. /* sign extend msqid */
  369. return compat_sys_msgctl((int)first, second, compat_ptr(ptr));
  370. case SHMAT:
  371. /* sign extend shmid */
  372. return compat_sys_shmat((int)first, second, third, version,
  373. compat_ptr(ptr));
  374. case SHMDT:
  375. return sys_shmdt(compat_ptr(ptr));
  376. case SHMGET:
  377. /* sign extend key_t */
  378. return sys_shmget((int)first, second, third);
  379. case SHMCTL:
  380. /* sign extend shmid */
  381. return compat_sys_shmctl((int)first, second, compat_ptr(ptr));
  382. default:
  383. return -ENOSYS;
  384. }
  385. return -ENOSYS;
  386. }
  387. #endif
  388. /* Note: it is necessary to treat out_fd and in_fd as unsigned ints,
  389. * with the corresponding cast to a signed int to insure that the
  390. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  391. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  392. */
  393. asmlinkage long compat_sys_sendfile(u32 out_fd, u32 in_fd, compat_off_t __user * offset, u32 count)
  394. {
  395. mm_segment_t old_fs = get_fs();
  396. int ret;
  397. off_t of;
  398. off_t __user *up;
  399. if (offset && get_user(of, offset))
  400. return -EFAULT;
  401. /* The __user pointer cast is valid because of the set_fs() */
  402. set_fs(KERNEL_DS);
  403. up = offset ? (off_t __user *) &of : NULL;
  404. ret = sys_sendfile((int)out_fd, (int)in_fd, up, count);
  405. set_fs(old_fs);
  406. if (offset && put_user(of, offset))
  407. return -EFAULT;
  408. return ret;
  409. }
  410. asmlinkage int compat_sys_sendfile64(int out_fd, int in_fd, compat_loff_t __user *offset, s32 count)
  411. {
  412. mm_segment_t old_fs = get_fs();
  413. int ret;
  414. loff_t lof;
  415. loff_t __user *up;
  416. if (offset && get_user(lof, offset))
  417. return -EFAULT;
  418. /* The __user pointer cast is valid because of the set_fs() */
  419. set_fs(KERNEL_DS);
  420. up = offset ? (loff_t __user *) &lof : NULL;
  421. ret = sys_sendfile64(out_fd, in_fd, up, count);
  422. set_fs(old_fs);
  423. if (offset && put_user(lof, offset))
  424. return -EFAULT;
  425. return ret;
  426. }
  427. long compat_sys_execve(unsigned long a0, unsigned long a1, unsigned long a2,
  428. unsigned long a3, unsigned long a4, unsigned long a5,
  429. struct pt_regs *regs)
  430. {
  431. int error;
  432. char * filename;
  433. filename = getname((char __user *) a0);
  434. error = PTR_ERR(filename);
  435. if (IS_ERR(filename))
  436. goto out;
  437. flush_fp_to_thread(current);
  438. flush_altivec_to_thread(current);
  439. error = compat_do_execve(filename, compat_ptr(a1), compat_ptr(a2), regs);
  440. if (error == 0) {
  441. task_lock(current);
  442. current->ptrace &= ~PT_DTRACE;
  443. task_unlock(current);
  444. }
  445. putname(filename);
  446. out:
  447. return error;
  448. }
  449. /* Note: it is necessary to treat option 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_prctl(u32 option, u32 arg2, u32 arg3, u32 arg4, u32 arg5)
  455. {
  456. return sys_prctl((int)option,
  457. (unsigned long) arg2,
  458. (unsigned long) arg3,
  459. (unsigned long) arg4,
  460. (unsigned long) arg5);
  461. }
  462. /* Note: it is necessary to treat pid as an unsigned int,
  463. * with the corresponding cast to a signed int to insure that the
  464. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  465. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  466. */
  467. asmlinkage long compat_sys_sched_rr_get_interval(u32 pid, struct compat_timespec __user *interval)
  468. {
  469. struct timespec t;
  470. int ret;
  471. mm_segment_t old_fs = get_fs ();
  472. /* The __user pointer cast is valid because of the set_fs() */
  473. set_fs (KERNEL_DS);
  474. ret = sys_sched_rr_get_interval((int)pid, (struct timespec __user *) &t);
  475. set_fs (old_fs);
  476. if (put_compat_timespec(&t, interval))
  477. return -EFAULT;
  478. return ret;
  479. }
  480. asmlinkage int compat_sys_pciconfig_read(u32 bus, u32 dfn, u32 off, u32 len, u32 ubuf)
  481. {
  482. return sys_pciconfig_read((unsigned long) bus,
  483. (unsigned long) dfn,
  484. (unsigned long) off,
  485. (unsigned long) len,
  486. compat_ptr(ubuf));
  487. }
  488. asmlinkage int compat_sys_pciconfig_write(u32 bus, u32 dfn, u32 off, u32 len, u32 ubuf)
  489. {
  490. return sys_pciconfig_write((unsigned long) bus,
  491. (unsigned long) dfn,
  492. (unsigned long) off,
  493. (unsigned long) len,
  494. compat_ptr(ubuf));
  495. }
  496. asmlinkage int compat_sys_pciconfig_iobase(u32 which, u32 in_bus, u32 in_devfn)
  497. {
  498. return sys_pciconfig_iobase(which, in_bus, in_devfn);
  499. }
  500. /* Note: it is necessary to treat mode 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_access(const char __user * filename, u32 mode)
  506. {
  507. return sys_access(filename, (int)mode);
  508. }
  509. /* Note: it is necessary to treat mode 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_creat(const char __user * pathname, u32 mode)
  515. {
  516. return sys_creat(pathname, (int)mode);
  517. }
  518. /* Note: it is necessary to treat pid and options 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_waitpid(u32 pid, unsigned int __user * stat_addr, u32 options)
  524. {
  525. return sys_waitpid((int)pid, stat_addr, (int)options);
  526. }
  527. /* Note: it is necessary to treat gidsetsize 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_getgroups(u32 gidsetsize, gid_t __user *grouplist)
  533. {
  534. return sys_getgroups((int)gidsetsize, grouplist);
  535. }
  536. /* Note: it is necessary to treat pid as an unsigned int,
  537. * with the corresponding cast to a signed int to insure that the
  538. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  539. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  540. */
  541. asmlinkage long compat_sys_getpgid(u32 pid)
  542. {
  543. return sys_getpgid((int)pid);
  544. }
  545. /* Note: it is necessary to treat pid as an unsigned int,
  546. * with the corresponding cast to a signed int to insure that the
  547. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  548. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  549. */
  550. asmlinkage long compat_sys_getsid(u32 pid)
  551. {
  552. return sys_getsid((int)pid);
  553. }
  554. /* Note: it is necessary to treat pid and sig as unsigned ints,
  555. * with the corresponding cast to a signed int to insure that the
  556. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  557. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  558. */
  559. asmlinkage long compat_sys_kill(u32 pid, u32 sig)
  560. {
  561. return sys_kill((int)pid, (int)sig);
  562. }
  563. /* Note: it is necessary to treat mode as an unsigned int,
  564. * with the corresponding cast to a signed int to insure that the
  565. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  566. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  567. */
  568. asmlinkage long compat_sys_mkdir(const char __user * pathname, u32 mode)
  569. {
  570. return sys_mkdir(pathname, (int)mode);
  571. }
  572. long compat_sys_nice(u32 increment)
  573. {
  574. /* sign extend increment */
  575. return sys_nice((int)increment);
  576. }
  577. off_t ppc32_lseek(unsigned int fd, u32 offset, unsigned int origin)
  578. {
  579. /* sign extend n */
  580. return sys_lseek(fd, (int)offset, origin);
  581. }
  582. /* Note: it is necessary to treat bufsiz 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_readlink(const char __user * path, char __user * buf, u32 bufsiz)
  588. {
  589. return sys_readlink(path, buf, (int)bufsiz);
  590. }
  591. /* Note: it is necessary to treat option 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_get_priority_max(u32 policy)
  597. {
  598. return sys_sched_get_priority_max((int)policy);
  599. }
  600. /* Note: it is necessary to treat policy as an unsigned int,
  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_get_priority_min(u32 policy)
  606. {
  607. return sys_sched_get_priority_min((int)policy);
  608. }
  609. /* Note: it is necessary to treat pid 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_sched_getparam(u32 pid, struct sched_param __user *param)
  615. {
  616. return sys_sched_getparam((int)pid, param);
  617. }
  618. /* Note: it is necessary to treat pid 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_sched_getscheduler(u32 pid)
  624. {
  625. return sys_sched_getscheduler((int)pid);
  626. }
  627. /* Note: it is necessary to treat pid as an unsigned int,
  628. * with the corresponding cast to a signed int to insure that the
  629. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  630. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  631. */
  632. asmlinkage long compat_sys_sched_setparam(u32 pid, struct sched_param __user *param)
  633. {
  634. return sys_sched_setparam((int)pid, param);
  635. }
  636. /* Note: it is necessary to treat pid and policy as unsigned ints,
  637. * with the corresponding cast to a signed int to insure that the
  638. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  639. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  640. */
  641. asmlinkage long compat_sys_sched_setscheduler(u32 pid, u32 policy, struct sched_param __user *param)
  642. {
  643. return sys_sched_setscheduler((int)pid, (int)policy, param);
  644. }
  645. /* Note: it is necessary to treat len as an unsigned int,
  646. * with the corresponding cast to a signed int to insure that the
  647. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  648. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  649. */
  650. asmlinkage long compat_sys_setdomainname(char __user *name, u32 len)
  651. {
  652. return sys_setdomainname(name, (int)len);
  653. }
  654. /* Note: it is necessary to treat gidsetsize as an unsigned int,
  655. * with the corresponding cast to a signed int to insure that the
  656. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  657. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  658. */
  659. asmlinkage long compat_sys_setgroups(u32 gidsetsize, gid_t __user *grouplist)
  660. {
  661. return sys_setgroups((int)gidsetsize, grouplist);
  662. }
  663. asmlinkage long compat_sys_sethostname(char __user *name, u32 len)
  664. {
  665. /* sign extend len */
  666. return sys_sethostname(name, (int)len);
  667. }
  668. /* Note: it is necessary to treat pid and pgid as unsigned ints,
  669. * with the corresponding cast to a signed int to insure that the
  670. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  671. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  672. */
  673. asmlinkage long compat_sys_setpgid(u32 pid, u32 pgid)
  674. {
  675. return sys_setpgid((int)pid, (int)pgid);
  676. }
  677. long compat_sys_getpriority(u32 which, u32 who)
  678. {
  679. /* sign extend which and who */
  680. return sys_getpriority((int)which, (int)who);
  681. }
  682. long compat_sys_setpriority(u32 which, u32 who, u32 niceval)
  683. {
  684. /* sign extend which, who and niceval */
  685. return sys_setpriority((int)which, (int)who, (int)niceval);
  686. }
  687. long compat_sys_ioprio_get(u32 which, u32 who)
  688. {
  689. /* sign extend which and who */
  690. return sys_ioprio_get((int)which, (int)who);
  691. }
  692. long compat_sys_ioprio_set(u32 which, u32 who, u32 ioprio)
  693. {
  694. /* sign extend which, who and ioprio */
  695. return sys_ioprio_set((int)which, (int)who, (int)ioprio);
  696. }
  697. /* Note: it is necessary to treat newmask as an unsigned int,
  698. * with the corresponding cast to a signed int to insure that the
  699. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  700. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  701. */
  702. asmlinkage long compat_sys_ssetmask(u32 newmask)
  703. {
  704. return sys_ssetmask((int) newmask);
  705. }
  706. asmlinkage long compat_sys_syslog(u32 type, char __user * buf, u32 len)
  707. {
  708. /* sign extend len */
  709. return sys_syslog(type, buf, (int)len);
  710. }
  711. /* Note: it is necessary to treat mask as an unsigned int,
  712. * with the corresponding cast to a signed int to insure that the
  713. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  714. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  715. */
  716. asmlinkage long compat_sys_umask(u32 mask)
  717. {
  718. return sys_umask((int)mask);
  719. }
  720. #ifdef CONFIG_SYSCTL
  721. struct __sysctl_args32 {
  722. u32 name;
  723. int nlen;
  724. u32 oldval;
  725. u32 oldlenp;
  726. u32 newval;
  727. u32 newlen;
  728. u32 __unused[4];
  729. };
  730. asmlinkage long compat_sys_sysctl(struct __sysctl_args32 __user *args)
  731. {
  732. struct __sysctl_args32 tmp;
  733. int error;
  734. size_t oldlen;
  735. size_t __user *oldlenp = NULL;
  736. unsigned long addr = (((unsigned long)&args->__unused[0]) + 7) & ~7;
  737. if (copy_from_user(&tmp, args, sizeof(tmp)))
  738. return -EFAULT;
  739. if (tmp.oldval && tmp.oldlenp) {
  740. /* Duh, this is ugly and might not work if sysctl_args
  741. is in read-only memory, but do_sysctl does indirectly
  742. a lot of uaccess in both directions and we'd have to
  743. basically copy the whole sysctl.c here, and
  744. glibc's __sysctl uses rw memory for the structure
  745. anyway. */
  746. oldlenp = (size_t __user *)addr;
  747. if (get_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)) ||
  748. put_user(oldlen, oldlenp))
  749. return -EFAULT;
  750. }
  751. lock_kernel();
  752. error = do_sysctl(compat_ptr(tmp.name), tmp.nlen,
  753. compat_ptr(tmp.oldval), oldlenp,
  754. compat_ptr(tmp.newval), tmp.newlen);
  755. unlock_kernel();
  756. if (oldlenp) {
  757. if (!error) {
  758. if (get_user(oldlen, oldlenp) ||
  759. put_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)))
  760. error = -EFAULT;
  761. }
  762. copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused));
  763. }
  764. return error;
  765. }
  766. #endif
  767. unsigned long compat_sys_mmap2(unsigned long addr, size_t len,
  768. unsigned long prot, unsigned long flags,
  769. unsigned long fd, unsigned long pgoff)
  770. {
  771. /* This should remain 12 even if PAGE_SIZE changes */
  772. return sys_mmap(addr, len, prot, flags, fd, pgoff << 12);
  773. }
  774. long compat_sys_tgkill(u32 tgid, u32 pid, int sig)
  775. {
  776. /* sign extend tgid, pid */
  777. return sys_tgkill((int)tgid, (int)pid, sig);
  778. }
  779. /*
  780. * long long munging:
  781. * The 32 bit ABI passes long longs in an odd even register pair.
  782. */
  783. compat_ssize_t compat_sys_pread64(unsigned int fd, char __user *ubuf, compat_size_t count,
  784. u32 reg6, u32 poshi, u32 poslo)
  785. {
  786. return sys_pread64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
  787. }
  788. compat_ssize_t compat_sys_pwrite64(unsigned int fd, char __user *ubuf, compat_size_t count,
  789. u32 reg6, u32 poshi, u32 poslo)
  790. {
  791. return sys_pwrite64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
  792. }
  793. compat_ssize_t compat_sys_readahead(int fd, u32 r4, u32 offhi, u32 offlo, u32 count)
  794. {
  795. return sys_readahead(fd, ((loff_t)offhi << 32) | offlo, count);
  796. }
  797. asmlinkage int compat_sys_truncate64(const char __user * path, u32 reg4,
  798. unsigned long high, unsigned long low)
  799. {
  800. return sys_truncate(path, (high << 32) | low);
  801. }
  802. asmlinkage int compat_sys_ftruncate64(unsigned int fd, u32 reg4, unsigned long high,
  803. unsigned long low)
  804. {
  805. return sys_ftruncate(fd, (high << 32) | low);
  806. }
  807. long ppc32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char __user *buf,
  808. size_t len)
  809. {
  810. return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low,
  811. buf, len);
  812. }
  813. long ppc32_fadvise64(int fd, u32 unused, u32 offset_high, u32 offset_low,
  814. size_t len, int advice)
  815. {
  816. return sys_fadvise64(fd, (u64)offset_high << 32 | offset_low, len,
  817. advice);
  818. }
  819. long ppc32_timer_create(clockid_t clock,
  820. struct compat_sigevent __user *ev32,
  821. timer_t __user *timer_id)
  822. {
  823. sigevent_t event;
  824. timer_t t;
  825. long err;
  826. mm_segment_t savefs;
  827. if (ev32 == NULL)
  828. return sys_timer_create(clock, NULL, timer_id);
  829. if (get_compat_sigevent(&event, ev32))
  830. return -EFAULT;
  831. if (!access_ok(VERIFY_WRITE, timer_id, sizeof(timer_t)))
  832. return -EFAULT;
  833. savefs = get_fs();
  834. set_fs(KERNEL_DS);
  835. /* The __user pointer casts are valid due to the set_fs() */
  836. err = sys_timer_create(clock,
  837. (sigevent_t __user *) &event,
  838. (timer_t __user *) &t);
  839. set_fs(savefs);
  840. if (err == 0)
  841. err = __put_user(t, timer_id);
  842. return err;
  843. }
  844. asmlinkage long compat_sys_add_key(const char __user *_type,
  845. const char __user *_description,
  846. const void __user *_payload,
  847. u32 plen,
  848. u32 ringid)
  849. {
  850. return sys_add_key(_type, _description, _payload, plen, ringid);
  851. }
  852. asmlinkage long compat_sys_request_key(const char __user *_type,
  853. const char __user *_description,
  854. const char __user *_callout_info,
  855. u32 destringid)
  856. {
  857. return sys_request_key(_type, _description, _callout_info, destringid);
  858. }