ClassLibraryPAL.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include "vm/Class.h"
  2. #include "vm/ClassLibraryPAL.h"
  3. #include "os/ClassLibraryPAL/pal_mirror_structs.h"
  4. #if IL2CPP_DEBUG && !RUNTIME_TINY && !RUNTIME_NONE
  5. #define IL2CPP_ENABLE_PAL_MIRROR_CHECK 1
  6. #else
  7. #define IL2CPP_ENABLE_PAL_MIRROR_CHECK 0
  8. #endif
  9. namespace il2cpp
  10. {
  11. namespace vm
  12. {
  13. #if IL2CPP_ENABLE_PAL_MIRROR_CHECK
  14. static Il2CppClass* GetSysKlass()
  15. {
  16. static Il2CppClass* sysKlass = NULL;
  17. if (!sysKlass)
  18. {
  19. Il2CppClass *interop = Class::FromName(il2cpp_defaults.corlib, "", "Interop");
  20. if (interop == NULL)
  21. return NULL;
  22. void* iter = NULL;
  23. while (auto nestedType = Class::GetNestedTypes(interop, &iter))
  24. {
  25. if (strcmp(nestedType->name, "Sys") == 0)
  26. {
  27. sysKlass = nestedType;
  28. break;
  29. }
  30. }
  31. }
  32. return sysKlass;
  33. }
  34. template<typename MirrorStructType>
  35. static void CheckStructSizeForInteropSys(const char* nameInClassLibrary)
  36. {
  37. do
  38. {
  39. Il2CppClass* sysClass = GetSysKlass();
  40. if (sysClass == NULL)
  41. return;
  42. void* iter = NULL;
  43. while (Il2CppClass* nestedType = Class::GetNestedTypes(sysClass, &iter))
  44. {
  45. if (!strcmp(nestedType->name, nameInClassLibrary))
  46. {
  47. IL2CPP_ASSERT(nestedType->native_size == sizeof(MirrorStructType));
  48. return;
  49. }
  50. }
  51. IL2CPP_ASSERT(0 && "Item not found");
  52. }
  53. while (0);
  54. }
  55. #endif
  56. void ClassLibraryPAL::Initialize()
  57. {
  58. #if IL2CPP_ENABLE_PAL_MIRROR_CHECK
  59. CheckStructSizeForInteropSys<struct FileStatus>("FileStatus");
  60. #endif
  61. }
  62. } // namespace vm
  63. } // namepsace il2cpp