sys_ppc32.c 30 KB

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