Skip to content

Commit

Permalink
Workaround JIT crash on arm64, especially for Saumsung S7 Edge
Browse files Browse the repository at this point in the history
  • Loading branch information
Kudo committed May 28, 2019
1 parent a89ef01 commit daf5700
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
41 changes: 41 additions & 0 deletions patches/jsc_fix_arm64_jit_crash.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
diff -aur target-org/webkit/Source/JavaScriptCore/assembler/ARM64Assembler.h target/webkit/Source/JavaScriptCore/assembler/ARM64Assembler.h
--- target-org/webkit/Source/JavaScriptCore/assembler/ARM64Assembler.h 2018-08-20 20:52:54.000000000 +0800
+++ target/webkit/Source/JavaScriptCore/assembler/ARM64Assembler.h 2019-05-28 13:50:53.000000000 +0800
@@ -2852,7 +2852,36 @@

unsigned debugOffset() { return m_buffer.debugOffset(); }

-#if OS(LINUX) && COMPILER(GCC_OR_CLANG)
+#if defined(CUSTOMIZE_REACT_NATIVE)
+ static inline void linuxPageFlush(uintptr_t start, uintptr_t end)
+ {
+ // NOTE(CUSTOMIZE_REACT_NATIVE): The code mostly copied from LLVM compiler-rt
+ // https://github.com/llvm-mirror/compiler-rt/blob/ff75f2a0260b1940436a483413091c5770427c04/lib/builtins/clear_cache.c#L142
+ // But only to modify "dc cvau" to "dc civac"
+
+ uint64_t xstart = (uint64_t)(uintptr_t)start;
+ uint64_t xend = (uint64_t)(uintptr_t)end;
+ uint64_t addr;
+
+ // Get Cache Type Info
+ uint64_t ctr_el0;
+ __asm __volatile("mrs %0, ctr_el0" : "=r"(ctr_el0));
+
+ // dc & ic instructions must use 64bit registers so we don't use
+ // uintptr_t in case this runs in an IPL32 environment.
+ const size_t dcache_line_size = 4 << ((ctr_el0 >> 16) & 15);
+ for (addr = xstart & ~(dcache_line_size - 1); addr < xend;
+ addr += dcache_line_size)
+ __asm __volatile("dc civac, %0" ::"r"(addr));
+ __asm __volatile("dsb ish");
+
+ const size_t icache_line_size = 4 << ((ctr_el0 >> 0) & 15);
+ for (addr = xstart & ~(icache_line_size - 1); addr < xend;
+ addr += icache_line_size)
+ __asm __volatile("ic ivau, %0" ::"r"(addr));
+ __asm __volatile("isb sy");
+ }
+#elif OS(LINUX) && COMPILER(GCC_OR_CLANG)
static inline void linuxPageFlush(uintptr_t begin, uintptr_t end)
{
__builtin___clear_cache(reinterpret_cast<char*>(begin), reinterpret_cast<char*>(end));
3 changes: 3 additions & 0 deletions scripts/patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ JSC_PATCHSET=(
# NDK r17c does not define __mulodi4, which is being used in debug build.
# (However, NDK r19 fixed this)
"jsc_fix_build_error_mulodi4.patch"

# Workaround JIT crash on arm64, especially for Saumsung S7 Edge
"jsc_fix_arm64_jit_crash.patch"
)

if [[ "$I18N" = false ]]
Expand Down

0 comments on commit daf5700

Please sign in to comment.