diff --git a/compiler-rt/lib/builtins/clear_cache.c b/compiler-rt/lib/builtins/clear_cache.c --- a/compiler-rt/lib/builtins/clear_cache.c +++ b/compiler-rt/lib/builtins/clear_cache.c @@ -46,6 +46,11 @@ #include #endif +#if defined(__linux__) && defined(__riscv) +// to get platform-specific syscall definitions +#include +#endif + // The compiler generates calls to __clear_cache() when creating // trampoline functions on the stack for use with nested functions. // It is expected to invalidate the instruction cache for the @@ -148,9 +153,10 @@ for (uintptr_t dword = start_dword; dword < end_dword; dword += dword_size) __asm__ volatile("flush %0" : : "r"(dword)); #elif defined(__riscv) && defined(__linux__) -#define __NR_riscv_flush_icache (244 + 15) + // See: arch/riscv/include/asm/cacheflush.h, arch/riscv/kernel/sys_riscv.c register void *start_reg __asm("a0") = start; const register void *end_reg __asm("a1") = end; + // "0" means that we clear cache for all threads (SYS_RISCV_FLUSH_ICACHE_ALL) const register long flags __asm("a2") = 0; const register long syscall_nr __asm("a7") = __NR_riscv_flush_icache; __asm __volatile("ecall"