linux32.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Conversion between 32-bit and 64-bit native system calls.
  4. *
  5. * Copyright (C) 2000 Silicon Graphics, Inc.
  6. * Written by Ulf Carlsson ([email protected])
  7. */
  8. #include <linux/compiler.h>
  9. #include <linux/mm.h>
  10. #include <linux/errno.h>
  11. #include <linux/file.h>
  12. #include <linux/highuid.h>
  13. #include <linux/resource.h>
  14. #include <linux/highmem.h>
  15. #include <linux/time.h>
  16. #include <linux/times.h>
  17. #include <linux/poll.h>
  18. #include <linux/skbuff.h>
  19. #include <linux/filter.h>
  20. #include <linux/shm.h>
  21. #include <linux/sem.h>
  22. #include <linux/msg.h>
  23. #include <linux/icmpv6.h>
  24. #include <linux/syscalls.h>
  25. #include <linux/sysctl.h>
  26. #include <linux/utime.h>
  27. #include <linux/utsname.h>
  28. #include <linux/personality.h>
  29. #include <linux/dnotify.h>
  30. #include <linux/binfmts.h>
  31. #include <linux/security.h>
  32. #include <linux/compat.h>
  33. #include <linux/vfs.h>
  34. #include <linux/ipc.h>
  35. #include <linux/slab.h>
  36. #include <net/sock.h>
  37. #include <net/scm.h>
  38. #include <asm/compat-signal.h>
  39. #include <asm/sim.h>
  40. #include <linux/uaccess.h>
  41. #include <asm/mmu_context.h>
  42. #include <asm/mman.h>
  43. #ifdef __MIPSEB__
  44. #define merge_64(r1, r2) ((((r1) & 0xffffffffUL) << 32) + ((r2) & 0xffffffffUL))
  45. #endif
  46. #ifdef __MIPSEL__
  47. #define merge_64(r1, r2) ((((r2) & 0xffffffffUL) << 32) + ((r1) & 0xffffffffUL))
  48. #endif
  49. SYSCALL_DEFINE4(32_truncate64, const char __user *, path,
  50. unsigned long, __dummy, unsigned long, a2, unsigned long, a3)
  51. {
  52. return ksys_truncate(path, merge_64(a2, a3));
  53. }
  54. SYSCALL_DEFINE4(32_ftruncate64, unsigned long, fd, unsigned long, __dummy,
  55. unsigned long, a2, unsigned long, a3)
  56. {
  57. return ksys_ftruncate(fd, merge_64(a2, a3));
  58. }
  59. SYSCALL_DEFINE5(32_llseek, unsigned int, fd, unsigned int, offset_high,
  60. unsigned int, offset_low, loff_t __user *, result,
  61. unsigned int, origin)
  62. {
  63. return sys_llseek(fd, offset_high, offset_low, result, origin);
  64. }
  65. /* From the Single Unix Spec: pread & pwrite act like lseek to pos + op +
  66. lseek back to original location. They fail just like lseek does on
  67. non-seekable files. */
  68. SYSCALL_DEFINE6(32_pread, unsigned long, fd, char __user *, buf, size_t, count,
  69. unsigned long, unused, unsigned long, a4, unsigned long, a5)
  70. {
  71. return ksys_pread64(fd, buf, count, merge_64(a4, a5));
  72. }
  73. SYSCALL_DEFINE6(32_pwrite, unsigned int, fd, const char __user *, buf,
  74. size_t, count, u32, unused, u64, a4, u64, a5)
  75. {
  76. return ksys_pwrite64(fd, buf, count, merge_64(a4, a5));
  77. }
  78. SYSCALL_DEFINE1(32_personality, unsigned long, personality)
  79. {
  80. unsigned int p = personality & 0xffffffff;
  81. int ret;
  82. if (personality(current->personality) == PER_LINUX32 &&
  83. personality(p) == PER_LINUX)
  84. p = (p & ~PER_MASK) | PER_LINUX32;
  85. ret = sys_personality(p);
  86. if (ret != -1 && personality(ret) == PER_LINUX32)
  87. ret = (ret & ~PER_MASK) | PER_LINUX;
  88. return ret;
  89. }
  90. asmlinkage ssize_t sys32_readahead(int fd, u32 pad0, u64 a2, u64 a3,
  91. size_t count)
  92. {
  93. return ksys_readahead(fd, merge_64(a2, a3), count);
  94. }
  95. asmlinkage long sys32_sync_file_range(int fd, int __pad,
  96. unsigned long a2, unsigned long a3,
  97. unsigned long a4, unsigned long a5,
  98. int flags)
  99. {
  100. return ksys_sync_file_range(fd,
  101. merge_64(a2, a3), merge_64(a4, a5),
  102. flags);
  103. }
  104. asmlinkage long sys32_fadvise64_64(int fd, int __pad,
  105. unsigned long a2, unsigned long a3,
  106. unsigned long a4, unsigned long a5,
  107. int flags)
  108. {
  109. return ksys_fadvise64_64(fd,
  110. merge_64(a2, a3), merge_64(a4, a5),
  111. flags);
  112. }
  113. asmlinkage long sys32_fallocate(int fd, int mode, unsigned offset_a2,
  114. unsigned offset_a3, unsigned len_a4, unsigned len_a5)
  115. {
  116. return ksys_fallocate(fd, mode, merge_64(offset_a2, offset_a3),
  117. merge_64(len_a4, len_a5));
  118. }