sys_ppc32.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*
  2. * sys_ppc32.c: Conversion between 32bit and 64bit native syscalls.
  3. *
  4. * Copyright (C) 2001 IBM
  5. * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  6. * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
  7. *
  8. * These routines maintain argument size conversion between 32bit and 64bit
  9. * environment.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version
  14. * 2 of the License, or (at your option) any later version.
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/sched.h>
  18. #include <linux/fs.h>
  19. #include <linux/mm.h>
  20. #include <linux/file.h>
  21. #include <linux/signal.h>
  22. #include <linux/resource.h>
  23. #include <linux/times.h>
  24. #include <linux/smp.h>
  25. #include <linux/sem.h>
  26. #include <linux/msg.h>
  27. #include <linux/shm.h>
  28. #include <linux/poll.h>
  29. #include <linux/personality.h>
  30. #include <linux/stat.h>
  31. #include <linux/mman.h>
  32. #include <linux/in.h>
  33. #include <linux/syscalls.h>
  34. #include <linux/unistd.h>
  35. #include <linux/sysctl.h>
  36. #include <linux/binfmts.h>
  37. #include <linux/security.h>
  38. #include <linux/compat.h>
  39. #include <linux/ptrace.h>
  40. #include <linux/elf.h>
  41. #include <linux/ipc.h>
  42. #include <linux/slab.h>
  43. #include <asm/ptrace.h>
  44. #include <asm/types.h>
  45. #include <asm/uaccess.h>
  46. #include <asm/unistd.h>
  47. #include <asm/time.h>
  48. #include <asm/mmu_context.h>
  49. #include <asm/ppc-pci.h>
  50. #include <asm/syscalls.h>
  51. #include <asm/switch_to.h>
  52. asmlinkage long ppc32_select(u32 n, compat_ulong_t __user *inp,
  53. compat_ulong_t __user *outp, compat_ulong_t __user *exp,
  54. compat_uptr_t tvp_x)
  55. {
  56. /* sign extend n */
  57. return compat_sys_select((int)n, inp, outp, exp, compat_ptr(tvp_x));
  58. }
  59. #ifdef CONFIG_SYSVIPC
  60. long compat_sys_ipc(u32 call, u32 first, u32 second, u32 third, compat_uptr_t ptr,
  61. u32 fifth)
  62. {
  63. int version;
  64. version = call >> 16; /* hack for backward compatibility */
  65. call &= 0xffff;
  66. switch (call) {
  67. case SEMTIMEDOP:
  68. if (fifth)
  69. /* sign extend semid */
  70. return compat_sys_semtimedop((int)first,
  71. compat_ptr(ptr), second,
  72. compat_ptr(fifth));
  73. /* else fall through for normal semop() */
  74. case SEMOP:
  75. /* struct sembuf is the same on 32 and 64bit :)) */
  76. /* sign extend semid */
  77. return sys_semtimedop((int)first, compat_ptr(ptr), second,
  78. NULL);
  79. case SEMGET:
  80. /* sign extend key, nsems */
  81. return sys_semget((int)first, (int)second, third);
  82. case SEMCTL:
  83. /* sign extend semid, semnum */
  84. return compat_sys_semctl((int)first, (int)second, third,
  85. compat_ptr(ptr));
  86. case MSGSND:
  87. /* sign extend msqid */
  88. return compat_sys_msgsnd((int)first, (int)second, third,
  89. compat_ptr(ptr));
  90. case MSGRCV:
  91. /* sign extend msqid, msgtyp */
  92. return compat_sys_msgrcv((int)first, second, (int)fifth,
  93. third, version, compat_ptr(ptr));
  94. case MSGGET:
  95. /* sign extend key */
  96. return sys_msgget((int)first, second);
  97. case MSGCTL:
  98. /* sign extend msqid */
  99. return compat_sys_msgctl((int)first, second, compat_ptr(ptr));
  100. case SHMAT:
  101. /* sign extend shmid */
  102. return compat_sys_shmat((int)first, second, third, version,
  103. compat_ptr(ptr));
  104. case SHMDT:
  105. return sys_shmdt(compat_ptr(ptr));
  106. case SHMGET:
  107. /* sign extend key_t */
  108. return sys_shmget((int)first, second, third);
  109. case SHMCTL:
  110. /* sign extend shmid */
  111. return compat_sys_shmctl((int)first, second, compat_ptr(ptr));
  112. default:
  113. return -ENOSYS;
  114. }
  115. return -ENOSYS;
  116. }
  117. #endif
  118. /* Note: it is necessary to treat out_fd and in_fd as unsigned ints,
  119. * with the corresponding cast to a signed int to insure that the
  120. * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
  121. * and the register representation of a signed int (msr in 64-bit mode) is performed.
  122. */
  123. asmlinkage long compat_sys_sendfile_wrapper(u32 out_fd, u32 in_fd,
  124. compat_off_t __user *offset, u32 count)
  125. {
  126. return compat_sys_sendfile((int)out_fd, (int)in_fd, offset, count);
  127. }
  128. asmlinkage long compat_sys_sendfile64_wrapper(u32 out_fd, u32 in_fd,
  129. compat_loff_t __user *offset, u32 count)
  130. {
  131. return sys_sendfile((int)out_fd, (int)in_fd,
  132. (off_t __user *)offset, count);
  133. }
  134. off_t ppc32_lseek(unsigned int fd, u32 offset, unsigned int origin)
  135. {
  136. /* sign extend n */
  137. return sys_lseek(fd, (int)offset, origin);
  138. }
  139. long compat_sys_truncate(const char __user * path, u32 length)
  140. {
  141. /* sign extend length */
  142. return sys_truncate(path, (int)length);
  143. }
  144. long compat_sys_ftruncate(int fd, u32 length)
  145. {
  146. /* sign extend length */
  147. return sys_ftruncate(fd, (int)length);
  148. }
  149. unsigned long compat_sys_mmap2(unsigned long addr, size_t len,
  150. unsigned long prot, unsigned long flags,
  151. unsigned long fd, unsigned long pgoff)
  152. {
  153. /* This should remain 12 even if PAGE_SIZE changes */
  154. return sys_mmap(addr, len, prot, flags, fd, pgoff << 12);
  155. }
  156. /*
  157. * long long munging:
  158. * The 32 bit ABI passes long longs in an odd even register pair.
  159. */
  160. compat_ssize_t compat_sys_pread64(unsigned int fd, char __user *ubuf, compat_size_t count,
  161. u32 reg6, u32 poshi, u32 poslo)
  162. {
  163. return sys_pread64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
  164. }
  165. compat_ssize_t compat_sys_pwrite64(unsigned int fd, const char __user *ubuf, compat_size_t count,
  166. u32 reg6, u32 poshi, u32 poslo)
  167. {
  168. return sys_pwrite64(fd, ubuf, count, ((loff_t)poshi << 32) | poslo);
  169. }
  170. compat_ssize_t compat_sys_readahead(int fd, u32 r4, u32 offhi, u32 offlo, u32 count)
  171. {
  172. return sys_readahead(fd, ((loff_t)offhi << 32) | offlo, count);
  173. }
  174. asmlinkage int compat_sys_truncate64(const char __user * path, u32 reg4,
  175. unsigned long high, unsigned long low)
  176. {
  177. return sys_truncate(path, (high << 32) | low);
  178. }
  179. asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo,
  180. u32 lenhi, u32 lenlo)
  181. {
  182. return sys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo,
  183. ((loff_t)lenhi << 32) | lenlo);
  184. }
  185. asmlinkage int compat_sys_ftruncate64(unsigned int fd, u32 reg4, unsigned long high,
  186. unsigned long low)
  187. {
  188. return sys_ftruncate(fd, (high << 32) | low);
  189. }
  190. long ppc32_lookup_dcookie(u32 cookie_high, u32 cookie_low, char __user *buf,
  191. size_t len)
  192. {
  193. return sys_lookup_dcookie((u64)cookie_high << 32 | cookie_low,
  194. buf, len);
  195. }
  196. long ppc32_fadvise64(int fd, u32 unused, u32 offset_high, u32 offset_low,
  197. size_t len, int advice)
  198. {
  199. return sys_fadvise64(fd, (u64)offset_high << 32 | offset_low, len,
  200. advice);
  201. }
  202. asmlinkage long compat_sys_add_key(const char __user *_type,
  203. const char __user *_description,
  204. const void __user *_payload,
  205. u32 plen,
  206. u32 ringid)
  207. {
  208. return sys_add_key(_type, _description, _payload, plen, ringid);
  209. }
  210. asmlinkage long compat_sys_request_key(const char __user *_type,
  211. const char __user *_description,
  212. const char __user *_callout_info,
  213. u32 destringid)
  214. {
  215. return sys_request_key(_type, _description, _callout_info, destringid);
  216. }
  217. asmlinkage long compat_sys_sync_file_range2(int fd, unsigned int flags,
  218. unsigned offset_hi, unsigned offset_lo,
  219. unsigned nbytes_hi, unsigned nbytes_lo)
  220. {
  221. loff_t offset = ((loff_t)offset_hi << 32) | offset_lo;
  222. loff_t nbytes = ((loff_t)nbytes_hi << 32) | nbytes_lo;
  223. return sys_sync_file_range(fd, offset, nbytes, flags);
  224. }
  225. asmlinkage long compat_sys_fanotify_mark(int fanotify_fd, unsigned int flags,
  226. unsigned mask_hi, unsigned mask_lo,
  227. int dfd, const char __user *pathname)
  228. {
  229. u64 mask = ((u64)mask_hi << 32) | mask_lo;
  230. return sys_fanotify_mark(fanotify_fd, flags, mask, dfd, pathname);
  231. }