FFI callbacks aren't profiler-safe #52814
Labels
area-vm
Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends.
crash
Process exits with SIGSEGV, SIGABRT, etc. An unhandled exception is not a crash.
library-ffi
P2
A bug or feature request we're likely to work on
triaged
Issue has been triaged by sub team
Our current (sync or async) ffi callbacks aren't profiler-safe: When enabling the profiler and it samples in the middle of a ffi callback it may crash the program.
A simple example how to provoke this:
and a small change to the C code:
Running this without the profiler works just fine
Running this with the profiler will crash pretty quickly
The root cause is that there's a window where we have transitioned from native to generated code, we have set the
VMTag::kDartTagId
(at which point the profiler will attempt to sample the dart stack - assuming it's executing dart code) - but it will not identify any entry frame.See il_x64.cc:NativeEntryInstr::EmitNativeCode:
Any profiler tick into
<... XXX ...>
can lead to a crash of the program - as it will blindly continue unwinding using PC/FP across C++ and Dart (instead of only walking dart frames recognizing entry-frame/exit-frame correctly)The native code that invokes the callback doesn't have to have frame pointers enabled. This is simulated above by using inline assembly to clear out
rbp
./cc @dcharkes @liamappelbe
The text was updated successfully, but these errors were encountered: