sys_ppc32.c 38 KB

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