author | Rich Felker <dalias@aerifal.cx> | 2019年05月24日 10:46:08 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2019年06月14日 17:13:05 -0400 |
commit | 0a48860c27a8eb291bcc7616ea9eb073dc660cab (patch) | |
tree | 6021d6d18943d7b883e38e2f3e20a3b81d916fc5 /src/linux/cache.c | |
parent | 5fc43798250255455e4b5f9b08000bd3102274d9 (diff) | |
download | musl-0a48860c27a8eb291bcc7616ea9eb073dc660cab.tar.gz |
-rw-r--r-- | src/linux/cache.c | 33 |
diff --git a/src/linux/cache.c b/src/linux/cache.c index 84a138a4..0eb051c2 100644 --- a/src/linux/cache.c +++ b/src/linux/cache.c @@ -1,4 +1,6 @@ +#include <errno.h> #include "syscall.h" +#include "atomic.h" #ifdef SYS_cacheflush int _flush_cache(void *addr, int len, int op) @@ -15,3 +17,34 @@ int __cachectl(void *addr, int len, int op) } weak_alias(__cachectl, cachectl); #endif + +#ifdef SYS_riscv_flush_icache + +#define VDSO_FLUSH_ICACHE_SYM "__vdso_flush_icache" +#define VDSO_FLUSH_ICACHE_VER "LINUX_4.5" + +static void *volatile vdso_func; + +static int flush_icache_init(void *start, void *end, unsigned long int flags) +{ + void *p = __vdsosym(VDSO_FLUSH_ICACHE_VER, VDSO_FLUSH_ICACHE_SYM); + int (*f)(void *, void *, unsigned long int) = + (int (*)(void *, void *, unsigned long int))p; + a_cas_p(&vdso_func, (void *)flush_icache_init, p); + return f ? f(start, end, flags) : -ENOSYS; +} + +static void *volatile vdso_func = (void *)flush_icache_init; + +int __riscv_flush_icache(void *start, void *end, unsigned long int flags) +{ + int (*f)(void *, void *, unsigned long int) = + (int (*)(void *, void *, unsigned long int))vdso_func; + if (f) { + int r = f(start, end, flags); + if (!r) return r; + if (r != -ENOSYS) return __syscall_ret(r); + } +} +weak_alias(__riscv_flush_icache, riscv_flush_icache); +#endif |