No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MetadataLoader.cpp 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "il2cpp-config.h"
  2. #include "MetadataLoader.h"
  3. #include "os/File.h"
  4. #include "os/Mutex.h"
  5. #include "utils/MemoryMappedFile.h"
  6. #include "utils/PathUtils.h"
  7. #include "utils/Runtime.h"
  8. #include "utils/Logging.h"
  9. void* il2cpp::vm::MetadataLoader::LoadMetadataFile(const char* fileName)
  10. {
  11. std::string resourcesDirectory = utils::PathUtils::Combine(utils::Runtime::GetDataDir(), utils::StringView<char>("Metadata"));
  12. std::string resourceFilePath = utils::PathUtils::Combine(resourcesDirectory, utils::StringView<char>(fileName, strlen(fileName)));
  13. int error = 0;
  14. os::FileHandle* handle = os::File::Open(resourceFilePath, kFileModeOpen, kFileAccessRead, kFileShareRead, kFileOptionsNone, &error);
  15. if (error != 0)
  16. {
  17. utils::Logging::Write("ERROR: Could not open %s", resourceFilePath.c_str());
  18. return NULL;
  19. }
  20. void* fileBuffer = utils::MemoryMappedFile::Map(handle);
  21. os::File::Close(handle, &error);
  22. if (error != 0)
  23. {
  24. utils::MemoryMappedFile::Unmap(fileBuffer);
  25. fileBuffer = NULL;
  26. return NULL;
  27. }
  28. return fileBuffer;
  29. }
  30. void il2cpp::vm::MetadataLoader::UnloadMetadataFile(void* fileBuffer)
  31. {
  32. bool success = il2cpp::utils::MemoryMappedFile::Unmap(fileBuffer);
  33. NO_UNUSED_WARNING(success);
  34. IL2CPP_ASSERT(success);
  35. }