ComObjectBase.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #include "il2cpp-config.h"
  2. #include "os/Atomic.h"
  3. #include "vm/COM.h"
  4. #include "vm/ComObjectBase.h"
  5. il2cpp_hresult_t STDCALL il2cpp::vm::ComObjectBase::GetIids(uint32_t* iidCount, Il2CppGuid** iids)
  6. {
  7. *iidCount = 0;
  8. *iids = NULL;
  9. return IL2CPP_S_OK;
  10. }
  11. il2cpp_hresult_t STDCALL il2cpp::vm::ComObjectBase::GetRuntimeClassName(Il2CppHString* className)
  12. {
  13. return GetRuntimeClassNameImpl(className);
  14. }
  15. il2cpp_hresult_t il2cpp::vm::ComObjectBase::GetRuntimeClassNameImpl(Il2CppHString* className)
  16. {
  17. *className = NULL;
  18. return IL2CPP_S_OK;
  19. }
  20. il2cpp_hresult_t STDCALL il2cpp::vm::ComObjectBase::GetTrustLevel(int32_t* trustLevel)
  21. {
  22. *trustLevel = 0;
  23. return IL2CPP_S_OK;
  24. }
  25. il2cpp_hresult_t STDCALL il2cpp::vm::ComObjectBase::GetUnmarshalClass(const Il2CppGuid& iid, void* object, uint32_t context, void* reserved, uint32_t flags, Il2CppGuid* clsid)
  26. {
  27. Il2CppIMarshal* freeThreadedMarshaler;
  28. il2cpp_hresult_t hr = GetFreeThreadedMarshalerNoAddRef(&freeThreadedMarshaler);
  29. if (IL2CPP_HR_FAILED(hr))
  30. return hr;
  31. return freeThreadedMarshaler->GetUnmarshalClass(iid, object, context, reserved, flags, clsid);
  32. }
  33. il2cpp_hresult_t STDCALL il2cpp::vm::ComObjectBase::GetMarshalSizeMax(const Il2CppGuid& iid, void* object, uint32_t context, void* reserved, uint32_t flags, uint32_t* size)
  34. {
  35. Il2CppIMarshal* freeThreadedMarshaler;
  36. il2cpp_hresult_t hr = GetFreeThreadedMarshalerNoAddRef(&freeThreadedMarshaler);
  37. if (IL2CPP_HR_FAILED(hr))
  38. return hr;
  39. return freeThreadedMarshaler->GetMarshalSizeMax(iid, object, context, reserved, flags, size);
  40. }
  41. il2cpp_hresult_t STDCALL il2cpp::vm::ComObjectBase::MarshalInterface(Il2CppIStream* stream, const Il2CppGuid& iid, void* object, uint32_t context, void* reserved, uint32_t flags)
  42. {
  43. Il2CppIMarshal* freeThreadedMarshaler;
  44. il2cpp_hresult_t hr = GetFreeThreadedMarshalerNoAddRef(&freeThreadedMarshaler);
  45. if (IL2CPP_HR_FAILED(hr))
  46. return hr;
  47. return freeThreadedMarshaler->MarshalInterface(stream, iid, object, context, reserved, flags);
  48. }
  49. il2cpp_hresult_t STDCALL il2cpp::vm::ComObjectBase::UnmarshalInterface(Il2CppIStream* stream, const Il2CppGuid& iid, void** object)
  50. {
  51. Il2CppIMarshal* freeThreadedMarshaler;
  52. il2cpp_hresult_t hr = GetFreeThreadedMarshalerNoAddRef(&freeThreadedMarshaler);
  53. if (IL2CPP_HR_FAILED(hr))
  54. return hr;
  55. return freeThreadedMarshaler->UnmarshalInterface(stream, iid, object);
  56. }
  57. il2cpp_hresult_t STDCALL il2cpp::vm::ComObjectBase::ReleaseMarshalData(Il2CppIStream* stream)
  58. {
  59. Il2CppIMarshal* freeThreadedMarshaler;
  60. il2cpp_hresult_t hr = GetFreeThreadedMarshalerNoAddRef(&freeThreadedMarshaler);
  61. if (IL2CPP_HR_FAILED(hr))
  62. return hr;
  63. return freeThreadedMarshaler->ReleaseMarshalData(stream);
  64. }
  65. il2cpp_hresult_t STDCALL il2cpp::vm::ComObjectBase::DisconnectObject(uint32_t reserved)
  66. {
  67. Il2CppIMarshal* freeThreadedMarshaler;
  68. il2cpp_hresult_t hr = GetFreeThreadedMarshalerNoAddRef(&freeThreadedMarshaler);
  69. if (IL2CPP_HR_FAILED(hr))
  70. return hr;
  71. return freeThreadedMarshaler->DisconnectObject(reserved);
  72. }
  73. il2cpp_hresult_t il2cpp::vm::ComObjectBase::GetFreeThreadedMarshalerNoAddRef(Il2CppIMarshal** destination)
  74. {
  75. Il2CppIMarshal* freeThreadedMarshaler = m_FreeThreadedMarshaler;
  76. if (freeThreadedMarshaler == NULL)
  77. {
  78. // We don't really want to aggregate FTM, as then we'd have to store its IUnknown too
  79. // So we pass NULL as the first parameter
  80. Il2CppIUnknown* freeThreadedMarshalerUnknown;
  81. il2cpp_hresult_t hr = COM::CreateFreeThreadedMarshaler(NULL, &freeThreadedMarshalerUnknown);
  82. if (IL2CPP_HR_FAILED(hr))
  83. return hr;
  84. hr = freeThreadedMarshalerUnknown->QueryInterface(Il2CppIMarshal::IID, reinterpret_cast<void**>(&freeThreadedMarshaler));
  85. freeThreadedMarshalerUnknown->Release();
  86. if (IL2CPP_HR_FAILED(hr))
  87. return hr;
  88. if (os::Atomic::CompareExchangePointer<Il2CppIMarshal>(&m_FreeThreadedMarshaler, freeThreadedMarshaler, NULL) != NULL)
  89. {
  90. freeThreadedMarshaler->Release();
  91. freeThreadedMarshaler = m_FreeThreadedMarshaler;
  92. }
  93. }
  94. *destination = freeThreadedMarshaler;
  95. return IL2CPP_S_OK;
  96. }