Skip to content

Commit 41208bd

Browse files
committed
arm64/linux: implement explicit I-cache flush in __clear_cache to avoid recursive builtin crash
1 parent 07b3a61 commit 41208bd

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

lib/lib-arm64.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,21 @@ static void *memcpy(void* d, void* s, __SIZE_TYPE__ c) {
3434
#if !defined __riscv && !defined __APPLE__
3535
void __clear_cache(void *beg, void *end)
3636
{
37+
#if defined(__aarch64__) && defined(__linux__)
38+
uintptr_t start = (uintptr_t)beg & ~(uintptr_t)63;
39+
uintptr_t stop = (uintptr_t)end;
40+
for (uintptr_t p = start; p < stop; p += 64) {
41+
__asm__ __volatile__("dc cvau, %0" : : "r"(p) : "memory");
42+
}
43+
__asm__ __volatile__("dsb ish" : : : "memory");
44+
for (uintptr_t p = start; p < stop; p += 64) {
45+
__asm__ __volatile__("ic ivau, %0" : : "r"(p) : "memory");
46+
}
47+
__asm__ __volatile__("dsb ish" : : : "memory");
48+
__asm__ __volatile__("isb" : : : "memory");
49+
#else
3750
__builtin___clear_cache(beg, end);
51+
#endif
3852
}
3953
#endif
4054

0 commit comments

Comments
 (0)