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