MCPcopy Create free account
hub / github.com/FEX-Emu/FEX / LoadVDSOThunks

Function LoadVDSOThunks

Source/Tools/LinuxEmulation/VDSO_Emulation.cpp:744–800  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

742}
743
744VDSOMapping LoadVDSOThunks(bool Is64Bit, FEX::HLE::SyscallHandler* const Handler) {
745 VDSOMapping Mapping {};
746 FEX_CONFIG_OPT(ThunkGuestLibs, THUNKGUESTLIBS);
747 fextl::string ThunkGuestPath = ThunkGuestLibs();
748 while (ThunkGuestPath.ends_with('/')) {
749 ThunkGuestPath.pop_back();
750 }
751 ThunkGuestPath = fextl::fmt::format("{}{}/libVDSO-guest.so", ThunkGuestPath, Is64Bit ? "" : "_32");
752 // Load VDSO if we can
753 int VDSOFD = ::open(ThunkGuestPath.c_str(), O_RDONLY);
754
755 if (VDSOFD != -1) {
756 // Get file size
757 Mapping.VDSOSize = lseek(VDSOFD, 0, SEEK_END);
758
759 if (Mapping.VDSOSize >= 4) {
760 // Reset to beginning
761 lseek(VDSOFD, 0, SEEK_SET);
762 Mapping.VDSOSize = FEXCore::AlignUp(Mapping.VDSOSize, 4096);
763
764 // Map the VDSO file to memory
765 Mapping.VDSOBase = Handler->GuestMmap(nullptr, nullptr, Mapping.VDSOSize, PROT_READ | PROT_EXEC, MAP_SHARED, VDSOFD, 0);
766
767 // Since we found our VDSO thunk library, find our host VDSO function implementations.
768 LoadHostVDSO();
769 }
770 close(VDSOFD);
771 LoadGuestVDSOSymbols(Is64Bit, reinterpret_cast<char*>(Mapping.VDSOBase));
772 }
773
774 if (!Is64Bit && (!VDSOPointers.VDSO_kernel_sigreturn || !VDSOPointers.VDSO_kernel_rt_sigreturn)) {
775 // If VDSO couldn't find sigreturn then FEX needs to provide unique implementations.
776 LoadUnique32BitSigreturn(&Mapping, Handler);
777 }
778
779 if (Is64Bit) {
780 // Set the Thunk definition pointers for x86-64
781 VDSODefinitions[0].ThunkFunction = FEX::VDSO::x64::Handler_time;
782 VDSODefinitions[1].ThunkFunction = FEX::VDSO::x64::Handler_gettimeofday;
783 VDSODefinitions[2].ThunkFunction = FEX::VDSO::x64::Handler_clock_gettime;
784 VDSODefinitions[3].ThunkFunction = FEX::VDSO::x64::Handler_clock_gettime;
785 VDSODefinitions[4].ThunkFunction = FEX::VDSO::x64::Handler_clock_getres;
786 VDSODefinitions[5].ThunkFunction = FEX::VDSO::x64::Handler_getcpu;
787 VDSODefinitions[6].ThunkFunction = FEX::VDSO::x64::Handler_getrandom;
788 } else {
789 // Set the Thunk definition pointers for x86
790 VDSODefinitions[0].ThunkFunction = FEX::VDSO::x32::Handler_time;
791 VDSODefinitions[1].ThunkFunction = FEX::VDSO::x32::Handler_gettimeofday;
792 VDSODefinitions[2].ThunkFunction = FEX::VDSO::x32::Handler_clock_gettime;
793 VDSODefinitions[3].ThunkFunction = FEX::VDSO::x32::Handler_clock_gettime64;
794 VDSODefinitions[4].ThunkFunction = FEX::VDSO::x32::Handler_clock_getres;
795 VDSODefinitions[5].ThunkFunction = FEX::VDSO::x32::Handler_getcpu;
796 // getrandom doesn't exist on 32-bit, so leave VDSODefinitions[6] unfilled
797 }
798
799 return Mapping;
800}
801

Callers 1

mainFunction · 0.85

Calls 7

formatFunction · 0.85
AlignUpFunction · 0.85
LoadHostVDSOFunction · 0.85
closeFunction · 0.85
LoadGuestVDSOSymbolsFunction · 0.85
LoadUnique32BitSigreturnFunction · 0.85
GuestMmapMethod · 0.45

Tested by

no test coverage detected