sys_ppc32.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275
  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 "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. struct linux_dirent32 {
  104. u32 d_ino;
  105. u32 d_off;
  106. unsigned short d_reclen;
  107. char d_name[1];
  108. };
  109. struct getdents_callback32 {
  110. struct linux_dirent32 __user * current_dir;
  111. struct linux_dirent32 __user * previous;
  112. int count;
  113. int error;
  114. };
  115. static int filldir(void * __buf, const char * name, int namlen, off_t offset,
  116. ino_t ino, unsigned int d_type)
  117. {
  118. struct linux_dirent32 __user * dirent;
  119. struct getdents_callback32 * buf = (struct getdents_callback32 *) __buf;
  120. int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 2);
  121. buf->error = -EINVAL; /* only used if we fail.. */
  122. if (reclen > buf->count)
  123. return -EINVAL;
  124. dirent = buf->previous;
  125. if (dirent) {
  126. if (__put_user(offset, &dirent->d_off))
  127. goto efault;
  128. }
  129. dirent = buf->current_dir;
  130. if (__put_user(ino, &dirent->d_ino))
  131. goto efault;
  132. if (__put_user(reclen, &dirent->d_reclen))
  133. goto efault;
  134. if (copy_to_user(dirent->d_name, name, namlen))
  135. goto efault;
  136. if (__put_user(0, dirent->d_name + namlen))
  137. goto efault;
  138. if (__put_user(d_type, (char __user *) dirent + reclen - 1))
  139. goto efault;
  140. buf->previous = dirent;
  141. dirent = (void __user *)dirent + reclen;
  142. buf->current_dir = dirent;
  143. buf->count -= reclen;
  144. return 0;
  145. efault:
  146. buf->error = -EFAULT;
  147. return -EFAULT;
  148. }
  149. asmlinkage long sys32_getdents(unsigned int fd, struct linux_dirent32 __user *dirent,
  150. unsigned int count)
  151. {
  152. struct file * file;
  153. struct linux_dirent32 __user * lastdirent;
  154. struct getdents_callback32 buf;
  155. int error;
  156. error = -EFAULT;
  157. if (!access_ok(VERIFY_WRITE, dirent, count))
  158. goto out;
  159. error = -EBADF;
  160. file = fget(fd);
  161. if (!file)
  162. goto out;
  163. buf.current_dir = dirent;
  164. buf.previous = NULL;
  165. buf.count = count;
  166. buf.error = 0;
  167. error = vfs_readdir(file, (filldir_t)filldir, &buf);
  168. if (error < 0)
  169. goto out_putf;
  170. error = buf.error;
  171. lastdirent = buf.previous;
  172. if (lastdirent) {
  173. if (put_user(file->f_pos, &lastdirent->d_off))
  174. error = -EFAULT;
  175. else
  176. error = count - buf.count;
  177. }
  178. out_putf:
  179. fput(file);
  180. out:
  181. return error;
  182. }
  183. asmlinkage long ppc32_select(u32 n, compat_ulong_t __user *inp,
  184. compat_ulong_t __user *outp, compat_ulong_t __user *exp,
  185. compat_uptr_t tvp_x)
  186. {
  187. /* sign extend n */
  188. return compat_sys_select((int)n, inp, outp, exp, compat_ptr(tvp_x));
  189. }
  190. int cp_compat_stat(struct kstat *stat, struct compat_stat __user *statbuf)
  191. {
  192. long err;
  193. if (stat->size > MAX_NON_LFS || !new_valid_dev(stat->dev) ||
  194. !new_valid_dev(stat->rdev))
  195. return -EOVERFLOW;
  196. err = access_ok(VERIFY_WRITE, statbuf, sizeof(*statbuf)) ? 0 : -EFAULT;
  197. err |= __put_user(new_encode_dev(stat->dev), &statbuf->st_dev);
  198. err |= __put_user(stat->ino, &statbuf->st_ino);
  199. err |= __put_user(stat->mode, &statbuf->st_mode);
  200. err |= __put_user(stat->nlink, &statbuf->st_nlink);
  201. err |= __put_user(stat->uid, &statbuf->st_uid);
  202. err |= __put_user(stat->gid, &statbuf->st_gid);
  203. err |= __put_user(new_encode_dev(stat->rdev), &statbuf->st_rdev);
  204. err |= __put_user(stat->size, &statbuf->st_size);
  205. err |= __put_user(stat->atime.tv_sec, &statbuf->st_atime);
  206. err |= __put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);
  207. err |= __put_user(stat->mtime.tv_sec, &statbuf->st_mtime);
  208. err |= __put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);
  209. err |= __put_user(stat->ctime.tv_sec, &statbuf->st_ctime);
  210. err |= __put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);
  211. err |= __put_user(stat->blksize, &statbuf->st_blksize);
  212. err |= __put_user(stat->blocks, &statbuf->st_blocks);
  213. err |= __put_user(0, &statbuf->__unused4[0]);
  214. err |= __put_user(0, &statbuf->__unused4[1]);
  215. return err;
  216. }
  217. /* Note: it is necessary to treat option as an unsigned int,
  218. * with the corresponding cast to a signed int to insure that the
  219. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  220. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  221. */
  222. asmlinkage long sys32_sysfs(u32 option, u32 arg1, u32 arg2)
  223. {
  224. return sys_sysfs((int)option, arg1, arg2);
  225. }
  226. /* Handle adjtimex compatibility. */
  227. struct timex32 {
  228. u32 modes;
  229. s32 offset, freq, maxerror, esterror;
  230. s32 status, constant, precision, tolerance;
  231. struct compat_timeval time;
  232. s32 tick;
  233. s32 ppsfreq, jitter, shift, stabil;
  234. s32 jitcnt, calcnt, errcnt, stbcnt;
  235. s32 :32; s32 :32; s32 :32; s32 :32;
  236. s32 :32; s32 :32; s32 :32; s32 :32;
  237. s32 :32; s32 :32; s32 :32; s32 :32;
  238. };
  239. extern int do_adjtimex(struct timex *);
  240. extern void ppc_adjtimex(void);
  241. asmlinkage long sys32_adjtimex(struct timex32 __user *utp)
  242. {
  243. struct timex txc;
  244. int ret;
  245. memset(&txc, 0, sizeof(struct timex));
  246. if(get_user(txc.modes, &utp->modes) ||
  247. __get_user(txc.offset, &utp->offset) ||
  248. __get_user(txc.freq, &utp->freq) ||
  249. __get_user(txc.maxerror, &utp->maxerror) ||
  250. __get_user(txc.esterror, &utp->esterror) ||
  251. __get_user(txc.status, &utp->status) ||
  252. __get_user(txc.constant, &utp->constant) ||
  253. __get_user(txc.precision, &utp->precision) ||
  254. __get_user(txc.tolerance, &utp->tolerance) ||
  255. __get_user(txc.time.tv_sec, &utp->time.tv_sec) ||
  256. __get_user(txc.time.tv_usec, &utp->time.tv_usec) ||
  257. __get_user(txc.tick, &utp->tick) ||
  258. __get_user(txc.ppsfreq, &utp->ppsfreq) ||
  259. __get_user(txc.jitter, &utp->jitter) ||
  260. __get_user(txc.shift, &utp->shift) ||
  261. __get_user(txc.stabil, &utp->stabil) ||
  262. __get_user(txc.jitcnt, &utp->jitcnt) ||
  263. __get_user(txc.calcnt, &utp->calcnt) ||
  264. __get_user(txc.errcnt, &utp->errcnt) ||
  265. __get_user(txc.stbcnt, &utp->stbcnt))
  266. return -EFAULT;
  267. ret = do_adjtimex(&txc);
  268. /* adjust the conversion of TB to time of day to track adjtimex */
  269. ppc_adjtimex();
  270. if(put_user(txc.modes, &utp->modes) ||
  271. __put_user(txc.offset, &utp->offset) ||
  272. __put_user(txc.freq, &utp->freq) ||
  273. __put_user(txc.maxerror, &utp->maxerror) ||
  274. __put_user(txc.esterror, &utp->esterror) ||
  275. __put_user(txc.status, &utp->status) ||
  276. __put_user(txc.constant, &utp->constant) ||
  277. __put_user(txc.precision, &utp->precision) ||
  278. __put_user(txc.tolerance, &utp->tolerance) ||
  279. __put_user(txc.time.tv_sec, &utp->time.tv_sec) ||
  280. __put_user(txc.time.tv_usec, &utp->time.tv_usec) ||
  281. __put_user(txc.tick, &utp->tick) ||
  282. __put_user(txc.ppsfreq, &utp->ppsfreq) ||
  283. __put_user(txc.jitter, &utp->jitter) ||
  284. __put_user(txc.shift, &utp->shift) ||
  285. __put_user(txc.stabil, &utp->stabil) ||
  286. __put_user(txc.jitcnt, &utp->jitcnt) ||
  287. __put_user(txc.calcnt, &utp->calcnt) ||
  288. __put_user(txc.errcnt, &utp->errcnt) ||
  289. __put_user(txc.stbcnt, &utp->stbcnt))
  290. ret = -EFAULT;
  291. return ret;
  292. }
  293. asmlinkage long sys32_pause(void)
  294. {
  295. current->state = TASK_INTERRUPTIBLE;
  296. schedule();
  297. return -ERESTARTNOHAND;
  298. }
  299. static inline long get_ts32(struct timespec *o, struct compat_timeval __user *i)
  300. {
  301. long usec;
  302. if (!access_ok(VERIFY_READ, i, sizeof(*i)))
  303. return -EFAULT;
  304. if (__get_user(o->tv_sec, &i->tv_sec))
  305. return -EFAULT;
  306. if (__get_user(usec, &i->tv_usec))
  307. return -EFAULT;
  308. o->tv_nsec = usec * 1000;
  309. return 0;
  310. }
  311. static inline long put_tv32(struct compat_timeval __user *o, struct timeval *i)
  312. {
  313. return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
  314. (__put_user(i->tv_sec, &o->tv_sec) |
  315. __put_user(i->tv_usec, &o->tv_usec)));
  316. }
  317. struct sysinfo32 {
  318. s32 uptime;
  319. u32 loads[3];
  320. u32 totalram;
  321. u32 freeram;
  322. u32 sharedram;
  323. u32 bufferram;
  324. u32 totalswap;
  325. u32 freeswap;
  326. unsigned short procs;
  327. unsigned short pad;
  328. u32 totalhigh;
  329. u32 freehigh;
  330. u32 mem_unit;
  331. char _f[20-2*sizeof(int)-sizeof(int)];
  332. };
  333. asmlinkage long sys32_sysinfo(struct sysinfo32 __user *info)
  334. {
  335. struct sysinfo s;
  336. int ret, err;
  337. int bitcount=0;
  338. mm_segment_t old_fs = get_fs ();
  339. /* The __user cast is valid due to set_fs() */
  340. set_fs (KERNEL_DS);
  341. ret = sys_sysinfo((struct sysinfo __user *)&s);
  342. set_fs (old_fs);
  343. /* Check to see if any memory value is too large for 32-bit and
  344. * scale down if needed.
  345. */
  346. if ((s.totalram >> 32) || (s.totalswap >> 32)) {
  347. while (s.mem_unit < PAGE_SIZE) {
  348. s.mem_unit <<= 1;
  349. bitcount++;
  350. }
  351. s.totalram >>=bitcount;
  352. s.freeram >>= bitcount;
  353. s.sharedram >>= bitcount;
  354. s.bufferram >>= bitcount;
  355. s.totalswap >>= bitcount;
  356. s.freeswap >>= bitcount;
  357. s.totalhigh >>= bitcount;
  358. s.freehigh >>= bitcount;
  359. }
  360. err = put_user (s.uptime, &info->uptime);
  361. err |= __put_user (s.loads[0], &info->loads[0]);
  362. err |= __put_user (s.loads[1], &info->loads[1]);
  363. err |= __put_user (s.loads[2], &info->loads[2]);
  364. err |= __put_user (s.totalram, &info->totalram);
  365. err |= __put_user (s.freeram, &info->freeram);
  366. err |= __put_user (s.sharedram, &info->sharedram);
  367. err |= __put_user (s.bufferram, &info->bufferram);
  368. err |= __put_user (s.totalswap, &info->totalswap);
  369. err |= __put_user (s.freeswap, &info->freeswap);
  370. err |= __put_user (s.procs, &info->procs);
  371. err |= __put_user (s.totalhigh, &info->totalhigh);
  372. err |= __put_user (s.freehigh, &info->freehigh);
  373. err |= __put_user (s.mem_unit, &info->mem_unit);
  374. if (err)
  375. return -EFAULT;
  376. return ret;
  377. }
  378. /* Translations due to time_t size differences. Which affects all
  379. sorts of things, like timeval and itimerval. */
  380. extern struct timezone sys_tz;
  381. asmlinkage long sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
  382. {
  383. if (tv) {
  384. struct timeval ktv;
  385. do_gettimeofday(&ktv);
  386. if (put_tv32(tv, &ktv))
  387. return -EFAULT;
  388. }
  389. if (tz) {
  390. if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
  391. return -EFAULT;
  392. }
  393. return 0;
  394. }
  395. asmlinkage long sys32_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
  396. {
  397. struct timespec kts;
  398. struct timezone ktz;
  399. if (tv) {
  400. if (get_ts32(&kts, tv))
  401. return -EFAULT;
  402. }
  403. if (tz) {
  404. if (copy_from_user(&ktz, tz, sizeof(ktz)))
  405. return -EFAULT;
  406. }
  407. return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
  408. }
  409. #ifdef CONFIG_SYSVIPC
  410. long sys32_ipc(u32 call, u32 first, u32 second, u32 third, compat_uptr_t ptr,
  411. u32 fifth)
  412. {
  413. int version;
  414. version = call >> 16; /* hack for backward compatibility */
  415. call &= 0xffff;
  416. switch (call) {
  417. case SEMTIMEDOP:
  418. if (fifth)
  419. /* sign extend semid */
  420. return compat_sys_semtimedop((int)first,
  421. compat_ptr(ptr), second,
  422. compat_ptr(fifth));
  423. /* else fall through for normal semop() */
  424. case SEMOP:
  425. /* struct sembuf is the same on 32 and 64bit :)) */
  426. /* sign extend semid */
  427. return sys_semtimedop((int)first, compat_ptr(ptr), second,
  428. NULL);
  429. case SEMGET:
  430. /* sign extend key, nsems */
  431. return sys_semget((int)first, (int)second, third);
  432. case SEMCTL:
  433. /* sign extend semid, semnum */
  434. return compat_sys_semctl((int)first, (int)second, third,
  435. compat_ptr(ptr));
  436. case MSGSND:
  437. /* sign extend msqid */
  438. return compat_sys_msgsnd((int)first, (int)second, third,
  439. compat_ptr(ptr));
  440. case MSGRCV:
  441. /* sign extend msqid, msgtyp */
  442. return compat_sys_msgrcv((int)first, second, (int)fifth,
  443. third, version, compat_ptr(ptr));
  444. case MSGGET:
  445. /* sign extend key */
  446. return sys_msgget((int)first, second);
  447. case MSGCTL:
  448. /* sign extend msqid */
  449. return compat_sys_msgctl((int)first, second, compat_ptr(ptr));
  450. case SHMAT:
  451. /* sign extend shmid */
  452. return compat_sys_shmat((int)first, second, third, version,
  453. compat_ptr(ptr));
  454. case SHMDT:
  455. return sys_shmdt(compat_ptr(ptr));
  456. case SHMGET:
  457. /* sign extend key_t */
  458. return sys_shmget((int)first, second, third);
  459. case SHMCTL:
  460. /* sign extend shmid */
  461. return compat_sys_shmctl((int)first, second, compat_ptr(ptr));
  462. default:
  463. return -ENOSYS;
  464. }
  465. return -ENOSYS;
  466. }
  467. #endif
  468. /* Note: it is necessary to treat out_fd and in_fd as unsigned ints,
  469. * with the corresponding cast to a signed int to insure that the
  470. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  471. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  472. */
  473. asmlinkage long sys32_sendfile(u32 out_fd, u32 in_fd, compat_off_t __user * offset, u32 count)
  474. {
  475. mm_segment_t old_fs = get_fs();
  476. int ret;
  477. off_t of;
  478. off_t __user *up;
  479. if (offset && get_user(of, offset))
  480. return -EFAULT;
  481. /* The __user pointer cast is valid because of the set_fs() */
  482. set_fs(KERNEL_DS);
  483. up = offset ? (off_t __user *) &of : NULL;
  484. ret = sys_sendfile((int)out_fd, (int)in_fd, up, count);
  485. set_fs(old_fs);
  486. if (offset && put_user(of, offset))
  487. return -EFAULT;
  488. return ret;
  489. }
  490. asmlinkage int sys32_sendfile64(int out_fd, int in_fd, compat_loff_t __user *offset, s32 count)
  491. {
  492. mm_segment_t old_fs = get_fs();
  493. int ret;
  494. loff_t lof;
  495. loff_t __user *up;
  496. if (offset && get_user(lof, offset))
  497. return -EFAULT;
  498. /* The __user pointer cast is valid because of the set_fs() */
  499. set_fs(KERNEL_DS);
  500. up = offset ? (loff_t __user *) &lof : NULL;
  501. ret = sys_sendfile64(out_fd, in_fd, up, count);
  502. set_fs(old_fs);
  503. if (offset && put_user(lof, offset))
  504. return -EFAULT;
  505. return ret;
  506. }
  507. long sys32_execve(unsigned long a0, unsigned long a1, unsigned long a2,
  508. unsigned long a3, unsigned long a4, unsigned long a5,
  509. struct pt_regs *regs)
  510. {
  511. int error;
  512. char * filename;
  513. filename = getname((char __user *) a0);
  514. error = PTR_ERR(filename);
  515. if (IS_ERR(filename))
  516. goto out;
  517. flush_fp_to_thread(current);
  518. flush_altivec_to_thread(current);
  519. error = compat_do_execve(filename, compat_ptr(a1), compat_ptr(a2), regs);
  520. if (error == 0) {
  521. task_lock(current);
  522. current->ptrace &= ~PT_DTRACE;
  523. task_unlock(current);
  524. }
  525. putname(filename);
  526. out:
  527. return error;
  528. }
  529. /* Set up a thread for executing a new program. */
  530. void start_thread32(struct pt_regs* regs, unsigned long nip, unsigned long sp)
  531. {
  532. set_fs(USER_DS);
  533. /*
  534. * If we exec out of a kernel thread then thread.regs will not be
  535. * set. Do it now.
  536. */
  537. if (!current->thread.regs) {
  538. unsigned long childregs = (unsigned long)current->thread_info +
  539. THREAD_SIZE;
  540. childregs -= sizeof(struct pt_regs);
  541. current->thread.regs = (struct pt_regs *)childregs;
  542. }
  543. /*
  544. * ELF_PLAT_INIT already clears all registers but it also sets r2.
  545. * So just clear r2 here.
  546. */
  547. regs->gpr[2] = 0;
  548. regs->nip = nip;
  549. regs->gpr[1] = sp;
  550. regs->msr = MSR_USER32;
  551. #ifndef CONFIG_SMP
  552. if (last_task_used_math == current)
  553. last_task_used_math = 0;
  554. #endif /* CONFIG_SMP */
  555. current->thread.fpscr = 0;
  556. memset(current->thread.fpr, 0, sizeof(current->thread.fpr));
  557. #ifdef CONFIG_ALTIVEC
  558. #ifndef CONFIG_SMP
  559. if (last_task_used_altivec == current)
  560. last_task_used_altivec = 0;
  561. #endif /* CONFIG_SMP */
  562. memset(current->thread.vr, 0, sizeof(current->thread.vr));
  563. current->thread.vscr.u[0] = 0;
  564. current->thread.vscr.u[1] = 0;
  565. current->thread.vscr.u[2] = 0;
  566. current->thread.vscr.u[3] = 0x00010000; /* Java mode disabled */
  567. current->thread.vrsave = 0;
  568. current->thread.used_vr = 0;
  569. #endif /* CONFIG_ALTIVEC */
  570. }
  571. /* Note: it is necessary to treat option as an unsigned int,
  572. * with the corresponding cast to a signed int to insure that the
  573. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  574. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  575. */
  576. asmlinkage long sys32_prctl(u32 option, u32 arg2, u32 arg3, u32 arg4, u32 arg5)
  577. {
  578. return sys_prctl((int)option,
  579. (unsigned long) arg2,
  580. (unsigned long) arg3,
  581. (unsigned long) arg4,
  582. (unsigned long) arg5);
  583. }
  584. /* Note: it is necessary to treat pid as an unsigned int,
  585. * with the corresponding cast to a signed int to insure that the
  586. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  587. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  588. */
  589. asmlinkage long sys32_sched_rr_get_interval(u32 pid, struct compat_timespec __user *interval)
  590. {
  591. struct timespec t;
  592. int ret;
  593. mm_segment_t old_fs = get_fs ();
  594. /* The __user pointer cast is valid because of the set_fs() */
  595. set_fs (KERNEL_DS);
  596. ret = sys_sched_rr_get_interval((int)pid, (struct timespec __user *) &t);
  597. set_fs (old_fs);
  598. if (put_compat_timespec(&t, interval))
  599. return -EFAULT;
  600. return ret;
  601. }
  602. asmlinkage int sys32_pciconfig_read(u32 bus, u32 dfn, u32 off, u32 len, u32 ubuf)
  603. {
  604. return sys_pciconfig_read((unsigned long) bus,
  605. (unsigned long) dfn,
  606. (unsigned long) off,
  607. (unsigned long) len,
  608. compat_ptr(ubuf));
  609. }
  610. asmlinkage int sys32_pciconfig_write(u32 bus, u32 dfn, u32 off, u32 len, u32 ubuf)
  611. {
  612. return sys_pciconfig_write((unsigned long) bus,
  613. (unsigned long) dfn,
  614. (unsigned long) off,
  615. (unsigned long) len,
  616. compat_ptr(ubuf));
  617. }
  618. #define IOBASE_BRIDGE_NUMBER 0
  619. #define IOBASE_MEMORY 1
  620. #define IOBASE_IO 2
  621. #define IOBASE_ISA_IO 3
  622. #define IOBASE_ISA_MEM 4
  623. asmlinkage int sys32_pciconfig_iobase(u32 which, u32 in_bus, u32 in_devfn)
  624. {
  625. #ifdef CONFIG_PCI
  626. struct pci_controller* hose;
  627. struct list_head *ln;
  628. struct pci_bus *bus = NULL;
  629. struct device_node *hose_node;
  630. /* Argh ! Please forgive me for that hack, but that's the
  631. * simplest way to get existing XFree to not lockup on some
  632. * G5 machines... So when something asks for bus 0 io base
  633. * (bus 0 is HT root), we return the AGP one instead.
  634. */
  635. #ifdef CONFIG_PPC_PMAC
  636. if (systemcfg->platform == PLATFORM_POWERMAC &&
  637. machine_is_compatible("MacRISC4"))
  638. if (in_bus == 0)
  639. in_bus = 0xf0;
  640. #endif /* CONFIG_PPC_PMAC */
  641. /* That syscall isn't quite compatible with PCI domains, but it's
  642. * used on pre-domains setup. We return the first match
  643. */
  644. for (ln = pci_root_buses.next; ln != &pci_root_buses; ln = ln->next) {
  645. bus = pci_bus_b(ln);
  646. if (in_bus >= bus->number && in_bus < (bus->number + bus->subordinate))
  647. break;
  648. bus = NULL;
  649. }
  650. if (bus == NULL || bus->sysdata == NULL)
  651. return -ENODEV;
  652. hose_node = (struct device_node *)bus->sysdata;
  653. hose = hose_node->phb;
  654. switch (which) {
  655. case IOBASE_BRIDGE_NUMBER:
  656. return (long)hose->first_busno;
  657. case IOBASE_MEMORY:
  658. return (long)hose->pci_mem_offset;
  659. case IOBASE_IO:
  660. return (long)hose->io_base_phys;
  661. case IOBASE_ISA_IO:
  662. return (long)isa_io_base;
  663. case IOBASE_ISA_MEM:
  664. return -EINVAL;
  665. }
  666. #endif /* CONFIG_PCI */
  667. return -EOPNOTSUPP;
  668. }
  669. /* Note: it is necessary to treat mode as an unsigned int,
  670. * with the corresponding cast to a signed int to insure that the
  671. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  672. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  673. */
  674. asmlinkage long sys32_access(const char __user * filename, u32 mode)
  675. {
  676. return sys_access(filename, (int)mode);
  677. }
  678. /* Note: it is necessary to treat mode as an unsigned int,
  679. * with the corresponding cast to a signed int to insure that the
  680. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  681. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  682. */
  683. asmlinkage long sys32_creat(const char __user * pathname, u32 mode)
  684. {
  685. return sys_creat(pathname, (int)mode);
  686. }
  687. /* Note: it is necessary to treat pid and options as unsigned ints,
  688. * with the corresponding cast to a signed int to insure that the
  689. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  690. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  691. */
  692. asmlinkage long sys32_waitpid(u32 pid, unsigned int __user * stat_addr, u32 options)
  693. {
  694. return sys_waitpid((int)pid, stat_addr, (int)options);
  695. }
  696. /* Note: it is necessary to treat gidsetsize as an unsigned int,
  697. * with the corresponding cast to a signed int to insure that the
  698. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  699. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  700. */
  701. asmlinkage long sys32_getgroups(u32 gidsetsize, gid_t __user *grouplist)
  702. {
  703. return sys_getgroups((int)gidsetsize, grouplist);
  704. }
  705. /* Note: it is necessary to treat pid as an unsigned int,
  706. * with the corresponding cast to a signed int to insure that the
  707. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  708. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  709. */
  710. asmlinkage long sys32_getpgid(u32 pid)
  711. {
  712. return sys_getpgid((int)pid);
  713. }
  714. /* Note: it is necessary to treat pid as an unsigned int,
  715. * with the corresponding cast to a signed int to insure that the
  716. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  717. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  718. */
  719. asmlinkage long sys32_getsid(u32 pid)
  720. {
  721. return sys_getsid((int)pid);
  722. }
  723. /* Note: it is necessary to treat pid and sig as unsigned ints,
  724. * with the corresponding cast to a signed int to insure that the
  725. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  726. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  727. */
  728. asmlinkage long sys32_kill(u32 pid, u32 sig)
  729. {
  730. return sys_kill((int)pid, (int)sig);
  731. }
  732. /* Note: it is necessary to treat mode as an unsigned int,
  733. * with the corresponding cast to a signed int to insure that the
  734. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  735. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  736. */
  737. asmlinkage long sys32_mkdir(const char __user * pathname, u32 mode)
  738. {
  739. return sys_mkdir(pathname, (int)mode);
  740. }
  741. long sys32_nice(u32 increment)
  742. {
  743. /* sign extend increment */
  744. return sys_nice((int)increment);
  745. }
  746. off_t ppc32_lseek(unsigned int fd, u32 offset, unsigned int origin)
  747. {
  748. /* sign extend n */
  749. return sys_lseek(fd, (int)offset, origin);
  750. }
  751. /* Note: it is necessary to treat bufsiz as an unsigned int,
  752. * with the corresponding cast to a signed int to insure that the
  753. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  754. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  755. */
  756. asmlinkage long sys32_readlink(const char __user * path, char __user * buf, u32 bufsiz)
  757. {
  758. return sys_readlink(path, buf, (int)bufsiz);
  759. }
  760. /* Note: it is necessary to treat option as an unsigned int,
  761. * with the corresponding cast to a signed int to insure that the
  762. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  763. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  764. */
  765. asmlinkage long sys32_sched_get_priority_max(u32 policy)
  766. {
  767. return sys_sched_get_priority_max((int)policy);
  768. }
  769. /* Note: it is necessary to treat policy as an unsigned int,
  770. * with the corresponding cast to a signed int to insure that the
  771. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  772. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  773. */
  774. asmlinkage long sys32_sched_get_priority_min(u32 policy)
  775. {
  776. return sys_sched_get_priority_min((int)policy);
  777. }
  778. /* Note: it is necessary to treat pid as an unsigned int,
  779. * with the corresponding cast to a signed int to insure that the
  780. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  781. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  782. */
  783. asmlinkage long sys32_sched_getparam(u32 pid, struct sched_param __user *param)
  784. {
  785. return sys_sched_getparam((int)pid, param);
  786. }
  787. /* Note: it is necessary to treat pid as an unsigned int,
  788. * with the corresponding cast to a signed int to insure that the
  789. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  790. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  791. */
  792. asmlinkage long sys32_sched_getscheduler(u32 pid)
  793. {
  794. return sys_sched_getscheduler((int)pid);
  795. }
  796. /* Note: it is necessary to treat pid as an unsigned int,
  797. * with the corresponding cast to a signed int to insure that the
  798. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  799. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  800. */
  801. asmlinkage long sys32_sched_setparam(u32 pid, struct sched_param __user *param)
  802. {
  803. return sys_sched_setparam((int)pid, param);
  804. }
  805. /* Note: it is necessary to treat pid and policy as unsigned ints,
  806. * with the corresponding cast to a signed int to insure that the
  807. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  808. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  809. */
  810. asmlinkage long sys32_sched_setscheduler(u32 pid, u32 policy, struct sched_param __user *param)
  811. {
  812. return sys_sched_setscheduler((int)pid, (int)policy, param);
  813. }
  814. /* Note: it is necessary to treat len as an unsigned int,
  815. * with the corresponding cast to a signed int to insure that the
  816. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  817. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  818. */
  819. asmlinkage long sys32_setdomainname(char __user *name, u32 len)
  820. {
  821. return sys_setdomainname(name, (int)len);
  822. }
  823. /* Note: it is necessary to treat gidsetsize as an unsigned int,
  824. * with the corresponding cast to a signed int to insure that the
  825. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  826. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  827. */
  828. asmlinkage long sys32_setgroups(u32 gidsetsize, gid_t __user *grouplist)
  829. {
  830. return sys_setgroups((int)gidsetsize, grouplist);
  831. }
  832. asmlinkage long sys32_sethostname(char __user *name, u32 len)
  833. {
  834. /* sign extend len */
  835. return sys_sethostname(name, (int)len);
  836. }
  837. /* Note: it is necessary to treat pid and pgid as unsigned ints,
  838. * with the corresponding cast to a signed int to insure that the
  839. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  840. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  841. */
  842. asmlinkage long sys32_setpgid(u32 pid, u32 pgid)
  843. {
  844. return sys_setpgid((int)pid, (int)pgid);
  845. }
  846. long sys32_getpriority(u32 which, u32 who)
  847. {
  848. /* sign extend which and who */
  849. return sys_getpriority((int)which, (int)who);
  850. }
  851. long sys32_setpriority(u32 which, u32 who, u32 niceval)
  852. {
  853. /* sign extend which, who and niceval */
  854. return sys_setpriority((int)which, (int)who, (int)niceval);
  855. }
  856. long sys32_ioprio_get(u32 which, u32 who)
  857. {
  858. /* sign extend which and who */
  859. return sys_ioprio_get((int)which, (int)who);
  860. }
  861. long sys32_ioprio_set(u32 which, u32 who, u32 ioprio)
  862. {
  863. /* sign extend which, who and ioprio */
  864. return sys_ioprio_set((int)which, (int)who, (int)ioprio);
  865. }
  866. /* Note: it is necessary to treat newmask as an unsigned int,
  867. * with the corresponding cast to a signed int to insure that the
  868. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  869. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  870. */
  871. asmlinkage long sys32_ssetmask(u32 newmask)
  872. {
  873. return sys_ssetmask((int) newmask);
  874. }
  875. asmlinkage long sys32_syslog(u32 type, char __user * buf, u32 len)
  876. {
  877. /* sign extend len */
  878. return sys_syslog(type, buf, (int)len);
  879. }
  880. /* Note: it is necessary to treat mask as an unsigned int,
  881. * with the corresponding cast to a signed int to insure that the
  882. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  883. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  884. */
  885. asmlinkage long sys32_umask(u32 mask)
  886. {
  887. return sys_umask((int)mask);
  888. }
  889. #ifdef CONFIG_SYSCTL
  890. struct __sysctl_args32 {
  891. u32 name;
  892. int nlen;
  893. u32 oldval;
  894. u32 oldlenp;
  895. u32 newval;
  896. u32 newlen;
  897. u32 __unused[4];
  898. };
  899. asmlinkage long sys32_sysctl(struct __sysctl_args32 __user *args)
  900. {
  901. struct __sysctl_args32 tmp;
  902. int error;
  903. size_t oldlen;
  904. size_t __user *oldlenp = NULL;
  905. unsigned long addr = (((unsigned long)&args->__unused[0]) + 7) & ~7;
  906. if (copy_from_user(&tmp, args, sizeof(tmp)))
  907. return -EFAULT;
  908. if (tmp.oldval && tmp.oldlenp) {
  909. /* Duh, this is ugly and might not work if sysctl_args
  910. is in read-only memory, but do_sysctl does indirectly
  911. a lot of uaccess in both directions and we'd have to
  912. basically copy the whole sysctl.c here, and
  913. glibc's __sysctl uses rw memory for the structure
  914. anyway. */
  915. oldlenp = (size_t __user *)addr;
  916. if (get_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)) ||
  917. put_user(oldlen, oldlenp))
  918. return -EFAULT;
  919. }
  920. lock_kernel();
  921. error = do_sysctl(compat_ptr(tmp.name), tmp.nlen,
  922. compat_ptr(tmp.oldval), oldlenp,
  923. compat_ptr(tmp.newval), tmp.newlen);
  924. unlock_kernel();
  925. if (oldlenp) {
  926. if (!error) {
  927. if (get_user(oldlen, oldlenp) ||
  928. put_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)))
  929. error = -EFAULT;
  930. }
  931. copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused));
  932. }
  933. return error;
  934. }
  935. #endif
  936. asmlinkage int sys32_uname(struct old_utsname __user * name)
  937. {
  938. int err = 0;
  939. down_read(&uts_sem);
  940. if (copy_to_user(name, &system_utsname, sizeof(*name)))
  941. err = -EFAULT;
  942. up_read(&uts_sem);
  943. if (!err && personality(current->personality) == PER_LINUX32) {
  944. /* change "ppc64" to "ppc" */
  945. if (__put_user(0, name->machine + 3)
  946. || __put_user(0, name->machine + 4))
  947. err = -EFAULT;
  948. }
  949. return err;
  950. }
  951. asmlinkage int sys32_olduname(struct oldold_utsname __user * name)
  952. {
  953. int error;
  954. if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
  955. return -EFAULT;
  956. down_read(&uts_sem);
  957. error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
  958. error |= __put_user(0,name->sysname+__OLD_UTS_LEN);
  959. error |= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
  960. error |= __put_user(0,name->nodename+__OLD_UTS_LEN);
  961. error |= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
  962. error |= __put_user(0,name->release+__OLD_UTS_LEN);
  963. error |= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
  964. error |= __put_user(0,name->version+__OLD_UTS_LEN);
  965. error |= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN);
  966. error |= __put_user(0,name->machine+__OLD_UTS_LEN);
  967. if (personality(current->personality) == PER_LINUX32) {
  968. /* change "ppc64" to "ppc" */
  969. error |= __put_user(0, name->machine + 3);
  970. error |= __put_user(0, name->machine + 4);
  971. }
  972. up_read(&uts_sem);
  973. error = error ? -EFAULT : 0;
  974. return error;
  975. }
  976. unsigned long sys32_mmap2(unsigned long addr, size_t len,
  977. unsigned long prot, unsigned long flags,
  978. unsigned long fd, unsigned long pgoff)
  979. {
  980. /* This should remain 12 even if PAGE_SIZE changes */
  981. return sys_mmap(addr, len, prot, flags, fd, pgoff << 12);
  982. }
  983. int get_compat_timeval(struct timeval *tv, struct compat_timeval __user *ctv)
  984. {
  985. return (!access_ok(VERIFY_READ, ctv, sizeof(*ctv)) ||
  986. __get_user(tv->tv_sec, &ctv->tv_sec) ||
  987. __get_user(tv->tv_usec, &ctv->tv_usec)) ? -EFAULT : 0;
  988. }
  989. asmlinkage long sys32_utimes(char __user *filename, struct compat_timeval __user *tvs)
  990. {
  991. struct timeval ktvs[2], *ptr;
  992. ptr = NULL;
  993. if (tvs) {
  994. if (get_compat_timeval(&ktvs[0], &tvs[0]) ||
  995. get_compat_timeval(&ktvs[1], &tvs[1]))
  996. return -EFAULT;
  997. ptr = ktvs;
  998. }
  999. return do_utimes(filename, ptr);
  1000. }
  1001. long sys32_tgkill(u32 tgid, u32 pid, int sig)
  1002. {
  1003. /* sign extend tgid, pid */
  1004. return sys_tgkill((int)tgid, (int)pid, sig);
  1005. }
  1006. /*
  1007. * long long munging:
  1008. * The 32 bit ABI passes long longs in an odd even register pair.
  1009. */
  1010. compat_ssize_t sys32_pread64(unsigned int fd, char __user *ubuf, compat_size_t count,
  1011. u32 reg6, u32 poshi, u32 poslo)
  1012. {
  1013. return sys_pread64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
  1014. }
  1015. compat_ssize_t sys32_pwrite64(unsigned int fd, char __user *ubuf, compat_size_t count,
  1016. u32 reg6, u32 poshi, u32 poslo)
  1017. {
  1018. return sys_pwrite64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
  1019. }
  1020. compat_ssize_t sys32_readahead(int fd, u32 r4, u32 offhi, u32 offlo, u32 count)
  1021. {
  1022. return sys_readahead(fd, ((loff_t)offhi << 32) | offlo, count);
  1023. }
  1024. asmlinkage int sys32_truncate64(const char __user * path, u32 reg4,
  1025. unsigned long high, unsigned long low)
  1026. {
  1027. return sys_truncate(path, (high << 32) | low);
  1028. }
  1029. asmlinkage int sys32_ftruncate64(unsigned int fd, u32 reg4, unsigned long high,
  1030. unsigned long low)
  1031. {
  1032. return sys_ftruncate(fd, (high << 32) | low);
  1033. }
  1034. long ppc32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char __user *buf,
  1035. size_t len)
  1036. {
  1037. return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low,
  1038. buf, len);
  1039. }
  1040. long ppc32_fadvise64(int fd, u32 unused, u32 offset_high, u32 offset_low,
  1041. size_t len, int advice)
  1042. {
  1043. return sys_fadvise64(fd, (u64)offset_high << 32 | offset_low, len,
  1044. advice);
  1045. }
  1046. long ppc32_fadvise64_64(int fd, int advice, u32 offset_high, u32 offset_low,
  1047. u32 len_high, u32 len_low)
  1048. {
  1049. return sys_fadvise64(fd, (u64)offset_high << 32 | offset_low,
  1050. (u64)len_high << 32 | len_low, advice);
  1051. }
  1052. long ppc32_timer_create(clockid_t clock,
  1053. struct compat_sigevent __user *ev32,
  1054. timer_t __user *timer_id)
  1055. {
  1056. sigevent_t event;
  1057. timer_t t;
  1058. long err;
  1059. mm_segment_t savefs;
  1060. if (ev32 == NULL)
  1061. return sys_timer_create(clock, NULL, timer_id);
  1062. if (get_compat_sigevent(&event, ev32))
  1063. return -EFAULT;
  1064. if (!access_ok(VERIFY_WRITE, timer_id, sizeof(timer_t)))
  1065. return -EFAULT;
  1066. savefs = get_fs();
  1067. set_fs(KERNEL_DS);
  1068. /* The __user pointer casts are valid due to the set_fs() */
  1069. err = sys_timer_create(clock,
  1070. (sigevent_t __user *) &event,
  1071. (timer_t __user *) &t);
  1072. set_fs(savefs);
  1073. if (err == 0)
  1074. err = __put_user(t, timer_id);
  1075. return err;
  1076. }
  1077. asmlinkage long sys32_add_key(const char __user *_type,
  1078. const char __user *_description,
  1079. const void __user *_payload,
  1080. u32 plen,
  1081. u32 ringid)
  1082. {
  1083. return sys_add_key(_type, _description, _payload, plen, ringid);
  1084. }
  1085. asmlinkage long sys32_request_key(const char __user *_type,
  1086. const char __user *_description,
  1087. const char __user *_callout_info,
  1088. u32 destringid)
  1089. {
  1090. return sys_request_key(_type, _description, _callout_info, destringid);
  1091. }