Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * This file contains various system calls that have different calling |
| 4 | * conventions on different platforms. |
| 5 | * |
| 6 | * Copyright (C) 1999-2000, 2002-2003, 2005 Hewlett-Packard Co |
| 7 | * David Mosberger-Tang <davidm@hpl.hp.com> |
| 8 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Ingo Molnar | 0104260 | 2017-02-08 18:51:31 +0100 | [diff] [blame] | 14 | #include <linux/sched/mm.h> |
Ingo Molnar | 68db0cf | 2017-02-08 18:51:37 +0100 | [diff] [blame] | 15 | #include <linux/sched/task_stack.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/shm.h> |
| 17 | #include <linux/file.h> /* doh, must come after sched.h... */ |
| 18 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/syscalls.h> |
| 20 | #include <linux/highuid.h> |
| 21 | #include <linux/hugetlb.h> |
| 22 | |
| 23 | #include <asm/shmparam.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 24 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | unsigned long |
| 27 | arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len, |
| 28 | unsigned long pgoff, unsigned long flags) |
| 29 | { |
| 30 | long map_shared = (flags & MAP_SHARED); |
Michel Lespinasse | f53f232 | 2013-02-21 15:10:28 -0800 | [diff] [blame] | 31 | unsigned long align_mask = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | struct mm_struct *mm = current->mm; |
Michel Lespinasse | f53f232 | 2013-02-21 15:10:28 -0800 | [diff] [blame] | 33 | struct vm_unmapped_area_info info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
| 35 | if (len > RGN_MAP_LIMIT) |
| 36 | return -ENOMEM; |
| 37 | |
Benjamin Herrenschmidt | afa3739 | 2007-05-06 14:50:09 -0700 | [diff] [blame] | 38 | /* handle fixed mapping: prevent overlap with huge pages */ |
| 39 | if (flags & MAP_FIXED) { |
| 40 | if (is_hugepage_only_range(mm, addr, len)) |
| 41 | return -EINVAL; |
| 42 | return addr; |
| 43 | } |
| 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #ifdef CONFIG_HUGETLB_PAGE |
Peter Chubb | 0a41e25 | 2005-08-16 19:54:00 -0700 | [diff] [blame] | 46 | if (REGION_NUMBER(addr) == RGN_HPAGE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | addr = 0; |
| 48 | #endif |
| 49 | if (!addr) |
Michel Lespinasse | f53f232 | 2013-02-21 15:10:28 -0800 | [diff] [blame] | 50 | addr = TASK_UNMAPPED_BASE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 52 | if (map_shared && (TASK_SIZE > 0xfffffffful)) |
| 53 | /* |
| 54 | * For 64-bit tasks, align shared segments to 1MB to avoid potential |
| 55 | * performance penalty due to virtual aliasing (see ASDM). For 32-bit |
| 56 | * tasks, we prefer to avoid exhausting the address space too quickly by |
| 57 | * limiting alignment to a single page. |
| 58 | */ |
Michel Lespinasse | f53f232 | 2013-02-21 15:10:28 -0800 | [diff] [blame] | 59 | align_mask = PAGE_MASK & (SHMLBA - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Michel Lespinasse | f53f232 | 2013-02-21 15:10:28 -0800 | [diff] [blame] | 61 | info.flags = 0; |
| 62 | info.length = len; |
| 63 | info.low_limit = addr; |
| 64 | info.high_limit = TASK_SIZE; |
| 65 | info.align_mask = align_mask; |
| 66 | info.align_offset = 0; |
| 67 | return vm_unmapped_area(&info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | asmlinkage long |
| 71 | ia64_getpriority (int which, int who) |
| 72 | { |
| 73 | long prio; |
| 74 | |
| 75 | prio = sys_getpriority(which, who); |
| 76 | if (prio >= 0) { |
| 77 | force_successful_syscall_return(); |
| 78 | prio = 20 - prio; |
| 79 | } |
| 80 | return prio; |
| 81 | } |
| 82 | |
| 83 | /* XXX obsolete, but leave it here until the old libc is gone... */ |
| 84 | asmlinkage unsigned long |
| 85 | sys_getpagesize (void) |
| 86 | { |
| 87 | return PAGE_SIZE; |
| 88 | } |
| 89 | |
| 90 | asmlinkage unsigned long |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | ia64_brk (unsigned long brk) |
| 92 | { |
Al Viro | bb52d66 | 2009-12-03 19:59:24 -0500 | [diff] [blame] | 93 | unsigned long retval = sys_brk(brk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | force_successful_syscall_return(); |
| 95 | return retval; |
| 96 | } |
| 97 | |
| 98 | /* |
| 99 | * On IA-64, we return the two file descriptors in ret0 and ret1 (r8 |
| 100 | * and r9) as this is faster than doing a copy_to_user(). |
| 101 | */ |
| 102 | asmlinkage long |
Heiko Carstens | 1134723 | 2009-01-14 14:13:56 +0100 | [diff] [blame] | 103 | sys_ia64_pipe (void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | { |
Al Viro | 6450578 | 2006-01-12 01:06:06 -0800 | [diff] [blame] | 105 | struct pt_regs *regs = task_pt_regs(current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | int fd[2]; |
| 107 | int retval; |
| 108 | |
Ulrich Drepper | ed8cae8 | 2008-07-23 21:29:30 -0700 | [diff] [blame] | 109 | retval = do_pipe_flags(fd, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | if (retval) |
| 111 | goto out; |
| 112 | retval = fd[0]; |
| 113 | regs->r9 = fd[1]; |
| 114 | out: |
| 115 | return retval; |
| 116 | } |
| 117 | |
Kirill Korotaev | 3a45975 | 2006-09-07 14:17:04 +0400 | [diff] [blame] | 118 | int ia64_mmap_check(unsigned long addr, unsigned long len, |
| 119 | unsigned long flags) |
| 120 | { |
| 121 | unsigned long roff; |
| 122 | |
| 123 | /* |
| 124 | * Don't permit mappings into unmapped space, the virtual page table |
| 125 | * of a region, or across a region boundary. Note: RGN_MAP_LIMIT is |
| 126 | * equal to 2^n-PAGE_SIZE (for some integer n <= 61) and len > 0. |
| 127 | */ |
| 128 | roff = REGION_OFFSET(addr); |
| 129 | if ((len > RGN_MAP_LIMIT) || (roff > (RGN_MAP_LIMIT - len))) |
| 130 | return -EINVAL; |
| 131 | return 0; |
| 132 | } |
| 133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | /* |
| 135 | * mmap2() is like mmap() except that the offset is expressed in units |
| 136 | * of PAGE_SIZE (instead of bytes). This allows to mmap2() (pieces |
| 137 | * of) files that are larger than the address space of the CPU. |
| 138 | */ |
| 139 | asmlinkage unsigned long |
| 140 | sys_mmap2 (unsigned long addr, unsigned long len, int prot, int flags, int fd, long pgoff) |
| 141 | { |
Dominik Brodowski | a90f590 | 2018-03-11 11:34:46 +0100 | [diff] [blame] | 142 | addr = ksys_mmap_pgoff(addr, len, prot, flags, fd, pgoff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | if (!IS_ERR((void *) addr)) |
| 144 | force_successful_syscall_return(); |
| 145 | return addr; |
| 146 | } |
| 147 | |
| 148 | asmlinkage unsigned long |
| 149 | sys_mmap (unsigned long addr, unsigned long len, int prot, int flags, int fd, long off) |
| 150 | { |
| 151 | if (offset_in_page(off) != 0) |
| 152 | return -EINVAL; |
| 153 | |
Dominik Brodowski | a90f590 | 2018-03-11 11:34:46 +0100 | [diff] [blame] | 154 | addr = ksys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | if (!IS_ERR((void *) addr)) |
| 156 | force_successful_syscall_return(); |
| 157 | return addr; |
| 158 | } |
| 159 | |
| 160 | asmlinkage unsigned long |
| 161 | ia64_mremap (unsigned long addr, unsigned long old_len, unsigned long new_len, unsigned long flags, |
| 162 | unsigned long new_addr) |
| 163 | { |
Al Viro | 657bec8 | 2012-05-30 02:12:40 -0400 | [diff] [blame] | 164 | addr = sys_mremap(addr, old_len, new_len, flags, new_addr); |
| 165 | if (!IS_ERR((void *) addr)) |
| 166 | force_successful_syscall_return(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | return addr; |
| 168 | } |
| 169 | |
| 170 | #ifndef CONFIG_PCI |
| 171 | |
| 172 | asmlinkage long |
| 173 | sys_pciconfig_read (unsigned long bus, unsigned long dfn, unsigned long off, unsigned long len, |
| 174 | void *buf) |
| 175 | { |
| 176 | return -ENOSYS; |
| 177 | } |
| 178 | |
| 179 | asmlinkage long |
| 180 | sys_pciconfig_write (unsigned long bus, unsigned long dfn, unsigned long off, unsigned long len, |
| 181 | void *buf) |
| 182 | { |
| 183 | return -ENOSYS; |
| 184 | } |
| 185 | |
| 186 | #endif /* CONFIG_PCI */ |