Skip to content

Commit 5c7b31f

Browse files
markatkMicky5991
authored andcommitted
Add execute assembly to clr startup
1 parent 4c820b2 commit 5c7b31f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

clrhost/include/clrHost.h

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class ClrHost {
5353
coreclr_initialize_ptr _initializeCoreCLR;
5454
coreclr_shutdown_2_ptr _shutdownCoreCLR;
5555
coreclr_create_delegate_ptr _createDelegate;
56+
coreclr_execute_assembly_ptr _executeAssembly;
5657

5758
void *_runtimeHost;
5859
unsigned int _domainId;

clrhost/src/clrHost.cpp

+21-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ ClrHost::ClrHost() {
6060
_initializeCoreCLR = nullptr;
6161
_shutdownCoreCLR = nullptr;
6262
_createDelegate = nullptr;
63+
_executeAssembly = nullptr;
6364
}
6465

6566
ClrHost::~ClrHost() {
@@ -122,6 +123,7 @@ bool ClrHost::loadCoreClr() {
122123
_initializeCoreCLR = (coreclr_initialize_ptr)GetProcAddress(_coreClrLib, "coreclr_initialize");
123124
_shutdownCoreCLR = (coreclr_shutdown_2_ptr)GetProcAddress(_coreClrLib, "coreclr_shutdown_2");
124125
_createDelegate = (coreclr_create_delegate_ptr)GetProcAddress(_coreClrLib, "coreclr_create_delegate");
126+
_executeAssembly = (coreclr_execute_assembly_ptr)GetProcAddress(_coreClrLib, "coreclr_execute_assembly");
125127
#else
126128
#ifdef __APPLE__
127129
coreClrDllPath += "libcoreclr.dylib";
@@ -141,7 +143,7 @@ bool ClrHost::loadCoreClr() {
141143
_createDelegate = (coreclr_create_delegate_ptr)dlsym(_coreClrLib, "coreclr_create_delegate");
142144
#endif
143145

144-
if (_initializeCoreCLR == nullptr || _shutdownCoreCLR == nullptr || _createDelegate == nullptr) {
146+
if (_initializeCoreCLR == nullptr || _shutdownCoreCLR == nullptr || _createDelegate == nullptr || _executeAssembly == nullptr) {
145147
std::cerr << "[.NET] Unable to find CoreCLR dll methods" << std::endl;
146148

147149
return false;
@@ -200,6 +202,24 @@ bool ClrHost::createAppDomain() {
200202
return false;
201203
}
202204

205+
// execute assembly to set a valid entry point which is needed by some libraries as mysql
206+
auto libraryPath = getAbsolutePath(std::string(PLUGIN_DIR_PATH) + PLUGIN_NAME);
207+
208+
result = _executeAssembly(
209+
_runtimeHost,
210+
_domainId,
211+
0,
212+
nullptr,
213+
libraryPath.c_str(),
214+
nullptr
215+
);
216+
217+
if (result < 0) {
218+
std::cerr << "[.NET] Unable to execute assembly: 0x" << std::hex << result << std::endl;
219+
220+
return false;
221+
}
222+
203223
return true;
204224
}
205225

0 commit comments

Comments
 (0)