Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * PARISC specific syscalls |
| 5 | * |
| 6 | * Copyright (C) 1999-2003 Matthew Wilcox <willy at parisc-linux.org> |
| 7 | * Copyright (C) 2000-2003 Paul Bame <bame at parisc-linux.org> |
| 8 | * Copyright (C) 2001 Thomas Bogendoerfer <tsbogend at parisc-linux.org> |
Helge Deller | 44a4c9e | 2020-10-22 18:40:07 +0200 | [diff] [blame] | 9 | * Copyright (C) 1999-2020 Helge Deller <deller@gmx.de> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 12 | #include <linux/uaccess.h> |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 13 | #include <asm/elf.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/file.h> |
| 15 | #include <linux/fs.h> |
| 16 | #include <linux/linkage.h> |
| 17 | #include <linux/mm.h> |
| 18 | #include <linux/mman.h> |
Ingo Molnar | 3f07c01 | 2017-02-08 18:51:30 +0100 | [diff] [blame] | 19 | #include <linux/sched/signal.h> |
Ingo Molnar | 0104260 | 2017-02-08 18:51:31 +0100 | [diff] [blame] | 20 | #include <linux/sched/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/shm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/syscalls.h> |
Kyle McMartin | 75a4958 | 2006-08-27 11:12:13 -0400 | [diff] [blame] | 23 | #include <linux/utsname.h> |
| 24 | #include <linux/personality.h> |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 25 | #include <linux/random.h> |
Helge Deller | 44a4c9e | 2020-10-22 18:40:07 +0200 | [diff] [blame] | 26 | #include <linux/compat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 28 | /* we construct an artificial offset for the mapping based on the physical |
| 29 | * address of the kernel mapping variable */ |
| 30 | #define GET_LAST_MMAP(filp) \ |
| 31 | (filp ? ((unsigned long) filp->f_mapping) >> 8 : 0UL) |
| 32 | #define SET_LAST_MMAP(filp, val) \ |
| 33 | { /* nothing */ } |
| 34 | |
| 35 | static int get_offset(unsigned int last_mmap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | { |
Helge Deller | 0ef36bd | 2014-04-09 19:49:28 +0200 | [diff] [blame] | 37 | return (last_mmap & (SHM_COLOUR-1)) >> PAGE_SHIFT; |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 38 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 40 | static unsigned long shared_align_offset(unsigned int last_mmap, |
| 41 | unsigned long pgoff) |
| 42 | { |
| 43 | return (get_offset(last_mmap) + pgoff) << PAGE_SHIFT; |
| 44 | } |
| 45 | |
| 46 | static inline unsigned long COLOR_ALIGN(unsigned long addr, |
| 47 | unsigned int last_mmap, unsigned long pgoff) |
| 48 | { |
Helge Deller | 0ef36bd | 2014-04-09 19:49:28 +0200 | [diff] [blame] | 49 | unsigned long base = (addr+SHM_COLOUR-1) & ~(SHM_COLOUR-1); |
| 50 | unsigned long off = (SHM_COLOUR-1) & |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 51 | (shared_align_offset(last_mmap, pgoff) << PAGE_SHIFT); |
| 52 | |
| 53 | return base + off; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Helge Deller | 22ee3ea | 2020-11-06 19:41:36 +0100 | [diff] [blame] | 56 | |
| 57 | #define STACK_SIZE_DEFAULT (USER_WIDE_MODE \ |
| 58 | ? (1 << 30) /* 1 GB */ \ |
| 59 | : (CONFIG_STACK_MAX_DEFAULT_SIZE_MB*1024*1024)) |
| 60 | |
| 61 | unsigned long calc_max_stack_size(unsigned long stack_max) |
| 62 | { |
| 63 | #ifdef CONFIG_COMPAT |
| 64 | if (!USER_WIDE_MODE && (stack_max == COMPAT_RLIM_INFINITY)) |
| 65 | stack_max = STACK_SIZE_DEFAULT; |
| 66 | else |
| 67 | #endif |
| 68 | if (stack_max == RLIM_INFINITY) |
| 69 | stack_max = STACK_SIZE_DEFAULT; |
| 70 | |
| 71 | return stack_max; |
| 72 | } |
| 73 | |
| 74 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | /* |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 76 | * Top of mmap area (just below the process stack). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | */ |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 78 | |
Kees Cook | 8f2af15 | 2018-04-10 16:34:53 -0700 | [diff] [blame] | 79 | /* |
| 80 | * When called from arch_get_unmapped_area(), rlim_stack will be NULL, |
| 81 | * indicating that "current" should be used instead of a passed-in |
| 82 | * value from the exec bprm as done with arch_pick_mmap_layout(). |
| 83 | */ |
| 84 | static unsigned long mmap_upper_limit(struct rlimit *rlim_stack) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | { |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 86 | unsigned long stack_base; |
| 87 | |
Helge Deller | 042d27a | 2014-04-30 23:26:02 +0200 | [diff] [blame] | 88 | /* Limit stack size - see setup_arg_pages() in fs/exec.c */ |
Kees Cook | 8f2af15 | 2018-04-10 16:34:53 -0700 | [diff] [blame] | 89 | stack_base = rlim_stack ? rlim_stack->rlim_max |
| 90 | : rlimit_max(RLIMIT_STACK); |
Helge Deller | 22ee3ea | 2020-11-06 19:41:36 +0100 | [diff] [blame] | 91 | |
| 92 | stack_base = calc_max_stack_size(stack_base); |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 93 | |
Helge Deller | d045c77 | 2015-05-11 22:01:27 +0200 | [diff] [blame] | 94 | /* Add space for stack randomization. */ |
Alexandre Ghiti | 17d9822 | 2019-04-04 02:26:22 -0400 | [diff] [blame] | 95 | if (current->flags & PF_RANDOMIZE) |
| 96 | stack_base += (STACK_RND_MASK << PAGE_SHIFT); |
Helge Deller | d045c77 | 2015-05-11 22:01:27 +0200 | [diff] [blame] | 97 | |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 98 | return PAGE_ALIGN(STACK_TOP - stack_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
| 102 | unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, |
| 103 | unsigned long len, unsigned long pgoff, unsigned long flags) |
| 104 | { |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 105 | struct mm_struct *mm = current->mm; |
Hugh Dickins | 1be7107 | 2017-06-19 04:03:24 -0700 | [diff] [blame] | 106 | struct vm_area_struct *vma, *prev; |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 107 | unsigned long task_size = TASK_SIZE; |
| 108 | int do_color_align, last_mmap; |
| 109 | struct vm_unmapped_area_info info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 111 | if (len > task_size) |
| 112 | return -ENOMEM; |
| 113 | |
| 114 | do_color_align = 0; |
Helge Deller | 0576da2 | 2013-11-20 23:07:42 +0100 | [diff] [blame] | 115 | if (filp || (flags & MAP_SHARED)) |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 116 | do_color_align = 1; |
| 117 | last_mmap = GET_LAST_MMAP(filp); |
| 118 | |
| 119 | if (flags & MAP_FIXED) { |
| 120 | if ((flags & MAP_SHARED) && last_mmap && |
| 121 | (addr - shared_align_offset(last_mmap, pgoff)) |
Helge Deller | 0ef36bd | 2014-04-09 19:49:28 +0200 | [diff] [blame] | 122 | & (SHM_COLOUR - 1)) |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 123 | return -EINVAL; |
| 124 | goto found_addr; |
| 125 | } |
| 126 | |
| 127 | if (addr) { |
| 128 | if (do_color_align && last_mmap) |
| 129 | addr = COLOR_ALIGN(addr, last_mmap, pgoff); |
| 130 | else |
| 131 | addr = PAGE_ALIGN(addr); |
| 132 | |
Hugh Dickins | 1be7107 | 2017-06-19 04:03:24 -0700 | [diff] [blame] | 133 | vma = find_vma_prev(mm, addr, &prev); |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 134 | if (task_size - len >= addr && |
Hugh Dickins | 1be7107 | 2017-06-19 04:03:24 -0700 | [diff] [blame] | 135 | (!vma || addr + len <= vm_start_gap(vma)) && |
| 136 | (!prev || addr >= vm_end_gap(prev))) |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 137 | goto found_addr; |
| 138 | } |
| 139 | |
| 140 | info.flags = 0; |
| 141 | info.length = len; |
| 142 | info.low_limit = mm->mmap_legacy_base; |
Kees Cook | 8f2af15 | 2018-04-10 16:34:53 -0700 | [diff] [blame] | 143 | info.high_limit = mmap_upper_limit(NULL); |
Helge Deller | 0ef36bd | 2014-04-09 19:49:28 +0200 | [diff] [blame] | 144 | info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0; |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 145 | info.align_offset = shared_align_offset(last_mmap, pgoff); |
| 146 | addr = vm_unmapped_area(&info); |
| 147 | |
| 148 | found_addr: |
| 149 | if (do_color_align && !last_mmap && !(addr & ~PAGE_MASK)) |
| 150 | SET_LAST_MMAP(filp, addr - (pgoff << PAGE_SHIFT)); |
Helge Deller | 0576da2 | 2013-11-20 23:07:42 +0100 | [diff] [blame] | 151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | return addr; |
| 153 | } |
| 154 | |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 155 | unsigned long |
| 156 | arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, |
| 157 | const unsigned long len, const unsigned long pgoff, |
| 158 | const unsigned long flags) |
| 159 | { |
Hugh Dickins | 1be7107 | 2017-06-19 04:03:24 -0700 | [diff] [blame] | 160 | struct vm_area_struct *vma, *prev; |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 161 | struct mm_struct *mm = current->mm; |
| 162 | unsigned long addr = addr0; |
| 163 | int do_color_align, last_mmap; |
| 164 | struct vm_unmapped_area_info info; |
| 165 | |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 166 | /* requested length too big for entire address space */ |
| 167 | if (len > TASK_SIZE) |
| 168 | return -ENOMEM; |
| 169 | |
| 170 | do_color_align = 0; |
| 171 | if (filp || (flags & MAP_SHARED)) |
| 172 | do_color_align = 1; |
| 173 | last_mmap = GET_LAST_MMAP(filp); |
| 174 | |
| 175 | if (flags & MAP_FIXED) { |
| 176 | if ((flags & MAP_SHARED) && last_mmap && |
| 177 | (addr - shared_align_offset(last_mmap, pgoff)) |
Helge Deller | 0ef36bd | 2014-04-09 19:49:28 +0200 | [diff] [blame] | 178 | & (SHM_COLOUR - 1)) |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 179 | return -EINVAL; |
| 180 | goto found_addr; |
| 181 | } |
| 182 | |
| 183 | /* requesting a specific address */ |
| 184 | if (addr) { |
| 185 | if (do_color_align && last_mmap) |
| 186 | addr = COLOR_ALIGN(addr, last_mmap, pgoff); |
| 187 | else |
| 188 | addr = PAGE_ALIGN(addr); |
Hugh Dickins | 1be7107 | 2017-06-19 04:03:24 -0700 | [diff] [blame] | 189 | |
| 190 | vma = find_vma_prev(mm, addr, &prev); |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 191 | if (TASK_SIZE - len >= addr && |
Hugh Dickins | 1be7107 | 2017-06-19 04:03:24 -0700 | [diff] [blame] | 192 | (!vma || addr + len <= vm_start_gap(vma)) && |
| 193 | (!prev || addr >= vm_end_gap(prev))) |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 194 | goto found_addr; |
| 195 | } |
| 196 | |
| 197 | info.flags = VM_UNMAPPED_AREA_TOPDOWN; |
| 198 | info.length = len; |
| 199 | info.low_limit = PAGE_SIZE; |
| 200 | info.high_limit = mm->mmap_base; |
Helge Deller | 0ef36bd | 2014-04-09 19:49:28 +0200 | [diff] [blame] | 201 | info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0; |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 202 | info.align_offset = shared_align_offset(last_mmap, pgoff); |
| 203 | addr = vm_unmapped_area(&info); |
| 204 | if (!(addr & ~PAGE_MASK)) |
| 205 | goto found_addr; |
| 206 | VM_BUG_ON(addr != -ENOMEM); |
| 207 | |
| 208 | /* |
| 209 | * A failed mmap() very likely causes application failure, |
| 210 | * so fall back to the bottom-up function here. This scenario |
| 211 | * can happen with large stack limits and large mmap() |
| 212 | * allocations. |
| 213 | */ |
| 214 | return arch_get_unmapped_area(filp, addr0, len, pgoff, flags); |
| 215 | |
| 216 | found_addr: |
| 217 | if (do_color_align && !last_mmap && !(addr & ~PAGE_MASK)) |
| 218 | SET_LAST_MMAP(filp, addr - (pgoff << PAGE_SHIFT)); |
| 219 | |
| 220 | return addr; |
| 221 | } |
| 222 | |
| 223 | static int mmap_is_legacy(void) |
| 224 | { |
| 225 | if (current->personality & ADDR_COMPAT_LAYOUT) |
| 226 | return 1; |
| 227 | |
| 228 | /* parisc stack always grows up - so a unlimited stack should |
| 229 | * not be an indicator to use the legacy memory layout. |
| 230 | * if (rlimit(RLIMIT_STACK) == RLIM_INFINITY) |
| 231 | * return 1; |
| 232 | */ |
| 233 | |
| 234 | return sysctl_legacy_va_layout; |
| 235 | } |
| 236 | |
| 237 | static unsigned long mmap_rnd(void) |
| 238 | { |
| 239 | unsigned long rnd = 0; |
| 240 | |
Helge Deller | 18d98a7 | 2016-10-16 00:02:27 +0200 | [diff] [blame] | 241 | if (current->flags & PF_RANDOMIZE) |
| 242 | rnd = get_random_int() & MMAP_RND_MASK; |
| 243 | |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 244 | return rnd << PAGE_SHIFT; |
| 245 | } |
| 246 | |
Helge Deller | 18d98a7 | 2016-10-16 00:02:27 +0200 | [diff] [blame] | 247 | unsigned long arch_mmap_rnd(void) |
| 248 | { |
| 249 | return (get_random_int() & MMAP_RND_MASK) << PAGE_SHIFT; |
| 250 | } |
| 251 | |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 252 | static unsigned long mmap_legacy_base(void) |
| 253 | { |
| 254 | return TASK_UNMAPPED_BASE + mmap_rnd(); |
| 255 | } |
| 256 | |
| 257 | /* |
| 258 | * This function, called very early during the creation of a new |
| 259 | * process VM image, sets up which VM layout function to use: |
| 260 | */ |
Kees Cook | 8f2af15 | 2018-04-10 16:34:53 -0700 | [diff] [blame] | 261 | void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack) |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 262 | { |
| 263 | mm->mmap_legacy_base = mmap_legacy_base(); |
Kees Cook | 8f2af15 | 2018-04-10 16:34:53 -0700 | [diff] [blame] | 264 | mm->mmap_base = mmap_upper_limit(rlim_stack); |
Helge Deller | 9dabf60 | 2014-01-31 22:19:52 +0100 | [diff] [blame] | 265 | |
| 266 | if (mmap_is_legacy()) { |
| 267 | mm->mmap_base = mm->mmap_legacy_base; |
| 268 | mm->get_unmapped_area = arch_get_unmapped_area; |
| 269 | } else { |
| 270 | mm->get_unmapped_area = arch_get_unmapped_area_topdown; |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len, |
| 276 | unsigned long prot, unsigned long flags, unsigned long fd, |
| 277 | unsigned long pgoff) |
| 278 | { |
| 279 | /* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE |
| 280 | we have. */ |
Dominik Brodowski | a90f590 | 2018-03-11 11:34:46 +0100 | [diff] [blame] | 281 | return ksys_mmap_pgoff(addr, len, prot, flags, fd, |
| 282 | pgoff >> (PAGE_SHIFT - 12)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len, |
| 286 | unsigned long prot, unsigned long flags, unsigned long fd, |
| 287 | unsigned long offset) |
| 288 | { |
| 289 | if (!(offset & ~PAGE_MASK)) { |
Dominik Brodowski | a90f590 | 2018-03-11 11:34:46 +0100 | [diff] [blame] | 290 | return ksys_mmap_pgoff(addr, len, prot, flags, fd, |
Al Viro | f8b7256 | 2009-11-30 17:37:04 -0500 | [diff] [blame] | 291 | offset >> PAGE_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | } else { |
| 293 | return -EINVAL; |
| 294 | } |
| 295 | } |
| 296 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | /* Fucking broken ABI */ |
| 298 | |
| 299 | #ifdef CONFIG_64BIT |
| 300 | asmlinkage long parisc_truncate64(const char __user * path, |
| 301 | unsigned int high, unsigned int low) |
| 302 | { |
Dominik Brodowski | df260e2 | 2018-03-19 17:32:11 +0100 | [diff] [blame] | 303 | return ksys_truncate(path, (long)high << 32 | low); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | asmlinkage long parisc_ftruncate64(unsigned int fd, |
| 307 | unsigned int high, unsigned int low) |
| 308 | { |
Dominik Brodowski | 411d947 | 2018-03-11 11:34:54 +0100 | [diff] [blame] | 309 | return ksys_ftruncate(fd, (long)high << 32 | low); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | /* stubs for the benefit of the syscall_table since truncate64 and truncate |
| 313 | * are identical on LP64 */ |
| 314 | asmlinkage long sys_truncate64(const char __user * path, unsigned long length) |
| 315 | { |
Dominik Brodowski | df260e2 | 2018-03-19 17:32:11 +0100 | [diff] [blame] | 316 | return ksys_truncate(path, length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | } |
| 318 | asmlinkage long sys_ftruncate64(unsigned int fd, unsigned long length) |
| 319 | { |
Dominik Brodowski | 411d947 | 2018-03-11 11:34:54 +0100 | [diff] [blame] | 320 | return ksys_ftruncate(fd, length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | } |
| 322 | asmlinkage long sys_fcntl64(unsigned int fd, unsigned int cmd, unsigned long arg) |
| 323 | { |
| 324 | return sys_fcntl(fd, cmd, arg); |
| 325 | } |
| 326 | #else |
| 327 | |
| 328 | asmlinkage long parisc_truncate64(const char __user * path, |
| 329 | unsigned int high, unsigned int low) |
| 330 | { |
Dominik Brodowski | df260e2 | 2018-03-19 17:32:11 +0100 | [diff] [blame] | 331 | return ksys_truncate(path, (loff_t)high << 32 | low); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | asmlinkage long parisc_ftruncate64(unsigned int fd, |
| 335 | unsigned int high, unsigned int low) |
| 336 | { |
| 337 | return sys_ftruncate64(fd, (loff_t)high << 32 | low); |
| 338 | } |
| 339 | #endif |
| 340 | |
| 341 | asmlinkage ssize_t parisc_pread64(unsigned int fd, char __user *buf, size_t count, |
| 342 | unsigned int high, unsigned int low) |
| 343 | { |
Dominik Brodowski | 36028d5 | 2018-03-19 17:38:31 +0100 | [diff] [blame] | 344 | return ksys_pread64(fd, buf, count, (loff_t)high << 32 | low); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | asmlinkage ssize_t parisc_pwrite64(unsigned int fd, const char __user *buf, |
| 348 | size_t count, unsigned int high, unsigned int low) |
| 349 | { |
Dominik Brodowski | 36028d5 | 2018-03-19 17:38:31 +0100 | [diff] [blame] | 350 | return ksys_pwrite64(fd, buf, count, (loff_t)high << 32 | low); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | asmlinkage ssize_t parisc_readahead(int fd, unsigned int high, unsigned int low, |
| 354 | size_t count) |
| 355 | { |
Dominik Brodowski | c7b95d5 | 2018-03-19 17:51:36 +0100 | [diff] [blame] | 356 | return ksys_readahead(fd, (loff_t)high << 32 | low, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | asmlinkage long parisc_fadvise64_64(int fd, |
| 360 | unsigned int high_off, unsigned int low_off, |
| 361 | unsigned int high_len, unsigned int low_len, int advice) |
| 362 | { |
Dominik Brodowski | 9d5b7c9 | 2018-03-11 11:34:45 +0100 | [diff] [blame] | 363 | return ksys_fadvise64_64(fd, (loff_t)high_off << 32 | low_off, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | (loff_t)high_len << 32 | low_len, advice); |
| 365 | } |
| 366 | |
Kyle McMartin | 6ca773c | 2006-04-20 04:44:07 +0000 | [diff] [blame] | 367 | asmlinkage long parisc_sync_file_range(int fd, |
| 368 | u32 hi_off, u32 lo_off, u32 hi_nbytes, u32 lo_nbytes, |
| 369 | unsigned int flags) |
| 370 | { |
Dominik Brodowski | 806cbae | 2018-03-11 11:34:47 +0100 | [diff] [blame] | 371 | return ksys_sync_file_range(fd, (loff_t)hi_off << 32 | lo_off, |
Kyle McMartin | 6ca773c | 2006-04-20 04:44:07 +0000 | [diff] [blame] | 372 | (loff_t)hi_nbytes << 32 | lo_nbytes, flags); |
| 373 | } |
| 374 | |
Helge Deller | 4474a33 | 2013-02-19 21:23:59 +0100 | [diff] [blame] | 375 | asmlinkage long parisc_fallocate(int fd, int mode, u32 offhi, u32 offlo, |
| 376 | u32 lenhi, u32 lenlo) |
| 377 | { |
Dominik Brodowski | edf292c | 2018-03-19 17:46:32 +0100 | [diff] [blame] | 378 | return ksys_fallocate(fd, mode, ((u64)offhi << 32) | offlo, |
| 379 | ((u64)lenhi << 32) | lenlo); |
Helge Deller | 4474a33 | 2013-02-19 21:23:59 +0100 | [diff] [blame] | 380 | } |
| 381 | |
Kyle McMartin | 75a4958 | 2006-08-27 11:12:13 -0400 | [diff] [blame] | 382 | long parisc_personality(unsigned long personality) |
| 383 | { |
| 384 | long err; |
| 385 | |
| 386 | if (personality(current->personality) == PER_LINUX32 |
Jiri Kosina | 5b24c42 | 2012-08-02 15:33:59 +0200 | [diff] [blame] | 387 | && personality(personality) == PER_LINUX) |
| 388 | personality = (personality & ~PER_MASK) | PER_LINUX32; |
Kyle McMartin | 75a4958 | 2006-08-27 11:12:13 -0400 | [diff] [blame] | 389 | |
| 390 | err = sys_personality(personality); |
Jiri Kosina | 5b24c42 | 2012-08-02 15:33:59 +0200 | [diff] [blame] | 391 | if (personality(err) == PER_LINUX32) |
| 392 | err = (err & ~PER_MASK) | PER_LINUX; |
Kyle McMartin | 75a4958 | 2006-08-27 11:12:13 -0400 | [diff] [blame] | 393 | |
| 394 | return err; |
| 395 | } |
Helge Deller | 44a4c9e | 2020-10-22 18:40:07 +0200 | [diff] [blame] | 396 | |
| 397 | /* |
| 398 | * Up to kernel v5.9 we defined O_NONBLOCK as 000200004, |
| 399 | * since then O_NONBLOCK is defined as 000200000. |
| 400 | * |
| 401 | * The following wrapper functions mask out the old |
| 402 | * O_NDELAY bit from calls which use O_NONBLOCK. |
| 403 | * |
| 404 | * XXX: Remove those in year 2022 (or later)? |
| 405 | */ |
| 406 | |
| 407 | #define O_NONBLOCK_OLD 000200004 |
| 408 | #define O_NONBLOCK_MASK_OUT (O_NONBLOCK_OLD & ~O_NONBLOCK) |
| 409 | |
| 410 | static int FIX_O_NONBLOCK(int flags) |
| 411 | { |
Helge Deller | 3759778 | 2021-10-17 18:53:31 +0200 | [diff] [blame] | 412 | if ((flags & O_NONBLOCK_MASK_OUT) && |
| 413 | !test_thread_flag(TIF_NONBLOCK_WARNING)) { |
| 414 | set_thread_flag(TIF_NONBLOCK_WARNING); |
| 415 | pr_warn("%s(%d) uses a deprecated O_NONBLOCK value." |
| 416 | " Please recompile with newer glibc.\n", |
| 417 | current->comm, current->pid); |
Helge Deller | 44a4c9e | 2020-10-22 18:40:07 +0200 | [diff] [blame] | 418 | } |
| 419 | return flags & ~O_NONBLOCK_MASK_OUT; |
| 420 | } |
| 421 | |
| 422 | asmlinkage long parisc_timerfd_create(int clockid, int flags) |
| 423 | { |
| 424 | flags = FIX_O_NONBLOCK(flags); |
| 425 | return sys_timerfd_create(clockid, flags); |
| 426 | } |
| 427 | |
| 428 | asmlinkage long parisc_signalfd4(int ufd, sigset_t __user *user_mask, |
| 429 | size_t sizemask, int flags) |
| 430 | { |
| 431 | flags = FIX_O_NONBLOCK(flags); |
| 432 | return sys_signalfd4(ufd, user_mask, sizemask, flags); |
| 433 | } |
| 434 | |
| 435 | #ifdef CONFIG_COMPAT |
| 436 | asmlinkage long parisc_compat_signalfd4(int ufd, |
| 437 | compat_sigset_t __user *user_mask, |
| 438 | compat_size_t sizemask, int flags) |
| 439 | { |
| 440 | flags = FIX_O_NONBLOCK(flags); |
| 441 | return compat_sys_signalfd4(ufd, user_mask, sizemask, flags); |
| 442 | } |
| 443 | #endif |
| 444 | |
| 445 | asmlinkage long parisc_eventfd2(unsigned int count, int flags) |
| 446 | { |
| 447 | flags = FIX_O_NONBLOCK(flags); |
| 448 | return sys_eventfd2(count, flags); |
| 449 | } |
| 450 | |
| 451 | asmlinkage long parisc_userfaultfd(int flags) |
| 452 | { |
| 453 | flags = FIX_O_NONBLOCK(flags); |
| 454 | return sys_userfaultfd(flags); |
| 455 | } |
| 456 | |
| 457 | asmlinkage long parisc_pipe2(int __user *fildes, int flags) |
| 458 | { |
| 459 | flags = FIX_O_NONBLOCK(flags); |
| 460 | return sys_pipe2(fildes, flags); |
| 461 | } |
| 462 | |
| 463 | asmlinkage long parisc_inotify_init1(int flags) |
| 464 | { |
| 465 | flags = FIX_O_NONBLOCK(flags); |
| 466 | return sys_inotify_init1(flags); |
| 467 | } |