sys_sparc32.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /* sys_sparc32.c: Conversion between 32bit and 64bit native syscalls.
  2. *
  3. * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  4. * Copyright (C) 1997, 2007 David S. Miller (davem@davemloft.net)
  5. *
  6. * These routines maintain argument size conversion between 32bit and 64bit
  7. * environment.
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/sched.h>
  11. #include <linux/capability.h>
  12. #include <linux/fs.h>
  13. #include <linux/mm.h>
  14. #include <linux/file.h>
  15. #include <linux/signal.h>
  16. #include <linux/resource.h>
  17. #include <linux/times.h>
  18. #include <linux/smp.h>
  19. #include <linux/sem.h>
  20. #include <linux/msg.h>
  21. #include <linux/shm.h>
  22. #include <linux/uio.h>
  23. #include <linux/nfs_fs.h>
  24. #include <linux/quota.h>
  25. #include <linux/poll.h>
  26. #include <linux/personality.h>
  27. #include <linux/stat.h>
  28. #include <linux/filter.h>
  29. #include <linux/highmem.h>
  30. #include <linux/highuid.h>
  31. #include <linux/mman.h>
  32. #include <linux/ipv6.h>
  33. #include <linux/in.h>
  34. #include <linux/icmpv6.h>
  35. #include <linux/syscalls.h>
  36. #include <linux/sysctl.h>
  37. #include <linux/binfmts.h>
  38. #include <linux/dnotify.h>
  39. #include <linux/security.h>
  40. #include <linux/compat.h>
  41. #include <linux/vfs.h>
  42. #include <linux/ptrace.h>
  43. #include <linux/slab.h>
  44. #include <asm/types.h>
  45. #include <asm/uaccess.h>
  46. #include <asm/fpumacro.h>
  47. #include <asm/mmu_context.h>
  48. #include <asm/compat_signal.h>
  49. #ifdef CONFIG_SYSVIPC
  50. asmlinkage long compat_sys_ipc(u32 call, u32 first, u32 second, u32 third, compat_uptr_t ptr, u32 fifth)
  51. {
  52. int version;
  53. version = call >> 16; /* hack for backward compatibility */
  54. call &= 0xffff;
  55. switch (call) {
  56. case SEMTIMEDOP:
  57. if (fifth)
  58. /* sign extend semid */
  59. return compat_sys_semtimedop((int)first,
  60. compat_ptr(ptr), second,
  61. compat_ptr(fifth));
  62. /* else fall through for normal semop() */
  63. case SEMOP:
  64. /* struct sembuf is the same on 32 and 64bit :)) */
  65. /* sign extend semid */
  66. return sys_semtimedop((int)first, compat_ptr(ptr), second,
  67. NULL);
  68. case SEMGET:
  69. /* sign extend key, nsems */
  70. return sys_semget((int)first, (int)second, third);
  71. case SEMCTL:
  72. /* sign extend semid, semnum */
  73. return compat_sys_semctl((int)first, (int)second, third,
  74. compat_ptr(ptr));
  75. case MSGSND:
  76. /* sign extend msqid */
  77. return compat_sys_msgsnd((int)first, (int)second, third,
  78. compat_ptr(ptr));
  79. case MSGRCV:
  80. /* sign extend msqid, msgtyp */
  81. return compat_sys_msgrcv((int)first, second, (int)fifth,
  82. third, version, compat_ptr(ptr));
  83. case MSGGET:
  84. /* sign extend key */
  85. return sys_msgget((int)first, second);
  86. case MSGCTL:
  87. /* sign extend msqid */
  88. return compat_sys_msgctl((int)first, second, compat_ptr(ptr));
  89. case SHMAT:
  90. /* sign extend shmid */
  91. return compat_sys_shmat((int)first, second, third, version,
  92. compat_ptr(ptr));
  93. case SHMDT:
  94. return sys_shmdt(compat_ptr(ptr));
  95. case SHMGET:
  96. /* sign extend key_t */
  97. return sys_shmget((int)first, second, third);
  98. case SHMCTL:
  99. /* sign extend shmid */
  100. return compat_sys_shmctl((int)first, second, compat_ptr(ptr));
  101. default:
  102. return -ENOSYS;
  103. }
  104. return -ENOSYS;
  105. }
  106. #endif
  107. asmlinkage long sys32_truncate64(const char __user * path, unsigned long high, unsigned long low)
  108. {
  109. if ((int)high < 0)
  110. return -EINVAL;
  111. else
  112. return sys_truncate(path, (high << 32) | low);
  113. }
  114. asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long high, unsigned long low)
  115. {
  116. if ((int)high < 0)
  117. return -EINVAL;
  118. else
  119. return sys_ftruncate(fd, (high << 32) | low);
  120. }
  121. static int cp_compat_stat64(struct kstat *stat,
  122. struct compat_stat64 __user *statbuf)
  123. {
  124. int err;
  125. err = put_user(huge_encode_dev(stat->dev), &statbuf->st_dev);
  126. err |= put_user(stat->ino, &statbuf->st_ino);
  127. err |= put_user(stat->mode, &statbuf->st_mode);
  128. err |= put_user(stat->nlink, &statbuf->st_nlink);
  129. err |= put_user(from_kuid_munged(current_user_ns(), stat->uid), &statbuf->st_uid);
  130. err |= put_user(from_kgid_munged(current_user_ns(), stat->gid), &statbuf->st_gid);
  131. err |= put_user(huge_encode_dev(stat->rdev), &statbuf->st_rdev);
  132. err |= put_user(0, (unsigned long __user *) &statbuf->__pad3[0]);
  133. err |= put_user(stat->size, &statbuf->st_size);
  134. err |= put_user(stat->blksize, &statbuf->st_blksize);
  135. err |= put_user(0, (unsigned int __user *) &statbuf->__pad4[0]);
  136. err |= put_user(0, (unsigned int __user *) &statbuf->__pad4[4]);
  137. err |= put_user(stat->blocks, &statbuf->st_blocks);
  138. err |= put_user(stat->atime.tv_sec, &statbuf->st_atime);
  139. err |= put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);
  140. err |= put_user(stat->mtime.tv_sec, &statbuf->st_mtime);
  141. err |= put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);
  142. err |= put_user(stat->ctime.tv_sec, &statbuf->st_ctime);
  143. err |= put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);
  144. err |= put_user(0, &statbuf->__unused4);
  145. err |= put_user(0, &statbuf->__unused5);
  146. return err;
  147. }
  148. asmlinkage long compat_sys_stat64(const char __user * filename,
  149. struct compat_stat64 __user *statbuf)
  150. {
  151. struct kstat stat;
  152. int error = vfs_stat(filename, &stat);
  153. if (!error)
  154. error = cp_compat_stat64(&stat, statbuf);
  155. return error;
  156. }
  157. asmlinkage long compat_sys_lstat64(const char __user * filename,
  158. struct compat_stat64 __user *statbuf)
  159. {
  160. struct kstat stat;
  161. int error = vfs_lstat(filename, &stat);
  162. if (!error)
  163. error = cp_compat_stat64(&stat, statbuf);
  164. return error;
  165. }
  166. asmlinkage long compat_sys_fstat64(unsigned int fd,
  167. struct compat_stat64 __user * statbuf)
  168. {
  169. struct kstat stat;
  170. int error = vfs_fstat(fd, &stat);
  171. if (!error)
  172. error = cp_compat_stat64(&stat, statbuf);
  173. return error;
  174. }
  175. asmlinkage long compat_sys_fstatat64(unsigned int dfd,
  176. const char __user *filename,
  177. struct compat_stat64 __user * statbuf, int flag)
  178. {
  179. struct kstat stat;
  180. int error;
  181. error = vfs_fstatat(dfd, filename, &stat, flag);
  182. if (error)
  183. return error;
  184. return cp_compat_stat64(&stat, statbuf);
  185. }
  186. COMPAT_SYSCALL_DEFINE3(sparc_sigaction, int, sig,
  187. struct compat_old_sigaction __user *,act,
  188. struct compat_old_sigaction __user *,oact)
  189. {
  190. WARN_ON_ONCE(sig >= 0);
  191. return compat_sys_sigaction(-sig, act, oact);
  192. }
  193. COMPAT_SYSCALL_DEFINE5(rt_sigaction, int, sig,
  194. struct compat_sigaction __user *,act,
  195. struct compat_sigaction __user *,oact,
  196. void __user *,restorer,
  197. compat_size_t,sigsetsize)
  198. {
  199. struct k_sigaction new_ka, old_ka;
  200. int ret;
  201. compat_sigset_t set32;
  202. /* XXX: Don't preclude handling different sized sigset_t's. */
  203. if (sigsetsize != sizeof(compat_sigset_t))
  204. return -EINVAL;
  205. if (act) {
  206. u32 u_handler, u_restorer;
  207. new_ka.ka_restorer = restorer;
  208. ret = get_user(u_handler, &act->sa_handler);
  209. new_ka.sa.sa_handler = compat_ptr(u_handler);
  210. ret |= __copy_from_user(&set32, &act->sa_mask, sizeof(compat_sigset_t));
  211. sigset_from_compat(&new_ka.sa.sa_mask, &set32);
  212. ret |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
  213. ret |= __get_user(u_restorer, &act->sa_restorer);
  214. new_ka.sa.sa_restorer = compat_ptr(u_restorer);
  215. if (ret)
  216. return -EFAULT;
  217. }
  218. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  219. if (!ret && oact) {
  220. sigset_to_compat(&set32, &old_ka.sa.sa_mask);
  221. ret = put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler);
  222. ret |= __copy_to_user(&oact->sa_mask, &set32, sizeof(compat_sigset_t));
  223. ret |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
  224. ret |= __put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer);
  225. if (ret)
  226. ret = -EFAULT;
  227. }
  228. return ret;
  229. }
  230. asmlinkage compat_ssize_t sys32_pread64(unsigned int fd,
  231. char __user *ubuf,
  232. compat_size_t count,
  233. unsigned long poshi,
  234. unsigned long poslo)
  235. {
  236. return sys_pread64(fd, ubuf, count, (poshi << 32) | poslo);
  237. }
  238. asmlinkage compat_ssize_t sys32_pwrite64(unsigned int fd,
  239. char __user *ubuf,
  240. compat_size_t count,
  241. unsigned long poshi,
  242. unsigned long poslo)
  243. {
  244. return sys_pwrite64(fd, ubuf, count, (poshi << 32) | poslo);
  245. }
  246. asmlinkage long compat_sys_readahead(int fd,
  247. unsigned long offhi,
  248. unsigned long offlo,
  249. compat_size_t count)
  250. {
  251. return sys_readahead(fd, (offhi << 32) | offlo, count);
  252. }
  253. long compat_sys_fadvise64(int fd,
  254. unsigned long offhi,
  255. unsigned long offlo,
  256. compat_size_t len, int advice)
  257. {
  258. return sys_fadvise64_64(fd, (offhi << 32) | offlo, len, advice);
  259. }
  260. long compat_sys_fadvise64_64(int fd,
  261. unsigned long offhi, unsigned long offlo,
  262. unsigned long lenhi, unsigned long lenlo,
  263. int advice)
  264. {
  265. return sys_fadvise64_64(fd,
  266. (offhi << 32) | offlo,
  267. (lenhi << 32) | lenlo,
  268. advice);
  269. }
  270. long sys32_lookup_dcookie(unsigned long cookie_high,
  271. unsigned long cookie_low,
  272. char __user *buf, size_t len)
  273. {
  274. return sys_lookup_dcookie((cookie_high << 32) | cookie_low,
  275. buf, len);
  276. }
  277. long compat_sync_file_range(int fd, unsigned long off_high, unsigned long off_low, unsigned long nb_high, unsigned long nb_low, int flags)
  278. {
  279. return sys_sync_file_range(fd,
  280. (off_high << 32) | off_low,
  281. (nb_high << 32) | nb_low,
  282. flags);
  283. }
  284. asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo,
  285. u32 lenhi, u32 lenlo)
  286. {
  287. return sys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo,
  288. ((loff_t)lenhi << 32) | lenlo);
  289. }