sys_ia64.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /*
  2. * This file contains various system calls that have different calling
  3. * conventions on different platforms.
  4. *
  5. * Copyright (C) 1999-2000, 2002-2003, 2005 Hewlett-Packard Co
  6. * David Mosberger-Tang <davidm@hpl.hp.com>
  7. */
  8. #include <linux/errno.h>
  9. #include <linux/fs.h>
  10. #include <linux/mm.h>
  11. #include <linux/mman.h>
  12. #include <linux/sched.h>
  13. #include <linux/shm.h>
  14. #include <linux/file.h> /* doh, must come after sched.h... */
  15. #include <linux/smp.h>
  16. #include <linux/smp_lock.h>
  17. #include <linux/syscalls.h>
  18. #include <linux/highuid.h>
  19. #include <linux/hugetlb.h>
  20. #include <asm/shmparam.h>
  21. #include <asm/uaccess.h>
  22. unsigned long
  23. arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len,
  24. unsigned long pgoff, unsigned long flags)
  25. {
  26. long map_shared = (flags & MAP_SHARED);
  27. unsigned long start_addr, align_mask = PAGE_SIZE - 1;
  28. struct mm_struct *mm = current->mm;
  29. struct vm_area_struct *vma;
  30. if (len > RGN_MAP_LIMIT)
  31. return -ENOMEM;
  32. /* handle fixed mapping: prevent overlap with huge pages */
  33. if (flags & MAP_FIXED) {
  34. if (is_hugepage_only_range(mm, addr, len))
  35. return -EINVAL;
  36. return addr;
  37. }
  38. #ifdef CONFIG_HUGETLB_PAGE
  39. if (REGION_NUMBER(addr) == RGN_HPAGE)
  40. addr = 0;
  41. #endif
  42. if (!addr)
  43. addr = mm->free_area_cache;
  44. if (map_shared && (TASK_SIZE > 0xfffffffful))
  45. /*
  46. * For 64-bit tasks, align shared segments to 1MB to avoid potential
  47. * performance penalty due to virtual aliasing (see ASDM). For 32-bit
  48. * tasks, we prefer to avoid exhausting the address space too quickly by
  49. * limiting alignment to a single page.
  50. */
  51. align_mask = SHMLBA - 1;
  52. full_search:
  53. start_addr = addr = (addr + align_mask) & ~align_mask;
  54. for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
  55. /* At this point: (!vma || addr < vma->vm_end). */
  56. if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
  57. if (start_addr != TASK_UNMAPPED_BASE) {
  58. /* Start a new search --- just in case we missed some holes. */
  59. addr = TASK_UNMAPPED_BASE;
  60. goto full_search;
  61. }
  62. return -ENOMEM;
  63. }
  64. if (!vma || addr + len <= vma->vm_start) {
  65. /* Remember the address where we stopped this search: */
  66. mm->free_area_cache = addr + len;
  67. return addr;
  68. }
  69. addr = (vma->vm_end + align_mask) & ~align_mask;
  70. }
  71. }
  72. asmlinkage long
  73. ia64_getpriority (int which, int who)
  74. {
  75. long prio;
  76. prio = sys_getpriority(which, who);
  77. if (prio >= 0) {
  78. force_successful_syscall_return();
  79. prio = 20 - prio;
  80. }
  81. return prio;
  82. }
  83. /* XXX obsolete, but leave it here until the old libc is gone... */
  84. asmlinkage unsigned long
  85. sys_getpagesize (void)
  86. {
  87. return PAGE_SIZE;
  88. }
  89. asmlinkage unsigned long
  90. ia64_brk (unsigned long brk)
  91. {
  92. unsigned long rlim, retval, newbrk, oldbrk;
  93. struct mm_struct *mm = current->mm;
  94. /*
  95. * Most of this replicates the code in sys_brk() except for an additional safety
  96. * check and the clearing of r8. However, we can't call sys_brk() because we need
  97. * to acquire the mmap_sem before we can do the test...
  98. */
  99. down_write(&mm->mmap_sem);
  100. if (brk < mm->end_code)
  101. goto out;
  102. newbrk = PAGE_ALIGN(brk);
  103. oldbrk = PAGE_ALIGN(mm->brk);
  104. if (oldbrk == newbrk)
  105. goto set_brk;
  106. /* Always allow shrinking brk. */
  107. if (brk <= mm->brk) {
  108. if (!do_munmap(mm, newbrk, oldbrk-newbrk))
  109. goto set_brk;
  110. goto out;
  111. }
  112. /* Check against unimplemented/unmapped addresses: */
  113. if ((newbrk - oldbrk) > RGN_MAP_LIMIT || REGION_OFFSET(newbrk) > RGN_MAP_LIMIT)
  114. goto out;
  115. /* Check against rlimit.. */
  116. rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
  117. if (rlim < RLIM_INFINITY && brk - mm->start_data > rlim)
  118. goto out;
  119. /* Check against existing mmap mappings. */
  120. if (find_vma_intersection(mm, oldbrk, newbrk+PAGE_SIZE))
  121. goto out;
  122. /* Ok, looks good - let it rip. */
  123. if (do_brk(oldbrk, newbrk-oldbrk) != oldbrk)
  124. goto out;
  125. set_brk:
  126. mm->brk = brk;
  127. out:
  128. retval = mm->brk;
  129. up_write(&mm->mmap_sem);
  130. force_successful_syscall_return();
  131. return retval;
  132. }
  133. /*
  134. * On IA-64, we return the two file descriptors in ret0 and ret1 (r8
  135. * and r9) as this is faster than doing a copy_to_user().
  136. */
  137. asmlinkage long
  138. sys_pipe (void)
  139. {
  140. struct pt_regs *regs = task_pt_regs(current);
  141. int fd[2];
  142. int retval;
  143. retval = do_pipe(fd);
  144. if (retval)
  145. goto out;
  146. retval = fd[0];
  147. regs->r9 = fd[1];
  148. out:
  149. return retval;
  150. }
  151. int ia64_mmap_check(unsigned long addr, unsigned long len,
  152. unsigned long flags)
  153. {
  154. unsigned long roff;
  155. /*
  156. * Don't permit mappings into unmapped space, the virtual page table
  157. * of a region, or across a region boundary. Note: RGN_MAP_LIMIT is
  158. * equal to 2^n-PAGE_SIZE (for some integer n <= 61) and len > 0.
  159. */
  160. roff = REGION_OFFSET(addr);
  161. if ((len > RGN_MAP_LIMIT) || (roff > (RGN_MAP_LIMIT - len)))
  162. return -EINVAL;
  163. return 0;
  164. }
  165. static inline unsigned long
  166. do_mmap2 (unsigned long addr, unsigned long len, int prot, int flags, int fd, unsigned long pgoff)
  167. {
  168. struct file *file = NULL;
  169. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  170. if (!(flags & MAP_ANONYMOUS)) {
  171. file = fget(fd);
  172. if (!file)
  173. return -EBADF;
  174. if (!file->f_op || !file->f_op->mmap) {
  175. addr = -ENODEV;
  176. goto out;
  177. }
  178. }
  179. /* Careful about overflows.. */
  180. len = PAGE_ALIGN(len);
  181. if (!len || len > TASK_SIZE) {
  182. addr = -EINVAL;
  183. goto out;
  184. }
  185. down_write(&current->mm->mmap_sem);
  186. addr = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  187. up_write(&current->mm->mmap_sem);
  188. out: if (file)
  189. fput(file);
  190. return addr;
  191. }
  192. /*
  193. * mmap2() is like mmap() except that the offset is expressed in units
  194. * of PAGE_SIZE (instead of bytes). This allows to mmap2() (pieces
  195. * of) files that are larger than the address space of the CPU.
  196. */
  197. asmlinkage unsigned long
  198. sys_mmap2 (unsigned long addr, unsigned long len, int prot, int flags, int fd, long pgoff)
  199. {
  200. addr = do_mmap2(addr, len, prot, flags, fd, pgoff);
  201. if (!IS_ERR((void *) addr))
  202. force_successful_syscall_return();
  203. return addr;
  204. }
  205. asmlinkage unsigned long
  206. sys_mmap (unsigned long addr, unsigned long len, int prot, int flags, int fd, long off)
  207. {
  208. if (offset_in_page(off) != 0)
  209. return -EINVAL;
  210. addr = do_mmap2(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
  211. if (!IS_ERR((void *) addr))
  212. force_successful_syscall_return();
  213. return addr;
  214. }
  215. asmlinkage unsigned long
  216. ia64_mremap (unsigned long addr, unsigned long old_len, unsigned long new_len, unsigned long flags,
  217. unsigned long new_addr)
  218. {
  219. extern unsigned long do_mremap (unsigned long addr,
  220. unsigned long old_len,
  221. unsigned long new_len,
  222. unsigned long flags,
  223. unsigned long new_addr);
  224. down_write(&current->mm->mmap_sem);
  225. {
  226. addr = do_mremap(addr, old_len, new_len, flags, new_addr);
  227. }
  228. up_write(&current->mm->mmap_sem);
  229. if (IS_ERR((void *) addr))
  230. return addr;
  231. force_successful_syscall_return();
  232. return addr;
  233. }
  234. #ifndef CONFIG_PCI
  235. asmlinkage long
  236. sys_pciconfig_read (unsigned long bus, unsigned long dfn, unsigned long off, unsigned long len,
  237. void *buf)
  238. {
  239. return -ENOSYS;
  240. }
  241. asmlinkage long
  242. sys_pciconfig_write (unsigned long bus, unsigned long dfn, unsigned long off, unsigned long len,
  243. void *buf)
  244. {
  245. return -ENOSYS;
  246. }
  247. #endif /* CONFIG_PCI */