Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/syscalls.h> |
Kyle McMartin | 75a4958 | 2006-08-27 11:12:13 -0400 | [diff] [blame] | 33 | #include <linux/utsname.h> |
| 34 | #include <linux/personality.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | static unsigned long get_unshared_area(unsigned long addr, unsigned long len) |
| 37 | { |
Michel Lespinasse | a003119 | 2013-02-27 17:02:40 -0800 | [diff] [blame] | 38 | struct vm_unmapped_area_info info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Michel Lespinasse | a003119 | 2013-02-27 17:02:40 -0800 | [diff] [blame] | 40 | info.flags = 0; |
| 41 | info.length = len; |
| 42 | info.low_limit = PAGE_ALIGN(addr); |
| 43 | info.high_limit = TASK_SIZE; |
| 44 | info.align_mask = 0; |
| 45 | info.align_offset = 0; |
| 46 | return vm_unmapped_area(&info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | /* |
| 50 | * We need to know the offset to use. Old scheme was to look for |
| 51 | * existing mapping and use the same offset. New scheme is to use the |
| 52 | * address of the kernel data structure as the seed for the offset. |
| 53 | * We'll see how that works... |
| 54 | * |
| 55 | * The mapping is cacheline aligned, so there's no information in the bottom |
| 56 | * few bits of the address. We're looking for 10 bits (4MB / 4k), so let's |
| 57 | * drop the bottom 8 bits and use bits 8-17. |
| 58 | */ |
| 59 | static int get_offset(struct address_space *mapping) |
| 60 | { |
Michel Lespinasse | a003119 | 2013-02-27 17:02:40 -0800 | [diff] [blame] | 61 | return (unsigned long) mapping >> 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Helge Deller | 0576da2 | 2013-11-20 23:07:42 +0100 | [diff] [blame^] | 64 | static unsigned long shared_align_offset(struct file *filp, unsigned long pgoff) |
| 65 | { |
| 66 | struct address_space *mapping = filp ? filp->f_mapping : NULL; |
| 67 | |
| 68 | return (get_offset(mapping) + pgoff) << PAGE_SHIFT; |
| 69 | } |
| 70 | |
| 71 | static unsigned long get_shared_area(struct file *filp, unsigned long addr, |
| 72 | unsigned long len, unsigned long pgoff) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | { |
Michel Lespinasse | a003119 | 2013-02-27 17:02:40 -0800 | [diff] [blame] | 74 | struct vm_unmapped_area_info info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Michel Lespinasse | a003119 | 2013-02-27 17:02:40 -0800 | [diff] [blame] | 76 | info.flags = 0; |
| 77 | info.length = len; |
| 78 | info.low_limit = PAGE_ALIGN(addr); |
| 79 | info.high_limit = TASK_SIZE; |
| 80 | info.align_mask = PAGE_MASK & (SHMLBA - 1); |
Helge Deller | 0576da2 | 2013-11-20 23:07:42 +0100 | [diff] [blame^] | 81 | info.align_offset = shared_align_offset(filp, pgoff); |
Michel Lespinasse | a003119 | 2013-02-27 17:02:40 -0800 | [diff] [blame] | 82 | return vm_unmapped_area(&info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, |
| 86 | unsigned long len, unsigned long pgoff, unsigned long flags) |
| 87 | { |
| 88 | if (len > TASK_SIZE) |
| 89 | return -ENOMEM; |
John David Anglin | 5ca8b91 | 2013-02-02 23:44:59 +0000 | [diff] [blame] | 90 | if (flags & MAP_FIXED) { |
| 91 | if ((flags & MAP_SHARED) && |
Helge Deller | 0576da2 | 2013-11-20 23:07:42 +0100 | [diff] [blame^] | 92 | (addr - shared_align_offset(filp, pgoff)) & (SHMLBA - 1)) |
John David Anglin | 5ca8b91 | 2013-02-02 23:44:59 +0000 | [diff] [blame] | 93 | return -EINVAL; |
Benjamin Herrenschmidt | 869e510 | 2007-05-06 14:50:09 -0700 | [diff] [blame] | 94 | return addr; |
John David Anglin | 5ca8b91 | 2013-02-02 23:44:59 +0000 | [diff] [blame] | 95 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | if (!addr) |
| 97 | addr = TASK_UNMAPPED_BASE; |
| 98 | |
Helge Deller | 0576da2 | 2013-11-20 23:07:42 +0100 | [diff] [blame^] | 99 | if (filp || (flags & MAP_SHARED)) |
| 100 | addr = get_shared_area(filp, addr, len, pgoff); |
| 101 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | addr = get_unshared_area(addr, len); |
Helge Deller | 0576da2 | 2013-11-20 23:07:42 +0100 | [diff] [blame^] | 103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | return addr; |
| 105 | } |
| 106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len, |
| 108 | unsigned long prot, unsigned long flags, unsigned long fd, |
| 109 | unsigned long pgoff) |
| 110 | { |
| 111 | /* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE |
| 112 | we have. */ |
Al Viro | f8b7256 | 2009-11-30 17:37:04 -0500 | [diff] [blame] | 113 | return sys_mmap_pgoff(addr, len, prot, flags, fd, |
| 114 | pgoff >> (PAGE_SHIFT - 12)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len, |
| 118 | unsigned long prot, unsigned long flags, unsigned long fd, |
| 119 | unsigned long offset) |
| 120 | { |
| 121 | if (!(offset & ~PAGE_MASK)) { |
Al Viro | f8b7256 | 2009-11-30 17:37:04 -0500 | [diff] [blame] | 122 | return sys_mmap_pgoff(addr, len, prot, flags, fd, |
| 123 | offset >> PAGE_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | } else { |
| 125 | return -EINVAL; |
| 126 | } |
| 127 | } |
| 128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | /* Fucking broken ABI */ |
| 130 | |
| 131 | #ifdef CONFIG_64BIT |
| 132 | asmlinkage long parisc_truncate64(const char __user * path, |
| 133 | unsigned int high, unsigned int low) |
| 134 | { |
| 135 | return sys_truncate(path, (long)high << 32 | low); |
| 136 | } |
| 137 | |
| 138 | asmlinkage long parisc_ftruncate64(unsigned int fd, |
| 139 | unsigned int high, unsigned int low) |
| 140 | { |
| 141 | return sys_ftruncate(fd, (long)high << 32 | low); |
| 142 | } |
| 143 | |
| 144 | /* stubs for the benefit of the syscall_table since truncate64 and truncate |
| 145 | * are identical on LP64 */ |
| 146 | asmlinkage long sys_truncate64(const char __user * path, unsigned long length) |
| 147 | { |
| 148 | return sys_truncate(path, length); |
| 149 | } |
| 150 | asmlinkage long sys_ftruncate64(unsigned int fd, unsigned long length) |
| 151 | { |
| 152 | return sys_ftruncate(fd, length); |
| 153 | } |
| 154 | asmlinkage long sys_fcntl64(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 155 | { |
| 156 | return sys_fcntl(fd, cmd, arg); |
| 157 | } |
| 158 | #else |
| 159 | |
| 160 | asmlinkage long parisc_truncate64(const char __user * path, |
| 161 | unsigned int high, unsigned int low) |
| 162 | { |
| 163 | return sys_truncate64(path, (loff_t)high << 32 | low); |
| 164 | } |
| 165 | |
| 166 | asmlinkage long parisc_ftruncate64(unsigned int fd, |
| 167 | unsigned int high, unsigned int low) |
| 168 | { |
| 169 | return sys_ftruncate64(fd, (loff_t)high << 32 | low); |
| 170 | } |
| 171 | #endif |
| 172 | |
| 173 | asmlinkage ssize_t parisc_pread64(unsigned int fd, char __user *buf, size_t count, |
| 174 | unsigned int high, unsigned int low) |
| 175 | { |
| 176 | return sys_pread64(fd, buf, count, (loff_t)high << 32 | low); |
| 177 | } |
| 178 | |
| 179 | asmlinkage ssize_t parisc_pwrite64(unsigned int fd, const char __user *buf, |
| 180 | size_t count, unsigned int high, unsigned int low) |
| 181 | { |
| 182 | return sys_pwrite64(fd, buf, count, (loff_t)high << 32 | low); |
| 183 | } |
| 184 | |
| 185 | asmlinkage ssize_t parisc_readahead(int fd, unsigned int high, unsigned int low, |
| 186 | size_t count) |
| 187 | { |
| 188 | return sys_readahead(fd, (loff_t)high << 32 | low, count); |
| 189 | } |
| 190 | |
| 191 | asmlinkage long parisc_fadvise64_64(int fd, |
| 192 | unsigned int high_off, unsigned int low_off, |
| 193 | unsigned int high_len, unsigned int low_len, int advice) |
| 194 | { |
| 195 | return sys_fadvise64_64(fd, (loff_t)high_off << 32 | low_off, |
| 196 | (loff_t)high_len << 32 | low_len, advice); |
| 197 | } |
| 198 | |
Kyle McMartin | 6ca773c | 2006-04-20 04:44:07 +0000 | [diff] [blame] | 199 | asmlinkage long parisc_sync_file_range(int fd, |
| 200 | u32 hi_off, u32 lo_off, u32 hi_nbytes, u32 lo_nbytes, |
| 201 | unsigned int flags) |
| 202 | { |
| 203 | return sys_sync_file_range(fd, (loff_t)hi_off << 32 | lo_off, |
| 204 | (loff_t)hi_nbytes << 32 | lo_nbytes, flags); |
| 205 | } |
| 206 | |
Helge Deller | 4474a33 | 2013-02-19 21:23:59 +0100 | [diff] [blame] | 207 | asmlinkage long parisc_fallocate(int fd, int mode, u32 offhi, u32 offlo, |
| 208 | u32 lenhi, u32 lenlo) |
| 209 | { |
| 210 | return sys_fallocate(fd, mode, ((u64)offhi << 32) | offlo, |
| 211 | ((u64)lenhi << 32) | lenlo); |
| 212 | } |
| 213 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | asmlinkage unsigned long sys_alloc_hugepages(int key, unsigned long addr, unsigned long len, int prot, int flag) |
| 215 | { |
| 216 | return -ENOMEM; |
| 217 | } |
| 218 | |
| 219 | asmlinkage int sys_free_hugepages(unsigned long addr) |
| 220 | { |
| 221 | return -EINVAL; |
| 222 | } |
Kyle McMartin | 75a4958 | 2006-08-27 11:12:13 -0400 | [diff] [blame] | 223 | |
| 224 | long parisc_personality(unsigned long personality) |
| 225 | { |
| 226 | long err; |
| 227 | |
| 228 | if (personality(current->personality) == PER_LINUX32 |
Jiri Kosina | 5b24c42 | 2012-08-02 15:33:59 +0200 | [diff] [blame] | 229 | && personality(personality) == PER_LINUX) |
| 230 | personality = (personality & ~PER_MASK) | PER_LINUX32; |
Kyle McMartin | 75a4958 | 2006-08-27 11:12:13 -0400 | [diff] [blame] | 231 | |
| 232 | err = sys_personality(personality); |
Jiri Kosina | 5b24c42 | 2012-08-02 15:33:59 +0200 | [diff] [blame] | 233 | if (personality(err) == PER_LINUX32) |
| 234 | err = (err & ~PER_MASK) | PER_LINUX; |
Kyle McMartin | 75a4958 | 2006-08-27 11:12:13 -0400 | [diff] [blame] | 235 | |
| 236 | return err; |
| 237 | } |