Skip to content

Commit 530fff9

Browse files
rmacnak-googleCommit Queue
authored andcommitted
[vm, simarm64] Handle exceptions during FFI callbacks.
TEST=ci Bug: #60204 Change-Id: If746fe07a10c9c71d228ca9591f398054635fea2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/413900 Reviewed-by: Daco Harkes <[email protected]> Commit-Queue: Ryan Macnak <[email protected]>
1 parent d9bd6a0 commit 530fff9

File tree

5 files changed

+25
-1
lines changed

5 files changed

+25
-1
lines changed

runtime/vm/runtime_entry.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class RuntimeEntry : public BaseRuntimeEntry {
5555
bool is_float() const { return is_float_; }
5656
bool can_lazy_deopt() const { return can_lazy_deopt_; }
5757
uword GetEntryPoint() const;
58+
uword GetEntryPointNoRedirect() const {
59+
return reinterpret_cast<uword>(function());
60+
}
5861

5962
static uword InterpretCallEntry();
6063

runtime/vm/simulator_arm64.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4088,6 +4088,17 @@ void Simulator::JumpToFrame(uword pc, uword sp, uword fp, Thread* thread) {
40884088

40894089
// Keep the following code in sync with `StubCode::JumpToFrameStub()`.
40904090

4091+
// Check if we exited generated from FFI. If so do transition - this is needed
4092+
// because normally runtime calls transition back to generated via destructor
4093+
// of TransitionGeneratedToVM/Native that is part of runtime boilerplate
4094+
// code (see DEFINE_RUNTIME_ENTRY_IMPL in runtime_entry.h). Ffi calls don't
4095+
// have this boilerplate, don't have this stack resource, have to transition
4096+
// explicitly.
4097+
if (thread->exit_through_ffi() == dart::Thread::kExitThroughFfi) {
4098+
thread->ExitSafepoint();
4099+
thread->set_execution_state(Thread::kThreadInGenerated);
4100+
}
4101+
40914102
// Unwind the C++ stack and continue simulation in the target frame.
40924103
set_pc(static_cast<int64_t>(pc));
40934104
set_register(nullptr, SP, static_cast<int64_t>(sp));

runtime/vm/thread.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,13 @@ void Thread::InitVMConstants() {
218218
LEAF_RUNTIME_ENTRY_LIST(INIT_VALUE)
219219
#undef INIT_VALUE
220220

221+
#if defined(SIMULATOR_FFI)
222+
// FfiCallInstr calls this through the CallNativeThroughSafepoint stub instead
223+
// of like a normal leaf runtime call.
224+
PropagateError_entry_point_ =
225+
kPropagateErrorRuntimeEntry.GetEntryPointNoRedirect();
226+
#endif
227+
221228
// Setup the thread specific reusable handles.
222229
#define REUSABLE_HANDLE_ALLOCATION(object) \
223230
this->object##_handle_ = this->AllocateReusableHandle<object>();

runtime/vm/thread.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ class Thread : public ThreadState {
485485
kExitThroughRuntimeCall = 2,
486486
};
487487

488+
uword exit_through_ffi() { return exit_through_ffi_; }
488489
static intptr_t exit_through_ffi_offset() {
489490
return OFFSET_OF(Thread, exit_through_ffi_);
490491
}

tests/ffi/abi_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ void testCurrent() {
1818
}
1919

2020
void testPlatformVersionCompatibility() {
21-
final abiStringFromPlatformVersion = Platform.version.split('"')[1];
21+
final abiStringFromPlatformVersion = Platform.version
22+
.split('"')[1]
23+
.replaceAll("sim", "");
2224
final abiStringFromCurrent = Abi.current().toString();
2325
Expect.equals(abiStringFromPlatformVersion, abiStringFromCurrent);
2426
}

0 commit comments

Comments
 (0)