sys_parisc.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. * PARISC specific syscalls
  3. *
  4. * Copyright (C) 1999-2003 Matthew Wilcox <willy at parisc-linux.org>
  5. * Copyright (C) 2000-2003 Paul Bame <bame at parisc-linux.org>
  6. * Copyright (C) 2001 Thomas Bogendoerfer <tsbogend at parisc-linux.org>
  7. *
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. #include <asm/uaccess.h>
  24. #include <linux/file.h>
  25. #include <linux/fs.h>
  26. #include <linux/linkage.h>
  27. #include <linux/mm.h>
  28. #include <linux/mman.h>
  29. #include <linux/shm.h>
  30. #include <linux/syscalls.h>
  31. #include <linux/utsname.h>
  32. #include <linux/personality.h>
  33. static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
  34. {
  35. struct vm_unmapped_area_info info;
  36. info.flags = 0;
  37. info.length = len;
  38. info.low_limit = PAGE_ALIGN(addr);
  39. info.high_limit = TASK_SIZE;
  40. info.align_mask = 0;
  41. info.align_offset = 0;
  42. return vm_unmapped_area(&info);
  43. }
  44. /*
  45. * We need to know the offset to use. Old scheme was to look for
  46. * existing mapping and use the same offset. New scheme is to use the
  47. * address of the kernel data structure as the seed for the offset.
  48. * We'll see how that works...
  49. *
  50. * The mapping is cacheline aligned, so there's no information in the bottom
  51. * few bits of the address. We're looking for 10 bits (4MB / 4k), so let's
  52. * drop the bottom 8 bits and use bits 8-17.
  53. */
  54. static int get_offset(struct address_space *mapping)
  55. {
  56. return (unsigned long) mapping >> 8;
  57. }
  58. static unsigned long shared_align_offset(struct file *filp, unsigned long pgoff)
  59. {
  60. struct address_space *mapping = filp ? filp->f_mapping : NULL;
  61. return (get_offset(mapping) + pgoff) << PAGE_SHIFT;
  62. }
  63. static unsigned long get_shared_area(struct file *filp, unsigned long addr,
  64. unsigned long len, unsigned long pgoff)
  65. {
  66. struct vm_unmapped_area_info info;
  67. info.flags = 0;
  68. info.length = len;
  69. info.low_limit = PAGE_ALIGN(addr);
  70. info.high_limit = TASK_SIZE;
  71. info.align_mask = PAGE_MASK & (SHMLBA - 1);
  72. info.align_offset = shared_align_offset(filp, pgoff);
  73. return vm_unmapped_area(&info);
  74. }
  75. unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
  76. unsigned long len, unsigned long pgoff, unsigned long flags)
  77. {
  78. if (len > TASK_SIZE)
  79. return -ENOMEM;
  80. if (flags & MAP_FIXED) {
  81. if ((flags & MAP_SHARED) &&
  82. (addr - shared_align_offset(filp, pgoff)) & (SHMLBA - 1))
  83. return -EINVAL;
  84. return addr;
  85. }
  86. if (!addr)
  87. addr = TASK_UNMAPPED_BASE;
  88. if (filp || (flags & MAP_SHARED))
  89. addr = get_shared_area(filp, addr, len, pgoff);
  90. else
  91. addr = get_unshared_area(addr, len);
  92. return addr;
  93. }
  94. asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len,
  95. unsigned long prot, unsigned long flags, unsigned long fd,
  96. unsigned long pgoff)
  97. {
  98. /* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE
  99. we have. */
  100. return sys_mmap_pgoff(addr, len, prot, flags, fd,
  101. pgoff >> (PAGE_SHIFT - 12));
  102. }
  103. asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len,
  104. unsigned long prot, unsigned long flags, unsigned long fd,
  105. unsigned long offset)
  106. {
  107. if (!(offset & ~PAGE_MASK)) {
  108. return sys_mmap_pgoff(addr, len, prot, flags, fd,
  109. offset >> PAGE_SHIFT);
  110. } else {
  111. return -EINVAL;
  112. }
  113. }
  114. /* Fucking broken ABI */
  115. #ifdef CONFIG_64BIT
  116. asmlinkage long parisc_truncate64(const char __user * path,
  117. unsigned int high, unsigned int low)
  118. {
  119. return sys_truncate(path, (long)high << 32 | low);
  120. }
  121. asmlinkage long parisc_ftruncate64(unsigned int fd,
  122. unsigned int high, unsigned int low)
  123. {
  124. return sys_ftruncate(fd, (long)high << 32 | low);
  125. }
  126. /* stubs for the benefit of the syscall_table since truncate64 and truncate
  127. * are identical on LP64 */
  128. asmlinkage long sys_truncate64(const char __user * path, unsigned long length)
  129. {
  130. return sys_truncate(path, length);
  131. }
  132. asmlinkage long sys_ftruncate64(unsigned int fd, unsigned long length)
  133. {
  134. return sys_ftruncate(fd, length);
  135. }
  136. asmlinkage long sys_fcntl64(unsigned int fd, unsigned int cmd, unsigned long arg)
  137. {
  138. return sys_fcntl(fd, cmd, arg);
  139. }
  140. #else
  141. asmlinkage long parisc_truncate64(const char __user * path,
  142. unsigned int high, unsigned int low)
  143. {
  144. return sys_truncate64(path, (loff_t)high << 32 | low);
  145. }
  146. asmlinkage long parisc_ftruncate64(unsigned int fd,
  147. unsigned int high, unsigned int low)
  148. {
  149. return sys_ftruncate64(fd, (loff_t)high << 32 | low);
  150. }
  151. #endif
  152. asmlinkage ssize_t parisc_pread64(unsigned int fd, char __user *buf, size_t count,
  153. unsigned int high, unsigned int low)
  154. {
  155. return sys_pread64(fd, buf, count, (loff_t)high << 32 | low);
  156. }
  157. asmlinkage ssize_t parisc_pwrite64(unsigned int fd, const char __user *buf,
  158. size_t count, unsigned int high, unsigned int low)
  159. {
  160. return sys_pwrite64(fd, buf, count, (loff_t)high << 32 | low);
  161. }
  162. asmlinkage ssize_t parisc_readahead(int fd, unsigned int high, unsigned int low,
  163. size_t count)
  164. {
  165. return sys_readahead(fd, (loff_t)high << 32 | low, count);
  166. }
  167. asmlinkage long parisc_fadvise64_64(int fd,
  168. unsigned int high_off, unsigned int low_off,
  169. unsigned int high_len, unsigned int low_len, int advice)
  170. {
  171. return sys_fadvise64_64(fd, (loff_t)high_off << 32 | low_off,
  172. (loff_t)high_len << 32 | low_len, advice);
  173. }
  174. asmlinkage long parisc_sync_file_range(int fd,
  175. u32 hi_off, u32 lo_off, u32 hi_nbytes, u32 lo_nbytes,
  176. unsigned int flags)
  177. {
  178. return sys_sync_file_range(fd, (loff_t)hi_off << 32 | lo_off,
  179. (loff_t)hi_nbytes << 32 | lo_nbytes, flags);
  180. }
  181. asmlinkage long parisc_fallocate(int fd, int mode, u32 offhi, u32 offlo,
  182. u32 lenhi, u32 lenlo)
  183. {
  184. return sys_fallocate(fd, mode, ((u64)offhi << 32) | offlo,
  185. ((u64)lenhi << 32) | lenlo);
  186. }
  187. asmlinkage unsigned long sys_alloc_hugepages(int key, unsigned long addr, unsigned long len, int prot, int flag)
  188. {
  189. return -ENOMEM;
  190. }
  191. asmlinkage int sys_free_hugepages(unsigned long addr)
  192. {
  193. return -EINVAL;
  194. }
  195. long parisc_personality(unsigned long personality)
  196. {
  197. long err;
  198. if (personality(current->personality) == PER_LINUX32
  199. && personality(personality) == PER_LINUX)
  200. personality = (personality & ~PER_MASK) | PER_LINUX32;
  201. err = sys_personality(personality);
  202. if (personality(err) == PER_LINUX32)
  203. err = (err & ~PER_MASK) | PER_LINUX;
  204. return err;
  205. }