diff --git a/Source/Windows/ARM64EC/Module.cpp b/Source/Windows/ARM64EC/Module.cpp index 2803110d6..b9be96164 100644 --- a/Source/Windows/ARM64EC/Module.cpp +++ b/Source/Windows/ARM64EC/Module.cpp @@ -614,7 +614,7 @@ NTSTATUS ProcessInit() { FEX::Windows::InitCRTProcess(); const auto ExecutablePath = FEX::Windows::GetExecutableFilePath(); - FEX::Config::LoadConfig(nullptr, ExecutablePath, nullptr, FEX::ReadPortabilityInformation()); + FEX::Config::LoadConfig(nullptr, ExecutablePath, _environ, FEX::ReadPortabilityInformation()); FEXCore::Config::ReloadMetaLayer(); FEX::Windows::Logging::Init(); diff --git a/Source/Windows/Common/CRT/Misc.cpp b/Source/Windows/Common/CRT/Misc.cpp index 09b12556b..76f8b997b 100644 --- a/Source/Windows/Common/CRT/Misc.cpp +++ b/Source/Windows/Common/CRT/Misc.cpp @@ -12,7 +12,10 @@ namespace { char* Env; +char** EnvArray; +} // namespace +namespace { void InitEnv() { RtlAcquirePebLock(); auto ProcessParams = reinterpret_cast(NtCurrentTeb()->ProcessEnvironmentBlock->ProcessParameters); @@ -25,12 +28,33 @@ void InitEnv() { RtlUnicodeToMultiByteSize(&Size, EnvW, SizeW); Env = reinterpret_cast(RtlAllocateHeap(GetProcessHeap(), 0, Size + 1)); RtlUnicodeToMultiByteN(Env, Size + 1, nullptr, EnvW, SizeW); + + size_t EnvCount = 0; + char* It = Env; + while (*It) { + EnvCount++; + It += strlen(It) + 1; + } + + EnvArray = reinterpret_cast(RtlAllocateHeap(GetProcessHeap(), 0, (EnvCount + 1) * sizeof(char*))); + + It = Env; + for (size_t i = 0; i < EnvCount; i++) { + EnvArray[i] = It; + It += strlen(It) + 1; + } + EnvArray[EnvCount] = nullptr; + RtlReleasePebLock(); } __attribute__((used, section(".CRT$FEXB"))) void (*_InitEnv)(void) = InitEnv; } // namespace +char*** __p__environ() { + return &EnvArray; +} + char* getenv(const char* VarName) { size_t VarNameLen = strlen(VarName); char* It = Env; diff --git a/Source/Windows/WOW64/Module.cpp b/Source/Windows/WOW64/Module.cpp index 7bb731958..d45464ab0 100644 --- a/Source/Windows/WOW64/Module.cpp +++ b/Source/Windows/WOW64/Module.cpp @@ -477,7 +477,7 @@ public: void BTCpuProcessInit() { FEX::Windows::InitCRTProcess(); const auto ExecutablePath = FEX::Windows::GetExecutableFilePath(); - FEX::Config::LoadConfig(nullptr, ExecutablePath, nullptr, FEX::ReadPortabilityInformation()); + FEX::Config::LoadConfig(nullptr, ExecutablePath, _environ, FEX::ReadPortabilityInformation()); FEXCore::Config::ReloadMetaLayer(); FEX::Windows::Logging::Init();