Skip to content

Commit 817a927

Browse files
committed
FEXCore: Fixes circular dependency with thunk callback
Fixes crash in thunks that use callbacks, introduced in FEX-Emu#5148. The dispatcher would call the syscallhandler to get the VDSO thunk callback. But due to reordering initialization, the VDSO thunk would have not been loaded at that point. This would cause thunks that use callbacks to crash with a nullptr exception. Instead, defer the thunk callback pointer loading until the thread starts executing, and load the pointer in to our thread state's pointer struct instead. Didn't get caught in my initial test sweep since I didn't run a Wine game with thunks.
1 parent c7eb4c8 commit 817a927

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

FEXCore/Source/Interface/Core/Core.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,9 @@ void ContextImpl::HandleCallback(FEXCore::Core::InternalThreadState* Thread, uin
363363
}
364364

365365
void ContextImpl::ExecuteThread(FEXCore::Core::InternalThreadState* Thread) {
366+
// Update the thread pointer for Thunk return to the latest.
367+
Thread->CurrentFrame->Pointers.AArch64.ThunkCallbackRet = SignalDelegation->GetThunkCallbackRET();
368+
366369
Dispatcher->ExecuteDispatch(Thread->CurrentFrame);
367370

368371
// If it is the parent thread that died then just leave

FEXCore/Source/Interface/Core/Dispatcher/Dispatcher.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ void Dispatcher::EmitDispatcher() {
488488

489489
// Now push the callback return trampoline to the guest stack
490490
// Guest will be misaligned because calling a thunk won't correct the guest's stack once we call the callback from the host
491-
LoadConstant(ARMEmitter::Size::i64Bit, ARMEmitter::Reg::r0, CTX->SignalDelegation->GetThunkCallbackRET());
491+
ldr(ARMEmitter::XReg::x0, STATE_PTR(CpuStateFrame, Pointers.AArch64.ThunkCallbackRet));
492492

493493
ldr(ARMEmitter::XReg::x2, STATE_PTR(CpuStateFrame, State.gregs[X86State::REG_RSP]));
494494
sub(ARMEmitter::Size::i64Bit, ARMEmitter::Reg::r2, ARMEmitter::Reg::r2, CTX->Config.Is64BitMode ? 16 : 12);

FEXCore/include/FEXCore/Core/CoreState.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ struct JITPointers {
370370
// Process specific
371371
uint64_t LUDIV {};
372372
uint64_t LDIV {};
373+
uint64_t ThunkCallbackRet {};
373374

374375
// Thread Specific
375376

0 commit comments

Comments
 (0)