| 631 | } |
| 632 | |
| 633 | NTSTATUS ProcessInit() { |
| 634 | InitSyscalls(); |
| 635 | |
| 636 | FEX::Windows::InitCRTProcess(); |
| 637 | const auto ExecutablePath = FEX::Windows::GetExecutableFilePath(); |
| 638 | FEX::Config::LoadConfig(nullptr, ExecutablePath, _environ, FEX::ReadPortabilityInformation()); |
| 639 | FEXCore::Config::ReloadMetaLayer(); |
| 640 | FEX::Windows::Logging::Init(); |
| 641 | |
| 642 | FEXCore::Config::Set(FEXCore::Config::CONFIG_IS64BIT_MODE, "1"); |
| 643 | |
| 644 | // Not applicable to Windows |
| 645 | FEXCore::Config::Set(FEXCore::Config::ConfigOption::CONFIG_TSOAUTOMIGRATION, "0"); |
| 646 | |
| 647 | FEXCore::Profiler::Init("", ""); |
| 648 | |
| 649 | FEX_CONFIG_OPT(ExtendedVolatileMetadataConfig, EXTENDEDVOLATILEMETADATA); |
| 650 | ExtendedMetaData = FEX::VolatileMetadata::ParseExtendedVolatileMetadata(ExtendedVolatileMetadataConfig()); |
| 651 | |
| 652 | SignalDelegator = fextl::make_unique<FEX::DummyHandlers::DummySignalDelegator>(); |
| 653 | SyscallHandler = fextl::make_unique<Exception::ECSyscallHandler>(); |
| 654 | Exception::HandlerConfig.emplace(); |
| 655 | |
| 656 | const auto NtDll = GetModuleHandle("ntdll.dll"); |
| 657 | const bool IsWine = !!GetProcAddress(NtDll, "wine_get_version"); |
| 658 | OvercommitTracker.emplace(IsWine); |
| 659 | |
| 660 | { |
| 661 | auto HostFeatures = FEX::Windows::CPUFeatures::FetchHostFeatures(IsWine); |
| 662 | CTX = FEXCore::Context::Context::CreateNewContext(HostFeatures); |
| 663 | } |
| 664 | |
| 665 | CTX->SetSignalDelegator(SignalDelegator.get()); |
| 666 | CTX->SetSyscallHandler(SyscallHandler.get()); |
| 667 | CTX->InitCore(); |
| 668 | |
| 669 | InvalidationTracker.emplace(*CTX, Threads); |
| 670 | |
| 671 | HandleImageMap(NtDllBase); |
| 672 | |
| 673 | auto MainModule = reinterpret_cast<__TEB*>(NtCurrentTeb())->Peb->ImageBaseAddress; |
| 674 | HandleImageMap(reinterpret_cast<uint64_t>(MainModule)); |
| 675 | |
| 676 | CPUFeatures.emplace(*CTX); |
| 677 | |
| 678 | X64ReturnInstr = ::VirtualAlloc(nullptr, FEXCore::Utils::FEX_PAGE_SIZE, MEM_COMMIT, PAGE_EXECUTE_READWRITE); |
| 679 | InvalidationTracker->HandleMemoryProtectionNotification(reinterpret_cast<uint64_t>(X64ReturnInstr), FEXCore::Utils::FEX_PAGE_SIZE, |
| 680 | PAGE_EXECUTE_READ); |
| 681 | *reinterpret_cast<uint8_t*>(X64ReturnInstr) = 0xc3; |
| 682 | |
| 683 | const uintptr_t KiUserExceptionDispatcherFFS = reinterpret_cast<uintptr_t>(GetProcAddress(NtDll, "KiUserExceptionDispatcher")); |
| 684 | Exception::KiUserExceptionDispatcher = NtDllRedirectionLUT[KiUserExceptionDispatcherFFS - NtDllBase] + NtDllBase; |
| 685 | |
| 686 | FEX_CONFIG_OPT(TSOEnabled, TSOENABLED); |
| 687 | if (TSOEnabled()) { |
| 688 | BOOL Enable = TRUE; |
| 689 | NTSTATUS Status = NtSetInformationProcess(NtCurrentProcess(), ProcessFexHardwareTso, &Enable, sizeof(Enable)); |
| 690 | if (Status == STATUS_SUCCESS) { |
nothing calls this directly
no test coverage detected