123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- #include "MetadataModule.h"
- #include "os/Atomic.h"
- #include "os/Mutex.h"
- #include "os/File.h"
- #include "vm/Exception.h"
- #include "vm/String.h"
- #include "vm/Assembly.h"
- #include "vm/Class.h"
- #include "vm/Object.h"
- #include "vm/Image.h"
- #include "vm/MetadataLock.h"
- #include "utils/Logging.h"
- #include "utils/MemoryMappedFile.h"
- #include "utils/Memory.h"
- #include "../interpreter/InterpreterModule.h"
- #include "Assembly.h"
- #include "InterpreterImage.h"
- #include "ConsistentAOTHomologousImage.h"
- #include "SuperSetAOTHomologousImage.h"
- #include "MetadataPool.h"
- using namespace il2cpp;
- namespace hybridclr
- {
- namespace metadata
- {
- void MetadataModule::Initialize()
- {
- MetadataPool::Initialize();
- InterpreterImage::Initialize();
- Assembly::InitializePlaceHolderAssemblies();
- }
- Image* MetadataModule::GetUnderlyingInterpreterImage(const MethodInfo* methodInfo)
- {
- return metadata::IsInterpreterMethod(methodInfo) ? hybridclr::metadata::MetadataModule::GetImage(methodInfo->klass)
- : (metadata::Image*)hybridclr::metadata::AOTHomologousImage::FindImageByAssembly(
- methodInfo->klass->rank ? il2cpp_defaults.corlib->assembly : methodInfo->klass->image->assembly);
- }
- LoadImageErrorCode MetadataModule::LoadMetadataForAOTAssembly(const void* dllBytes, uint32_t dllSize, HomologousImageMode mode)
- {
- il2cpp::os::FastAutoLock lock(&il2cpp::vm::g_MetadataLock);
- AOTHomologousImage* image = nullptr;
- switch (mode)
- {
- case HomologousImageMode::CONSISTENT: image = new ConsistentAOTHomologousImage(); break;
- case HomologousImageMode::SUPERSET: image = new SuperSetAOTHomologousImage(); break;
- default: return LoadImageErrorCode::INVALID_HOMOLOGOUS_MODE;
- }
- LoadImageErrorCode err = image->Load((byte*)CopyBytes(dllBytes, dllSize), dllSize);
- if (err != LoadImageErrorCode::OK)
- {
- return err;
- }
- if (AOTHomologousImage::FindImageByAssemblyLocked(image->GetAOTAssembly(), lock))
- {
- return LoadImageErrorCode::HOMOLOGOUS_ASSEMBLY_HAS_BEEN_LOADED;
- }
- image->InitRuntimeMetadatas();
- AOTHomologousImage::RegisterLocked(image, lock);
- return LoadImageErrorCode::OK;
- }
- }
- }
|