sys_ppc32.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325
  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. struct pci_controller* hose;
  647. struct list_head *ln;
  648. struct pci_bus *bus = NULL;
  649. struct device_node *hose_node;
  650. /* Argh ! Please forgive me for that hack, but that's the
  651. * simplest way to get existing XFree to not lockup on some
  652. * G5 machines... So when something asks for bus 0 io base
  653. * (bus 0 is HT root), we return the AGP one instead.
  654. */
  655. #ifdef CONFIG_PPC_PMAC
  656. if (systemcfg->platform == PLATFORM_POWERMAC &&
  657. machine_is_compatible("MacRISC4"))
  658. if (in_bus == 0)
  659. in_bus = 0xf0;
  660. #endif /* CONFIG_PPC_PMAC */
  661. /* That syscall isn't quite compatible with PCI domains, but it's
  662. * used on pre-domains setup. We return the first match
  663. */
  664. for (ln = pci_root_buses.next; ln != &pci_root_buses; ln = ln->next) {
  665. bus = pci_bus_b(ln);
  666. if (in_bus >= bus->number && in_bus < (bus->number + bus->subordinate))
  667. break;
  668. bus = NULL;
  669. }
  670. if (bus == NULL || bus->sysdata == NULL)
  671. return -ENODEV;
  672. hose_node = (struct device_node *)bus->sysdata;
  673. hose = hose_node->phb;
  674. switch (which) {
  675. case IOBASE_BRIDGE_NUMBER:
  676. return (long)hose->first_busno;
  677. case IOBASE_MEMORY:
  678. return (long)hose->pci_mem_offset;
  679. case IOBASE_IO:
  680. return (long)hose->io_base_phys;
  681. case IOBASE_ISA_IO:
  682. return (long)isa_io_base;
  683. case IOBASE_ISA_MEM:
  684. return -EINVAL;
  685. }
  686. return -EOPNOTSUPP;
  687. }
  688. /* Note: it is necessary to treat mode as an unsigned int,
  689. * with the corresponding cast to a signed int to insure that the
  690. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  691. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  692. */
  693. asmlinkage long sys32_access(const char __user * filename, u32 mode)
  694. {
  695. return sys_access(filename, (int)mode);
  696. }
  697. /* Note: it is necessary to treat mode as an unsigned int,
  698. * with the corresponding cast to a signed int to insure that the
  699. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  700. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  701. */
  702. asmlinkage long sys32_creat(const char __user * pathname, u32 mode)
  703. {
  704. return sys_creat(pathname, (int)mode);
  705. }
  706. /* Note: it is necessary to treat pid and options as unsigned ints,
  707. * with the corresponding cast to a signed int to insure that the
  708. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  709. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  710. */
  711. asmlinkage long sys32_waitpid(u32 pid, unsigned int __user * stat_addr, u32 options)
  712. {
  713. return sys_waitpid((int)pid, stat_addr, (int)options);
  714. }
  715. /* Note: it is necessary to treat gidsetsize as an unsigned int,
  716. * with the corresponding cast to a signed int to insure that the
  717. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  718. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  719. */
  720. asmlinkage long sys32_getgroups(u32 gidsetsize, gid_t __user *grouplist)
  721. {
  722. return sys_getgroups((int)gidsetsize, grouplist);
  723. }
  724. /* Note: it is necessary to treat pid as an unsigned int,
  725. * with the corresponding cast to a signed int to insure that the
  726. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  727. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  728. */
  729. asmlinkage long sys32_getpgid(u32 pid)
  730. {
  731. return sys_getpgid((int)pid);
  732. }
  733. /* Note: it is necessary to treat which and who as unsigned ints,
  734. * with the corresponding cast to a signed int to insure that the
  735. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  736. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  737. */
  738. asmlinkage long sys32_getpriority(u32 which, u32 who)
  739. {
  740. return sys_getpriority((int)which, (int)who);
  741. }
  742. /* Note: it is necessary to treat pid as an unsigned int,
  743. * with the corresponding cast to a signed int to insure that the
  744. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  745. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  746. */
  747. asmlinkage long sys32_getsid(u32 pid)
  748. {
  749. return sys_getsid((int)pid);
  750. }
  751. /* Note: it is necessary to treat pid and sig as unsigned ints,
  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_kill(u32 pid, u32 sig)
  757. {
  758. return sys_kill((int)pid, (int)sig);
  759. }
  760. /* Note: it is necessary to treat mode 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_mkdir(const char __user * pathname, u32 mode)
  766. {
  767. return sys_mkdir(pathname, (int)mode);
  768. }
  769. long sys32_nice(u32 increment)
  770. {
  771. /* sign extend increment */
  772. return sys_nice((int)increment);
  773. }
  774. off_t ppc32_lseek(unsigned int fd, u32 offset, unsigned int origin)
  775. {
  776. /* sign extend n */
  777. return sys_lseek(fd, (int)offset, origin);
  778. }
  779. /*
  780. * This is just a version for 32-bit applications which does
  781. * not force O_LARGEFILE on.
  782. */
  783. asmlinkage long sys32_open(const char __user * filename, int flags, int mode)
  784. {
  785. char * tmp;
  786. int fd, error;
  787. tmp = getname(filename);
  788. fd = PTR_ERR(tmp);
  789. if (!IS_ERR(tmp)) {
  790. fd = get_unused_fd();
  791. if (fd >= 0) {
  792. struct file * f = filp_open(tmp, flags, mode);
  793. error = PTR_ERR(f);
  794. if (IS_ERR(f))
  795. goto out_error;
  796. fd_install(fd, f);
  797. }
  798. out:
  799. putname(tmp);
  800. }
  801. return fd;
  802. out_error:
  803. put_unused_fd(fd);
  804. fd = error;
  805. goto out;
  806. }
  807. /* Note: it is necessary to treat bufsiz as an unsigned int,
  808. * with the corresponding cast to a signed int to insure that the
  809. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  810. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  811. */
  812. asmlinkage long sys32_readlink(const char __user * path, char __user * buf, u32 bufsiz)
  813. {
  814. return sys_readlink(path, buf, (int)bufsiz);
  815. }
  816. /* Note: it is necessary to treat option as an unsigned int,
  817. * with the corresponding cast to a signed int to insure that the
  818. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  819. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  820. */
  821. asmlinkage long sys32_sched_get_priority_max(u32 policy)
  822. {
  823. return sys_sched_get_priority_max((int)policy);
  824. }
  825. /* Note: it is necessary to treat policy as an unsigned int,
  826. * with the corresponding cast to a signed int to insure that the
  827. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  828. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  829. */
  830. asmlinkage long sys32_sched_get_priority_min(u32 policy)
  831. {
  832. return sys_sched_get_priority_min((int)policy);
  833. }
  834. /* Note: it is necessary to treat pid as an unsigned int,
  835. * with the corresponding cast to a signed int to insure that the
  836. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  837. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  838. */
  839. asmlinkage long sys32_sched_getparam(u32 pid, struct sched_param __user *param)
  840. {
  841. return sys_sched_getparam((int)pid, param);
  842. }
  843. /* Note: it is necessary to treat pid as an unsigned int,
  844. * with the corresponding cast to a signed int to insure that the
  845. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  846. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  847. */
  848. asmlinkage long sys32_sched_getscheduler(u32 pid)
  849. {
  850. return sys_sched_getscheduler((int)pid);
  851. }
  852. /* Note: it is necessary to treat pid as an unsigned int,
  853. * with the corresponding cast to a signed int to insure that the
  854. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  855. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  856. */
  857. asmlinkage long sys32_sched_setparam(u32 pid, struct sched_param __user *param)
  858. {
  859. return sys_sched_setparam((int)pid, param);
  860. }
  861. /* Note: it is necessary to treat pid and policy as unsigned ints,
  862. * with the corresponding cast to a signed int to insure that the
  863. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  864. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  865. */
  866. asmlinkage long sys32_sched_setscheduler(u32 pid, u32 policy, struct sched_param __user *param)
  867. {
  868. return sys_sched_setscheduler((int)pid, (int)policy, param);
  869. }
  870. /* Note: it is necessary to treat len as an unsigned int,
  871. * with the corresponding cast to a signed int to insure that the
  872. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  873. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  874. */
  875. asmlinkage long sys32_setdomainname(char __user *name, u32 len)
  876. {
  877. return sys_setdomainname(name, (int)len);
  878. }
  879. /* Note: it is necessary to treat gidsetsize as an unsigned int,
  880. * with the corresponding cast to a signed int to insure that the
  881. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  882. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  883. */
  884. asmlinkage long sys32_setgroups(u32 gidsetsize, gid_t __user *grouplist)
  885. {
  886. return sys_setgroups((int)gidsetsize, grouplist);
  887. }
  888. asmlinkage long sys32_sethostname(char __user *name, u32 len)
  889. {
  890. /* sign extend len */
  891. return sys_sethostname(name, (int)len);
  892. }
  893. /* Note: it is necessary to treat pid and pgid as unsigned ints,
  894. * with the corresponding cast to a signed int to insure that the
  895. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  896. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  897. */
  898. asmlinkage long sys32_setpgid(u32 pid, u32 pgid)
  899. {
  900. return sys_setpgid((int)pid, (int)pgid);
  901. }
  902. long sys32_setpriority(u32 which, u32 who, u32 niceval)
  903. {
  904. /* sign extend which, who and niceval */
  905. return sys_setpriority((int)which, (int)who, (int)niceval);
  906. }
  907. /* Note: it is necessary to treat newmask as an unsigned int,
  908. * with the corresponding cast to a signed int to insure that the
  909. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  910. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  911. */
  912. asmlinkage long sys32_ssetmask(u32 newmask)
  913. {
  914. return sys_ssetmask((int) newmask);
  915. }
  916. asmlinkage long sys32_syslog(u32 type, char __user * buf, u32 len)
  917. {
  918. /* sign extend len */
  919. return sys_syslog(type, buf, (int)len);
  920. }
  921. /* Note: it is necessary to treat mask as an unsigned int,
  922. * with the corresponding cast to a signed int to insure that the
  923. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  924. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  925. */
  926. asmlinkage long sys32_umask(u32 mask)
  927. {
  928. return sys_umask((int)mask);
  929. }
  930. #ifdef CONFIG_SYSCTL
  931. struct __sysctl_args32 {
  932. u32 name;
  933. int nlen;
  934. u32 oldval;
  935. u32 oldlenp;
  936. u32 newval;
  937. u32 newlen;
  938. u32 __unused[4];
  939. };
  940. asmlinkage long sys32_sysctl(struct __sysctl_args32 __user *args)
  941. {
  942. struct __sysctl_args32 tmp;
  943. int error;
  944. size_t oldlen;
  945. size_t __user *oldlenp = NULL;
  946. unsigned long addr = (((unsigned long)&args->__unused[0]) + 7) & ~7;
  947. if (copy_from_user(&tmp, args, sizeof(tmp)))
  948. return -EFAULT;
  949. if (tmp.oldval && tmp.oldlenp) {
  950. /* Duh, this is ugly and might not work if sysctl_args
  951. is in read-only memory, but do_sysctl does indirectly
  952. a lot of uaccess in both directions and we'd have to
  953. basically copy the whole sysctl.c here, and
  954. glibc's __sysctl uses rw memory for the structure
  955. anyway. */
  956. oldlenp = (size_t __user *)addr;
  957. if (get_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)) ||
  958. put_user(oldlen, oldlenp))
  959. return -EFAULT;
  960. }
  961. lock_kernel();
  962. error = do_sysctl(compat_ptr(tmp.name), tmp.nlen,
  963. compat_ptr(tmp.oldval), oldlenp,
  964. compat_ptr(tmp.newval), tmp.newlen);
  965. unlock_kernel();
  966. if (oldlenp) {
  967. if (!error) {
  968. if (get_user(oldlen, oldlenp) ||
  969. put_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)))
  970. error = -EFAULT;
  971. }
  972. copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused));
  973. }
  974. return error;
  975. }
  976. #endif
  977. asmlinkage int sys32_uname(struct old_utsname __user * name)
  978. {
  979. int err = 0;
  980. down_read(&uts_sem);
  981. if (copy_to_user(name, &system_utsname, sizeof(*name)))
  982. err = -EFAULT;
  983. up_read(&uts_sem);
  984. if (!err && personality(current->personality) == PER_LINUX32) {
  985. /* change "ppc64" to "ppc" */
  986. if (__put_user(0, name->machine + 3)
  987. || __put_user(0, name->machine + 4))
  988. err = -EFAULT;
  989. }
  990. return err;
  991. }
  992. asmlinkage int sys32_olduname(struct oldold_utsname __user * name)
  993. {
  994. int error;
  995. if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
  996. return -EFAULT;
  997. down_read(&uts_sem);
  998. error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
  999. error |= __put_user(0,name->sysname+__OLD_UTS_LEN);
  1000. error |= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
  1001. error |= __put_user(0,name->nodename+__OLD_UTS_LEN);
  1002. error |= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
  1003. error |= __put_user(0,name->release+__OLD_UTS_LEN);
  1004. error |= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
  1005. error |= __put_user(0,name->version+__OLD_UTS_LEN);
  1006. error |= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN);
  1007. error |= __put_user(0,name->machine+__OLD_UTS_LEN);
  1008. if (personality(current->personality) == PER_LINUX32) {
  1009. /* change "ppc64" to "ppc" */
  1010. error |= __put_user(0, name->machine + 3);
  1011. error |= __put_user(0, name->machine + 4);
  1012. }
  1013. up_read(&uts_sem);
  1014. error = error ? -EFAULT : 0;
  1015. return error;
  1016. }
  1017. unsigned long sys32_mmap2(unsigned long addr, size_t len,
  1018. unsigned long prot, unsigned long flags,
  1019. unsigned long fd, unsigned long pgoff)
  1020. {
  1021. /* This should remain 12 even if PAGE_SIZE changes */
  1022. return sys_mmap(addr, len, prot, flags, fd, pgoff << 12);
  1023. }
  1024. int get_compat_timeval(struct timeval *tv, struct compat_timeval __user *ctv)
  1025. {
  1026. return (!access_ok(VERIFY_READ, ctv, sizeof(*ctv)) ||
  1027. __get_user(tv->tv_sec, &ctv->tv_sec) ||
  1028. __get_user(tv->tv_usec, &ctv->tv_usec)) ? -EFAULT : 0;
  1029. }
  1030. asmlinkage long sys32_utimes(char __user *filename, struct compat_timeval __user *tvs)
  1031. {
  1032. struct timeval ktvs[2], *ptr;
  1033. ptr = NULL;
  1034. if (tvs) {
  1035. if (get_compat_timeval(&ktvs[0], &tvs[0]) ||
  1036. get_compat_timeval(&ktvs[1], &tvs[1]))
  1037. return -EFAULT;
  1038. ptr = ktvs;
  1039. }
  1040. return do_utimes(filename, ptr);
  1041. }
  1042. long sys32_tgkill(u32 tgid, u32 pid, int sig)
  1043. {
  1044. /* sign extend tgid, pid */
  1045. return sys_tgkill((int)tgid, (int)pid, sig);
  1046. }
  1047. /*
  1048. * long long munging:
  1049. * The 32 bit ABI passes long longs in an odd even register pair.
  1050. */
  1051. compat_ssize_t sys32_pread64(unsigned int fd, char __user *ubuf, compat_size_t count,
  1052. u32 reg6, u32 poshi, u32 poslo)
  1053. {
  1054. return sys_pread64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
  1055. }
  1056. compat_ssize_t sys32_pwrite64(unsigned int fd, char __user *ubuf, compat_size_t count,
  1057. u32 reg6, u32 poshi, u32 poslo)
  1058. {
  1059. return sys_pwrite64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
  1060. }
  1061. compat_ssize_t sys32_readahead(int fd, u32 r4, u32 offhi, u32 offlo, u32 count)
  1062. {
  1063. return sys_readahead(fd, ((loff_t)offhi << 32) | offlo, count);
  1064. }
  1065. asmlinkage int sys32_truncate64(const char __user * path, u32 reg4,
  1066. unsigned long high, unsigned long low)
  1067. {
  1068. return sys_truncate(path, (high << 32) | low);
  1069. }
  1070. asmlinkage int sys32_ftruncate64(unsigned int fd, u32 reg4, unsigned long high,
  1071. unsigned long low)
  1072. {
  1073. return sys_ftruncate(fd, (high << 32) | low);
  1074. }
  1075. long ppc32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char __user *buf,
  1076. size_t len)
  1077. {
  1078. return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low,
  1079. buf, len);
  1080. }
  1081. long ppc32_fadvise64(int fd, u32 unused, u32 offset_high, u32 offset_low,
  1082. size_t len, int advice)
  1083. {
  1084. return sys_fadvise64(fd, (u64)offset_high << 32 | offset_low, len,
  1085. advice);
  1086. }
  1087. long ppc32_fadvise64_64(int fd, int advice, u32 offset_high, u32 offset_low,
  1088. u32 len_high, u32 len_low)
  1089. {
  1090. return sys_fadvise64(fd, (u64)offset_high << 32 | offset_low,
  1091. (u64)len_high << 32 | len_low, advice);
  1092. }
  1093. extern asmlinkage long sys_timer_create(clockid_t, sigevent_t __user *, timer_t __user *);
  1094. long ppc32_timer_create(clockid_t clock,
  1095. struct compat_sigevent __user *ev32,
  1096. timer_t __user *timer_id)
  1097. {
  1098. sigevent_t event;
  1099. timer_t t;
  1100. long err;
  1101. mm_segment_t savefs;
  1102. if (ev32 == NULL)
  1103. return sys_timer_create(clock, NULL, timer_id);
  1104. if (get_compat_sigevent(&event, ev32))
  1105. return -EFAULT;
  1106. if (!access_ok(VERIFY_WRITE, timer_id, sizeof(timer_t)))
  1107. return -EFAULT;
  1108. savefs = get_fs();
  1109. set_fs(KERNEL_DS);
  1110. /* The __user pointer casts are valid due to the set_fs() */
  1111. err = sys_timer_create(clock,
  1112. (sigevent_t __user *) &event,
  1113. (timer_t __user *) &t);
  1114. set_fs(savefs);
  1115. if (err == 0)
  1116. err = __put_user(t, timer_id);
  1117. return err;
  1118. }
  1119. asmlinkage long sys32_add_key(const char __user *_type,
  1120. const char __user *_description,
  1121. const void __user *_payload,
  1122. u32 plen,
  1123. u32 ringid)
  1124. {
  1125. return sys_add_key(_type, _description, _payload, plen, ringid);
  1126. }
  1127. asmlinkage long sys32_request_key(const char __user *_type,
  1128. const char __user *_description,
  1129. const char __user *_callout_info,
  1130. u32 destringid)
  1131. {
  1132. return sys_request_key(_type, _description, _callout_info, destringid);
  1133. }