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