linux32.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * Conversion between 32-bit and 64-bit native system calls.
  3. *
  4. * Copyright (C) 2000 Silicon Graphics, Inc.
  5. * Written by Ulf Carlsson (ulfc@engr.sgi.com)
  6. */
  7. #include <linux/compiler.h>
  8. #include <linux/mm.h>
  9. #include <linux/errno.h>
  10. #include <linux/file.h>
  11. #include <linux/highuid.h>
  12. #include <linux/resource.h>
  13. #include <linux/highmem.h>
  14. #include <linux/time.h>
  15. #include <linux/times.h>
  16. #include <linux/poll.h>
  17. #include <linux/skbuff.h>
  18. #include <linux/filter.h>
  19. #include <linux/shm.h>
  20. #include <linux/sem.h>
  21. #include <linux/msg.h>
  22. #include <linux/icmpv6.h>
  23. #include <linux/syscalls.h>
  24. #include <linux/sysctl.h>
  25. #include <linux/utime.h>
  26. #include <linux/utsname.h>
  27. #include <linux/personality.h>
  28. #include <linux/dnotify.h>
  29. #include <linux/module.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 <asm/uaccess.h>
  41. #include <asm/mmu_context.h>
  42. #include <asm/mman.h>
  43. /* Use this to get at 32-bit user passed pointers. */
  44. /* A() macro should be used for places where you e.g.
  45. have some internal variable u32 and just want to get
  46. rid of a compiler warning. AA() has to be used in
  47. places where you want to convert a function argument
  48. to 32bit pointer or when you e.g. access pt_regs
  49. structure and want to consider 32bit registers only.
  50. */
  51. #define A(__x) ((unsigned long)(__x))
  52. #define AA(__x) ((unsigned long)((int)__x))
  53. #ifdef __MIPSEB__
  54. #define merge_64(r1, r2) ((((r1) & 0xffffffffUL) << 32) + ((r2) & 0xffffffffUL))
  55. #endif
  56. #ifdef __MIPSEL__
  57. #define merge_64(r1, r2) ((((r2) & 0xffffffffUL) << 32) + ((r1) & 0xffffffffUL))
  58. #endif
  59. SYSCALL_DEFINE6(32_mmap2, unsigned long, addr, unsigned long, len,
  60. unsigned long, prot, unsigned long, flags, unsigned long, fd,
  61. unsigned long, pgoff)
  62. {
  63. unsigned long error;
  64. error = -EINVAL;
  65. if (pgoff & (~PAGE_MASK >> 12))
  66. goto out;
  67. error = sys_mmap_pgoff(addr, len, prot, flags, fd,
  68. pgoff >> (PAGE_SHIFT-12));
  69. out:
  70. return error;
  71. }
  72. #define RLIM_INFINITY32 0x7fffffff
  73. #define RESOURCE32(x) ((x > RLIM_INFINITY32) ? RLIM_INFINITY32 : x)
  74. struct rlimit32 {
  75. int rlim_cur;
  76. int rlim_max;
  77. };
  78. SYSCALL_DEFINE4(32_truncate64, const char __user *, path,
  79. unsigned long, __dummy, unsigned long, a2, unsigned long, a3)
  80. {
  81. return sys_truncate(path, merge_64(a2, a3));
  82. }
  83. SYSCALL_DEFINE4(32_ftruncate64, unsigned long, fd, unsigned long, __dummy,
  84. unsigned long, a2, unsigned long, a3)
  85. {
  86. return sys_ftruncate(fd, merge_64(a2, a3));
  87. }
  88. SYSCALL_DEFINE5(32_llseek, unsigned int, fd, unsigned int, offset_high,
  89. unsigned int, offset_low, loff_t __user *, result,
  90. unsigned int, origin)
  91. {
  92. return sys_llseek(fd, offset_high, offset_low, result, origin);
  93. }
  94. /* From the Single Unix Spec: pread & pwrite act like lseek to pos + op +
  95. lseek back to original location. They fail just like lseek does on
  96. non-seekable files. */
  97. SYSCALL_DEFINE6(32_pread, unsigned long, fd, char __user *, buf, size_t, count,
  98. unsigned long, unused, unsigned long, a4, unsigned long, a5)
  99. {
  100. return sys_pread64(fd, buf, count, merge_64(a4, a5));
  101. }
  102. SYSCALL_DEFINE6(32_pwrite, unsigned int, fd, const char __user *, buf,
  103. size_t, count, u32, unused, u64, a4, u64, a5)
  104. {
  105. return sys_pwrite64(fd, buf, count, merge_64(a4, a5));
  106. }
  107. SYSCALL_DEFINE1(32_personality, unsigned long, personality)
  108. {
  109. unsigned int p = personality & 0xffffffff;
  110. int ret;
  111. if (personality(current->personality) == PER_LINUX32 &&
  112. personality(p) == PER_LINUX)
  113. p = (p & ~PER_MASK) | PER_LINUX32;
  114. ret = sys_personality(p);
  115. if (ret != -1 && personality(ret) == PER_LINUX32)
  116. ret = (ret & ~PER_MASK) | PER_LINUX;
  117. return ret;
  118. }
  119. asmlinkage ssize_t sys32_readahead(int fd, u32 pad0, u64 a2, u64 a3,
  120. size_t count)
  121. {
  122. return sys_readahead(fd, merge_64(a2, a3), count);
  123. }
  124. asmlinkage long sys32_sync_file_range(int fd, int __pad,
  125. unsigned long a2, unsigned long a3,
  126. unsigned long a4, unsigned long a5,
  127. int flags)
  128. {
  129. return sys_sync_file_range(fd,
  130. merge_64(a2, a3), merge_64(a4, a5),
  131. flags);
  132. }
  133. asmlinkage long sys32_fadvise64_64(int fd, int __pad,
  134. unsigned long a2, unsigned long a3,
  135. unsigned long a4, unsigned long a5,
  136. int flags)
  137. {
  138. return sys_fadvise64_64(fd,
  139. merge_64(a2, a3), merge_64(a4, a5),
  140. flags);
  141. }
  142. asmlinkage long sys32_fallocate(int fd, int mode, unsigned offset_a2,
  143. unsigned offset_a3, unsigned len_a4, unsigned len_a5)
  144. {
  145. return sys_fallocate(fd, mode, merge_64(offset_a2, offset_a3),
  146. merge_64(len_a4, len_a5));
  147. }