Print dotnet stack trace on veh error msgbox, and use precompiled headers.

This commit is contained in:
Soreepeong 2021-12-24 12:23:23 +09:00
parent 2c99778eeb
commit e64cc7e687
16 changed files with 298 additions and 170 deletions

View file

@ -72,7 +72,17 @@ bool CoreCLR::load_runtime(const std::wstring& runtime_config_path, const struct
hdt_load_assembly_and_get_function_pointer,
reinterpret_cast<void**>(&m_load_assembly_and_get_function_pointer_fptr));
if (result != 0 || m_load_assembly_and_get_function_pointer_fptr == nullptr)
if (result != 0 || m_load_assembly_and_get_function_pointer_fptr == nullptr) {
m_hostfxr_close_fptr(context);
return result;
}
result = m_hostfxr_get_runtime_delegate_fptr(
context,
hdt_get_function_pointer,
reinterpret_cast<void**>(&m_get_function_pointer_fptr));
if (result != 0 || m_get_function_pointer_fptr == nullptr)
{
m_hostfxr_close_fptr(context);
return result;
@ -99,6 +109,22 @@ int CoreCLR::load_assembly_and_get_function_pointer(
return result;
};
int CoreCLR::get_function_pointer(
const wchar_t* type_name,
const wchar_t* method_name,
const wchar_t* delegate_type_name,
void* load_context,
void* reserved,
void** delegate) const
{
int result = m_get_function_pointer_fptr(type_name, method_name, delegate_type_name, load_context, reserved, delegate);
if (result != 0)
delegate = nullptr;
return result;
}
/* Helpers */
uint64_t CoreCLR::load_library(const wchar_t* path)
{

View file

@ -24,12 +24,20 @@ class CoreCLR {
const wchar_t* delegate_type_name,
void* reserved,
void** delegate) const;
int get_function_pointer(
const wchar_t* type_name,
const wchar_t* method_name,
const wchar_t* delegate_type_name,
void* load_context,
void* reserved,
void** delegate) const;
private:
/* HostFXR delegates. */
hostfxr_initialize_for_runtime_config_fn m_hostfxr_initialize_for_runtime_config_fptr{};
hostfxr_get_runtime_delegate_fn m_hostfxr_get_runtime_delegate_fptr{};
hostfxr_close_fn m_hostfxr_close_fptr{};
get_function_pointer_fn m_get_function_pointer_fptr = nullptr;
load_assembly_and_get_function_pointer_fn m_load_assembly_and_get_function_pointer_fptr = nullptr;
/* Helper functions. */

View file

@ -23,6 +23,8 @@ void ConsoleTeardown()
FreeConsole();
}
std::optional<CoreCLR> g_clr;
int InitializeClrAndGetEntryPoint(
std::wstring runtimeconfig_path,
std::wstring module_path,
@ -31,8 +33,9 @@ int InitializeClrAndGetEntryPoint(
std::wstring entrypoint_delegate_type_name,
void** entrypoint_fn)
{
g_clr = CoreCLR();
int result;
CoreCLR clr;
SetEnvironmentVariable(L"DOTNET_MULTILEVEL_LOOKUP", L"0");
//SetEnvironmentVariable(L"COMPlus_legacyCorruptedStateExceptionsPolicy", L"1");
SetEnvironmentVariable(L"DOTNET_legacyCorruptedStateExceptionsPolicy", L"1");
@ -85,7 +88,7 @@ int InitializeClrAndGetEntryPoint(
};
printf("Loading hostfxr... ");
if ((result = clr.load_hostfxr(&init_parameters)) != 0)
if ((result = g_clr->load_hostfxr(&init_parameters)) != 0)
{
printf("\nError: Failed to load the `hostfxr` library (err=%d)\n", result);
return result;
@ -102,7 +105,7 @@ int InitializeClrAndGetEntryPoint(
};
printf("Loading coreclr... ");;
if ((result = clr.load_runtime(runtimeconfig_path, &runtime_parameters)) != 0)
if ((result = g_clr->load_runtime(runtimeconfig_path, &runtime_parameters)) != 0)
{
printf("\nError: Failed to load coreclr (err=%d)\n", result);
return result;
@ -112,7 +115,7 @@ int InitializeClrAndGetEntryPoint(
// =========================================================================== //
printf("Loading module... ");
if ((result = clr.load_assembly_and_get_function_pointer(
if ((result = g_clr->load_assembly_and_get_function_pointer(
module_path.c_str(),
entrypoint_assembly_name.c_str(),
entrypoint_method_name.c_str(),

View file

@ -1,7 +0,0 @@
#pragma once
// Exclude rarely-used stuff from Windows headers
#define WIN32_LEAN_AND_MEAN
// Windows Header Files
#include <windows.h>

View file

@ -1,5 +0,0 @@
// pch.cpp: source file corresponding to the pre-compiled header
#include "pch.h"
// When you are using pre-compiled headers, this source file is necessary for compilation to succeed.

View file

@ -1,13 +0,0 @@
// pch.h: This is a precompiled header file.
// Files listed below are compiled only once, improving build performance for future builds.
// This also affects IntelliSense performance, including code completion and many code browsing features.
// However, files listed here are ALL re-compiled if any one of them is updated between builds.
// Do not add files here that you will be updating frequently as this negates the performance advantage.
#ifndef PCH_H
#define PCH_H
// add headers that you want to pre-compile here
#include "framework.h"
#endif //PCH_H