From e9586a5d1419f9c32c2a4466b58c86a52217e6b1 Mon Sep 17 00:00:00 2001 From: Vyacheslav Egorov Date: Mon, 24 Sep 2018 20:16:08 +0000 Subject: [PATCH] [vm] Update workaround for Android Kernel bug (b089d4f). Previous workaround was only compilable by GCC - new one is compilable with both but is less robust because theoretically compiler can simply use registers r0-r2 as temporaries whenever it desires. Bug: https://github.com/flutter/flutter/issues/22172 Change-Id: Ic73fde8d3342c1455ab01ed8b7d4b267aebda136 Reviewed-on: https://dart-review.googlesource.com/76021 Reviewed-by: Zach Anderson Commit-Queue: Vyacheslav Egorov --- runtime/vm/signal_handler.h | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/runtime/vm/signal_handler.h b/runtime/vm/signal_handler.h index 69e897ac173..41eea90dc59 100644 --- a/runtime/vm/signal_handler.h +++ b/runtime/vm/signal_handler.h @@ -94,19 +94,26 @@ class SignalHandler : public AllStatic { void* context_) { // IT (If-Then) instruction makes up to four instructions that follow it // conditional. - asm volatile("nop; nop; nop; nop" : : : "memory"); + // Note: clobber all register so that compiler does not attempt to hoist + // anything from the next assembly block past this one. + asm volatile("nop; nop; nop; nop;" + : + : + : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", + "r10", "r11", "r12", "r13", "r14", "memory"); // Tail-call into the actual signal handler. + // // Note: this code is split into a separate inline assembly block because // any code that compiler generates to satisfy register constraints must // be generated after four NOPs. - register int arg0 asm("r0") = signal; - register siginfo_t* arg1 asm("r1") = info; - register void* arg2 asm("r2") = context_; - asm volatile("bx %3" - : - : "r"(arg0), "r"(arg1), "r"(arg2), "r"(action) - : "memory"); + // + // Note: there is no portable way to specify that we want to have + // signal, info and context_ in r0 - r2 respectively. So we just mark them + // as clobbered and hope that compiler does not emit any code that uses + // these registers to satisfy action constraint (we tested on clang and + // the generated code looks like one would expect). + asm volatile("bx %0;" : : "r"(action) : "r0", "r1", "r2", "memory"); } #endif // defined(USE_SIGNAL_HANDLER_TRAMPOLINE) };