sys_sparc32.c 7.2 KB

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