1 // SPDX-License-Identifier: GPL-2.0
3 * This file contains various system calls that have different calling
4 * conventions on different platforms.
6 * Copyright (C) 1999-2000, 2002-2003, 2005 Hewlett-Packard Co
7 * David Mosberger-Tang <davidm@hpl.hp.com>
9 #include <linux/errno.h>
12 #include <linux/mman.h>
13 #include <linux/sched.h>
14 #include <linux/sched/mm.h>
15 #include <linux/sched/task_stack.h>
16 #include <linux/shm.h>
17 #include <linux/file.h> /* doh, must come after sched.h... */
18 #include <linux/smp.h>
19 #include <linux/syscalls.h>
20 #include <linux/highuid.h>
21 #include <linux/hugetlb.h>
23 #include <asm/shmparam.h>
24 #include <linux/uaccess.h>
27 arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len,
28 unsigned long pgoff, unsigned long flags)
30 long map_shared = (flags & MAP_SHARED);
31 unsigned long align_mask = 0;
32 struct mm_struct *mm = current->mm;
33 struct vm_unmapped_area_info info;
35 if (len > RGN_MAP_LIMIT)
38 /* handle fixed mapping: prevent overlap with huge pages */
39 if (flags & MAP_FIXED) {
40 if (is_hugepage_only_range(mm, addr, len))
45 #ifdef CONFIG_HUGETLB_PAGE
46 if (REGION_NUMBER(addr) == RGN_HPAGE)
50 addr = TASK_UNMAPPED_BASE;
52 if (map_shared && (TASK_SIZE > 0xfffffffful))
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.
59 align_mask = PAGE_MASK & (SHMLBA - 1);
63 info.low_limit = addr;
64 info.high_limit = TASK_SIZE;
65 info.align_mask = align_mask;
66 info.align_offset = pgoff << PAGE_SHIFT;
67 return vm_unmapped_area(&info);
71 ia64_getpriority (int which, int who)
75 prio = sys_getpriority(which, who);
77 force_successful_syscall_return();
83 /* XXX obsolete, but leave it here until the old libc is gone... */
84 asmlinkage unsigned long
85 sys_getpagesize (void)
90 asmlinkage unsigned long
91 ia64_brk (unsigned long brk)
93 unsigned long retval = sys_brk(brk);
94 force_successful_syscall_return();
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().
105 struct pt_regs *regs = task_pt_regs(current);
109 retval = do_pipe_flags(fd, 0);
118 int ia64_mmap_check(unsigned long addr, unsigned long len,
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.
128 roff = REGION_OFFSET(addr);
129 if ((len > RGN_MAP_LIMIT) || (roff > (RGN_MAP_LIMIT - len)))
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.
139 asmlinkage unsigned long
140 sys_mmap2 (unsigned long addr, unsigned long len, int prot, int flags, int fd, long pgoff)
142 addr = ksys_mmap_pgoff(addr, len, prot, flags, fd, pgoff);
143 if (!IS_ERR_VALUE(addr))
144 force_successful_syscall_return();
148 asmlinkage unsigned long
149 sys_mmap (unsigned long addr, unsigned long len, int prot, int flags, int fd, long off)
151 if (offset_in_page(off) != 0)
154 addr = ksys_mmap_pgoff(addr, len, prot, flags, fd, off >> PAGE_SHIFT);
155 if (!IS_ERR_VALUE(addr))
156 force_successful_syscall_return();
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)
164 addr = sys_mremap(addr, old_len, new_len, flags, new_addr);
165 if (!IS_ERR_VALUE(addr))
166 force_successful_syscall_return();
171 ia64_clock_getres(const clockid_t which_clock, struct __kernel_timespec __user *tp)
173 struct timespec64 rtn_tp;
177 * ia64's clock_gettime() syscall is implemented as a vdso call
178 * fsys_clock_gettime(). Currently it handles only
179 * CLOCK_REALTIME and CLOCK_MONOTONIC. Both are based on
180 * 'ar.itc' counter which gets incremented at a constant
181 * frequency. It's usually 400MHz, ~2.5x times slower than CPU
182 * clock frequency. Which is almost a 1ns hrtimer, but not quite.
184 * Let's special-case these timers to report correct precision
185 * based on ITC frequency and not HZ frequency for supported
188 switch (which_clock) {
190 case CLOCK_MONOTONIC:
191 tick_ns = DIV_ROUND_UP(NSEC_PER_SEC, local_cpu_data->itc_freq);
192 rtn_tp = ns_to_timespec64(tick_ns);
193 return put_timespec64(&rtn_tp, tp);
196 return sys_clock_getres(which_clock, tp);