]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/riscv/flush-icache.c
riscv: Do not use __has_include__
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / riscv / flush-icache.c
1 /* RISC-V instruction cache flushing VDSO calls
2 Copyright (C) 2017-2019 Free Software Foundation, Inc.
3
4 This file is part of the GNU C Library.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
19
20 #include <dl-vdso.h>
21 #include <stdlib.h>
22 #include <atomic.h>
23 #include <sys/cachectl.h>
24 #if __has_include (<asm/syscalls.h>)
25 # include <asm/syscalls.h>
26 #else
27 # include <asm/unistd.h>
28 #endif
29
30 typedef int (*func_type) (void *, void *, unsigned long int);
31
32 static int
33 __riscv_flush_icache_syscall (void *start, void *end, unsigned long int flags)
34 {
35 return INLINE_SYSCALL (riscv_flush_icache, 3, start, end, flags);
36 }
37
38 static func_type
39 __lookup_riscv_flush_icache (void)
40 {
41 PREPARE_VERSION_KNOWN (linux_version, LINUX_4_15);
42
43 func_type func = _dl_vdso_vsym ("__vdso_flush_icache", &linux_version);
44
45 /* If there is no vDSO entry then call the system call directly. All Linux
46 versions provide the vDSO entry, but QEMU's user-mode emulation doesn't
47 provide a vDSO. */
48 if (!func)
49 func = &__riscv_flush_icache_syscall;
50
51 return func;
52 }
53
54 #ifdef SHARED
55
56 # define INIT_ARCH()
57 libc_ifunc (__riscv_flush_icache, __lookup_riscv_flush_icache ())
58
59 #else
60
61 int
62 __riscv_flush_icache (void *start, void *end, unsigned long int flags)
63 {
64 static volatile func_type cached_func;
65
66 func_type func = atomic_load_relaxed (&cached_func);
67
68 if (!func)
69 {
70 func = __lookup_riscv_flush_icache ();
71 atomic_store_relaxed (&cached_func, func);
72 }
73
74 return func (start, end, flags);
75 }
76
77 #endif