sys_sparc32.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. asmlinkage long sys32_truncate64(const char __user * path, unsigned long high, unsigned long low)
  50. {
  51. if ((int)high < 0)
  52. return -EINVAL;
  53. else
  54. return sys_truncate(path, (high << 32) | low);
  55. }
  56. asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long high, unsigned long low)
  57. {
  58. if ((int)high < 0)
  59. return -EINVAL;
  60. else
  61. return sys_ftruncate(fd, (high << 32) | low);
  62. }
  63. static int cp_compat_stat64(struct kstat *stat,
  64. struct compat_stat64 __user *statbuf)
  65. {
  66. int err;
  67. err = put_user(huge_encode_dev(stat->dev), &statbuf->st_dev);
  68. err |= put_user(stat->ino, &statbuf->st_ino);
  69. err |= put_user(stat->mode, &statbuf->st_mode);
  70. err |= put_user(stat->nlink, &statbuf->st_nlink);
  71. err |= put_user(from_kuid_munged(current_user_ns(), stat->uid), &statbuf->st_uid);
  72. err |= put_user(from_kgid_munged(current_user_ns(), stat->gid), &statbuf->st_gid);
  73. err |= put_user(huge_encode_dev(stat->rdev), &statbuf->st_rdev);
  74. err |= put_user(0, (unsigned long __user *) &statbuf->__pad3[0]);
  75. err |= put_user(stat->size, &statbuf->st_size);
  76. err |= put_user(stat->blksize, &statbuf->st_blksize);
  77. err |= put_user(0, (unsigned int __user *) &statbuf->__pad4[0]);
  78. err |= put_user(0, (unsigned int __user *) &statbuf->__pad4[4]);
  79. err |= put_user(stat->blocks, &statbuf->st_blocks);
  80. err |= put_user(stat->atime.tv_sec, &statbuf->st_atime);
  81. err |= put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);
  82. err |= put_user(stat->mtime.tv_sec, &statbuf->st_mtime);
  83. err |= put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);
  84. err |= put_user(stat->ctime.tv_sec, &statbuf->st_ctime);
  85. err |= put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);
  86. err |= put_user(0, &statbuf->__unused4);
  87. err |= put_user(0, &statbuf->__unused5);
  88. return err;
  89. }
  90. asmlinkage long compat_sys_stat64(const char __user * filename,
  91. struct compat_stat64 __user *statbuf)
  92. {
  93. struct kstat stat;
  94. int error = vfs_stat(filename, &stat);
  95. if (!error)
  96. error = cp_compat_stat64(&stat, statbuf);
  97. return error;
  98. }
  99. asmlinkage long compat_sys_lstat64(const char __user * filename,
  100. struct compat_stat64 __user *statbuf)
  101. {
  102. struct kstat stat;
  103. int error = vfs_lstat(filename, &stat);
  104. if (!error)
  105. error = cp_compat_stat64(&stat, statbuf);
  106. return error;
  107. }
  108. asmlinkage long compat_sys_fstat64(unsigned int fd,
  109. struct compat_stat64 __user * statbuf)
  110. {
  111. struct kstat stat;
  112. int error = vfs_fstat(fd, &stat);
  113. if (!error)
  114. error = cp_compat_stat64(&stat, statbuf);
  115. return error;
  116. }
  117. asmlinkage long compat_sys_fstatat64(unsigned int dfd,
  118. const char __user *filename,
  119. struct compat_stat64 __user * statbuf, int flag)
  120. {
  121. struct kstat stat;
  122. int error;
  123. error = vfs_fstatat(dfd, filename, &stat, flag);
  124. if (error)
  125. return error;
  126. return cp_compat_stat64(&stat, statbuf);
  127. }
  128. COMPAT_SYSCALL_DEFINE3(sparc_sigaction, int, sig,
  129. struct compat_old_sigaction __user *,act,
  130. struct compat_old_sigaction __user *,oact)
  131. {
  132. WARN_ON_ONCE(sig >= 0);
  133. return compat_sys_sigaction(-sig, act, oact);
  134. }
  135. COMPAT_SYSCALL_DEFINE5(rt_sigaction, int, sig,
  136. struct compat_sigaction __user *,act,
  137. struct compat_sigaction __user *,oact,
  138. void __user *,restorer,
  139. compat_size_t,sigsetsize)
  140. {
  141. struct k_sigaction new_ka, old_ka;
  142. int ret;
  143. compat_sigset_t set32;
  144. /* XXX: Don't preclude handling different sized sigset_t's. */
  145. if (sigsetsize != sizeof(compat_sigset_t))
  146. return -EINVAL;
  147. if (act) {
  148. u32 u_handler, u_restorer;
  149. new_ka.ka_restorer = restorer;
  150. ret = get_user(u_handler, &act->sa_handler);
  151. new_ka.sa.sa_handler = compat_ptr(u_handler);
  152. ret |= __copy_from_user(&set32, &act->sa_mask, sizeof(compat_sigset_t));
  153. sigset_from_compat(&new_ka.sa.sa_mask, &set32);
  154. ret |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
  155. ret |= __get_user(u_restorer, &act->sa_restorer);
  156. new_ka.sa.sa_restorer = compat_ptr(u_restorer);
  157. if (ret)
  158. return -EFAULT;
  159. }
  160. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  161. if (!ret && oact) {
  162. sigset_to_compat(&set32, &old_ka.sa.sa_mask);
  163. ret = put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler);
  164. ret |= __copy_to_user(&oact->sa_mask, &set32, sizeof(compat_sigset_t));
  165. ret |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
  166. ret |= __put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer);
  167. if (ret)
  168. ret = -EFAULT;
  169. }
  170. return ret;
  171. }
  172. asmlinkage compat_ssize_t sys32_pread64(unsigned int fd,
  173. char __user *ubuf,
  174. compat_size_t count,
  175. unsigned long poshi,
  176. unsigned long poslo)
  177. {
  178. return sys_pread64(fd, ubuf, count, (poshi << 32) | poslo);
  179. }
  180. asmlinkage compat_ssize_t sys32_pwrite64(unsigned int fd,
  181. char __user *ubuf,
  182. compat_size_t count,
  183. unsigned long poshi,
  184. unsigned long poslo)
  185. {
  186. return sys_pwrite64(fd, ubuf, count, (poshi << 32) | poslo);
  187. }
  188. asmlinkage long compat_sys_readahead(int fd,
  189. unsigned long offhi,
  190. unsigned long offlo,
  191. compat_size_t count)
  192. {
  193. return sys_readahead(fd, (offhi << 32) | offlo, count);
  194. }
  195. long compat_sys_fadvise64(int fd,
  196. unsigned long offhi,
  197. unsigned long offlo,
  198. compat_size_t len, int advice)
  199. {
  200. return sys_fadvise64_64(fd, (offhi << 32) | offlo, len, advice);
  201. }
  202. long compat_sys_fadvise64_64(int fd,
  203. unsigned long offhi, unsigned long offlo,
  204. unsigned long lenhi, unsigned long lenlo,
  205. int advice)
  206. {
  207. return sys_fadvise64_64(fd,
  208. (offhi << 32) | offlo,
  209. (lenhi << 32) | lenlo,
  210. advice);
  211. }
  212. long sys32_sync_file_range(unsigned int fd, unsigned long off_high, unsigned long off_low, unsigned long nb_high, unsigned long nb_low, unsigned int flags)
  213. {
  214. return sys_sync_file_range(fd,
  215. (off_high << 32) | off_low,
  216. (nb_high << 32) | nb_low,
  217. flags);
  218. }
  219. asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo,
  220. u32 lenhi, u32 lenlo)
  221. {
  222. return sys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo,
  223. ((loff_t)lenhi << 32) | lenlo);
  224. }