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