sys_parisc32.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. /*
  2. * sys_parisc32.c: Conversion between 32bit and 64bit native syscalls.
  3. *
  4. * Copyright (C) 2000-2001 Hewlett Packard Company
  5. * Copyright (C) 2000 John Marvin
  6. * Copyright (C) 2001 Matthew Wilcox
  7. *
  8. * These routines maintain argument size conversion between 32bit and 64bit
  9. * environment. Based heavily on sys_ia32.c and sys_sparc32.c.
  10. */
  11. #include <linux/compat.h>
  12. #include <linux/kernel.h>
  13. #include <linux/sched.h>
  14. #include <linux/fs.h>
  15. #include <linux/mm.h>
  16. #include <linux/file.h>
  17. #include <linux/signal.h>
  18. #include <linux/resource.h>
  19. #include <linux/times.h>
  20. #include <linux/utsname.h>
  21. #include <linux/time.h>
  22. #include <linux/smp.h>
  23. #include <linux/smp_lock.h>
  24. #include <linux/sem.h>
  25. #include <linux/msg.h>
  26. #include <linux/shm.h>
  27. #include <linux/slab.h>
  28. #include <linux/uio.h>
  29. #include <linux/nfs_fs.h>
  30. #include <linux/ncp_fs.h>
  31. #include <linux/sunrpc/svc.h>
  32. #include <linux/nfsd/nfsd.h>
  33. #include <linux/nfsd/cache.h>
  34. #include <linux/nfsd/xdr.h>
  35. #include <linux/nfsd/syscall.h>
  36. #include <linux/poll.h>
  37. #include <linux/personality.h>
  38. #include <linux/stat.h>
  39. #include <linux/highmem.h>
  40. #include <linux/highuid.h>
  41. #include <linux/mman.h>
  42. #include <linux/binfmts.h>
  43. #include <linux/namei.h>
  44. #include <linux/vfs.h>
  45. #include <linux/ptrace.h>
  46. #include <linux/swap.h>
  47. #include <linux/syscalls.h>
  48. #include <asm/types.h>
  49. #include <asm/uaccess.h>
  50. #include <asm/mmu_context.h>
  51. #include "sys32.h"
  52. #undef DEBUG
  53. #ifdef DEBUG
  54. #define DBG(x) printk x
  55. #else
  56. #define DBG(x)
  57. #endif
  58. /*
  59. * sys32_execve() executes a new program.
  60. */
  61. asmlinkage int sys32_execve(struct pt_regs *regs)
  62. {
  63. int error;
  64. char *filename;
  65. DBG(("sys32_execve(%p) r26 = 0x%lx\n", regs, regs->gr[26]));
  66. filename = getname((const char __user *) regs->gr[26]);
  67. error = PTR_ERR(filename);
  68. if (IS_ERR(filename))
  69. goto out;
  70. error = compat_do_execve(filename, compat_ptr(regs->gr[25]),
  71. compat_ptr(regs->gr[24]), regs);
  72. if (error == 0) {
  73. task_lock(current);
  74. current->ptrace &= ~PT_DTRACE;
  75. task_unlock(current);
  76. }
  77. putname(filename);
  78. out:
  79. return error;
  80. }
  81. asmlinkage long sys32_unimplemented(int r26, int r25, int r24, int r23,
  82. int r22, int r21, int r20)
  83. {
  84. printk(KERN_ERR "%s(%d): Unimplemented 32 on 64 syscall #%d!\n",
  85. current->comm, current->pid, r20);
  86. return -ENOSYS;
  87. }
  88. #ifdef CONFIG_SYSCTL
  89. struct __sysctl_args32 {
  90. u32 name;
  91. int nlen;
  92. u32 oldval;
  93. u32 oldlenp;
  94. u32 newval;
  95. u32 newlen;
  96. u32 __unused[4];
  97. };
  98. asmlinkage long sys32_sysctl(struct __sysctl_args32 __user *args)
  99. {
  100. #ifndef CONFIG_SYSCTL_SYSCALL
  101. return -ENOSYS;
  102. #else
  103. struct __sysctl_args32 tmp;
  104. int error;
  105. unsigned int oldlen32;
  106. size_t oldlen, __user *oldlenp = NULL;
  107. unsigned long addr = (((long __force)&args->__unused[0]) + 7) & ~7;
  108. DBG(("sysctl32(%p)\n", args));
  109. if (copy_from_user(&tmp, args, sizeof(tmp)))
  110. return -EFAULT;
  111. if (tmp.oldval && tmp.oldlenp) {
  112. /* Duh, this is ugly and might not work if sysctl_args
  113. is in read-only memory, but do_sysctl does indirectly
  114. a lot of uaccess in both directions and we'd have to
  115. basically copy the whole sysctl.c here, and
  116. glibc's __sysctl uses rw memory for the structure
  117. anyway. */
  118. /* a possibly better hack than this, which will avoid the
  119. * problem if the struct is read only, is to push the
  120. * 'oldlen' value out to the user's stack instead. -PB
  121. */
  122. if (get_user(oldlen32, (u32 *)(u64)tmp.oldlenp))
  123. return -EFAULT;
  124. oldlen = oldlen32;
  125. if (put_user(oldlen, (size_t *)addr))
  126. return -EFAULT;
  127. oldlenp = (size_t *)addr;
  128. }
  129. lock_kernel();
  130. error = do_sysctl((int __user *)(u64)tmp.name, tmp.nlen,
  131. (void __user *)(u64)tmp.oldval, oldlenp,
  132. (void __user *)(u64)tmp.newval, tmp.newlen);
  133. unlock_kernel();
  134. if (oldlenp) {
  135. if (!error) {
  136. if (get_user(oldlen, (size_t *)addr)) {
  137. error = -EFAULT;
  138. } else {
  139. oldlen32 = oldlen;
  140. if (put_user(oldlen32, (u32 *)(u64)tmp.oldlenp))
  141. error = -EFAULT;
  142. }
  143. }
  144. if (copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused)))
  145. error = -EFAULT;
  146. }
  147. return error;
  148. #endif
  149. }
  150. #endif /* CONFIG_SYSCTL */
  151. asmlinkage long sys32_sched_rr_get_interval(pid_t pid,
  152. struct compat_timespec __user *interval)
  153. {
  154. struct timespec t;
  155. int ret;
  156. KERNEL_SYSCALL(ret, sys_sched_rr_get_interval, pid, (struct timespec __user *)&t);
  157. if (put_compat_timespec(&t, interval))
  158. return -EFAULT;
  159. return ret;
  160. }
  161. static int
  162. put_compat_timeval(struct compat_timeval __user *u, struct timeval *t)
  163. {
  164. struct compat_timeval t32;
  165. t32.tv_sec = t->tv_sec;
  166. t32.tv_usec = t->tv_usec;
  167. return copy_to_user(u, &t32, sizeof t32);
  168. }
  169. static inline long get_ts32(struct timespec *o, struct compat_timeval __user *i)
  170. {
  171. long usec;
  172. if (__get_user(o->tv_sec, &i->tv_sec))
  173. return -EFAULT;
  174. if (__get_user(usec, &i->tv_usec))
  175. return -EFAULT;
  176. o->tv_nsec = usec * 1000;
  177. return 0;
  178. }
  179. asmlinkage int
  180. sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
  181. {
  182. extern void do_gettimeofday(struct timeval *tv);
  183. if (tv) {
  184. struct timeval ktv;
  185. do_gettimeofday(&ktv);
  186. if (put_compat_timeval(tv, &ktv))
  187. return -EFAULT;
  188. }
  189. if (tz) {
  190. extern struct timezone sys_tz;
  191. if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
  192. return -EFAULT;
  193. }
  194. return 0;
  195. }
  196. asmlinkage
  197. int sys32_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
  198. {
  199. struct timespec kts;
  200. struct timezone ktz;
  201. if (tv) {
  202. if (get_ts32(&kts, tv))
  203. return -EFAULT;
  204. }
  205. if (tz) {
  206. if (copy_from_user(&ktz, tz, sizeof(ktz)))
  207. return -EFAULT;
  208. }
  209. return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
  210. }
  211. int cp_compat_stat(struct kstat *stat, struct compat_stat __user *statbuf)
  212. {
  213. compat_ino_t ino;
  214. int err;
  215. if (stat->size > MAX_NON_LFS || !new_valid_dev(stat->dev) ||
  216. !new_valid_dev(stat->rdev))
  217. return -EOVERFLOW;
  218. ino = stat->ino;
  219. if (sizeof(ino) < sizeof(stat->ino) && ino != stat->ino)
  220. return -EOVERFLOW;
  221. err = put_user(new_encode_dev(stat->dev), &statbuf->st_dev);
  222. err |= put_user(ino, &statbuf->st_ino);
  223. err |= put_user(stat->mode, &statbuf->st_mode);
  224. err |= put_user(stat->nlink, &statbuf->st_nlink);
  225. err |= put_user(0, &statbuf->st_reserved1);
  226. err |= put_user(0, &statbuf->st_reserved2);
  227. err |= put_user(new_encode_dev(stat->rdev), &statbuf->st_rdev);
  228. err |= put_user(stat->size, &statbuf->st_size);
  229. err |= put_user(stat->atime.tv_sec, &statbuf->st_atime);
  230. err |= put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);
  231. err |= put_user(stat->mtime.tv_sec, &statbuf->st_mtime);
  232. err |= put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);
  233. err |= put_user(stat->ctime.tv_sec, &statbuf->st_ctime);
  234. err |= put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);
  235. err |= put_user(stat->blksize, &statbuf->st_blksize);
  236. err |= put_user(stat->blocks, &statbuf->st_blocks);
  237. err |= put_user(0, &statbuf->__unused1);
  238. err |= put_user(0, &statbuf->__unused2);
  239. err |= put_user(0, &statbuf->__unused3);
  240. err |= put_user(0, &statbuf->__unused4);
  241. err |= put_user(0, &statbuf->__unused5);
  242. err |= put_user(0, &statbuf->st_fstype); /* not avail */
  243. err |= put_user(0, &statbuf->st_realdev); /* not avail */
  244. err |= put_user(0, &statbuf->st_basemode); /* not avail */
  245. err |= put_user(0, &statbuf->st_spareshort);
  246. err |= put_user(stat->uid, &statbuf->st_uid);
  247. err |= put_user(stat->gid, &statbuf->st_gid);
  248. err |= put_user(0, &statbuf->st_spare4[0]);
  249. err |= put_user(0, &statbuf->st_spare4[1]);
  250. err |= put_user(0, &statbuf->st_spare4[2]);
  251. return err;
  252. }
  253. /*** copied from mips64 ***/
  254. /*
  255. * Ooo, nasty. We need here to frob 32-bit unsigned longs to
  256. * 64-bit unsigned longs.
  257. */
  258. static inline int
  259. get_fd_set32(unsigned long n, u32 *ufdset, unsigned long *fdset)
  260. {
  261. n = (n + 8*sizeof(u32) - 1) / (8*sizeof(u32));
  262. if (ufdset) {
  263. unsigned long odd;
  264. if (!access_ok(VERIFY_WRITE, ufdset, n*sizeof(u32)))
  265. return -EFAULT;
  266. odd = n & 1UL;
  267. n &= ~1UL;
  268. while (n) {
  269. unsigned long h, l;
  270. __get_user(l, ufdset);
  271. __get_user(h, ufdset+1);
  272. ufdset += 2;
  273. *fdset++ = h << 32 | l;
  274. n -= 2;
  275. }
  276. if (odd)
  277. __get_user(*fdset, ufdset);
  278. } else {
  279. /* Tricky, must clear full unsigned long in the
  280. * kernel fdset at the end, this makes sure that
  281. * actually happens.
  282. */
  283. memset(fdset, 0, ((n + 1) & ~1)*sizeof(u32));
  284. }
  285. return 0;
  286. }
  287. static inline void
  288. set_fd_set32(unsigned long n, u32 *ufdset, unsigned long *fdset)
  289. {
  290. unsigned long odd;
  291. n = (n + 8*sizeof(u32) - 1) / (8*sizeof(u32));
  292. if (!ufdset)
  293. return;
  294. odd = n & 1UL;
  295. n &= ~1UL;
  296. while (n) {
  297. unsigned long h, l;
  298. l = *fdset++;
  299. h = l >> 32;
  300. __put_user(l, ufdset);
  301. __put_user(h, ufdset+1);
  302. ufdset += 2;
  303. n -= 2;
  304. }
  305. if (odd)
  306. __put_user(*fdset, ufdset);
  307. }
  308. struct msgbuf32 {
  309. int mtype;
  310. char mtext[1];
  311. };
  312. asmlinkage long sys32_msgsnd(int msqid,
  313. struct msgbuf32 __user *umsgp32,
  314. size_t msgsz, int msgflg)
  315. {
  316. struct msgbuf *mb;
  317. struct msgbuf32 mb32;
  318. int err;
  319. if ((mb = kmalloc(msgsz + sizeof *mb + 4, GFP_KERNEL)) == NULL)
  320. return -ENOMEM;
  321. err = get_user(mb32.mtype, &umsgp32->mtype);
  322. mb->mtype = mb32.mtype;
  323. err |= copy_from_user(mb->mtext, &umsgp32->mtext, msgsz);
  324. if (err)
  325. err = -EFAULT;
  326. else
  327. KERNEL_SYSCALL(err, sys_msgsnd, msqid, (struct msgbuf __user *)mb, msgsz, msgflg);
  328. kfree(mb);
  329. return err;
  330. }
  331. asmlinkage long sys32_msgrcv(int msqid,
  332. struct msgbuf32 __user *umsgp32,
  333. size_t msgsz, long msgtyp, int msgflg)
  334. {
  335. struct msgbuf *mb;
  336. struct msgbuf32 mb32;
  337. int err, len;
  338. if ((mb = kmalloc(msgsz + sizeof *mb + 4, GFP_KERNEL)) == NULL)
  339. return -ENOMEM;
  340. KERNEL_SYSCALL(err, sys_msgrcv, msqid, (struct msgbuf __user *)mb, msgsz, msgtyp, msgflg);
  341. if (err >= 0) {
  342. len = err;
  343. mb32.mtype = mb->mtype;
  344. err = put_user(mb32.mtype, &umsgp32->mtype);
  345. err |= copy_to_user(&umsgp32->mtext, mb->mtext, len);
  346. if (err)
  347. err = -EFAULT;
  348. else
  349. err = len;
  350. }
  351. kfree(mb);
  352. return err;
  353. }
  354. asmlinkage int sys32_sendfile(int out_fd, int in_fd, compat_off_t __user *offset, s32 count)
  355. {
  356. mm_segment_t old_fs = get_fs();
  357. int ret;
  358. off_t of;
  359. if (offset && get_user(of, offset))
  360. return -EFAULT;
  361. set_fs(KERNEL_DS);
  362. ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL, count);
  363. set_fs(old_fs);
  364. if (offset && put_user(of, offset))
  365. return -EFAULT;
  366. return ret;
  367. }
  368. asmlinkage int sys32_sendfile64(int out_fd, int in_fd, compat_loff_t __user *offset, s32 count)
  369. {
  370. mm_segment_t old_fs = get_fs();
  371. int ret;
  372. loff_t lof;
  373. if (offset && get_user(lof, offset))
  374. return -EFAULT;
  375. set_fs(KERNEL_DS);
  376. ret = sys_sendfile64(out_fd, in_fd, offset ? (loff_t __user *)&lof : NULL, count);
  377. set_fs(old_fs);
  378. if (offset && put_user(lof, offset))
  379. return -EFAULT;
  380. return ret;
  381. }
  382. /* lseek() needs a wrapper because 'offset' can be negative, but the top
  383. * half of the argument has been zeroed by syscall.S.
  384. */
  385. asmlinkage int sys32_lseek(unsigned int fd, int offset, unsigned int origin)
  386. {
  387. return sys_lseek(fd, offset, origin);
  388. }
  389. asmlinkage long sys32_semctl(int semid, int semnum, int cmd, union semun arg)
  390. {
  391. union semun u;
  392. if (cmd == SETVAL) {
  393. /* Ugh. arg is a union of int,ptr,ptr,ptr, so is 8 bytes.
  394. * The int should be in the first 4, but our argument
  395. * frobbing has left it in the last 4.
  396. */
  397. u.val = *((int *)&arg + 1);
  398. return sys_semctl (semid, semnum, cmd, u);
  399. }
  400. return sys_semctl (semid, semnum, cmd, arg);
  401. }
  402. long sys32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char __user *buf,
  403. size_t len)
  404. {
  405. return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low,
  406. buf, len);
  407. }
  408. asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo,
  409. u32 lenhi, u32 lenlo)
  410. {
  411. return sys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo,
  412. ((loff_t)lenhi << 32) | lenlo);
  413. }