sys_sparc32.c 6.8 KB

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