il2cpp-vm-support.h 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #pragma once
  2. #include "il2cpp-config.h"
  3. // This file is a compile-time abstraction for VM support needed by code in the os and utils namespaces that is used by both the
  4. // libil2cpp and the libmono runtimes. Code in those namespaces should never depend up on the vm namespace directly.
  5. #if defined(RUNTIME_MONO)
  6. #include "mono-api.h"
  7. #include "il2cpp-mono-support.h"
  8. #include <cassert>
  9. #define IL2CPP_VM_RAISE_EXCEPTION(exception) mono_raise_exception(exception)
  10. #define IL2CPP_VM_RAISE_COM_EXCEPTION(hresult, defaultToCOMException) assert(false && "COM exceptions are not implemented yet.")
  11. #define IL2CPP_VM_RAISE_IF_FAILED(hresult, defaultToCOMException) assert(false && "COM exceptions are not implemented yet.")
  12. #define IL2CPP_VM_STRING_EMPTY() mono_string_empty(g_MonoDomain)
  13. #define IL2CPP_VM_STRING_NEW_UTF16(value, length) mono_string_new_utf16(g_MonoDomain, value, length)
  14. #define IL2CPP_VM_STRING_NEW_LEN(value, length) mono_string_new_len(g_MonoDomain, value, length);
  15. #define IL2CPP_VM_NOT_SUPPORTED(func, reason) mono_raise_exception(mono_get_exception_not_supported(NOTSUPPORTEDICALLMESSAGE ("IL2CPP", #func, #reason)))
  16. #define IL2CPP_VM_METHOD_METADATA_FROM_INDEX(isGeneric, methodIndex) isGeneric ? GenericMethodFromIndex(methodIndex) : MethodFromIndex(methodIndex)
  17. #define IL2CPP_VM_SHUTDOWN() do { if (mono_runtime_try_shutdown()) mono_runtime_quit(); } while(0)
  18. #define IL2CPP_VM_GET_CREATE_CCW_EXCEPTION(ex) NULL
  19. #define IL2CPP_VM_PROFILE_FILEIO(kind, count) if (mono_profiler_get_events () & MONO_PROFILE_FILEIO) mono_profiler_fileio (kind, count);
  20. typedef MonoString VmString;
  21. typedef MonoMethod VmMethod;
  22. #elif RUNTIME_NONE // OS layer compiled with no runtime
  23. #define IL2CPP_VM_RAISE_EXCEPTION(exception) IL2CPP_ASSERT(0 && "This is not implemented without a VM runtime backend.")
  24. #define IL2CPP_VM_RAISE_COM_EXCEPTION(hresult, defaultToCOMException) IL2CPP_ASSERT(0 && "This is not implemented without a VM runtime backend.")
  25. #define IL2CPP_VM_RAISE_IF_FAILED(hresult, defaultToCOMException) IL2CPP_ASSERT(0 && "This is not implemented without a VM runtime backend.")
  26. #define IL2CPP_VM_STRING_EMPTY() NULL
  27. #define IL2CPP_VM_STRING_NEW_UTF16(value, length) NULL
  28. #define IL2CPP_VM_STRING_NEW_LEN(value, length) NULL
  29. #define IL2CPP_VM_NOT_SUPPORTED(func, reason) IL2CPP_ASSERT(0 && "This is not implemented without a VM runtime backend.")
  30. #define IL2CPP_VM_METHOD_METADATA_FROM_INDEX(isGeneric, methodIndex) IL2CPP_ASSERT(0 && "This is not implemented wihout a VM runtime backend.")
  31. #define IL2CPP_VM_SHUTDOWN() IL2CPP_ASSERT(0 && "This is not implemented without a VM runtime backend.")
  32. #define IL2CPP_VM_GET_CREATE_CCW_EXCEPTION(ex) NULL
  33. #define IL2CPP_VM_PROFILE_FILEIO(kind, count) NULL
  34. #else // Assume the libil2cpp runtime
  35. #include "vm/Exception.h"
  36. #include "vm/MetadataCache.h"
  37. #include "vm/StackTrace.h"
  38. #include "vm/String.h"
  39. #include "vm/Profiler.h"
  40. #define IL2CPP_VM_RAISE_EXCEPTION(exception) il2cpp::vm::Exception::Raise(exception)
  41. #define IL2CPP_VM_RAISE_COM_EXCEPTION(hresult, defaultToCOMException) il2cpp::vm::Exception::Raise(hresult, defaultToCOMException)
  42. #define IL2CPP_VM_RAISE_IF_FAILED(hresult, defaultToCOMException) il2cpp::vm::Exception::RaiseIfFailed(hresult, defaultToCOMException)
  43. #define IL2CPP_VM_STRING_EMPTY() il2cpp::vm::String::Empty()
  44. #define IL2CPP_VM_STRING_NEW_UTF16(value, length) il2cpp::vm::String::NewUtf16(value, length)
  45. #define IL2CPP_VM_STRING_NEW_LEN(value, length) il2cpp::vm::String::NewLen(value, length)
  46. #define IL2CPP_VM_NOT_SUPPORTED(func, reason) NOT_SUPPORTED_IL2CPP(func, reason)
  47. #define IL2CPP_VM_METHOD_METADATA_FROM_INDEX(isGeneric, methodIndex) il2cpp::vm::MetadataCache::GetMethodInfoFromMethodDefinitionIndex (methodIndex)
  48. #define IL2CPP_VM_SHUTDOWN() il2cpp_shutdown()
  49. #define IL2CPP_VM_GET_CREATE_CCW_EXCEPTION(ex) vm::CCW::GetOrCreate(reinterpret_cast<Il2CppObject*>(ex), Il2CppIUnknown::IID)
  50. #define IL2CPP_VM_PROFILE_FILEIO(kind, count) if (il2cpp::vm::Profiler::ProfileFileIO()) il2cpp::vm::Profiler::FileIO(kind, count);
  51. typedef Il2CppString VmString;
  52. typedef MethodInfo VmMethod;
  53. #endif