sys_ia64.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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/syscalls.h>
  17. #include <linux/highuid.h>
  18. #include <linux/hugetlb.h>
  19. #include <asm/shmparam.h>
  20. #include <asm/uaccess.h>
  21. unsigned long
  22. arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len,
  23. unsigned long pgoff, unsigned long flags)
  24. {
  25. long map_shared = (flags & MAP_SHARED);
  26. unsigned long start_addr, align_mask = PAGE_SIZE - 1;
  27. struct mm_struct *mm = current->mm;
  28. struct vm_area_struct *vma;
  29. if (len > RGN_MAP_LIMIT)
  30. return -ENOMEM;
  31. /* handle fixed mapping: prevent overlap with huge pages */
  32. if (flags & MAP_FIXED) {
  33. if (is_hugepage_only_range(mm, addr, len))
  34. return -EINVAL;
  35. return addr;
  36. }
  37. #ifdef CONFIG_HUGETLB_PAGE
  38. if (REGION_NUMBER(addr) == RGN_HPAGE)
  39. addr = 0;
  40. #endif
  41. if (!addr)
  42. addr = mm->free_area_cache;
  43. if (map_shared && (TASK_SIZE > 0xfffffffful))
  44. /*
  45. * For 64-bit tasks, align shared segments to 1MB to avoid potential
  46. * performance penalty due to virtual aliasing (see ASDM). For 32-bit
  47. * tasks, we prefer to avoid exhausting the address space too quickly by
  48. * limiting alignment to a single page.
  49. */
  50. align_mask = SHMLBA - 1;
  51. full_search:
  52. start_addr = addr = (addr + align_mask) & ~align_mask;
  53. for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
  54. /* At this point: (!vma || addr < vma->vm_end). */
  55. if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
  56. if (start_addr != TASK_UNMAPPED_BASE) {
  57. /* Start a new search --- just in case we missed some holes. */
  58. addr = TASK_UNMAPPED_BASE;
  59. goto full_search;
  60. }
  61. return -ENOMEM;
  62. }
  63. if (!vma || addr + len <= vma->vm_start) {
  64. /* Remember the address where we stopped this search: */
  65. mm->free_area_cache = addr + len;
  66. return addr;
  67. }
  68. addr = (vma->vm_end + align_mask) & ~align_mask;
  69. }
  70. }
  71. asmlinkage long
  72. ia64_getpriority (int which, int who)
  73. {
  74. long prio;
  75. prio = sys_getpriority(which, who);
  76. if (prio >= 0) {
  77. force_successful_syscall_return();
  78. prio = 20 - prio;
  79. }
  80. return prio;
  81. }
  82. /* XXX obsolete, but leave it here until the old libc is gone... */
  83. asmlinkage unsigned long
  84. sys_getpagesize (void)
  85. {
  86. return PAGE_SIZE;
  87. }
  88. asmlinkage unsigned long
  89. ia64_brk (unsigned long brk)
  90. {
  91. unsigned long retval = sys_brk(brk);
  92. force_successful_syscall_return();
  93. return retval;
  94. }
  95. /*
  96. * On IA-64, we return the two file descriptors in ret0 and ret1 (r8
  97. * and r9) as this is faster than doing a copy_to_user().
  98. */
  99. asmlinkage long
  100. sys_ia64_pipe (void)
  101. {
  102. struct pt_regs *regs = task_pt_regs(current);
  103. int fd[2];
  104. int retval;
  105. retval = do_pipe_flags(fd, 0);
  106. if (retval)
  107. goto out;
  108. retval = fd[0];
  109. regs->r9 = fd[1];
  110. out:
  111. return retval;
  112. }
  113. int ia64_mmap_check(unsigned long addr, unsigned long len,
  114. unsigned long flags)
  115. {
  116. unsigned long roff;
  117. /*
  118. * Don't permit mappings into unmapped space, the virtual page table
  119. * of a region, or across a region boundary. Note: RGN_MAP_LIMIT is
  120. * equal to 2^n-PAGE_SIZE (for some integer n <= 61) and len > 0.
  121. */
  122. roff = REGION_OFFSET(addr);
  123. if ((len > RGN_MAP_LIMIT) || (roff > (RGN_MAP_LIMIT - len)))
  124. return -EINVAL;
  125. return 0;
  126. }
  127. /*
  128. * mmap2() is like mmap() except that the offset is expressed in units
  129. * of PAGE_SIZE (instead of bytes). This allows to mmap2() (pieces
  130. * of) files that are larger than the address space of the CPU.
  131. */
  132. asmlinkage unsigned long
  133. sys_mmap2 (unsigned long addr, unsigned long len, int prot, int flags, int fd, long pgoff)
  134. {
  135. addr = sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff);
  136. if (!IS_ERR((void *) addr))
  137. force_successful_syscall_return();
  138. return addr;
  139. }
  140. asmlinkage unsigned long
  141. sys_mmap (unsigned long addr, unsigned long len, int prot, int flags, int fd, long off)
  142. {
  143. if (offset_in_page(off) != 0)
  144. return -EINVAL;
  145. addr = sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
  146. if (!IS_ERR((void *) addr))
  147. force_successful_syscall_return();
  148. return addr;
  149. }
  150. asmlinkage unsigned long
  151. ia64_mremap (unsigned long addr, unsigned long old_len, unsigned long new_len, unsigned long flags,
  152. unsigned long new_addr)
  153. {
  154. addr = sys_mremap(addr, old_len, new_len, flags, new_addr);
  155. if (!IS_ERR((void *) addr))
  156. force_successful_syscall_return();
  157. return addr;
  158. }
  159. #ifndef CONFIG_PCI
  160. asmlinkage long
  161. sys_pciconfig_read (unsigned long bus, unsigned long dfn, unsigned long off, unsigned long len,
  162. void *buf)
  163. {
  164. return -ENOSYS;
  165. }
  166. asmlinkage long
  167. sys_pciconfig_write (unsigned long bus, unsigned long dfn, unsigned long off, unsigned long len,
  168. void *buf)
  169. {
  170. return -ENOSYS;
  171. }
  172. #endif /* CONFIG_PCI */