sys_parisc32.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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/time.h>
  21. #include <linux/smp.h>
  22. #include <linux/smp_lock.h>
  23. #include <linux/sem.h>
  24. #include <linux/msg.h>
  25. #include <linux/shm.h>
  26. #include <linux/slab.h>
  27. #include <linux/uio.h>
  28. #include <linux/nfs_fs.h>
  29. #include <linux/ncp_fs.h>
  30. #include <linux/sunrpc/svc.h>
  31. #include <linux/nfsd/nfsd.h>
  32. #include <linux/nfsd/cache.h>
  33. #include <linux/nfsd/xdr.h>
  34. #include <linux/nfsd/syscall.h>
  35. #include <linux/poll.h>
  36. #include <linux/personality.h>
  37. #include <linux/stat.h>
  38. #include <linux/highmem.h>
  39. #include <linux/highuid.h>
  40. #include <linux/mman.h>
  41. #include <linux/binfmts.h>
  42. #include <linux/namei.h>
  43. #include <linux/vfs.h>
  44. #include <linux/ptrace.h>
  45. #include <linux/swap.h>
  46. #include <linux/syscalls.h>
  47. #include <asm/types.h>
  48. #include <asm/uaccess.h>
  49. #include <asm/mmu_context.h>
  50. #include "sys32.h"
  51. #undef DEBUG
  52. #ifdef DEBUG
  53. #define DBG(x) printk x
  54. #else
  55. #define DBG(x)
  56. #endif
  57. /*
  58. * sys32_execve() executes a new program.
  59. */
  60. asmlinkage int sys32_execve(struct pt_regs *regs)
  61. {
  62. int error;
  63. char *filename;
  64. DBG(("sys32_execve(%p) r26 = 0x%lx\n", regs, regs->gr[26]));
  65. filename = getname((const char __user *) regs->gr[26]);
  66. error = PTR_ERR(filename);
  67. if (IS_ERR(filename))
  68. goto out;
  69. error = compat_do_execve(filename, compat_ptr(regs->gr[25]),
  70. compat_ptr(regs->gr[24]), regs);
  71. putname(filename);
  72. out:
  73. return error;
  74. }
  75. asmlinkage long sys32_unimplemented(int r26, int r25, int r24, int r23,
  76. int r22, int r21, int r20)
  77. {
  78. printk(KERN_ERR "%s(%d): Unimplemented 32 on 64 syscall #%d!\n",
  79. current->comm, current->pid, r20);
  80. return -ENOSYS;
  81. }
  82. #ifdef CONFIG_SYSCTL
  83. struct __sysctl_args32 {
  84. u32 name;
  85. int nlen;
  86. u32 oldval;
  87. u32 oldlenp;
  88. u32 newval;
  89. u32 newlen;
  90. u32 __unused[4];
  91. };
  92. asmlinkage long sys32_sysctl(struct __sysctl_args32 __user *args)
  93. {
  94. #ifndef CONFIG_SYSCTL_SYSCALL
  95. return -ENOSYS;
  96. #else
  97. struct __sysctl_args32 tmp;
  98. int error;
  99. unsigned int oldlen32;
  100. size_t oldlen, __user *oldlenp = NULL;
  101. unsigned long addr = (((long __force)&args->__unused[0]) + 7) & ~7;
  102. DBG(("sysctl32(%p)\n", args));
  103. if (copy_from_user(&tmp, args, sizeof(tmp)))
  104. return -EFAULT;
  105. if (tmp.oldval && tmp.oldlenp) {
  106. /* Duh, this is ugly and might not work if sysctl_args
  107. is in read-only memory, but do_sysctl does indirectly
  108. a lot of uaccess in both directions and we'd have to
  109. basically copy the whole sysctl.c here, and
  110. glibc's __sysctl uses rw memory for the structure
  111. anyway. */
  112. /* a possibly better hack than this, which will avoid the
  113. * problem if the struct is read only, is to push the
  114. * 'oldlen' value out to the user's stack instead. -PB
  115. */
  116. if (get_user(oldlen32, (u32 *)(u64)tmp.oldlenp))
  117. return -EFAULT;
  118. oldlen = oldlen32;
  119. if (put_user(oldlen, (size_t *)addr))
  120. return -EFAULT;
  121. oldlenp = (size_t *)addr;
  122. }
  123. lock_kernel();
  124. error = do_sysctl((int __user *)(u64)tmp.name, tmp.nlen,
  125. (void __user *)(u64)tmp.oldval, oldlenp,
  126. (void __user *)(u64)tmp.newval, tmp.newlen);
  127. unlock_kernel();
  128. if (oldlenp) {
  129. if (!error) {
  130. if (get_user(oldlen, (size_t *)addr)) {
  131. error = -EFAULT;
  132. } else {
  133. oldlen32 = oldlen;
  134. if (put_user(oldlen32, (u32 *)(u64)tmp.oldlenp))
  135. error = -EFAULT;
  136. }
  137. }
  138. if (copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused)))
  139. error = -EFAULT;
  140. }
  141. return error;
  142. #endif
  143. }
  144. #endif /* CONFIG_SYSCTL */
  145. asmlinkage long sys32_sched_rr_get_interval(pid_t pid,
  146. struct compat_timespec __user *interval)
  147. {
  148. struct timespec t;
  149. int ret;
  150. KERNEL_SYSCALL(ret, sys_sched_rr_get_interval, pid, (struct timespec __user *)&t);
  151. if (put_compat_timespec(&t, interval))
  152. return -EFAULT;
  153. return ret;
  154. }
  155. struct msgbuf32 {
  156. int mtype;
  157. char mtext[1];
  158. };
  159. asmlinkage long sys32_msgsnd(int msqid,
  160. struct msgbuf32 __user *umsgp32,
  161. size_t msgsz, int msgflg)
  162. {
  163. struct msgbuf *mb;
  164. struct msgbuf32 mb32;
  165. int err;
  166. if ((mb = kmalloc(msgsz + sizeof *mb + 4, GFP_KERNEL)) == NULL)
  167. return -ENOMEM;
  168. err = get_user(mb32.mtype, &umsgp32->mtype);
  169. mb->mtype = mb32.mtype;
  170. err |= copy_from_user(mb->mtext, &umsgp32->mtext, msgsz);
  171. if (err)
  172. err = -EFAULT;
  173. else
  174. KERNEL_SYSCALL(err, sys_msgsnd, msqid, (struct msgbuf __user *)mb, msgsz, msgflg);
  175. kfree(mb);
  176. return err;
  177. }
  178. asmlinkage long sys32_msgrcv(int msqid,
  179. struct msgbuf32 __user *umsgp32,
  180. size_t msgsz, long msgtyp, int msgflg)
  181. {
  182. struct msgbuf *mb;
  183. struct msgbuf32 mb32;
  184. int err, len;
  185. if ((mb = kmalloc(msgsz + sizeof *mb + 4, GFP_KERNEL)) == NULL)
  186. return -ENOMEM;
  187. KERNEL_SYSCALL(err, sys_msgrcv, msqid, (struct msgbuf __user *)mb, msgsz, msgtyp, msgflg);
  188. if (err >= 0) {
  189. len = err;
  190. mb32.mtype = mb->mtype;
  191. err = put_user(mb32.mtype, &umsgp32->mtype);
  192. err |= copy_to_user(&umsgp32->mtext, mb->mtext, len);
  193. if (err)
  194. err = -EFAULT;
  195. else
  196. err = len;
  197. }
  198. kfree(mb);
  199. return err;
  200. }
  201. asmlinkage int sys32_sendfile(int out_fd, int in_fd, compat_off_t __user *offset, s32 count)
  202. {
  203. mm_segment_t old_fs = get_fs();
  204. int ret;
  205. off_t of;
  206. if (offset && get_user(of, offset))
  207. return -EFAULT;
  208. set_fs(KERNEL_DS);
  209. ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL, count);
  210. set_fs(old_fs);
  211. if (offset && put_user(of, offset))
  212. return -EFAULT;
  213. return ret;
  214. }
  215. asmlinkage int sys32_sendfile64(int out_fd, int in_fd, compat_loff_t __user *offset, s32 count)
  216. {
  217. mm_segment_t old_fs = get_fs();
  218. int ret;
  219. loff_t lof;
  220. if (offset && get_user(lof, offset))
  221. return -EFAULT;
  222. set_fs(KERNEL_DS);
  223. ret = sys_sendfile64(out_fd, in_fd, offset ? (loff_t __user *)&lof : NULL, count);
  224. set_fs(old_fs);
  225. if (offset && put_user(lof, offset))
  226. return -EFAULT;
  227. return ret;
  228. }
  229. /* lseek() needs a wrapper because 'offset' can be negative, but the top
  230. * half of the argument has been zeroed by syscall.S.
  231. */
  232. asmlinkage int sys32_lseek(unsigned int fd, int offset, unsigned int origin)
  233. {
  234. return sys_lseek(fd, offset, origin);
  235. }
  236. asmlinkage long sys32_semctl(int semid, int semnum, int cmd, union semun arg)
  237. {
  238. union semun u;
  239. if (cmd == SETVAL) {
  240. /* Ugh. arg is a union of int,ptr,ptr,ptr, so is 8 bytes.
  241. * The int should be in the first 4, but our argument
  242. * frobbing has left it in the last 4.
  243. */
  244. u.val = *((int *)&arg + 1);
  245. return sys_semctl (semid, semnum, cmd, u);
  246. }
  247. return sys_semctl (semid, semnum, cmd, arg);
  248. }
  249. long sys32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char __user *buf,
  250. size_t len)
  251. {
  252. return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low,
  253. buf, len);
  254. }
  255. asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo,
  256. u32 lenhi, u32 lenlo)
  257. {
  258. return sys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo,
  259. ((loff_t)lenhi << 32) | lenlo);
  260. }