sys_sparc32.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. COMPAT_SYSCALL_DEFINE3(truncate64, const char __user *, path, u32, high, u32, low)
  52. {
  53. return ksys_truncate(path, ((u64)high << 32) | low);
  54. }
  55. COMPAT_SYSCALL_DEFINE3(ftruncate64, unsigned int, fd, u32, high, u32, low)
  56. {
  57. return ksys_ftruncate(fd, ((u64)high << 32) | low);
  58. }
  59. static int cp_compat_stat64(struct kstat *stat,
  60. struct compat_stat64 __user *statbuf)
  61. {
  62. int err;
  63. err = put_user(huge_encode_dev(stat->dev), &statbuf->st_dev);
  64. err |= put_user(stat->ino, &statbuf->st_ino);
  65. err |= put_user(stat->mode, &statbuf->st_mode);
  66. err |= put_user(stat->nlink, &statbuf->st_nlink);
  67. err |= put_user(from_kuid_munged(current_user_ns(), stat->uid), &statbuf->st_uid);
  68. err |= put_user(from_kgid_munged(current_user_ns(), stat->gid), &statbuf->st_gid);
  69. err |= put_user(huge_encode_dev(stat->rdev), &statbuf->st_rdev);
  70. err |= put_user(0, (unsigned long __user *) &statbuf->__pad3[0]);
  71. err |= put_user(stat->size, &statbuf->st_size);
  72. err |= put_user(stat->blksize, &statbuf->st_blksize);
  73. err |= put_user(0, (unsigned int __user *) &statbuf->__pad4[0]);
  74. err |= put_user(0, (unsigned int __user *) &statbuf->__pad4[4]);
  75. err |= put_user(stat->blocks, &statbuf->st_blocks);
  76. err |= put_user(stat->atime.tv_sec, &statbuf->st_atime);
  77. err |= put_user(stat->atime.tv_nsec, &statbuf->st_atime_nsec);
  78. err |= put_user(stat->mtime.tv_sec, &statbuf->st_mtime);
  79. err |= put_user(stat->mtime.tv_nsec, &statbuf->st_mtime_nsec);
  80. err |= put_user(stat->ctime.tv_sec, &statbuf->st_ctime);
  81. err |= put_user(stat->ctime.tv_nsec, &statbuf->st_ctime_nsec);
  82. err |= put_user(0, &statbuf->__unused4);
  83. err |= put_user(0, &statbuf->__unused5);
  84. return err;
  85. }
  86. COMPAT_SYSCALL_DEFINE2(stat64, const char __user *, filename,
  87. struct compat_stat64 __user *, statbuf)
  88. {
  89. struct kstat stat;
  90. int error = vfs_stat(filename, &stat);
  91. if (!error)
  92. error = cp_compat_stat64(&stat, statbuf);
  93. return error;
  94. }
  95. COMPAT_SYSCALL_DEFINE2(lstat64, const char __user *, filename,
  96. struct compat_stat64 __user *, statbuf)
  97. {
  98. struct kstat stat;
  99. int error = vfs_lstat(filename, &stat);
  100. if (!error)
  101. error = cp_compat_stat64(&stat, statbuf);
  102. return error;
  103. }
  104. COMPAT_SYSCALL_DEFINE2(fstat64, unsigned int, fd,
  105. struct compat_stat64 __user *, statbuf)
  106. {
  107. struct kstat stat;
  108. int error = vfs_fstat(fd, &stat);
  109. if (!error)
  110. error = cp_compat_stat64(&stat, statbuf);
  111. return error;
  112. }
  113. COMPAT_SYSCALL_DEFINE4(fstatat64, unsigned int, dfd,
  114. const char __user *, filename,
  115. struct compat_stat64 __user *, statbuf, int, flag)
  116. {
  117. struct kstat stat;
  118. int error;
  119. error = vfs_fstatat(dfd, filename, &stat, flag);
  120. if (error)
  121. return error;
  122. return cp_compat_stat64(&stat, statbuf);
  123. }
  124. COMPAT_SYSCALL_DEFINE3(sparc_sigaction, int, sig,
  125. struct compat_old_sigaction __user *,act,
  126. struct compat_old_sigaction __user *,oact)
  127. {
  128. WARN_ON_ONCE(sig >= 0);
  129. return compat_sys_sigaction(-sig, act, oact);
  130. }
  131. COMPAT_SYSCALL_DEFINE5(rt_sigaction, int, sig,
  132. struct compat_sigaction __user *,act,
  133. struct compat_sigaction __user *,oact,
  134. void __user *,restorer,
  135. compat_size_t,sigsetsize)
  136. {
  137. struct k_sigaction new_ka, old_ka;
  138. int ret;
  139. /* XXX: Don't preclude handling different sized sigset_t's. */
  140. if (sigsetsize != sizeof(compat_sigset_t))
  141. return -EINVAL;
  142. if (act) {
  143. u32 u_handler, u_restorer;
  144. new_ka.ka_restorer = restorer;
  145. ret = get_user(u_handler, &act->sa_handler);
  146. new_ka.sa.sa_handler = compat_ptr(u_handler);
  147. ret |= get_compat_sigset(&new_ka.sa.sa_mask, &act->sa_mask);
  148. ret |= get_user(new_ka.sa.sa_flags, &act->sa_flags);
  149. ret |= get_user(u_restorer, &act->sa_restorer);
  150. new_ka.sa.sa_restorer = compat_ptr(u_restorer);
  151. if (ret)
  152. return -EFAULT;
  153. }
  154. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  155. if (!ret && oact) {
  156. ret = put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler);
  157. ret |= put_compat_sigset(&oact->sa_mask, &old_ka.sa.sa_mask,
  158. sizeof(oact->sa_mask));
  159. ret |= put_user(old_ka.sa.sa_flags, &oact->sa_flags);
  160. ret |= put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer);
  161. if (ret)
  162. ret = -EFAULT;
  163. }
  164. return ret;
  165. }
  166. COMPAT_SYSCALL_DEFINE5(pread64, unsigned int, fd, char __user *, ubuf,
  167. compat_size_t, count, u32, poshi, u32, poslo)
  168. {
  169. return ksys_pread64(fd, ubuf, count, ((u64)poshi << 32) | poslo);
  170. }
  171. COMPAT_SYSCALL_DEFINE5(pwrite64, unsigned int, fd, char __user *, ubuf,
  172. compat_size_t, count, u32, poshi, u32, poslo)
  173. {
  174. return ksys_pwrite64(fd, ubuf, count, ((u64)poshi << 32) | poslo);
  175. }
  176. COMPAT_SYSCALL_DEFINE4(readahead, int, fd, u32, offhi, u32, offlo,
  177. compat_size_t, count)
  178. {
  179. return ksys_readahead(fd, ((u64)offhi << 32) | offlo, count);
  180. }
  181. COMPAT_SYSCALL_DEFINE5(fadvise64, int, fd, u32, offhi, u32, offlo,
  182. compat_size_t, len, int, advice)
  183. {
  184. return ksys_fadvise64_64(fd, ((u64)offhi << 32) | offlo, len, advice);
  185. }
  186. COMPAT_SYSCALL_DEFINE6(fadvise64_64, int, fd, u32, offhi, u32, offlo,
  187. u32, lenhi, u32, lenlo, int, advice)
  188. {
  189. return ksys_fadvise64_64(fd,
  190. ((u64)offhi << 32) | offlo,
  191. ((u64)lenhi << 32) | lenlo,
  192. advice);
  193. }
  194. COMPAT_SYSCALL_DEFINE6(sync_file_range, unsigned int, fd, u32, off_high, u32, off_low,
  195. u32, nb_high, u32, nb_low, unsigned int, flags)
  196. {
  197. return ksys_sync_file_range(fd,
  198. ((u64)off_high << 32) | off_low,
  199. ((u64)nb_high << 32) | nb_low,
  200. flags);
  201. }
  202. COMPAT_SYSCALL_DEFINE6(fallocate, int, fd, int, mode, u32, offhi, u32, offlo,
  203. u32, lenhi, u32, lenlo)
  204. {
  205. return ksys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo,
  206. ((loff_t)lenhi << 32) | lenlo);
  207. }