feat: make ETW configurable, doesn't actually do anything yet because we're stuck on .NET 5

This commit is contained in:
goaaats 2022-06-22 16:58:53 +02:00
parent e7b0da9f7a
commit 8744e82979
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
8 changed files with 18 additions and 5 deletions

View file

@ -86,6 +86,7 @@ void from_json(const nlohmann::json& json, DalamudStartInfo& config) {
config.BootWaitDebugger = json.value("BootWaitDebugger", config.BootWaitDebugger); config.BootWaitDebugger = json.value("BootWaitDebugger", config.BootWaitDebugger);
config.BootVehEnabled = json.value("BootVehEnabled", config.BootVehEnabled); config.BootVehEnabled = json.value("BootVehEnabled", config.BootVehEnabled);
config.BootVehFull = json.value("BootVehFull", config.BootVehFull); config.BootVehFull = json.value("BootVehFull", config.BootVehFull);
config.BootEnableEtw = json.value("BootEnableEtw", config.BootEnableEtw);
config.BootDotnetOpenProcessHookMode = json.value("BootDotnetOpenProcessHookMode", config.BootDotnetOpenProcessHookMode); config.BootDotnetOpenProcessHookMode = json.value("BootDotnetOpenProcessHookMode", config.BootDotnetOpenProcessHookMode);
if (const auto it = json.find("BootEnabledGameFixes"); it != json.end() && it->is_array()) { if (const auto it = json.find("BootEnabledGameFixes"); it != json.end() && it->is_array()) {
config.BootEnabledGameFixes.clear(); config.BootEnabledGameFixes.clear();
@ -107,6 +108,7 @@ void DalamudStartInfo::from_envvars() {
BootWaitDebugger = utils::get_env<bool>(L"DALAMUD_WAIT_DEBUGGER"); BootWaitDebugger = utils::get_env<bool>(L"DALAMUD_WAIT_DEBUGGER");
BootVehEnabled = utils::get_env<bool>(L"DALAMUD_IS_VEH"); BootVehEnabled = utils::get_env<bool>(L"DALAMUD_IS_VEH");
BootVehFull = utils::get_env<bool>(L"DALAMUD_IS_VEH_FULL"); BootVehFull = utils::get_env<bool>(L"DALAMUD_IS_VEH_FULL");
BootEnableEtw = utils::get_env<bool>(L"DALAMUD_ENABLE_ETW");
BootDotnetOpenProcessHookMode = static_cast<DotNetOpenProcessHookMode>(utils::get_env<int>(L"DALAMUD_DOTNET_OPENPROCESS_HOOKMODE")); BootDotnetOpenProcessHookMode = static_cast<DotNetOpenProcessHookMode>(utils::get_env<int>(L"DALAMUD_DOTNET_OPENPROCESS_HOOKMODE"));
for (const auto& item : utils::get_env_list<std::string>(L"DALAMUD_GAMEFIX_LIST")) for (const auto& item : utils::get_env_list<std::string>(L"DALAMUD_GAMEFIX_LIST"))
BootEnabledGameFixes.insert(unicode::convert<std::string>(item, &unicode::lower)); BootEnabledGameFixes.insert(unicode::convert<std::string>(item, &unicode::lower));

View file

@ -38,6 +38,7 @@ struct DalamudStartInfo {
bool BootWaitDebugger = false; bool BootWaitDebugger = false;
bool BootVehEnabled = false; bool BootVehEnabled = false;
bool BootVehFull = false; bool BootVehFull = false;
bool BootEnableEtw = false;
DotNetOpenProcessHookMode BootDotnetOpenProcessHookMode = DotNetOpenProcessHookMode::ImportHooks; DotNetOpenProcessHookMode BootDotnetOpenProcessHookMode = DotNetOpenProcessHookMode::ImportHooks;
std::set<std::string> BootEnabledGameFixes{}; std::set<std::string> BootEnabledGameFixes{};
std::set<std::string> BootUnhookDlls{}; std::set<std::string> BootUnhookDlls{};

View file

@ -116,6 +116,7 @@ DllExport DWORD WINAPI Initialize(LPVOID lpParam, HANDLE hMainThreadContinue) {
void* entrypoint_vfn; void* entrypoint_vfn;
int result = InitializeClrAndGetEntryPoint( int result = InitializeClrAndGetEntryPoint(
g_hModule, g_hModule,
g_startInfo.BootEnableEtw,
runtimeconfig_path, runtimeconfig_path,
module_path, module_path,
L"Dalamud.EntryPoint, Dalamud", L"Dalamud.EntryPoint, Dalamud",

View file

@ -24,6 +24,7 @@ int wmain(int argc, wchar_t** argv)
void* entrypoint_vfn; void* entrypoint_vfn;
int result = InitializeClrAndGetEntryPoint( int result = InitializeClrAndGetEntryPoint(
GetModuleHandleW(nullptr), GetModuleHandleW(nullptr),
false,
runtimeconfig_path, runtimeconfig_path,
module_path, module_path,
L"Dalamud.Injector.EntryPoint, Dalamud.Injector", L"Dalamud.Injector.EntryPoint, Dalamud.Injector",

View file

@ -83,7 +83,8 @@ namespace Dalamud.Injector
} }
startInfo = ExtractAndInitializeStartInfoFromArguments(startInfo, args); startInfo = ExtractAndInitializeStartInfoFromArguments(startInfo, args);
args.Remove("--console"); // Remove "console" flag args.Remove("--console"); // Remove "console" flag, already handled
args.Remove("--etw"); // Remove "etw" flag, already handled
var mainCommand = args[1].ToLowerInvariant(); var mainCommand = args[1].ToLowerInvariant();
if (mainCommand.Length > 0 && mainCommand.Length <= 6 && "inject"[..mainCommand.Length] == mainCommand) if (mainCommand.Length > 0 && mainCommand.Length <= 6 && "inject"[..mainCommand.Length] == mainCommand)
@ -321,6 +322,7 @@ namespace Dalamud.Injector
// Set boot defaults // Set boot defaults
startInfo.BootShowConsole = args.Contains("--console"); startInfo.BootShowConsole = args.Contains("--console");
startInfo.BootEnableEtw = args.Contains("--etw");
startInfo.BootLogPath = GetLogPath("dalamud.boot"); startInfo.BootLogPath = GetLogPath("dalamud.boot");
startInfo.BootEnabledGameFixes = new List<string> { "prevent_devicechange_crashes", "disable_game_openprocess_access_check", "redirect_openprocess" }; startInfo.BootEnabledGameFixes = new List<string> { "prevent_devicechange_crashes", "disable_game_openprocess_access_check", "redirect_openprocess" };
startInfo.BootDotnetOpenProcessHookMode = 0; startInfo.BootDotnetOpenProcessHookMode = 0;
@ -361,6 +363,7 @@ namespace Dalamud.Injector
Console.WriteLine("Verbose logging:\t[-v]"); Console.WriteLine("Verbose logging:\t[-v]");
Console.WriteLine("Show Console:\t[--console]"); Console.WriteLine("Show Console:\t[--console]");
Console.WriteLine("Enable ETW:\t[--etw]");
return 0; return 0;
} }

View file

@ -41,6 +41,7 @@ namespace Dalamud
this.BootWaitDebugger = other.BootWaitDebugger; this.BootWaitDebugger = other.BootWaitDebugger;
this.BootVehEnabled = other.BootVehEnabled; this.BootVehEnabled = other.BootVehEnabled;
this.BootVehFull = other.BootVehFull; this.BootVehFull = other.BootVehFull;
this.BootEnableEtw = other.BootEnableEtw;
this.BootDotnetOpenProcessHookMode = other.BootDotnetOpenProcessHookMode; this.BootDotnetOpenProcessHookMode = other.BootDotnetOpenProcessHookMode;
this.BootEnabledGameFixes = other.BootEnabledGameFixes; this.BootEnabledGameFixes = other.BootEnabledGameFixes;
this.BootUnhookDlls = other.BootUnhookDlls; this.BootUnhookDlls = other.BootUnhookDlls;
@ -122,6 +123,11 @@ namespace Dalamud
/// </summary> /// </summary>
public bool BootVehFull { get; set; } public bool BootVehFull { get; set; }
/// <summary>
/// Gets or sets a value indicating whether or not ETW should be enabled.
/// </summary>
public bool BootEnableEtw { get; set; }
/// <summary> /// <summary>
/// Gets or sets a value choosing the OpenProcess hookmode. /// Gets or sets a value choosing the OpenProcess hookmode.
/// </summary> /// </summary>

View file

@ -29,6 +29,7 @@ std::optional<CoreCLR> g_clr;
int InitializeClrAndGetEntryPoint( int InitializeClrAndGetEntryPoint(
void* calling_module, void* calling_module,
bool enableEtw,
std::wstring runtimeconfig_path, std::wstring runtimeconfig_path,
std::wstring module_path, std::wstring module_path,
std::wstring entrypoint_assembly_name, std::wstring entrypoint_assembly_name,
@ -49,10 +50,7 @@ int InitializeClrAndGetEntryPoint(
SetEnvironmentVariable(L"DOTNET_TC_QuickJitForLoops", L"1"); SetEnvironmentVariable(L"DOTNET_TC_QuickJitForLoops", L"1");
SetEnvironmentVariable(L"DOTNET_ReadyToRun", L"1"); SetEnvironmentVariable(L"DOTNET_ReadyToRun", L"1");
#if NDEBUG SetEnvironmentVariable(L"COMPlus_ETWEnabled", enableEtw ? L"1" : L"0");
// This might fix extremely bad performance in some algorithms on insider builds
SetEnvironmentVariable(L"COMPlus_ETWEnabled", L"0");
#endif
wchar_t* dotnet_path; wchar_t* dotnet_path;
wchar_t* _appdata; wchar_t* _appdata;

View file

@ -3,6 +3,7 @@ void ConsoleTeardown();
int InitializeClrAndGetEntryPoint( int InitializeClrAndGetEntryPoint(
void* calling_module, void* calling_module,
bool enableEtw,
std::wstring runtimeconfig_path, std::wstring runtimeconfig_path,
std::wstring module_path, std::wstring module_path,
std::wstring entrypoint_assembly_name, std::wstring entrypoint_assembly_name,