sys_ia64.c 7.1 KB

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