| 463 | #endif |
| 464 | |
| 465 | bool MCore::LoadEngine() |
| 466 | { |
| 467 | PROFILE_CPU(); |
| 468 | ASSERT(Globals::MonoPath.IsANSI()); |
| 469 | |
| 470 | // Debugging Mono GC |
| 471 | //Platform::SetEnvironmentVariable(TEXT("MONO_GC_DEBUG"), TEXT("6:gc-log.txt,check-remset-consistency,nursery-canaries")); |
| 472 | |
| 473 | #if 0 |
| 474 | // Override memory allocation callback |
| 475 | // TODO: use ENABLE_OVERRIDABLE_ALLOCATORS when building Mono to support memory callbacks or use counters for memory profiling |
| 476 | MonoAllocatorVTable alloc; |
| 477 | alloc.version = MONO_ALLOCATOR_VTABLE_VERSION; |
| 478 | alloc.malloc = MonoMalloc; |
| 479 | alloc.realloc = MonoRealloc; |
| 480 | alloc.free = MonoFree; |
| 481 | alloc.calloc = MonoCalloc; |
| 482 | mono_set_allocator_vtable(&alloc); |
| 483 | #endif |
| 484 | |
| 485 | #if USE_MONO_AOT |
| 486 | mono_jit_set_aot_mode(USE_MONO_AOT_MODE); |
| 487 | #endif |
| 488 | |
| 489 | #ifdef USE_MONO_AOT_MODULE |
| 490 | // Load AOT module |
| 491 | const DateTime aotModuleLoadStartTime = DateTime::Now(); |
| 492 | LOG(Info, "Loading Mono AOT module..."); |
| 493 | void* libAotModule = Platform::LoadLibrary(TEXT(USE_MONO_AOT_MODULE)); |
| 494 | if (libAotModule == nullptr) |
| 495 | { |
| 496 | LOG(Error, "Failed to laod Mono AOT module (" TEXT(USE_MONO_AOT_MODULE) ")"); |
| 497 | return true; |
| 498 | } |
| 499 | MonoAotModuleHandle = libAotModule; |
| 500 | void* getModulesPtr = Platform::GetProcAddress(libAotModule, "GetMonoModules"); |
| 501 | if (getModulesPtr == nullptr) |
| 502 | { |
| 503 | LOG(Error, "Failed to get Mono AOT modules getter."); |
| 504 | return true; |
| 505 | } |
| 506 | typedef int (*GetMonoModulesFunc)(void** buffer, int bufferSize); |
| 507 | const auto getModules = (GetMonoModulesFunc)getModulesPtr; |
| 508 | const int32 moduelsCount = getModules(nullptr, 0); |
| 509 | void** modules = (void**)Allocator::Allocate(moduelsCount * sizeof(void*)); |
| 510 | getModules(modules, moduelsCount); |
| 511 | for (int32 i = 0; i < moduelsCount; i++) |
| 512 | { |
| 513 | mono_aot_register_module((void**)modules[i]); |
| 514 | } |
| 515 | Allocator::Free(modules); |
| 516 | LOG(Info, "Mono AOT module loaded in {0}ms", (int32)(DateTime::Now() - aotModuleLoadStartTime).GetTotalMilliseconds()); |
| 517 | #endif |
| 518 | |
| 519 | // Set mono assemblies path |
| 520 | StringAnsi pathLib = (Globals::MonoPath / TEXT("/lib")).ToStringAnsi(); |
| 521 | StringAnsi pathEtc = (Globals::MonoPath / TEXT("/etc")).ToStringAnsi(); |
| 522 | mono_set_dirs(pathLib.Get(), pathEtc.Get()); |
nothing calls this directly
no test coverage detected