blob: 54d619d4cac6107c0df8d7ccd5f111dd5e0486c0 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/syscalls.h>
Kyle McMartin75a49582006-08-27 11:12:13 -040033#include <linux/utsname.h>
34#include <linux/personality.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Linus Torvalds1da177e2005-04-16 15:20:36 -070036static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
37{
38 struct vm_area_struct *vma;
39
40 addr = PAGE_ALIGN(addr);
41
42 for (vma = find_vma(current->mm, addr); ; vma = vma->vm_next) {
43 /* At this point: (!vma || addr < vma->vm_end). */
44 if (TASK_SIZE - len < addr)
45 return -ENOMEM;
46 if (!vma || addr + len <= vma->vm_start)
47 return addr;
48 addr = vma->vm_end;
49 }
50}
51
52#define DCACHE_ALIGN(addr) (((addr) + (SHMLBA - 1)) &~ (SHMLBA - 1))
53
54/*
55 * We need to know the offset to use. Old scheme was to look for
56 * existing mapping and use the same offset. New scheme is to use the
57 * address of the kernel data structure as the seed for the offset.
58 * We'll see how that works...
59 *
60 * The mapping is cacheline aligned, so there's no information in the bottom
61 * few bits of the address. We're looking for 10 bits (4MB / 4k), so let's
62 * drop the bottom 8 bits and use bits 8-17.
63 */
64static int get_offset(struct address_space *mapping)
65{
66 int offset = (unsigned long) mapping << (PAGE_SHIFT - 8);
67 return offset & 0x3FF000;
68}
69
70static unsigned long get_shared_area(struct address_space *mapping,
71 unsigned long addr, unsigned long len, unsigned long pgoff)
72{
73 struct vm_area_struct *vma;
74 int offset = mapping ? get_offset(mapping) : 0;
75
James Bottomley949a05d2012-11-02 12:30:53 +000076 offset = (offset + (pgoff << PAGE_SHIFT)) & 0x3FF000;
77
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 addr = DCACHE_ALIGN(addr - offset) + offset;
79
80 for (vma = find_vma(current->mm, addr); ; vma = vma->vm_next) {
81 /* At this point: (!vma || addr < vma->vm_end). */
82 if (TASK_SIZE - len < addr)
83 return -ENOMEM;
84 if (!vma || addr + len <= vma->vm_start)
85 return addr;
86 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
87 if (addr < vma->vm_end) /* handle wraparound */
88 return -ENOMEM;
89 }
90}
91
92unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
93 unsigned long len, unsigned long pgoff, unsigned long flags)
94{
95 if (len > TASK_SIZE)
96 return -ENOMEM;
John David Anglin5ca8b912013-02-02 23:44:59 +000097 if (flags & MAP_FIXED) {
98 if ((flags & MAP_SHARED) &&
99 (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))
100 return -EINVAL;
Benjamin Herrenschmidt869e5102007-05-06 14:50:09 -0700101 return addr;
John David Anglin5ca8b912013-02-02 23:44:59 +0000102 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 if (!addr)
104 addr = TASK_UNMAPPED_BASE;
105
106 if (filp) {
107 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
108 } else if(flags & MAP_SHARED) {
109 addr = get_shared_area(NULL, addr, len, pgoff);
110 } else {
111 addr = get_unshared_area(addr, len);
112 }
113 return addr;
114}
115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len,
117 unsigned long prot, unsigned long flags, unsigned long fd,
118 unsigned long pgoff)
119{
120 /* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE
121 we have. */
Al Virof8b72562009-11-30 17:37:04 -0500122 return sys_mmap_pgoff(addr, len, prot, flags, fd,
123 pgoff >> (PAGE_SHIFT - 12));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124}
125
126asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len,
127 unsigned long prot, unsigned long flags, unsigned long fd,
128 unsigned long offset)
129{
130 if (!(offset & ~PAGE_MASK)) {
Al Virof8b72562009-11-30 17:37:04 -0500131 return sys_mmap_pgoff(addr, len, prot, flags, fd,
132 offset >> PAGE_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 } else {
134 return -EINVAL;
135 }
136}
137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138/* Fucking broken ABI */
139
140#ifdef CONFIG_64BIT
141asmlinkage long parisc_truncate64(const char __user * path,
142 unsigned int high, unsigned int low)
143{
144 return sys_truncate(path, (long)high << 32 | low);
145}
146
147asmlinkage long parisc_ftruncate64(unsigned int fd,
148 unsigned int high, unsigned int low)
149{
150 return sys_ftruncate(fd, (long)high << 32 | low);
151}
152
153/* stubs for the benefit of the syscall_table since truncate64 and truncate
154 * are identical on LP64 */
155asmlinkage long sys_truncate64(const char __user * path, unsigned long length)
156{
157 return sys_truncate(path, length);
158}
159asmlinkage long sys_ftruncate64(unsigned int fd, unsigned long length)
160{
161 return sys_ftruncate(fd, length);
162}
163asmlinkage long sys_fcntl64(unsigned int fd, unsigned int cmd, unsigned long arg)
164{
165 return sys_fcntl(fd, cmd, arg);
166}
167#else
168
169asmlinkage long parisc_truncate64(const char __user * path,
170 unsigned int high, unsigned int low)
171{
172 return sys_truncate64(path, (loff_t)high << 32 | low);
173}
174
175asmlinkage long parisc_ftruncate64(unsigned int fd,
176 unsigned int high, unsigned int low)
177{
178 return sys_ftruncate64(fd, (loff_t)high << 32 | low);
179}
180#endif
181
182asmlinkage ssize_t parisc_pread64(unsigned int fd, char __user *buf, size_t count,
183 unsigned int high, unsigned int low)
184{
185 return sys_pread64(fd, buf, count, (loff_t)high << 32 | low);
186}
187
188asmlinkage ssize_t parisc_pwrite64(unsigned int fd, const char __user *buf,
189 size_t count, unsigned int high, unsigned int low)
190{
191 return sys_pwrite64(fd, buf, count, (loff_t)high << 32 | low);
192}
193
194asmlinkage ssize_t parisc_readahead(int fd, unsigned int high, unsigned int low,
195 size_t count)
196{
197 return sys_readahead(fd, (loff_t)high << 32 | low, count);
198}
199
200asmlinkage long parisc_fadvise64_64(int fd,
201 unsigned int high_off, unsigned int low_off,
202 unsigned int high_len, unsigned int low_len, int advice)
203{
204 return sys_fadvise64_64(fd, (loff_t)high_off << 32 | low_off,
205 (loff_t)high_len << 32 | low_len, advice);
206}
207
Kyle McMartin6ca773c2006-04-20 04:44:07 +0000208asmlinkage long parisc_sync_file_range(int fd,
209 u32 hi_off, u32 lo_off, u32 hi_nbytes, u32 lo_nbytes,
210 unsigned int flags)
211{
212 return sys_sync_file_range(fd, (loff_t)hi_off << 32 | lo_off,
213 (loff_t)hi_nbytes << 32 | lo_nbytes, flags);
214}
215
Helge Deller4474a332013-02-19 21:23:59 +0100216asmlinkage long parisc_fallocate(int fd, int mode, u32 offhi, u32 offlo,
217 u32 lenhi, u32 lenlo)
218{
219 return sys_fallocate(fd, mode, ((u64)offhi << 32) | offlo,
220 ((u64)lenhi << 32) | lenlo);
221}
222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223asmlinkage unsigned long sys_alloc_hugepages(int key, unsigned long addr, unsigned long len, int prot, int flag)
224{
225 return -ENOMEM;
226}
227
228asmlinkage int sys_free_hugepages(unsigned long addr)
229{
230 return -EINVAL;
231}
Kyle McMartin75a49582006-08-27 11:12:13 -0400232
233long parisc_personality(unsigned long personality)
234{
235 long err;
236
237 if (personality(current->personality) == PER_LINUX32
Jiri Kosina5b24c422012-08-02 15:33:59 +0200238 && personality(personality) == PER_LINUX)
239 personality = (personality & ~PER_MASK) | PER_LINUX32;
Kyle McMartin75a49582006-08-27 11:12:13 -0400240
241 err = sys_personality(personality);
Jiri Kosina5b24c422012-08-02 15:33:59 +0200242 if (personality(err) == PER_LINUX32)
243 err = (err & ~PER_MASK) | PER_LINUX;
Kyle McMartin75a49582006-08-27 11:12:13 -0400244
245 return err;
246}