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

Function BTCpuProcessInit

Source/Windows/WOW64/Module.cpp:510–593  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

508};
509
510void BTCpuProcessInit() {
511 FEX::Windows::InitCRTProcess();
512 const auto ExecutablePath = FEX::Windows::GetExecutableFilePath();
513 FEX::Config::LoadConfig(nullptr, ExecutablePath, _environ, FEX::ReadPortabilityInformation());
514 FEXCore::Config::ReloadMetaLayer();
515 FEX::Windows::Logging::Init();
516
517 FEXCore::Config::Set(FEXCore::Config::CONFIG_IS_INTERPRETER, "0");
518 FEXCore::Config::Set(FEXCore::Config::CONFIG_INTERPRETER_INSTALLED, "0");
519 FEXCore::Config::Set(FEXCore::Config::CONFIG_IS64BIT_MODE, "0");
520
521 // Not applicable to Windows
522 FEXCore::Config::Set(FEXCore::Config::ConfigOption::CONFIG_TSOAUTOMIGRATION, "0");
523
524 FEXCore::Profiler::Init("", "");
525
526 FEX_CONFIG_OPT(ExtendedVolatileMetadataConfig, EXTENDEDVOLATILEMETADATA);
527 ExtendedMetaData = FEX::VolatileMetadata::ParseExtendedVolatileMetadata(ExtendedVolatileMetadataConfig());
528
529 SignalDelegator = fextl::make_unique<FEX::DummyHandlers::DummySignalDelegator>();
530 SyscallHandler = fextl::make_unique<WowSyscallHandler>();
531 Context::HandlerConfig.emplace();
532 const auto NtDll = GetModuleHandle("ntdll.dll");
533 const bool IsWine = !!GetProcAddress(NtDll, "wine_get_version");
534 OvercommitTracker.emplace(IsWine);
535
536 {
537 auto HostFeatures = FEX::Windows::CPUFeatures::FetchHostFeatures(IsWine);
538 CTX = FEXCore::Context::Context::CreateNewContext(HostFeatures);
539 }
540
541 CTX->SetSignalDelegator(SignalDelegator.get());
542 CTX->SetSyscallHandler(SyscallHandler.get());
543 CTX->InitCore();
544
545 InvalidationTracker.emplace(*CTX, Threads);
546
547 auto NtDllX86 = reinterpret_cast<SYSTEM_DLL_INIT_BLOCK*>(GetProcAddress(NtDll, "LdrSystemDllInitBlock"))->ntdll_handle;
548 HandleImageMap(NtDllX86);
549
550 auto MainModule = reinterpret_cast<__TEB*>(NtCurrentTeb())->Peb->ImageBaseAddress;
551 HandleImageMap(reinterpret_cast<uint64_t>(MainModule));
552
553 CPUFeatures.emplace(*CTX);
554
555 // Allocate the syscall/unixcall trampolines in the lower 2GB of the address space
556 SIZE_T Size = 4;
557 void* Addr = nullptr;
558 NtAllocateVirtualMemory(NtCurrentProcess(), &Addr, (1U << 31) - 1, &Size, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
559 InvalidationTracker->HandleMemoryProtectionNotification(reinterpret_cast<uint64_t>(Addr), Size, PAGE_EXECUTE);
560 *reinterpret_cast<uint32_t*>(Addr) = 0x2ecd2ecd;
561 BridgeInstrs::Syscall = Addr;
562 BridgeInstrs::UnixCall = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(Addr) + 2);
563
564 const auto Sym = GetProcAddress(NtDll, "__wine_unix_call_dispatcher");
565 if (Sym) {
566 WineUnixCall = *reinterpret_cast<decltype(WineUnixCall)*>(Sym);
567 }

Callers

nothing calls this directly

Calls 15

InitCRTProcessFunction · 0.85
GetExecutableFilePathFunction · 0.85
LoadConfigFunction · 0.85
ReloadMetaLayerFunction · 0.85
FetchHostFeaturesFunction · 0.85
GetTLSFunction · 0.85
IFmtFunction · 0.85
emplaceMethod · 0.80
SetSignalDelegatorMethod · 0.80
getMethod · 0.80
SetSyscallHandlerMethod · 0.80

Tested by

no test coverage detected