Skip to content

Commit

Permalink
Windows: Load per-application configs
Browse files Browse the repository at this point in the history
  • Loading branch information
bylaws committed Sep 3, 2024
1 parent e664f61 commit ccba993
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
8 changes: 3 additions & 5 deletions Source/Windows/ARM64EC/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ desc: Implements the ARM64EC BT module API using FEXCore
#include <FEXCore/Utils/MathUtils.h>
#include <FEXCore/Utils/TypeDefines.h>

#include "Common/ArgumentLoader.h"
#include "Common/Config.h"
#include "Common/Exception.h"
#include "Common/InvalidationTracker.h"
#include "Common/TSOHandlerConfig.h"
#include "Common/CPUFeatures.h"
#include "Common/Logging.h"
#include "Common/Module.h"
#include "Common/CRT/CRT.h"
#include "DummyHandlers.h"
#include "BTInterface.h"
Expand Down Expand Up @@ -456,11 +458,7 @@ extern "C" void SyncThreadContext(CONTEXT* Context) {

NTSTATUS ProcessInit() {
FEX::Windows::InitCRTProcess();
FEX::Config::InitializeConfigs(FEX::Config::PortableInformation {});
FEXCore::Config::Initialize();
FEXCore::Config::AddLayer(FEX::Config::CreateGlobalMainLayer());
FEXCore::Config::AddLayer(FEX::Config::CreateMainLayer());
FEXCore::Config::Load();
FEX::Config::LoadConfig(nullptr, FEX::Windows::GetExecutableFilePath());
FEXCore::Config::ReloadMetaLayer();
FEX::Windows::Logging::Init();

Expand Down
24 changes: 24 additions & 0 deletions Source/Windows/Common/Module.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT
#pragma once

#include <array>
#include <FEXCore/fextl/string.h>
#include <winternl.h>

namespace FEX::Windows {
fextl::string GetExecutableFilePath() {
std::array<WCHAR, PATH_MAX> Buf;
UNICODE_STRING PathW {.Length = 0, .MaximumLength = Buf.size() * sizeof(WCHAR), .Buffer = Buf.data()};

if (LdrGetDllFullName(nullptr, &PathW)) {
return {};
}

STRING PathA;
RtlUnicodeStringToAnsiString(&PathA, &PathW, TRUE);
fextl::string Path(PathA.Buffer);
RtlFreeAnsiString(&PathA);

return Path.substr(Path.find_last_of('\\') + 1);
}
} // namespace FEX::Windows
8 changes: 3 additions & 5 deletions Source/Windows/WOW64/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ desc: Implements the WOW64 BT module API using FEXCore
#include <FEXCore/Utils/ArchHelpers/Arm64.h>
#include <FEXCore/Utils/TypeDefines.h>

#include "Common/ArgumentLoader.h"
#include "Common/Config.h"
#include "Common/Exception.h"
#include "Common/TSOHandlerConfig.h"
#include "Common/InvalidationTracker.h"
#include "Common/CPUFeatures.h"
#include "Common/Logging.h"
#include "Common/Module.h"
#include "Common/CRT/CRT.h"
#include "DummyHandlers.h"
#include "BTInterface.h"
Expand Down Expand Up @@ -424,11 +426,7 @@ class WowSyscallHandler : public FEXCore::HLE::SyscallHandler, public FEXCore::A

void BTCpuProcessInit() {
FEX::Windows::InitCRTProcess();
FEX::Config::InitializeConfigs(FEX::Config::PortableInformation {});
FEXCore::Config::Initialize();
FEXCore::Config::AddLayer(FEX::Config::CreateGlobalMainLayer());
FEXCore::Config::AddLayer(FEX::Config::CreateMainLayer());
FEXCore::Config::Load();
FEX::Config::LoadConfig(nullptr, FEX::Windows::GetExecutableFilePath());
FEXCore::Config::ReloadMetaLayer();
FEX::Windows::Logging::Init();

Expand Down
1 change: 1 addition & 0 deletions Source/Windows/include/winternl.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ typedef struct _KEY_VALUE_PARTIAL_INFORMATION {

NTSTATUS WINAPIV DbgPrint(LPCSTR fmt, ...);
NTSTATUS WINAPI LdrDisableThreadCalloutsForDll(HMODULE);
NTSTATUS WINAPI LdrGetDllFullName(HMODULE, UNICODE_STRING*);
NTSTATUS WINAPI LdrGetDllHandle(LPCWSTR, ULONG, const UNICODE_STRING*, HMODULE*);
NTSTATUS WINAPI LdrGetProcedureAddress(HMODULE, const ANSI_STRING*, ULONG, void**);
NTSTATUS WINAPI NtAllocateVirtualMemoryEx(HANDLE, PVOID*, SIZE_T*, ULONG, ULONG, MEM_EXTENDED_PARAMETER*, ULONG);
Expand Down

0 comments on commit ccba993

Please sign in to comment.