sys_parisc32.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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. /*** copied from mips64 ***/
  162. /*
  163. * Ooo, nasty. We need here to frob 32-bit unsigned longs to
  164. * 64-bit unsigned longs.
  165. */
  166. static inline int
  167. get_fd_set32(unsigned long n, u32 *ufdset, unsigned long *fdset)
  168. {
  169. n = (n + 8*sizeof(u32) - 1) / (8*sizeof(u32));
  170. if (ufdset) {
  171. unsigned long odd;
  172. if (!access_ok(VERIFY_WRITE, ufdset, n*sizeof(u32)))
  173. return -EFAULT;
  174. odd = n & 1UL;
  175. n &= ~1UL;
  176. while (n) {
  177. unsigned long h, l;
  178. __get_user(l, ufdset);
  179. __get_user(h, ufdset+1);
  180. ufdset += 2;
  181. *fdset++ = h << 32 | l;
  182. n -= 2;
  183. }
  184. if (odd)
  185. __get_user(*fdset, ufdset);
  186. } else {
  187. /* Tricky, must clear full unsigned long in the
  188. * kernel fdset at the end, this makes sure that
  189. * actually happens.
  190. */
  191. memset(fdset, 0, ((n + 1) & ~1)*sizeof(u32));
  192. }
  193. return 0;
  194. }
  195. static inline void
  196. set_fd_set32(unsigned long n, u32 *ufdset, unsigned long *fdset)
  197. {
  198. unsigned long odd;
  199. n = (n + 8*sizeof(u32) - 1) / (8*sizeof(u32));
  200. if (!ufdset)
  201. return;
  202. odd = n & 1UL;
  203. n &= ~1UL;
  204. while (n) {
  205. unsigned long h, l;
  206. l = *fdset++;
  207. h = l >> 32;
  208. __put_user(l, ufdset);
  209. __put_user(h, ufdset+1);
  210. ufdset += 2;
  211. n -= 2;
  212. }
  213. if (odd)
  214. __put_user(*fdset, ufdset);
  215. }
  216. struct msgbuf32 {
  217. int mtype;
  218. char mtext[1];
  219. };
  220. asmlinkage long sys32_msgsnd(int msqid,
  221. struct msgbuf32 __user *umsgp32,
  222. size_t msgsz, int msgflg)
  223. {
  224. struct msgbuf *mb;
  225. struct msgbuf32 mb32;
  226. int err;
  227. if ((mb = kmalloc(msgsz + sizeof *mb + 4, GFP_KERNEL)) == NULL)
  228. return -ENOMEM;
  229. err = get_user(mb32.mtype, &umsgp32->mtype);
  230. mb->mtype = mb32.mtype;
  231. err |= copy_from_user(mb->mtext, &umsgp32->mtext, msgsz);
  232. if (err)
  233. err = -EFAULT;
  234. else
  235. KERNEL_SYSCALL(err, sys_msgsnd, msqid, (struct msgbuf __user *)mb, msgsz, msgflg);
  236. kfree(mb);
  237. return err;
  238. }
  239. asmlinkage long sys32_msgrcv(int msqid,
  240. struct msgbuf32 __user *umsgp32,
  241. size_t msgsz, long msgtyp, int msgflg)
  242. {
  243. struct msgbuf *mb;
  244. struct msgbuf32 mb32;
  245. int err, len;
  246. if ((mb = kmalloc(msgsz + sizeof *mb + 4, GFP_KERNEL)) == NULL)
  247. return -ENOMEM;
  248. KERNEL_SYSCALL(err, sys_msgrcv, msqid, (struct msgbuf __user *)mb, msgsz, msgtyp, msgflg);
  249. if (err >= 0) {
  250. len = err;
  251. mb32.mtype = mb->mtype;
  252. err = put_user(mb32.mtype, &umsgp32->mtype);
  253. err |= copy_to_user(&umsgp32->mtext, mb->mtext, len);
  254. if (err)
  255. err = -EFAULT;
  256. else
  257. err = len;
  258. }
  259. kfree(mb);
  260. return err;
  261. }
  262. asmlinkage int sys32_sendfile(int out_fd, int in_fd, compat_off_t __user *offset, s32 count)
  263. {
  264. mm_segment_t old_fs = get_fs();
  265. int ret;
  266. off_t of;
  267. if (offset && get_user(of, offset))
  268. return -EFAULT;
  269. set_fs(KERNEL_DS);
  270. ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL, count);
  271. set_fs(old_fs);
  272. if (offset && put_user(of, offset))
  273. return -EFAULT;
  274. return ret;
  275. }
  276. asmlinkage int sys32_sendfile64(int out_fd, int in_fd, compat_loff_t __user *offset, s32 count)
  277. {
  278. mm_segment_t old_fs = get_fs();
  279. int ret;
  280. loff_t lof;
  281. if (offset && get_user(lof, offset))
  282. return -EFAULT;
  283. set_fs(KERNEL_DS);
  284. ret = sys_sendfile64(out_fd, in_fd, offset ? (loff_t __user *)&lof : NULL, count);
  285. set_fs(old_fs);
  286. if (offset && put_user(lof, offset))
  287. return -EFAULT;
  288. return ret;
  289. }
  290. /* lseek() needs a wrapper because 'offset' can be negative, but the top
  291. * half of the argument has been zeroed by syscall.S.
  292. */
  293. asmlinkage int sys32_lseek(unsigned int fd, int offset, unsigned int origin)
  294. {
  295. return sys_lseek(fd, offset, origin);
  296. }
  297. asmlinkage long sys32_semctl(int semid, int semnum, int cmd, union semun arg)
  298. {
  299. union semun u;
  300. if (cmd == SETVAL) {
  301. /* Ugh. arg is a union of int,ptr,ptr,ptr, so is 8 bytes.
  302. * The int should be in the first 4, but our argument
  303. * frobbing has left it in the last 4.
  304. */
  305. u.val = *((int *)&arg + 1);
  306. return sys_semctl (semid, semnum, cmd, u);
  307. }
  308. return sys_semctl (semid, semnum, cmd, arg);
  309. }
  310. long sys32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char __user *buf,
  311. size_t len)
  312. {
  313. return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low,
  314. buf, len);
  315. }
  316. asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo,
  317. u32 lenhi, u32 lenlo)
  318. {
  319. return sys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo,
  320. ((loff_t)lenhi << 32) | lenlo);
  321. }