@@ -24,29 +24,31 @@ static const char * const coreClrDll = "libcoreclr.dylib";
24
24
static const char * const coreClrDll = " libcoreclr.so" ;
25
25
#endif
26
26
27
- // Windows types used by the ExecuteAssembly function
28
- typedef unsigned int DWORD;
29
- typedef const char16_t * LPCWSTR;
30
- typedef const char * LPCSTR;
31
- typedef int32_t HRESULT;
32
-
33
- #define SUCCEEDED (Status ) ((HRESULT)(Status) >= 0 )
34
-
35
- // Prototype of the ExecuteAssembly function from the libcoreclr.do
36
- typedef HRESULT (*ExecuteAssemblyFunction)(
37
- LPCSTR exePath,
38
- LPCSTR coreClrPath,
39
- LPCSTR appDomainFriendlyName,
40
- int propertyCount,
41
- LPCSTR* propertyKeys,
42
- LPCSTR* propertyValues,
43
- int argc,
44
- LPCSTR* argv,
45
- LPCSTR managedAssemblyPath,
46
- LPCSTR entryPointAssemblyName,
47
- LPCSTR entryPointTypeName,
48
- LPCSTR entryPointMethodsName,
49
- DWORD* exitCode);
27
+ #define SUCCEEDED (Status ) ((Status) >= 0 )
28
+
29
+ // Prototype of the coreclr_initialize function from the libcoreclr.so
30
+ typedef int (*InitializeCoreCLRFunction)(
31
+ const char * exePath,
32
+ const char * appDomainFriendlyName,
33
+ int propertyCount,
34
+ const char ** propertyKeys,
35
+ const char ** propertyValues,
36
+ void ** hostHandle,
37
+ unsigned int * domainId);
38
+
39
+ // Prototype of the coreclr_shutdown function from the libcoreclr.so
40
+ typedef int (*ShutdownCoreCLRFunction)(
41
+ void * hostHandle,
42
+ unsigned int domainId);
43
+
44
+ // Prototype of the coreclr_execute_assembly function from the libcoreclr.so
45
+ typedef int (*ExecuteAssemblyFunction)(
46
+ void * hostHandle,
47
+ unsigned int domainId,
48
+ int argc,
49
+ const char ** argv,
50
+ const char * managedAssemblyPath,
51
+ unsigned int * exitCode);
50
52
51
53
bool GetAbsolutePath (const char * path, std::string& absolutePath)
52
54
{
@@ -233,8 +235,23 @@ int ExecuteManagedAssembly(
233
235
void * coreclrLib = dlopen (coreClrDllPath.c_str (), RTLD_NOW | RTLD_LOCAL);
234
236
if (coreclrLib != nullptr )
235
237
{
236
- ExecuteAssemblyFunction executeAssembly = (ExecuteAssemblyFunction)dlsym (coreclrLib, " ExecuteAssembly" );
237
- if (executeAssembly != nullptr )
238
+ InitializeCoreCLRFunction initializeCoreCLR = (InitializeCoreCLRFunction)dlsym (coreclrLib, " coreclr_initialize" );
239
+ ExecuteAssemblyFunction executeAssembly = (ExecuteAssemblyFunction)dlsym (coreclrLib, " coreclr_execute_assembly" );
240
+ ShutdownCoreCLRFunction shutdownCoreCLR = (ShutdownCoreCLRFunction)dlsym (coreclrLib, " coreclr_shutdown" );
241
+
242
+ if (initializeCoreCLR == nullptr )
243
+ {
244
+ fprintf (stderr, " Function coreclr_initialize not found in the libcoreclr.so\n " );
245
+ }
246
+ else if (executeAssembly == nullptr )
247
+ {
248
+ fprintf (stderr, " Function coreclr_execute_assembly not found in the libcoreclr.so\n " );
249
+ }
250
+ else if (shutdownCoreCLR == nullptr )
251
+ {
252
+ fprintf (stderr, " Function coreclr_shutdown not found in the libcoreclr.so\n " );
253
+ }
254
+ else
238
255
{
239
256
// Allowed property names:
240
257
// APPBASE
@@ -272,30 +289,46 @@ int ExecuteManagedAssembly(
272
289
" UseLatestBehaviorWhenTFMNotSpecified"
273
290
};
274
291
275
- HRESULT st = executeAssembly (
276
- currentExeAbsolutePath,
277
- coreClrDllPath.c_str (),
278
- " unixcorerun" ,
279
- sizeof (propertyKeys) / sizeof (propertyKeys[0 ]),
280
- propertyKeys,
281
- propertyValues,
282
- managedAssemblyArgc,
283
- managedAssemblyArgv,
284
- managedAssemblyAbsolutePath,
285
- NULL ,
286
- NULL ,
287
- NULL ,
288
- (DWORD*)&exitCode);
292
+ void * hostHandle;
293
+ unsigned int domainId;
294
+
295
+ int st = initializeCoreCLR (
296
+ currentExeAbsolutePath,
297
+ " unixcorerun" ,
298
+ sizeof (propertyKeys) / sizeof (propertyKeys[0 ]),
299
+ propertyKeys,
300
+ propertyValues,
301
+ &hostHandle,
302
+ &domainId);
289
303
290
304
if (!SUCCEEDED (st))
291
305
{
292
- fprintf (stderr, " ExecuteAssembly failed - status: 0x%08x\n " , st);
306
+ fprintf (stderr, " coreclr_initialize failed - status: 0x%08x\n " , st);
293
307
exitCode = -1 ;
294
308
}
295
- }
296
- else
297
- {
298
- fprintf (stderr, " Function ExecuteAssembly not found in the libcoreclr.so\n " );
309
+ else
310
+ {
311
+ st = executeAssembly (
312
+ hostHandle,
313
+ domainId,
314
+ managedAssemblyArgc,
315
+ managedAssemblyArgv,
316
+ managedAssemblyAbsolutePath,
317
+ (unsigned int *)&exitCode);
318
+
319
+ if (!SUCCEEDED (st))
320
+ {
321
+ fprintf (stderr, " coreclr_execute_assembly failed - status: 0x%08x\n " , st);
322
+ exitCode = -1 ;
323
+ }
324
+
325
+ st = shutdownCoreCLR (hostHandle, domainId);
326
+ if (!SUCCEEDED (st))
327
+ {
328
+ fprintf (stderr, " coreclr_shutdown failed - status: 0x%08x\n " , st);
329
+ exitCode = -1 ;
330
+ }
331
+ }
299
332
}
300
333
301
334
if (dlclose (coreclrLib) != 0 )
0 commit comments