sys_sparc32.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* sys_sparc32.c: Conversion between 32bit and 64bit native syscalls.
  3. *
  4. * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  5. * Copyright (C) 1997, 2007 David S. Miller (davem@davemloft.net)
  6. *
  7. * These routines maintain argument size conversion between 32bit and 64bit
  8. * environment.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/sched.h>
  12. #include <linux/capability.h>
  13. #include <linux/fs.h>
  14. #include <linux/mm.h>
  15. #include <linux/file.h>
  16. #include <linux/signal.h>
  17. #include <linux/resource.h>
  18. #include <linux/times.h>
  19. #include <linux/smp.h>
  20. #include <linux/sem.h>
  21. #include <linux/msg.h>
  22. #include <linux/shm.h>
  23. #include <linux/uio.h>
  24. #include <linux/nfs_fs.h>
  25. #include <linux/quota.h>
  26. #include <linux/poll.h>
  27. #include <linux/personality.h>
  28. #include <linux/stat.h>
  29. #include <linux/filter.h>
  30. #include <linux/highmem.h>
  31. #include <linux/highuid.h>
  32. #include <linux/mman.h>
  33. #include <linux/ipv6.h>
  34. #include <linux/in.h>
  35. #include <linux/icmpv6.h>
  36. #include <linux/syscalls.h>
  37. #include <linux/sysctl.h>
  38. #include <linux/binfmts.h>
  39. #include <linux/dnotify.h>
  40. #include <linux/security.h>
  41. #include <linux/compat.h>
  42. #include <linux/vfs.h>
  43. #include <linux/ptrace.h>
  44. #include <linux/slab.h>
  45. #include <asm/types.h>
  46. #include <linux/uaccess.h>
  47. #include <asm/fpumacro.h>
  48. #include <asm/mmu_context.h>
  49. #include <asm/compat_signal.h>
  50. #include "systbls.h"
  51. asmlinkage long sys32_truncate64(const char __user * path, unsigned long high, unsigned long low)
  52. {
  53. if ((int)high < 0)
  54. return -EINVAL;
  55. else
  56. return ksys_truncate(path, (high << 32) | low);
  57. }
  58. asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long high, unsigned long low)
  59. {
  60. if ((int)high < 0)
  61. return -EINVAL;
  62. else
  63. return ksys_ftruncate(fd, (high << 32) | low);
  64. }
  65. static int cp_compat_stat64(struct kstat *stat,
  66. struct compat_stat64 __user *statbuf)
  67. {
  68. int err;
  69. err = put_user(huge_encode_dev(stat->dev), &statbuf->st_dev);
  70. err |= put_user(stat->ino, &statbuf->st_ino);
  71. err |= put_user(stat->mode, &statbuf->st_mode);
  72. err |= put_user(stat->nlink, &statbuf->st_nlink);
  73. err |= put_user(from_kuid_munged(current_user_ns(), stat->uid), &statbuf->st_uid);
  74. err |= put_user(from_kgid_munged(current_user_ns(), stat->gid), &statbuf->st_gid);
  75. err |= put_user(huge_encode_dev(stat->rdev), &statbuf->st_rdev);
  76. err |= put_user(0, (unsigned long __user *) &statbuf->__pad3[0]);
  77. err |= put_user(stat->size, &statbuf->st_size);
  78. err |= put_user(stat->blksize, &statbuf->st_blksize);
  79. err |= put_user(0, (unsigned int __user *) &statbuf->__pad4[0]);
  80. err |= put_user(0, (unsigned int __user *) &statbuf->__pad4[4]);
  81. err |= put_user(stat->blocks, &statbuf->st_blocks);
  82. err |= put_user(stat->atime.tv_sec, &statbuf->st_atime);
  83. err |= put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);
  84. err |= put_user(stat->mtime.tv_sec, &statbuf->st_mtime);
  85. err |= put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);
  86. err |= put_user(stat->ctime.tv_sec, &statbuf->st_ctime);
  87. err |= put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);
  88. err |= put_user(0, &statbuf->__unused4);
  89. err |= put_user(0, &statbuf->__unused5);
  90. return err;
  91. }
  92. asmlinkage long compat_sys_stat64(const char __user * filename,
  93. struct compat_stat64 __user *statbuf)
  94. {
  95. struct kstat stat;
  96. int error = vfs_stat(filename, &stat);
  97. if (!error)
  98. error = cp_compat_stat64(&stat, statbuf);
  99. return error;
  100. }
  101. asmlinkage long compat_sys_lstat64(const char __user * filename,
  102. struct compat_stat64 __user *statbuf)
  103. {
  104. struct kstat stat;
  105. int error = vfs_lstat(filename, &stat);
  106. if (!error)
  107. error = cp_compat_stat64(&stat, statbuf);
  108. return error;
  109. }
  110. asmlinkage long compat_sys_fstat64(unsigned int fd,
  111. struct compat_stat64 __user * statbuf)
  112. {
  113. struct kstat stat;
  114. int error = vfs_fstat(fd, &stat);
  115. if (!error)
  116. error = cp_compat_stat64(&stat, statbuf);
  117. return error;
  118. }
  119. asmlinkage long compat_sys_fstatat64(unsigned int dfd,
  120. const char __user *filename,
  121. struct compat_stat64 __user * statbuf, int flag)
  122. {
  123. struct kstat stat;
  124. int error;
  125. error = vfs_fstatat(dfd, filename, &stat, flag);
  126. if (error)
  127. return error;
  128. return cp_compat_stat64(&stat, statbuf);
  129. }
  130. COMPAT_SYSCALL_DEFINE3(sparc_sigaction, int, sig,
  131. struct compat_old_sigaction __user *,act,
  132. struct compat_old_sigaction __user *,oact)
  133. {
  134. WARN_ON_ONCE(sig >= 0);
  135. return compat_sys_sigaction(-sig, act, oact);
  136. }
  137. COMPAT_SYSCALL_DEFINE5(rt_sigaction, int, sig,
  138. struct compat_sigaction __user *,act,
  139. struct compat_sigaction __user *,oact,
  140. void __user *,restorer,
  141. compat_size_t,sigsetsize)
  142. {
  143. struct k_sigaction new_ka, old_ka;
  144. int ret;
  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 |= get_compat_sigset(&new_ka.sa.sa_mask, &act->sa_mask);
  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. ret = put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler);
  163. ret |= put_compat_sigset(&oact->sa_mask, &old_ka.sa.sa_mask,
  164. sizeof(oact->sa_mask));
  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 ksys_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 ksys_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 ksys_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 ksys_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 ksys_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 ksys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo,
  223. ((loff_t)lenhi << 32) | lenlo);
  224. }