sys_ia32.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. * sys_ia32.c: Conversion between 32bit and 64bit native syscalls. Based on
  3. * sys_sparc32
  4. *
  5. * Copyright (C) 2000 VA Linux Co
  6. * Copyright (C) 2000 Don Dugger <n0ano@valinux.com>
  7. * Copyright (C) 1999 Arun Sharma <arun.sharma@intel.com>
  8. * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  9. * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
  10. * Copyright (C) 2000 Hewlett-Packard Co.
  11. * Copyright (C) 2000 David Mosberger-Tang <davidm@hpl.hp.com>
  12. * Copyright (C) 2000,2001,2002 Andi Kleen, SuSE Labs (x86-64 port)
  13. *
  14. * These routines maintain argument size conversion between 32bit and 64bit
  15. * environment. In 2.5 most of this should be moved to a generic directory.
  16. *
  17. * This file assumes that there is a hole at the end of user address space.
  18. *
  19. * Some of the functions are LE specific currently. These are
  20. * hopefully all marked. This should be fixed.
  21. */
  22. #include <linux/kernel.h>
  23. #include <linux/sched.h>
  24. #include <linux/fs.h>
  25. #include <linux/file.h>
  26. #include <linux/signal.h>
  27. #include <linux/syscalls.h>
  28. #include <linux/times.h>
  29. #include <linux/utsname.h>
  30. #include <linux/mm.h>
  31. #include <linux/uio.h>
  32. #include <linux/poll.h>
  33. #include <linux/personality.h>
  34. #include <linux/stat.h>
  35. #include <linux/rwsem.h>
  36. #include <linux/compat.h>
  37. #include <linux/vfs.h>
  38. #include <linux/ptrace.h>
  39. #include <linux/highuid.h>
  40. #include <linux/sysctl.h>
  41. #include <linux/slab.h>
  42. #include <asm/mman.h>
  43. #include <asm/types.h>
  44. #include <asm/uaccess.h>
  45. #include <linux/atomic.h>
  46. #include <asm/vgtod.h>
  47. #include <asm/sys_ia32.h>
  48. #define AA(__x) ((unsigned long)(__x))
  49. asmlinkage long sys32_truncate64(const char __user *filename,
  50. unsigned long offset_low,
  51. unsigned long offset_high)
  52. {
  53. return sys_truncate(filename, ((loff_t) offset_high << 32) | offset_low);
  54. }
  55. asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
  56. unsigned long offset_high)
  57. {
  58. return sys_ftruncate(fd, ((loff_t) offset_high << 32) | offset_low);
  59. }
  60. /*
  61. * Another set for IA32/LFS -- x86_64 struct stat is different due to
  62. * support for 64bit inode numbers.
  63. */
  64. static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
  65. {
  66. typeof(ubuf->st_uid) uid = 0;
  67. typeof(ubuf->st_gid) gid = 0;
  68. SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
  69. SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
  70. if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
  71. __put_user(huge_encode_dev(stat->dev), &ubuf->st_dev) ||
  72. __put_user(stat->ino, &ubuf->__st_ino) ||
  73. __put_user(stat->ino, &ubuf->st_ino) ||
  74. __put_user(stat->mode, &ubuf->st_mode) ||
  75. __put_user(stat->nlink, &ubuf->st_nlink) ||
  76. __put_user(uid, &ubuf->st_uid) ||
  77. __put_user(gid, &ubuf->st_gid) ||
  78. __put_user(huge_encode_dev(stat->rdev), &ubuf->st_rdev) ||
  79. __put_user(stat->size, &ubuf->st_size) ||
  80. __put_user(stat->atime.tv_sec, &ubuf->st_atime) ||
  81. __put_user(stat->atime.tv_nsec, &ubuf->st_atime_nsec) ||
  82. __put_user(stat->mtime.tv_sec, &ubuf->st_mtime) ||
  83. __put_user(stat->mtime.tv_nsec, &ubuf->st_mtime_nsec) ||
  84. __put_user(stat->ctime.tv_sec, &ubuf->st_ctime) ||
  85. __put_user(stat->ctime.tv_nsec, &ubuf->st_ctime_nsec) ||
  86. __put_user(stat->blksize, &ubuf->st_blksize) ||
  87. __put_user(stat->blocks, &ubuf->st_blocks))
  88. return -EFAULT;
  89. return 0;
  90. }
  91. asmlinkage long sys32_stat64(const char __user *filename,
  92. struct stat64 __user *statbuf)
  93. {
  94. struct kstat stat;
  95. int ret = vfs_stat(filename, &stat);
  96. if (!ret)
  97. ret = cp_stat64(statbuf, &stat);
  98. return ret;
  99. }
  100. asmlinkage long sys32_lstat64(const char __user *filename,
  101. struct stat64 __user *statbuf)
  102. {
  103. struct kstat stat;
  104. int ret = vfs_lstat(filename, &stat);
  105. if (!ret)
  106. ret = cp_stat64(statbuf, &stat);
  107. return ret;
  108. }
  109. asmlinkage long sys32_fstat64(unsigned int fd, struct stat64 __user *statbuf)
  110. {
  111. struct kstat stat;
  112. int ret = vfs_fstat(fd, &stat);
  113. if (!ret)
  114. ret = cp_stat64(statbuf, &stat);
  115. return ret;
  116. }
  117. asmlinkage long sys32_fstatat(unsigned int dfd, const char __user *filename,
  118. struct stat64 __user *statbuf, int flag)
  119. {
  120. struct kstat stat;
  121. int error;
  122. error = vfs_fstatat(dfd, filename, &stat, flag);
  123. if (error)
  124. return error;
  125. return cp_stat64(statbuf, &stat);
  126. }
  127. /*
  128. * Linux/i386 didn't use to be able to handle more than
  129. * 4 system call parameters, so these system calls used a memory
  130. * block for parameter passing..
  131. */
  132. struct mmap_arg_struct32 {
  133. unsigned int addr;
  134. unsigned int len;
  135. unsigned int prot;
  136. unsigned int flags;
  137. unsigned int fd;
  138. unsigned int offset;
  139. };
  140. asmlinkage long sys32_mmap(struct mmap_arg_struct32 __user *arg)
  141. {
  142. struct mmap_arg_struct32 a;
  143. if (copy_from_user(&a, arg, sizeof(a)))
  144. return -EFAULT;
  145. if (a.offset & ~PAGE_MASK)
  146. return -EINVAL;
  147. return sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd,
  148. a.offset>>PAGE_SHIFT);
  149. }
  150. asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
  151. int options)
  152. {
  153. return compat_sys_wait4(pid, stat_addr, options, NULL);
  154. }
  155. /* warning: next two assume little endian */
  156. asmlinkage long sys32_pread(unsigned int fd, char __user *ubuf, u32 count,
  157. u32 poslo, u32 poshi)
  158. {
  159. return sys_pread64(fd, ubuf, count,
  160. ((loff_t)AA(poshi) << 32) | AA(poslo));
  161. }
  162. asmlinkage long sys32_pwrite(unsigned int fd, const char __user *ubuf,
  163. u32 count, u32 poslo, u32 poshi)
  164. {
  165. return sys_pwrite64(fd, ubuf, count,
  166. ((loff_t)AA(poshi) << 32) | AA(poslo));
  167. }
  168. /*
  169. * Some system calls that need sign extended arguments. This could be
  170. * done by a generic wrapper.
  171. */
  172. long sys32_fadvise64_64(int fd, __u32 offset_low, __u32 offset_high,
  173. __u32 len_low, __u32 len_high, int advice)
  174. {
  175. return sys_fadvise64_64(fd,
  176. (((u64)offset_high)<<32) | offset_low,
  177. (((u64)len_high)<<32) | len_low,
  178. advice);
  179. }
  180. asmlinkage ssize_t sys32_readahead(int fd, unsigned off_lo, unsigned off_hi,
  181. size_t count)
  182. {
  183. return sys_readahead(fd, ((u64)off_hi << 32) | off_lo, count);
  184. }
  185. asmlinkage long sys32_sync_file_range(int fd, unsigned off_low, unsigned off_hi,
  186. unsigned n_low, unsigned n_hi, int flags)
  187. {
  188. return sys_sync_file_range(fd,
  189. ((u64)off_hi << 32) | off_low,
  190. ((u64)n_hi << 32) | n_low, flags);
  191. }
  192. asmlinkage long sys32_fadvise64(int fd, unsigned offset_lo, unsigned offset_hi,
  193. size_t len, int advice)
  194. {
  195. return sys_fadvise64_64(fd, ((u64)offset_hi << 32) | offset_lo,
  196. len, advice);
  197. }
  198. asmlinkage long sys32_fallocate(int fd, int mode, unsigned offset_lo,
  199. unsigned offset_hi, unsigned len_lo,
  200. unsigned len_hi)
  201. {
  202. return sys_fallocate(fd, mode, ((u64)offset_hi << 32) | offset_lo,
  203. ((u64)len_hi << 32) | len_lo);
  204. }