Skip to content

Commit a4cb2fb

Browse files
mcfimeta-codesync[bot]
authored andcommitted
Emit udf for trap vasm instead of brk
Summary: Previously, vasm trap is implemented with a `brk` on Arm64. However, `brk` triggers a SIGTRAP signal, which is not handled by HHVM's crash reporter code, which is the root cause for `hphp/test/slow/static-analysis-error.php` test failure. This diffs fixes the issue by implementing vasm trap on Arm64 with a `udf #1` instruction, which is Arm64's counterpart to x86's `ud2` instruction. `udf` triggers a SIGILL just like what `ud2` does. This fixes `hphp/test/slow/static-analysis-error.php` and achieves platform parity in terms of trap and crash handling. Reviewed By: binliu19 Differential Revision: D94627667 fbshipit-source-id: 16654bd424f1147e5fb1e7e336086dbf8cda612d
1 parent 385aff0 commit a4cb2fb

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

hphp/runtime/base/crash-reporter.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@
4545

4646
#include <fcntl.h>
4747
#include <signal.h>
48-
#ifdef __x86_64__
4948
#include <ucontext.h>
50-
#endif
5149

5250
#include <folly/portability/Fcntl.h>
5351
#include <folly/portability/Stdio.h>
@@ -147,8 +145,12 @@ void bt_handler(int sigin, siginfo_t* info, void* args) {
147145
#ifdef __x86_64__
148146
static uintptr_t sig_rbp = ((ucontext_t*) args)->uc_mcontext.gregs[REG_RBP];
149147
static uintptr_t sig_rip = ((ucontext_t*) args)->uc_mcontext.gregs[REG_RIP];
148+
#elif defined(__aarch64__)
149+
static uintptr_t sig_rbp = ((ucontext_t*) args)->uc_mcontext.regs[29];
150+
static uintptr_t sig_rip = ((ucontext_t*) args)->uc_mcontext.pc;
150151
#else
151152
static uintptr_t sig_rbp = 0;
153+
static uintptr_t sig_rip = 0;
152154
#endif
153155

154156
switch (s_crash_report_stage) {
@@ -322,11 +324,7 @@ void bt_handler(int sigin, siginfo_t* info, void* args) {
322324
auto const frame = BTFrame::regular(ar, kInvalidOffset);
323325
auto const addr = [&] () -> jit::CTCA {
324326
if (sig != SIGILL && sig != SIGSEGV) return (jit::CTCA) sig_addr;
325-
#if defined(__x86_64__)
326327
return (jit::CTCA) sig_rip;
327-
#else
328-
return (jit::CTCA) 0;
329-
#endif
330328
}();
331329
auto const trace = createCrashBacktrace(frame, (jit::CTCA) addr);
332330

hphp/runtime/vm/jit/vasm-arm.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,9 @@ void Vgen::emit(const trap& i) {
12521252
env.meta.trapFixups.emplace_back(a->frontier(), i.fix);
12531253
env.record_inline_stack(a->frontier());
12541254
}
1255-
a->Brk(1);
1255+
// UDF #1 — permanently undefined instruction that raises SIGILL, matching
1256+
// x86_64's ud2 behavior. TODO: switch to a->udf(1) once vixl is updated.
1257+
a->dc32(1);
12561258
}
12571259

12581260
void Vgen::emit(const unpcklpd& i) {

0 commit comments

Comments
 (0)