• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/linux/linux-2.6.36/arch/ia64/kernel/
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
20#include <asm/shmparam.h>
21#include <asm/uaccess.h>
22
23unsigned long
24arch_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
32	if (len > RGN_MAP_LIMIT)
33		return -ENOMEM;
34
35	/* handle fixed mapping: prevent overlap with huge pages */
36	if (flags & MAP_FIXED) {
37		if (is_hugepage_only_range(mm, addr, len))
38			return -EINVAL;
39		return addr;
40	}
41
42#ifdef CONFIG_HUGETLB_PAGE
43	if (REGION_NUMBER(addr) == RGN_HPAGE)
44		addr = 0;
45#endif
46	if (!addr)
47		addr = mm->free_area_cache;
48
49	if (map_shared && (TASK_SIZE > 0xfffffffful))
50		/*
51		 * For 64-bit tasks, align shared segments to 1MB to avoid potential
52		 * performance penalty due to virtual aliasing (see ASDM).  For 32-bit
53		 * tasks, we prefer to avoid exhausting the address space too quickly by
54		 * limiting alignment to a single page.
55		 */
56		align_mask = SHMLBA - 1;
57
58  full_search:
59	start_addr = addr = (addr + align_mask) & ~align_mask;
60
61	for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
62		/* At this point:  (!vma || addr < vma->vm_end). */
63		if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
64			if (start_addr != TASK_UNMAPPED_BASE) {
65				/* Start a new search --- just in case we missed some holes.  */
66				addr = TASK_UNMAPPED_BASE;
67				goto full_search;
68			}
69			return -ENOMEM;
70		}
71		if (!vma || addr + len <= vma->vm_start) {
72			/* Remember the address where we stopped this search:  */
73			mm->free_area_cache = addr + len;
74			return addr;
75		}
76		addr = (vma->vm_end + align_mask) & ~align_mask;
77	}
78}
79
80asmlinkage long
81ia64_getpriority (int which, int who)
82{
83	long prio;
84
85	prio = sys_getpriority(which, who);
86	if (prio >= 0) {
87		force_successful_syscall_return();
88		prio = 20 - prio;
89	}
90	return prio;
91}
92
93asmlinkage unsigned long
94sys_getpagesize (void)
95{
96	return PAGE_SIZE;
97}
98
99asmlinkage unsigned long
100ia64_brk (unsigned long brk)
101{
102	unsigned long retval = sys_brk(brk);
103	force_successful_syscall_return();
104	return retval;
105}
106
107/*
108 * On IA-64, we return the two file descriptors in ret0 and ret1 (r8
109 * and r9) as this is faster than doing a copy_to_user().
110 */
111asmlinkage long
112sys_ia64_pipe (void)
113{
114	struct pt_regs *regs = task_pt_regs(current);
115	int fd[2];
116	int retval;
117
118	retval = do_pipe_flags(fd, 0);
119	if (retval)
120		goto out;
121	retval = fd[0];
122	regs->r9 = fd[1];
123  out:
124	return retval;
125}
126
127int ia64_mmap_check(unsigned long addr, unsigned long len,
128		unsigned long flags)
129{
130	unsigned long roff;
131
132	/*
133	 * Don't permit mappings into unmapped space, the virtual page table
134	 * of a region, or across a region boundary.  Note: RGN_MAP_LIMIT is
135	 * equal to 2^n-PAGE_SIZE (for some integer n <= 61) and len > 0.
136	 */
137	roff = REGION_OFFSET(addr);
138	if ((len > RGN_MAP_LIMIT) || (roff > (RGN_MAP_LIMIT - len)))
139		return -EINVAL;
140	return 0;
141}
142
143/*
144 * mmap2() is like mmap() except that the offset is expressed in units
145 * of PAGE_SIZE (instead of bytes).  This allows to mmap2() (pieces
146 * of) files that are larger than the address space of the CPU.
147 */
148asmlinkage unsigned long
149sys_mmap2 (unsigned long addr, unsigned long len, int prot, int flags, int fd, long pgoff)
150{
151	addr = sys_mmap_pgoff(addr, len, prot, flags, fd, pgoff);
152	if (!IS_ERR((void *) addr))
153		force_successful_syscall_return();
154	return addr;
155}
156
157asmlinkage unsigned long
158sys_mmap (unsigned long addr, unsigned long len, int prot, int flags, int fd, long off)
159{
160	if (offset_in_page(off) != 0)
161		return -EINVAL;
162
163	addr = sys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
164	if (!IS_ERR((void *) addr))
165		force_successful_syscall_return();
166	return addr;
167}
168
169asmlinkage unsigned long
170ia64_mremap (unsigned long addr, unsigned long old_len, unsigned long new_len, unsigned long flags,
171	     unsigned long new_addr)
172{
173	extern unsigned long do_mremap (unsigned long addr,
174					unsigned long old_len,
175					unsigned long new_len,
176					unsigned long flags,
177					unsigned long new_addr);
178
179	down_write(&current->mm->mmap_sem);
180	{
181		addr = do_mremap(addr, old_len, new_len, flags, new_addr);
182	}
183	up_write(&current->mm->mmap_sem);
184
185	if (IS_ERR((void *) addr))
186		return addr;
187
188	force_successful_syscall_return();
189	return addr;
190}
191
192#ifndef CONFIG_PCI
193
194asmlinkage long
195sys_pciconfig_read (unsigned long bus, unsigned long dfn, unsigned long off, unsigned long len,
196		    void *buf)
197{
198	return -ENOSYS;
199}
200
201asmlinkage long
202sys_pciconfig_write (unsigned long bus, unsigned long dfn, unsigned long off, unsigned long len,
203		     void *buf)
204{
205	return -ENOSYS;
206}
207
208#endif /* CONFIG_PCI */
209