sys_parisc.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 get_shared_area(struct address_space *mapping,
  59. unsigned long addr, unsigned long len, unsigned long pgoff)
  60. {
  61. struct vm_unmapped_area_info info;
  62. info.flags = 0;
  63. info.length = len;
  64. info.low_limit = PAGE_ALIGN(addr);
  65. info.high_limit = TASK_SIZE;
  66. info.align_mask = PAGE_MASK & (SHMLBA - 1);
  67. info.align_offset = (get_offset(mapping) + pgoff) << PAGE_SHIFT;
  68. return vm_unmapped_area(&info);
  69. }
  70. unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
  71. unsigned long len, unsigned long pgoff, unsigned long flags)
  72. {
  73. if (len > TASK_SIZE)
  74. return -ENOMEM;
  75. if (flags & MAP_FIXED) {
  76. if ((flags & MAP_SHARED) &&
  77. (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))
  78. return -EINVAL;
  79. return addr;
  80. }
  81. if (!addr)
  82. addr = TASK_UNMAPPED_BASE;
  83. if (filp) {
  84. addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
  85. } else if(flags & MAP_SHARED) {
  86. addr = get_shared_area(NULL, addr, len, pgoff);
  87. } else {
  88. addr = get_unshared_area(addr, len);
  89. }
  90. return addr;
  91. }
  92. asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len,
  93. unsigned long prot, unsigned long flags, unsigned long fd,
  94. unsigned long pgoff)
  95. {
  96. /* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE
  97. we have. */
  98. return sys_mmap_pgoff(addr, len, prot, flags, fd,
  99. pgoff >> (PAGE_SHIFT - 12));
  100. }
  101. asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len,
  102. unsigned long prot, unsigned long flags, unsigned long fd,
  103. unsigned long offset)
  104. {
  105. if (!(offset & ~PAGE_MASK)) {
  106. return sys_mmap_pgoff(addr, len, prot, flags, fd,
  107. offset >> PAGE_SHIFT);
  108. } else {
  109. return -EINVAL;
  110. }
  111. }
  112. /* Fucking broken ABI */
  113. #ifdef CONFIG_64BIT
  114. asmlinkage long parisc_truncate64(const char __user * path,
  115. unsigned int high, unsigned int low)
  116. {
  117. return sys_truncate(path, (long)high << 32 | low);
  118. }
  119. asmlinkage long parisc_ftruncate64(unsigned int fd,
  120. unsigned int high, unsigned int low)
  121. {
  122. return sys_ftruncate(fd, (long)high << 32 | low);
  123. }
  124. /* stubs for the benefit of the syscall_table since truncate64 and truncate
  125. * are identical on LP64 */
  126. asmlinkage long sys_truncate64(const char __user * path, unsigned long length)
  127. {
  128. return sys_truncate(path, length);
  129. }
  130. asmlinkage long sys_ftruncate64(unsigned int fd, unsigned long length)
  131. {
  132. return sys_ftruncate(fd, length);
  133. }
  134. asmlinkage long sys_fcntl64(unsigned int fd, unsigned int cmd, unsigned long arg)
  135. {
  136. return sys_fcntl(fd, cmd, arg);
  137. }
  138. #else
  139. asmlinkage long parisc_truncate64(const char __user * path,
  140. unsigned int high, unsigned int low)
  141. {
  142. return sys_truncate64(path, (loff_t)high << 32 | low);
  143. }
  144. asmlinkage long parisc_ftruncate64(unsigned int fd,
  145. unsigned int high, unsigned int low)
  146. {
  147. return sys_ftruncate64(fd, (loff_t)high << 32 | low);
  148. }
  149. #endif
  150. asmlinkage ssize_t parisc_pread64(unsigned int fd, char __user *buf, size_t count,
  151. unsigned int high, unsigned int low)
  152. {
  153. return sys_pread64(fd, buf, count, (loff_t)high << 32 | low);
  154. }
  155. asmlinkage ssize_t parisc_pwrite64(unsigned int fd, const char __user *buf,
  156. size_t count, unsigned int high, unsigned int low)
  157. {
  158. return sys_pwrite64(fd, buf, count, (loff_t)high << 32 | low);
  159. }
  160. asmlinkage ssize_t parisc_readahead(int fd, unsigned int high, unsigned int low,
  161. size_t count)
  162. {
  163. return sys_readahead(fd, (loff_t)high << 32 | low, count);
  164. }
  165. asmlinkage long parisc_fadvise64_64(int fd,
  166. unsigned int high_off, unsigned int low_off,
  167. unsigned int high_len, unsigned int low_len, int advice)
  168. {
  169. return sys_fadvise64_64(fd, (loff_t)high_off << 32 | low_off,
  170. (loff_t)high_len << 32 | low_len, advice);
  171. }
  172. asmlinkage long parisc_sync_file_range(int fd,
  173. u32 hi_off, u32 lo_off, u32 hi_nbytes, u32 lo_nbytes,
  174. unsigned int flags)
  175. {
  176. return sys_sync_file_range(fd, (loff_t)hi_off << 32 | lo_off,
  177. (loff_t)hi_nbytes << 32 | lo_nbytes, flags);
  178. }
  179. asmlinkage long parisc_fallocate(int fd, int mode, u32 offhi, u32 offlo,
  180. u32 lenhi, u32 lenlo)
  181. {
  182. return sys_fallocate(fd, mode, ((u64)offhi << 32) | offlo,
  183. ((u64)lenhi << 32) | lenlo);
  184. }
  185. asmlinkage unsigned long sys_alloc_hugepages(int key, unsigned long addr, unsigned long len, int prot, int flag)
  186. {
  187. return -ENOMEM;
  188. }
  189. asmlinkage int sys_free_hugepages(unsigned long addr)
  190. {
  191. return -EINVAL;
  192. }
  193. long parisc_personality(unsigned long personality)
  194. {
  195. long err;
  196. if (personality(current->personality) == PER_LINUX32
  197. && personality(personality) == PER_LINUX)
  198. personality = (personality & ~PER_MASK) | PER_LINUX32;
  199. err = sys_personality(personality);
  200. if (personality(err) == PER_LINUX32)
  201. err = (err & ~PER_MASK) | PER_LINUX;
  202. return err;
  203. }