MetadataModule.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "MetadataModule.h"
  2. #include "os/Atomic.h"
  3. #include "os/Mutex.h"
  4. #include "os/File.h"
  5. #include "vm/Exception.h"
  6. #include "vm/String.h"
  7. #include "vm/Assembly.h"
  8. #include "vm/Class.h"
  9. #include "vm/Object.h"
  10. #include "vm/Image.h"
  11. #include "vm/MetadataLock.h"
  12. #include "utils/Logging.h"
  13. #include "utils/MemoryMappedFile.h"
  14. #include "utils/Memory.h"
  15. #include "../interpreter/InterpreterModule.h"
  16. #include "Assembly.h"
  17. #include "InterpreterImage.h"
  18. #include "ConsistentAOTHomologousImage.h"
  19. #include "SuperSetAOTHomologousImage.h"
  20. #include "MetadataPool.h"
  21. using namespace il2cpp;
  22. namespace hybridclr
  23. {
  24. namespace metadata
  25. {
  26. void MetadataModule::Initialize()
  27. {
  28. MetadataPool::Initialize();
  29. InterpreterImage::Initialize();
  30. Assembly::InitializePlaceHolderAssemblies();
  31. }
  32. Image* MetadataModule::GetUnderlyingInterpreterImage(const MethodInfo* methodInfo)
  33. {
  34. return metadata::IsInterpreterMethod(methodInfo) ? hybridclr::metadata::MetadataModule::GetImage(methodInfo->klass)
  35. : (metadata::Image*)hybridclr::metadata::AOTHomologousImage::FindImageByAssembly(
  36. methodInfo->klass->rank ? il2cpp_defaults.corlib->assembly : methodInfo->klass->image->assembly);
  37. }
  38. LoadImageErrorCode MetadataModule::LoadMetadataForAOTAssembly(const void* dllBytes, uint32_t dllSize, HomologousImageMode mode)
  39. {
  40. il2cpp::os::FastAutoLock lock(&il2cpp::vm::g_MetadataLock);
  41. AOTHomologousImage* image = nullptr;
  42. switch (mode)
  43. {
  44. case HomologousImageMode::CONSISTENT: image = new ConsistentAOTHomologousImage(); break;
  45. case HomologousImageMode::SUPERSET: image = new SuperSetAOTHomologousImage(); break;
  46. default: return LoadImageErrorCode::INVALID_HOMOLOGOUS_MODE;
  47. }
  48. LoadImageErrorCode err = image->Load((byte*)CopyBytes(dllBytes, dllSize), dllSize);
  49. if (err != LoadImageErrorCode::OK)
  50. {
  51. return err;
  52. }
  53. if (AOTHomologousImage::FindImageByAssemblyLocked(image->GetAOTAssembly(), lock))
  54. {
  55. return LoadImageErrorCode::HOMOLOGOUS_ASSEMBLY_HAS_BEEN_LOADED;
  56. }
  57. image->InitRuntimeMetadatas();
  58. AOTHomologousImage::RegisterLocked(image, lock);
  59. return LoadImageErrorCode::OK;
  60. }
  61. }
  62. }