blob: 6fed0803c59378ef038694ed2038805516899d0a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
2/*
3 * PARISC specific syscalls
4 *
5 * Copyright (C) 1999-2003 Matthew Wilcox <willy at parisc-linux.org>
6 * Copyright (C) 2000-2003 Paul Bame <bame at parisc-linux.org>
7 * Copyright (C) 2001 Thomas Bogendoerfer <tsbogend at parisc-linux.org>
8 *
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
25#include <asm/uaccess.h>
26#include <linux/file.h>
27#include <linux/fs.h>
28#include <linux/linkage.h>
29#include <linux/mm.h>
30#include <linux/mman.h>
31#include <linux/shm.h>
32#include <linux/smp_lock.h>
33#include <linux/syscalls.h>
Kyle McMartin75a49582006-08-27 11:12:13 -040034#include <linux/utsname.h>
35#include <linux/personality.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37int sys_pipe(int __user *fildes)
38{
39 int fd[2];
40 int error;
41
42 error = do_pipe(fd);
43 if (!error) {
44 if (copy_to_user(fildes, fd, 2*sizeof(int)))
45 error = -EFAULT;
46 }
47 return error;
48}
49
50static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
51{
52 struct vm_area_struct *vma;
53
54 addr = PAGE_ALIGN(addr);
55
56 for (vma = find_vma(current->mm, addr); ; vma = vma->vm_next) {
57 /* At this point: (!vma || addr < vma->vm_end). */
58 if (TASK_SIZE - len < addr)
59 return -ENOMEM;
60 if (!vma || addr + len <= vma->vm_start)
61 return addr;
62 addr = vma->vm_end;
63 }
64}
65
66#define DCACHE_ALIGN(addr) (((addr) + (SHMLBA - 1)) &~ (SHMLBA - 1))
67
68/*
69 * We need to know the offset to use. Old scheme was to look for
70 * existing mapping and use the same offset. New scheme is to use the
71 * address of the kernel data structure as the seed for the offset.
72 * We'll see how that works...
73 *
74 * The mapping is cacheline aligned, so there's no information in the bottom
75 * few bits of the address. We're looking for 10 bits (4MB / 4k), so let's
76 * drop the bottom 8 bits and use bits 8-17.
77 */
78static int get_offset(struct address_space *mapping)
79{
80 int offset = (unsigned long) mapping << (PAGE_SHIFT - 8);
81 return offset & 0x3FF000;
82}
83
84static unsigned long get_shared_area(struct address_space *mapping,
85 unsigned long addr, unsigned long len, unsigned long pgoff)
86{
87 struct vm_area_struct *vma;
88 int offset = mapping ? get_offset(mapping) : 0;
89
90 addr = DCACHE_ALIGN(addr - offset) + offset;
91
92 for (vma = find_vma(current->mm, addr); ; vma = vma->vm_next) {
93 /* At this point: (!vma || addr < vma->vm_end). */
94 if (TASK_SIZE - len < addr)
95 return -ENOMEM;
96 if (!vma || addr + len <= vma->vm_start)
97 return addr;
98 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
99 if (addr < vma->vm_end) /* handle wraparound */
100 return -ENOMEM;
101 }
102}
103
104unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
105 unsigned long len, unsigned long pgoff, unsigned long flags)
106{
107 if (len > TASK_SIZE)
108 return -ENOMEM;
Benjamin Herrenschmidt869e5102007-05-06 14:50:09 -0700109 /* Might want to check for cache aliasing issues for MAP_FIXED case
110 * like ARM or MIPS ??? --BenH.
111 */
112 if (flags & MAP_FIXED)
113 return addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 if (!addr)
115 addr = TASK_UNMAPPED_BASE;
116
117 if (filp) {
118 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
119 } else if(flags & MAP_SHARED) {
120 addr = get_shared_area(NULL, addr, len, pgoff);
121 } else {
122 addr = get_unshared_area(addr, len);
123 }
124 return addr;
125}
126
127static unsigned long do_mmap2(unsigned long addr, unsigned long len,
128 unsigned long prot, unsigned long flags, unsigned long fd,
129 unsigned long pgoff)
130{
131 struct file * file = NULL;
132 unsigned long error = -EBADF;
133 if (!(flags & MAP_ANONYMOUS)) {
134 file = fget(fd);
135 if (!file)
136 goto out;
137 }
138
139 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
140
141 down_write(&current->mm->mmap_sem);
142 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
143 up_write(&current->mm->mmap_sem);
144
145 if (file != NULL)
146 fput(file);
147out:
148 return error;
149}
150
151asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len,
152 unsigned long prot, unsigned long flags, unsigned long fd,
153 unsigned long pgoff)
154{
155 /* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE
156 we have. */
157 return do_mmap2(addr, len, prot, flags, fd, pgoff >> (PAGE_SHIFT - 12));
158}
159
160asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len,
161 unsigned long prot, unsigned long flags, unsigned long fd,
162 unsigned long offset)
163{
164 if (!(offset & ~PAGE_MASK)) {
165 return do_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
166 } else {
167 return -EINVAL;
168 }
169}
170
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171/* Fucking broken ABI */
172
173#ifdef CONFIG_64BIT
174asmlinkage long parisc_truncate64(const char __user * path,
175 unsigned int high, unsigned int low)
176{
177 return sys_truncate(path, (long)high << 32 | low);
178}
179
180asmlinkage long parisc_ftruncate64(unsigned int fd,
181 unsigned int high, unsigned int low)
182{
183 return sys_ftruncate(fd, (long)high << 32 | low);
184}
185
186/* stubs for the benefit of the syscall_table since truncate64 and truncate
187 * are identical on LP64 */
188asmlinkage long sys_truncate64(const char __user * path, unsigned long length)
189{
190 return sys_truncate(path, length);
191}
192asmlinkage long sys_ftruncate64(unsigned int fd, unsigned long length)
193{
194 return sys_ftruncate(fd, length);
195}
196asmlinkage long sys_fcntl64(unsigned int fd, unsigned int cmd, unsigned long arg)
197{
198 return sys_fcntl(fd, cmd, arg);
199}
200#else
201
202asmlinkage long parisc_truncate64(const char __user * path,
203 unsigned int high, unsigned int low)
204{
205 return sys_truncate64(path, (loff_t)high << 32 | low);
206}
207
208asmlinkage long parisc_ftruncate64(unsigned int fd,
209 unsigned int high, unsigned int low)
210{
211 return sys_ftruncate64(fd, (loff_t)high << 32 | low);
212}
213#endif
214
215asmlinkage ssize_t parisc_pread64(unsigned int fd, char __user *buf, size_t count,
216 unsigned int high, unsigned int low)
217{
218 return sys_pread64(fd, buf, count, (loff_t)high << 32 | low);
219}
220
221asmlinkage ssize_t parisc_pwrite64(unsigned int fd, const char __user *buf,
222 size_t count, unsigned int high, unsigned int low)
223{
224 return sys_pwrite64(fd, buf, count, (loff_t)high << 32 | low);
225}
226
227asmlinkage ssize_t parisc_readahead(int fd, unsigned int high, unsigned int low,
228 size_t count)
229{
230 return sys_readahead(fd, (loff_t)high << 32 | low, count);
231}
232
233asmlinkage long parisc_fadvise64_64(int fd,
234 unsigned int high_off, unsigned int low_off,
235 unsigned int high_len, unsigned int low_len, int advice)
236{
237 return sys_fadvise64_64(fd, (loff_t)high_off << 32 | low_off,
238 (loff_t)high_len << 32 | low_len, advice);
239}
240
Kyle McMartin6ca773c2006-04-20 04:44:07 +0000241asmlinkage long parisc_sync_file_range(int fd,
242 u32 hi_off, u32 lo_off, u32 hi_nbytes, u32 lo_nbytes,
243 unsigned int flags)
244{
245 return sys_sync_file_range(fd, (loff_t)hi_off << 32 | lo_off,
246 (loff_t)hi_nbytes << 32 | lo_nbytes, flags);
247}
248
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249asmlinkage unsigned long sys_alloc_hugepages(int key, unsigned long addr, unsigned long len, int prot, int flag)
250{
251 return -ENOMEM;
252}
253
254asmlinkage int sys_free_hugepages(unsigned long addr)
255{
256 return -EINVAL;
257}
Kyle McMartin75a49582006-08-27 11:12:13 -0400258
259long parisc_personality(unsigned long personality)
260{
261 long err;
262
263 if (personality(current->personality) == PER_LINUX32
264 && personality == PER_LINUX)
265 personality = PER_LINUX32;
266
267 err = sys_personality(personality);
268 if (err == PER_LINUX32)
269 err = PER_LINUX;
270
271 return err;
272}
273
Matthew Wilcoxf64ef292006-10-04 13:33:53 -0600274long parisc_newuname(struct new_utsname __user *name)
Kyle McMartin75a49582006-08-27 11:12:13 -0400275{
Matthew Wilcoxf64ef292006-10-04 13:33:53 -0600276 int err = sys_newuname(name);
Kyle McMartin75a49582006-08-27 11:12:13 -0400277
Matthew Wilcoxf64ef292006-10-04 13:33:53 -0600278#ifdef CONFIG_COMPAT
279 if (!err && personality(current->personality) == PER_LINUX32) {
280 if (__put_user(0, name->machine + 6) ||
281 __put_user(0, name->machine + 7))
282 err = -EFAULT;
283 }
284#endif
Kyle McMartin75a49582006-08-27 11:12:13 -0400285
Matthew Wilcoxf64ef292006-10-04 13:33:53 -0600286 return err;
Kyle McMartin75a49582006-08-27 11:12:13 -0400287}