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