guard against compilers failing to handle setjmp specially by default
[musl.git] / src / linux / cache.c
blob0eb051c2d4acecbce4ca780413f125369ffecf14
1 #include <errno.h>
2 #include "syscall.h"
3 #include "atomic.h"
5 #ifdef SYS_cacheflush
6 int _flush_cache(void *addr, int len, int op)
8 return syscall(SYS_cacheflush, addr, len, op);
10 weak_alias(_flush_cache, cacheflush);
11 #endif
13 #ifdef SYS_cachectl
14 int __cachectl(void *addr, int len, int op)
16 return syscall(SYS_cachectl, addr, len, op);
18 weak_alias(__cachectl, cachectl);
19 #endif
21 #ifdef SYS_riscv_flush_icache
23 #define VDSO_FLUSH_ICACHE_SYM "__vdso_flush_icache"
24 #define VDSO_FLUSH_ICACHE_VER "LINUX_4.5"
26 static void *volatile vdso_func;
28 static int flush_icache_init(void *start, void *end, unsigned long int flags)
30 void *p = __vdsosym(VDSO_FLUSH_ICACHE_VER, VDSO_FLUSH_ICACHE_SYM);
31 int (*f)(void *, void *, unsigned long int) =
32 (int (*)(void *, void *, unsigned long int))p;
33 a_cas_p(&vdso_func, (void *)flush_icache_init, p);
34 return f ? f(start, end, flags) : -ENOSYS;
37 static void *volatile vdso_func = (void *)flush_icache_init;
39 int __riscv_flush_icache(void *start, void *end, unsigned long int flags)
41 int (*f)(void *, void *, unsigned long int) =
42 (int (*)(void *, void *, unsigned long int))vdso_func;
43 if (f) {
44 int r = f(start, end, flags);
45 if (!r) return r;
46 if (r != -ENOSYS) return __syscall_ret(r);
49 weak_alias(__riscv_flush_icache, riscv_flush_icache);
50 #endif