1
2
3
4
5
6
7
8#include <linux/syscalls.h>
9#include <asm/unistd.h>
10#include <asm/cacheflush.h>
11#include <asm-generic/mman-common.h>
12
13static long riscv_sys_mmap(unsigned long addr, unsigned long len,
14 unsigned long prot, unsigned long flags,
15 unsigned long fd, off_t offset,
16 unsigned long page_shift_offset)
17{
18 if (unlikely(offset & (~PAGE_MASK >> page_shift_offset)))
19 return -EINVAL;
20
21 if ((prot & PROT_WRITE) && (prot & PROT_EXEC))
22 if (unlikely(!(prot & PROT_READ)))
23 return -EINVAL;
24
25 return ksys_mmap_pgoff(addr, len, prot, flags, fd,
26 offset >> (PAGE_SHIFT - page_shift_offset));
27}
28
29#ifdef CONFIG_64BIT
30SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
31 unsigned long, prot, unsigned long, flags,
32 unsigned long, fd, off_t, offset)
33{
34 return riscv_sys_mmap(addr, len, prot, flags, fd, offset, 0);
35}
36#else
37SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
38 unsigned long, prot, unsigned long, flags,
39 unsigned long, fd, off_t, offset)
40{
41
42
43
44
45 return riscv_sys_mmap(addr, len, prot, flags, fd, offset, 12);
46}
47#endif
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63SYSCALL_DEFINE3(riscv_flush_icache, uintptr_t, start, uintptr_t, end,
64 uintptr_t, flags)
65{
66
67 if (unlikely(flags & ~SYS_RISCV_FLUSH_ICACHE_ALL))
68 return -EINVAL;
69
70 flush_icache_mm(current->mm, flags & SYS_RISCV_FLUSH_ICACHE_LOCAL);
71
72 return 0;
73}
74