Runtime.h 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #pragma once
  2. #include <stdint.h>
  3. #include <vector>
  4. #include <string>
  5. #include "il2cpp-config.h"
  6. #include "il2cpp-metadata.h"
  7. #include "il2cpp-object-internals.h"
  8. #include "metadata/GenericMethod.h"
  9. #include "vm/Exception.h"
  10. #include "vm/Class.h"
  11. #include "vm/MetadataCache.h"
  12. #include "utils/StringUtils.h"
  13. struct Il2CppArray;
  14. struct Il2CppDelegate;
  15. struct Il2CppObject;
  16. struct MethodInfo;
  17. struct Il2CppClass;
  18. typedef void (*MetadataInitializerCleanupFunc)();
  19. namespace il2cpp
  20. {
  21. namespace vm
  22. {
  23. class LIBIL2CPP_CODEGEN_API Runtime
  24. {
  25. public:
  26. static bool Init(const char* domainName = "IL2CPP Root Domain");
  27. static void Shutdown();
  28. static bool IsShuttingDown();
  29. static void SetConfigDir(const char *path);
  30. static void SetConfigUtf16(const Il2CppChar* executablePath);
  31. static void SetConfig(const char* executablePath);
  32. static void SetUnityTlsInterface(const void* unitytlsInterface);
  33. static std::string GetConfigDir();
  34. static const void* GetUnityTlsInterface();
  35. static const char *GetFrameworkVersion();
  36. static const MethodInfo* GetDelegateInvoke(Il2CppClass* klass);
  37. static Il2CppObject* DelegateInvoke(Il2CppDelegate *obj, void **params, Il2CppException **exc);
  38. static Il2CppObject* Invoke(const MethodInfo *method, void *obj, void **params, Il2CppException **exc);
  39. static Il2CppObject* InvokeWithThrow(const MethodInfo *method, void *obj, void **params);
  40. static Il2CppObject* InvokeConvertArgs(const MethodInfo *method, void *obj, Il2CppObject **params, int paramCount, Il2CppException **exc);
  41. static Il2CppObject* InvokeArray(const MethodInfo *method, void *obj, Il2CppArray *params, Il2CppException **exc);
  42. static void ObjectInit(Il2CppObject* object);
  43. static void ObjectInitException(Il2CppObject* object, Il2CppException **exc);
  44. static void SetUnhandledExceptionPolicy(Il2CppRuntimeUnhandledExceptionPolicy value);
  45. static const MethodInfo* GetGenericVirtualMethod(const MethodInfo* methodDefinition, const MethodInfo* inflatedMethod);
  46. static void RaiseExecutionEngineExceptionIfMethodIsNotFound(const MethodInfo* method);
  47. static void AlwaysRaiseExecutionEngineException(const MethodInfo* method);
  48. public:
  49. // internal
  50. static Il2CppRuntimeUnhandledExceptionPolicy GetUnhandledExceptionPolicy();
  51. static void UnhandledException(Il2CppException* exc);
  52. static void ClassInit(Il2CppClass *klass);
  53. static const char *GetBundledMachineConfig();
  54. static void RegisterBundledMachineConfig(const char *config_xml);
  55. static int32_t GetExitCode();
  56. static void SetExitCode(int32_t value);
  57. static InvokerMethod GetMissingMethodInvoker();
  58. private:
  59. static void CallUnhandledExceptionDelegate(Il2CppDomain* domain, Il2CppDelegate* delegate, Il2CppException* exc);
  60. static Il2CppObject* CreateUnhandledExceptionEventArgs(Il2CppException* exc);
  61. static void VerifyApiVersion();
  62. static inline void RaiseExecutionEngineExceptionIfMethodIsNotFound(const MethodInfo* method, const Il2CppGenericMethod* genericMethod)
  63. {
  64. if (method->methodPointer == NULL)
  65. RaiseExecutionEngineException(metadata::GenericMethod::GetFullName(genericMethod).c_str());
  66. }
  67. static inline void RaiseExecutionEngineException(const char* methodFullName)
  68. {
  69. Exception::Raise(Exception::GetExecutionEngineException(utils::StringUtils::Printf("Attempting to call method '%s' for which no ahead of time (AOT) code was generated.", methodFullName).c_str()));
  70. }
  71. };
  72. } /* namespace vm */
  73. } /* namespace il2cpp */