Skip to content

Commit

Permalink
VDSO: Fixes a pretty nasty bug where we were never using the host VDSO
Browse files Browse the repository at this point in the history
This must have happened during a refactor or something, but since we're
making a copy of the function pointers, it would have only gotten the
version /prior/ to loading host VDSO symbols.

Moves the VDSO thunk definition setting to the end after VDSO symbol
definitions in order to get host VDSO symbols working again.
  • Loading branch information
Sonicadvance1 committed Sep 2, 2024
1 parent 114112a commit f8eaf9c
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions Source/Tools/LinuxEmulation/VDSO_Emulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,26 +608,9 @@ VDSOMapping LoadVDSOThunks(bool Is64Bit, FEX::HLE::SyscallHandler* const Handler
fextl::string ThunkGuestPath {};
if (Is64Bit) {
ThunkGuestPath = fextl::fmt::format("{}/libVDSO-guest.so", ThunkGuestLibs());

// Set the Thunk definition pointers for x86-64
VDSODefinitions[0].ThunkFunction = FEX::VDSO::x64::Handler_time;
VDSODefinitions[1].ThunkFunction = FEX::VDSO::x64::Handler_gettimeofday;
VDSODefinitions[2].ThunkFunction = FEX::VDSO::x64::Handler_clock_gettime;
VDSODefinitions[3].ThunkFunction = FEX::VDSO::x64::Handler_clock_gettime;
VDSODefinitions[4].ThunkFunction = FEX::VDSO::x64::Handler_clock_getres;
VDSODefinitions[5].ThunkFunction = FEX::VDSO::x64::Handler_getcpu;
} else {
ThunkGuestPath = fextl::fmt::format("{}/libVDSO-guest.so", ThunkGuestLibs32());

// Set the Thunk definition pointers for x86
VDSODefinitions[0].ThunkFunction = FEX::VDSO::x32::Handler_time;
VDSODefinitions[1].ThunkFunction = FEX::VDSO::x32::Handler_gettimeofday;
VDSODefinitions[2].ThunkFunction = FEX::VDSO::x32::Handler_clock_gettime;
VDSODefinitions[3].ThunkFunction = FEX::VDSO::x32::Handler_clock_gettime64;
VDSODefinitions[4].ThunkFunction = FEX::VDSO::x32::Handler_clock_getres;
VDSODefinitions[5].ThunkFunction = FEX::VDSO::x32::Handler_getcpu;
}

// Load VDSO if we can
int VDSOFD = ::open(ThunkGuestPath.c_str(), O_RDONLY);

Expand Down Expand Up @@ -655,6 +638,24 @@ VDSOMapping LoadVDSOThunks(bool Is64Bit, FEX::HLE::SyscallHandler* const Handler
LoadUnique32BitSigreturn(&Mapping);
}

if (Is64Bit) {
// Set the Thunk definition pointers for x86-64
VDSODefinitions[0].ThunkFunction = FEX::VDSO::x64::Handler_time;
VDSODefinitions[1].ThunkFunction = FEX::VDSO::x64::Handler_gettimeofday;
VDSODefinitions[2].ThunkFunction = FEX::VDSO::x64::Handler_clock_gettime;
VDSODefinitions[3].ThunkFunction = FEX::VDSO::x64::Handler_clock_gettime;
VDSODefinitions[4].ThunkFunction = FEX::VDSO::x64::Handler_clock_getres;
VDSODefinitions[5].ThunkFunction = FEX::VDSO::x64::Handler_getcpu;
} else {
// Set the Thunk definition pointers for x86
VDSODefinitions[0].ThunkFunction = FEX::VDSO::x32::Handler_time;
VDSODefinitions[1].ThunkFunction = FEX::VDSO::x32::Handler_gettimeofday;
VDSODefinitions[2].ThunkFunction = FEX::VDSO::x32::Handler_clock_gettime;
VDSODefinitions[3].ThunkFunction = FEX::VDSO::x32::Handler_clock_gettime64;
VDSODefinitions[4].ThunkFunction = FEX::VDSO::x32::Handler_clock_getres;
VDSODefinitions[5].ThunkFunction = FEX::VDSO::x32::Handler_getcpu;
}

return Mapping;
}

Expand Down

0 comments on commit f8eaf9c

Please sign in to comment.