Initial commit.

This commit is contained in:
2019-07-01 14:33:21 +02:00
parent 92a04d779e
commit baa2e0279d
1624 changed files with 3204958 additions and 0 deletions
@@ -0,0 +1,68 @@
#pragma once
#include <stdint.h>
#include "il2cpp-config.h"
struct Il2CppArray;
struct Il2CppObject;
struct Il2CppString;
struct Il2CppClass;
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API Array
{
public:
static Il2CppArray* Clone(Il2CppArray* arr);
static int32_t GetElementSize(const Il2CppClass *klass);
static uint32_t GetLength(Il2CppArray* array);
static uint32_t GetByteLength(Il2CppArray* array);
static Il2CppArray* New(Il2CppClass *elementTypeInfo, il2cpp_array_size_t length);
static Il2CppArray* NewSpecific(Il2CppClass *arrayTypeInfo, il2cpp_array_size_t length);
static Il2CppArray* NewFull(Il2CppClass *array_class, il2cpp_array_size_t *lengths, il2cpp_array_size_t *lower_bounds);
public:
// internal
static Il2CppArray* NewCached(Il2CppClass *elementTypeInfo, il2cpp_array_size_t length)
{
return New(elementTypeInfo, length);
}
static char* GetFirstElementAddress(Il2CppArray *array);
};
} /* namespace vm */
} /* namespace il2cpp */
LIBIL2CPP_CODEGEN_API char* il2cpp_array_addr_with_size(Il2CppArray *array, int32_t size, uintptr_t idx);
extern "C"
{
IL2CPP_EXPORT int il2cpp_array_element_size(const Il2CppClass *ac);
}
#define load_array_elema(arr, idx, size) ((((uint8_t*)(arr)) + kIl2CppSizeOfArray) + ((size) * (idx)))
#define il2cpp_array_setwithsize(array, elementSize, index, value) \
do { \
void*__p = (void*) il2cpp_array_addr_with_size ((array), elementSize, (index)); \
memcpy(__p, &(value), elementSize); \
} while (0)
#define il2cpp_array_setrefwithsize(array, elementSize, index, value) \
do { \
void*__p = (void*) il2cpp_array_addr_with_size ((array), elementSize, (index)); \
memcpy(__p, value, elementSize); \
} while (0)
#define il2cpp_array_addr(array, type, index) ((type*)(void*) il2cpp_array_addr_with_size (array, sizeof (type), index))
#define il2cpp_array_get(array, type, index) ( *(type*)il2cpp_array_addr ((array), type, (index)) )
#define il2cpp_array_set(array, type, index, value) \
do { \
type *__p = (type *) il2cpp_array_addr ((array), type, (index)); \
*__p = (value); \
} while (0)
#define il2cpp_array_setref(array, index, value) \
do { \
void* *__p = (void* *) il2cpp_array_addr ((array), void*, (index)); \
/* il2cpp_gc_wbarrier_set_arrayref ((array), __p, (MonoObject*)(value)); */\
*__p = (value); \
} while (0)
@@ -0,0 +1,35 @@
#pragma once
#include <stdint.h>
#include <vector>
#include <string>
#include "il2cpp-config.h"
struct Il2CppAssembly;
struct Il2CppAssemblyName;
struct Il2CppImage;
struct Il2CppArray;
namespace il2cpp
{
namespace vm
{
typedef std::vector<const Il2CppAssembly*> AssemblyVector;
typedef std::vector<const Il2CppAssemblyName*> AssemblyNameVector;
class LIBIL2CPP_CODEGEN_API Assembly
{
// exported
public:
static Il2CppImage* GetImage(const Il2CppAssembly* assembly);
static void GetReferencedAssemblies(const Il2CppAssembly* assembly, AssemblyNameVector* target);
public:
static AssemblyVector* GetAllAssemblies();
static const Il2CppAssembly* GetLoadedAssembly(const char* name);
static const Il2CppAssembly* Load(const char* name);
static void Register(const Il2CppAssembly* assembly);
static void Initialize();
private:
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,27 @@
#pragma once
#include <stdint.h>
#include <vector>
#include <string>
#include "il2cpp-config.h"
struct Il2CppAssemblyName;
struct Il2CppReflectionAssemblyName;
struct Il2CppMonoAssemblyName;
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API AssemblyName
{
// exported
public:
static std::string AssemblyNameToString(const Il2CppAssemblyName& aname);
static bool ParseName(Il2CppReflectionAssemblyName* aname, std::string assemblyName);
#if NET_4_0
static void FillNativeAssemblyName(const Il2CppAssemblyName& aname, Il2CppMonoAssemblyName* nativeName);
#endif
private:
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,101 @@
#pragma once
#include <stdint.h>
#include "il2cpp-config.h"
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API Atomic
{
public:
static int32_t Add(volatile int32_t* location1, int32_t value);
static int64_t Add64(volatile int64_t* location1, int64_t value);
static int32_t Increment(volatile int32_t* value);
static int64_t Increment64(volatile int64_t* value);
static int32_t Decrement(volatile int32_t* value);
static int64_t Decrement64(volatile int64_t* value);
static int32_t CompareExchange(volatile int32_t* dest, int32_t exchange, int32_t comparand);
static int64_t CompareExchange64(volatile int64_t* dest, int64_t exchange, int64_t comparand);
static void* CompareExchangePointer(void* volatile* dest, void* exchange, void* comparand);
static int32_t Exchange(volatile int32_t* dest, int32_t exchange);
static int64_t Exchange64(volatile int64_t* dest, int64_t exchange);
static void* ExchangePointer(void* volatile* dest, void* exchange);
static int64_t Read64(volatile int64_t* addr);
static void FullMemoryBarrier();
static inline uint32_t Add(volatile uint32_t* location1, uint32_t value)
{
return static_cast<uint32_t>(Add((volatile int32_t*)location1, (int32_t)value));
}
template<typename T>
static inline T* CompareExchangePointer(T* volatile* dest, T* newValue, T* oldValue)
{
return static_cast<T*>(CompareExchangePointer((void*volatile*)dest, newValue, oldValue));
}
template<typename T>
static inline T* ExchangePointer(T* volatile* dest, T* newValue)
{
return static_cast<T*>(ExchangePointer((void*volatile*)dest, newValue));
}
static inline uint64_t Read64(volatile uint64_t* addr)
{
return static_cast<uint64_t>(Read64((volatile int64_t*)addr));
}
template<typename T>
static inline T* ReadPointer(T* volatile* pointer)
{
#if IL2CPP_SIZEOF_VOID_P == 4
return reinterpret_cast<T*>(Add(reinterpret_cast<volatile int32_t*>(pointer), 0));
#else
return reinterpret_cast<T*>(Add64(reinterpret_cast<volatile int64_t*>(pointer), 0));
#endif
}
static inline uint32_t Increment(volatile uint32_t* value)
{
return static_cast<uint32_t>(Increment(reinterpret_cast<volatile int32_t*>(value)));
}
static inline uint64_t Increment64(volatile uint64_t* value)
{
return static_cast<uint64_t>(Increment64(reinterpret_cast<volatile int64_t*>(value)));
}
static inline uint32_t Decrement(volatile uint32_t* value)
{
return static_cast<uint32_t>(Decrement(reinterpret_cast<volatile int32_t*>(value)));
}
static inline uint64_t Decrement64(volatile uint64_t* value)
{
return static_cast<uint64_t>(Decrement64(reinterpret_cast<volatile int64_t*>(value)));
}
static inline uint32_t CompareExchange(volatile uint32_t* value, uint32_t newValue, uint32_t oldValue)
{
return static_cast<uint32_t>(CompareExchange(reinterpret_cast<volatile int32_t*>(value), newValue, oldValue));
}
static inline uint64_t CompareExchange64(volatile uint64_t* value, uint64_t newValue, uint64_t oldValue)
{
return static_cast<uint64_t>(CompareExchange64(reinterpret_cast<volatile int64_t*>(value), newValue, oldValue));
}
static inline uint32_t Exchange(volatile uint32_t* value, uint32_t newValue)
{
return static_cast<uint32_t>(Exchange(reinterpret_cast<volatile int32_t*>(value), newValue));
}
static inline uint64_t Exchange64(volatile uint64_t* value, uint64_t newValue)
{
return static_cast<uint64_t>(Exchange64(reinterpret_cast<volatile int64_t*>(value), newValue));
}
};
} /* namesapce vm */
} /* namespace il2cpp */
@@ -0,0 +1,31 @@
#pragma once
#include "gc/GarbageCollector.h"
struct Il2CppIUnknown;
struct Il2CppObject;
struct Il2CppException;
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API CCW
{
public:
// CreateCCW returns upcasted Il2CppIManagedObjectHolder if the CCW is cachable!
static Il2CppIUnknown* CreateCCW(Il2CppObject* obj);
static inline Il2CppIUnknown* GetOrCreate(Il2CppObject* obj, const Il2CppGuid& iid)
{
return gc::GarbageCollector::GetOrCreateCCW(obj, iid);
}
static il2cpp_hresult_t HandleInvalidIPropertyConversion(const char* fromType, const char* toType);
static il2cpp_hresult_t HandleInvalidIPropertyConversion(Il2CppObject* value, const char* fromType, const char* toType);
static il2cpp_hresult_t HandleInvalidIPropertyArrayConversion(const char* fromArrayType, const char* fromElementType, const char* toElementType, il2cpp_array_size_t index);
static il2cpp_hresult_t HandleInvalidIPropertyArrayConversion(Il2CppObject* value, const char* fromArrayType, const char* fromElementType, const char* toElementType, il2cpp_array_size_t index);
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,46 @@
#pragma once
#include "il2cpp-class-internals.h"
#include "il2cpp-vm-support.h"
#include "os/COM.h"
#include "vm/Exception.h"
struct Il2CppGuid;
struct Il2CppSafeArrayBound;
struct Il2CppSafeArray;
struct Il2CppIUnknown;
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API COM
{
public:
static inline void CreateInstance(const Il2CppGuid& clsid, Il2CppIUnknown** object)
{
const il2cpp_hresult_t hr = os::COM::CreateInstance(clsid, object);
IL2CPP_VM_RAISE_IF_FAILED(hr, true);
}
static inline il2cpp_hresult_t CreateFreeThreadedMarshaler(Il2CppIUnknown* outer, Il2CppIUnknown** marshal)
{
return os::COM::CreateFreeThreadedMarshaler(outer, marshal);
}
static void MarshalVariant(Il2CppObject* obj, Il2CppVariant* variant);
static Il2CppObject* MarshalVariantResult(const Il2CppVariant* variant);
static void DestroyVariant(Il2CppVariant* variant);
static Il2CppSafeArray* MarshalSafeArray(uint16_t variantType, Il2CppArray* managedArray);
static Il2CppArray* MarshalSafeArrayResult(uint16_t variantType, Il2CppClass* type, Il2CppSafeArray* safeArray);
static Il2CppSafeArray* MarshalSafeArrayBString(Il2CppArray* managedArray);
static Il2CppArray* MarshalSafeArrayBStringResult(Il2CppClass* type, Il2CppSafeArray* safeArray);
static inline void DestroySafeArray(Il2CppSafeArray* safeArray)
{
const il2cpp_hresult_t hr = os::COM::SafeArrayDestroy(safeArray);
IL2CPP_VM_RAISE_IF_FAILED(hr, true);
}
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,88 @@
#pragma once
#include "gc/GCHandle.h"
#include "vm/Atomic.h"
#include "vm/ComObjectBase.h"
#include "utils/Memory.h"
#include "utils/TemplateUtils.h"
namespace il2cpp
{
namespace vm
{
// Alright, so the lifetime of this guy is pretty weird
// For a single managed object, the IUnknown of its COM Callable Wrapper must always be the same
// That means that we have to keep the same COM Callable Wrapper alive for an object once we create it
// They are cached in il2cpp::vm::g_CCWCache, which is managed by il2cpp::vm::CCW class
//
// Here comes the tricky part: when a native object has a reference to the COM Callable Wrapper,
// the managed object is not supposed to be garbage collected. However, when no native objects are referencing
// it, it should not prevent the GC from collecting the managed object. We implement this by keeping a GC handle
// on the managed object if our reference count is 1 or more. We acquire it when it gets increased from 0 (this
// is safe because such AddRef can only come when this object is retrieved from CCW Cache) and release the GC
// handle when our reference count gets decreased to 0. Here's a kicker: we don't destroy the COM Callable Wrapper
// when the reference count reaches 0; we instead rely on GC finalizer of the managed object to both remove it from
// CCW cache and also destroy it.
template<typename TDerived>
struct NOVTABLE CachedCCWBase : ComObjectBase
{
private:
volatile uint32_t m_RefCount;
uint32_t m_GCHandle;
public:
inline CachedCCWBase(Il2CppObject* obj) :
ComObjectBase(obj),
m_RefCount(0), // We do not hold any references upon its creation
m_GCHandle(0)
{
Il2CppStaticAssert(utils::TemplateUtils::IsBaseOf<CachedCCWBase<TDerived>, TDerived>::value);
}
virtual uint32_t STDCALL AddRef() IL2CPP_OVERRIDE
{
return AddRefImpl();
}
virtual uint32_t STDCALL Release() IL2CPP_OVERRIDE
{
return ReleaseImpl();
}
FORCE_INLINE uint32_t AddRefImpl()
{
const uint32_t refCount = Atomic::Increment(&m_RefCount);
if (refCount == 1)
{
IL2CPP_ASSERT(m_GCHandle == 0);
m_GCHandle = gc::GCHandle::New(GetManagedObjectInline(), false);
}
return refCount;
}
FORCE_INLINE uint32_t ReleaseImpl()
{
const uint32_t count = Atomic::Decrement(&m_RefCount);
if (count == 0)
{
IL2CPP_ASSERT(m_GCHandle != 0);
gc::GCHandle::Free(m_GCHandle);
m_GCHandle = 0;
}
return count;
}
virtual void STDCALL Destroy() IL2CPP_FINAL IL2CPP_OVERRIDE
{
IL2CPP_ASSERT(m_RefCount == 0);
TDerived* instance = static_cast<TDerived*>(this);
instance->~TDerived();
utils::Memory::Free(instance);
}
};
}
}
@@ -0,0 +1,246 @@
#pragma once
#include <stdint.h>
#include "il2cpp-config.h"
#include "il2cpp-blob.h"
#include "il2cpp-class-internals.h"
#include "metadata/Il2CppTypeVector.h"
#include "utils/dynamic_array.h"
#include "il2cpp-class-internals.h"
#include "il2cpp-object-internals.h"
#include "Exception.h"
#include "Type.h"
#if NET_4_0
#include "vm/MetadataCache.h"
#include "il2cpp-tabledefs.h"
#endif
struct Il2CppClass;
struct EventInfo;
struct FieldInfo;
struct PropertyInfo;
struct MethodInfo;
struct Il2CppImage;
struct Il2CppReflectionType;
struct Il2CppType;
struct Il2CppGenericContainer;
struct Il2CppGenericContext;
struct Il2CppGenericParameter;
namespace il2cpp
{
namespace vm
{
class TypeNameParseInfo;
enum TypeSearchFlags
{
kTypeSearchFlagNone = 0x0,
kTypeSearchFlagIgnoreCase = 0x1,
kTypeSearchFlagThrowOnError = 0x2,
kTypeSearchFlagDontUseExecutingImage = 0x4
};
class LIBIL2CPP_CODEGEN_API Class
{
public:
static Il2CppClass* FromIl2CppType(const Il2CppType* type);
static Il2CppClass* FromName(const Il2CppImage* image, const char* namespaze, const char *name);
static Il2CppClass* FromSystemType(Il2CppReflectionType *type);
static Il2CppClass* FromGenericParameter(const Il2CppGenericParameter *param);
static Il2CppClass* GetElementClass(Il2CppClass *klass);
static const Il2CppType* GetEnumBaseType(Il2CppClass *klass);
static const EventInfo* GetEvents(Il2CppClass *klass, void* *iter);
static FieldInfo* GetFields(Il2CppClass *klass, void* *iter);
static FieldInfo* GetFieldFromName(Il2CppClass *klass, const char* name);
static const MethodInfo* GetFinalizer(Il2CppClass *klass);
static int32_t GetInstanceSize(const Il2CppClass *klass);
static Il2CppClass* GetInterfaces(Il2CppClass *klass, void* *iter);
static const MethodInfo* GetMethods(Il2CppClass *klass, void* *iter);
static const MethodInfo* GetMethodFromName(Il2CppClass *klass, const char* name, int argsCount);
static const MethodInfo* GetMethodFromNameFlags(Il2CppClass *klass, const char* name, int argsCount, int32_t flags);
static const char* GetName(Il2CppClass *klass);
static const char* GetNamespace(Il2CppClass *klass);
static Il2CppClass* GetNestedTypes(Il2CppClass *klass, void* *iter);
static size_t GetNumMethods(const Il2CppClass* klass);
static size_t GetNumProperties(const Il2CppClass* klass);
static size_t GetNumFields(const Il2CppClass* klass);
static Il2CppClass* GetParent(Il2CppClass *klass);
static const PropertyInfo* GetProperties(Il2CppClass *klass, void* *iter);
static const PropertyInfo* GetPropertyFromName(Il2CppClass *klass, const char* name);
static int32_t GetValueSize(Il2CppClass *klass, uint32_t *align);
static bool HasParent(Il2CppClass *klass, Il2CppClass *parent);
// we assume that the Il2CppClass's have already been initialized in this case, like in code generation
static bool HasParentUnsafe(const Il2CppClass* klass, const Il2CppClass* parent) { return klass->typeHierarchyDepth >= parent->typeHierarchyDepth && klass->typeHierarchy[parent->typeHierarchyDepth - 1] == parent; }
static bool IsAssignableFrom(Il2CppClass *klass, Il2CppClass *oklass);
static bool IsGeneric(const Il2CppClass *klass);
static bool IsInflated(const Il2CppClass *klass);
static bool IsSubclassOf(Il2CppClass *klass, Il2CppClass *klassc, bool check_interfaces);
static bool IsValuetype(const Il2CppClass *klass);
static bool IsBlittable(const Il2CppClass *klass);
static bool HasDefaultConstructor(Il2CppClass* klass);
static int GetFlags(const Il2CppClass *klass);
static bool IsAbstract(const Il2CppClass *klass);
static bool IsInterface(const Il2CppClass *klass);
static bool IsNullable(const Il2CppClass *klass);
static Il2CppClass* GetNullableArgument(const Il2CppClass* klass);
static int GetArrayElementSize(const Il2CppClass *klass);
static const Il2CppType* GetType(Il2CppClass *klass);
static const Il2CppType* GetType(Il2CppClass *klass, const TypeNameParseInfo &info);
static bool HasAttribute(Il2CppClass *klass, Il2CppClass *attr_class);
static bool IsEnum(const Il2CppClass *klass);
static const Il2CppImage* GetImage(Il2CppClass* klass);
static const char *GetAssemblyName(const Il2CppClass *klass);
static const char *GetAssemblyNameNoExtension(const Il2CppClass *klass);
static const int IgnoreNumberOfArguments;
public:
//internal
static FORCE_INLINE const VirtualInvokeData& GetInterfaceInvokeDataFromVTable(const Il2CppObject* obj, const Il2CppClass* itf, Il2CppMethodSlot slot)
{
const Il2CppClass* klass = obj->klass;
IL2CPP_ASSERT(klass->initialized);
IL2CPP_ASSERT(slot < itf->method_count);
for (uint16_t i = 0; i < klass->interface_offsets_count; i++)
{
if (klass->interfaceOffsets[i].interfaceType == itf)
{
int32_t offset = klass->interfaceOffsets[i].offset;
IL2CPP_ASSERT(offset != -1);
IL2CPP_ASSERT(offset + slot < klass->vtable_count);
return klass->vtable[offset + slot];
}
}
return GetInterfaceInvokeDataFromVTableSlowPath(obj, itf, slot);
}
static FORCE_INLINE const VirtualInvokeData* GetInterfaceInvokeDataFromVTable(const Il2CppClass* klass, const Il2CppClass* itf, Il2CppMethodSlot slot)
{
IL2CPP_ASSERT(klass->initialized);
IL2CPP_ASSERT(slot < itf->method_count);
for (uint16_t i = 0; i < klass->interface_offsets_count; i++)
{
if (klass->interfaceOffsets[i].interfaceType == itf)
{
int32_t offset = klass->interfaceOffsets[i].offset;
IL2CPP_ASSERT(offset != -1);
IL2CPP_ASSERT(offset + slot < klass->vtable_count);
return &klass->vtable[offset + slot];
}
}
return GetInterfaceInvokeDataFromVTableSlowPath(klass, itf, slot);
}
static bool Init(Il2CppClass *klass);
// This function is critical for performance, before optimization it
// caused up to 20% of all CPU usage in code generated by il2cpp
static FORCE_INLINE bool InitFromCodegen(Il2CppClass *klass)
{
if (klass->initialized_and_no_error)
return true;
return InitFromCodegenSlow(klass);
}
static Il2CppClass* GetArrayClass(Il2CppClass *element_class, uint32_t rank);
static Il2CppClass* GetBoundedArrayClass(Il2CppClass *element_class, uint32_t rank, bool bounded);
static Il2CppClass* GetInflatedGenericInstanceClass(Il2CppClass* klass, const metadata::Il2CppTypeVector& types);
static Il2CppClass* GetInflatedGenericInstanceClass(Il2CppClass* klass, const Il2CppGenericInst* genericInst);
static Il2CppClass* InflateGenericClass(Il2CppClass* klass, Il2CppGenericContext *context);
static const Il2CppType* InflateGenericType(const Il2CppType* type, Il2CppGenericContext *context);
static Il2CppClass* GetArrayClassCached(Il2CppClass *element_class, uint32_t rank, bool bounded)
{
return GetBoundedArrayClass(element_class, rank, bounded);
}
static const Il2CppGenericContainer* GetGenericContainer(Il2CppClass *klass);
static const MethodInfo* GetCCtor(Il2CppClass *klass);
static const char* GetFieldDefaultValue(const FieldInfo *field, const Il2CppType** type);
static int GetFieldMarshaledSize(const FieldInfo *field);
static Il2CppClass* GetPtrClass(const Il2CppType* type);
static Il2CppClass* GetPtrClass(Il2CppClass* elementClass);
static bool HasReferences(Il2CppClass *klass);
static void SetupEvents(Il2CppClass *klass);
static void SetupFields(Il2CppClass *klass);
static void SetupMethods(Il2CppClass *klass);
static void SetupNestedTypes(Il2CppClass *klass);
static void SetupProperties(Il2CppClass *klass);
static void SetupTypeHierarchy(Il2CppClass *klass);
static void SetupInterfaces(Il2CppClass *klass);
static const il2cpp::utils::dynamic_array<Il2CppClass*>& GetStaticFieldData();
static size_t GetBitmapSize(const Il2CppClass* klass);
static void GetBitmap(Il2CppClass* klass, size_t* bitmap, size_t& maxSetBit);
static const Il2CppType* il2cpp_type_from_type_info(const TypeNameParseInfo& info, TypeSearchFlags searchFlags);
static Il2CppClass* GetDeclaringType(Il2CppClass* klass);
static void UpdateInitializedAndNoError(Il2CppClass *klass);
private:
static IL2CPP_NO_INLINE bool InitFromCodegenSlow(Il2CppClass *klass);
#if NET_4_0
static FORCE_INLINE bool IsGenericClassAssignableFrom(const Il2CppClass* klass, const Il2CppClass* oklass, const Il2CppGenericContainer* genericContainer)
{
const Il2CppGenericClass* genericClass = klass->generic_class;
const Il2CppGenericClass* oGenericClass = oklass->generic_class;
if (oGenericClass == NULL || oGenericClass->typeDefinitionIndex != genericClass->typeDefinitionIndex)
return false;
const int32_t genericParameterCount = genericContainer->type_argc;
const Il2CppGenericInst* genericInst = genericClass->context.class_inst;
IL2CPP_ASSERT(genericInst->type_argc == genericParameterCount);
const Il2CppGenericInst* oGenericInst = oGenericClass->context.class_inst;
IL2CPP_ASSERT(oGenericInst->type_argc == genericParameterCount);
for (int32_t i = 0; i < genericParameterCount; ++i)
{
const Il2CppGenericParameter* genericParameter = MetadataCache::GetGenericParameterFromIndex(genericContainer->genericParameterStart + i);
const int32_t parameterVariance = genericParameter->flags & IL2CPP_GENERIC_PARAMETER_ATTRIBUTE_VARIANCE_MASK;
Il2CppClass* genericParameterType = Class::FromIl2CppType(genericInst->type_argv[i]);
Il2CppClass* oGenericParameterType = Class::FromIl2CppType(oGenericInst->type_argv[i]);
if (parameterVariance == IL2CPP_GENERIC_PARAMETER_ATTRIBUTE_NON_VARIANT || Class::IsValuetype(genericParameterType) || Class::IsValuetype(oGenericParameterType))
{
if (genericParameterType != oGenericParameterType)
return false;
}
else if (parameterVariance == IL2CPP_GENERIC_PARAMETER_ATTRIBUTE_COVARIANT)
{
if (!Class::IsAssignableFrom(genericParameterType, oGenericParameterType))
return false;
}
else
{
IL2CPP_ASSERT(parameterVariance == IL2CPP_GENERIC_PARAMETER_ATTRIBUTE_CONTRAVARIANT);
if (!Class::IsAssignableFrom(oGenericParameterType, genericParameterType))
return false;
}
}
return true;
}
#endif
// we don't want this method to get inlined because that makes GetInterfaceInvokeDataFromVTable method itself very large and performance suffers
static IL2CPP_NO_INLINE const VirtualInvokeData& GetInterfaceInvokeDataFromVTableSlowPath(const Il2CppObject* obj, const Il2CppClass* itf, Il2CppMethodSlot slot);
static IL2CPP_NO_INLINE const VirtualInvokeData* GetInterfaceInvokeDataFromVTableSlowPath(const Il2CppClass* klass, const Il2CppClass* itf, Il2CppMethodSlot slot);
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,59 @@
#pragma once
#include "il2cpp-object-internals.h"
namespace il2cpp
{
namespace vm
{
struct LIBIL2CPP_CODEGEN_API NOVTABLE ComObjectBase : Il2CppIInspectable, Il2CppIMarshal, Il2CppIManagedObjectHolder, Il2CppIWeakReferenceSource
{
private:
Il2CppIMarshal* m_FreeThreadedMarshaler;
Il2CppObject* m_ManagedObject;
public:
inline ComObjectBase(Il2CppObject* obj) :
m_ManagedObject(obj),
m_FreeThreadedMarshaler(NULL)
{
IL2CPP_ASSERT(obj != NULL);
}
inline ~ComObjectBase()
{
if (m_FreeThreadedMarshaler)
m_FreeThreadedMarshaler->Release();
}
virtual il2cpp_hresult_t STDCALL GetIids(uint32_t* iidCount, Il2CppGuid** iids) IL2CPP_OVERRIDE;
virtual il2cpp_hresult_t STDCALL GetRuntimeClassName(Il2CppHString* className) IL2CPP_OVERRIDE;
virtual il2cpp_hresult_t STDCALL GetTrustLevel(int32_t* trustLevel) IL2CPP_OVERRIDE;
virtual Il2CppObject* STDCALL GetManagedObject() IL2CPP_OVERRIDE;
virtual il2cpp_hresult_t STDCALL GetUnmarshalClass(const Il2CppGuid& iid, void* object, uint32_t context, void* reserved, uint32_t flags, Il2CppGuid* clsid) IL2CPP_OVERRIDE;
virtual il2cpp_hresult_t STDCALL GetMarshalSizeMax(const Il2CppGuid& iid, void* object, uint32_t context, void* reserved, uint32_t flags, uint32_t* size) IL2CPP_OVERRIDE;
virtual il2cpp_hresult_t STDCALL MarshalInterface(Il2CppIStream* stream, const Il2CppGuid& iid, void* object, uint32_t context, void* reserved, uint32_t flags) IL2CPP_OVERRIDE;
virtual il2cpp_hresult_t STDCALL UnmarshalInterface(Il2CppIStream* stream, const Il2CppGuid& iid, void** object) IL2CPP_OVERRIDE;
virtual il2cpp_hresult_t STDCALL ReleaseMarshalData(Il2CppIStream* stream) IL2CPP_OVERRIDE;
virtual il2cpp_hresult_t STDCALL DisconnectObject(uint32_t reserved) IL2CPP_OVERRIDE;
virtual il2cpp_hresult_t STDCALL GetWeakReference(Il2CppIWeakReference** weakReference) IL2CPP_FINAL IL2CPP_OVERRIDE;
FORCE_INLINE Il2CppObject* GetManagedObjectInline() const
{
return m_ManagedObject;
}
protected:
FORCE_INLINE Il2CppIInspectable* GetIdentity()
{
return this;
}
private:
ComObjectBase(const ComObjectBase&);
ComObjectBase& operator=(const ComObjectBase&);
il2cpp_hresult_t GetFreeThreadedMarshalerNoAddRef(Il2CppIMarshal** destination);
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,25 @@
#pragma once
#include <stdint.h>
#include "il2cpp-config.h"
struct Il2CppDomain;
struct Il2CppAppContext;
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API Domain
{
public:
static Il2CppDomain* GetCurrent();
static Il2CppDomain* GetRoot();
static void ContextInit(Il2CppDomain *domain);
static void ContextSet(Il2CppAppContext* context);
static Il2CppAppContext* ContextGet();
private:
static Il2CppDomain* S_domain;
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,17 @@
#pragma once
#include <stdint.h>
#include "il2cpp-config.h"
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API Enum
{
public:
// exported
static bool GetEnumValuesAndNames(Il2CppClass* enumType, Il2CppArray** values, Il2CppArray** names);
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,19 @@
#pragma once
#include <stdint.h>
#include "il2cpp-config.h"
struct EventInfo;
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API Event
{
public:
// exported
static uint32_t GetToken(const EventInfo *eventInfo);
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,93 @@
#pragma once
#include <stdint.h>
#include <string>
#include "il2cpp-config.h"
#include "utils/StringView.h"
#include "../il2cpp-class-internals.h"
struct Il2CppException;
struct Il2CppImage;
struct Il2CppClass;
namespace il2cpp
{
namespace vm
{
class TypeNameParseInfo;
class LIBIL2CPP_CODEGEN_API Exception
{
// exported
public:
static Il2CppException* Get(il2cpp_hresult_t hresult, bool defaultToCOMException);
static void PrepareExceptionForThrow(Il2CppException* ex, Il2CppSequencePoint *seqPoint = NULL, MethodInfo* lastManagedFrame = NULL);
static NORETURN void Raise(Il2CppException* ex, Il2CppSequencePoint *seqPoint = NULL, MethodInfo* lastManagedFrame = NULL);
static NORETURN void RaiseOutOfMemoryException(Il2CppSequencePoint *seqPoint = NULL);
static NORETURN void RaiseOutOfMemoryException(const utils::StringView<Il2CppChar>& msg, Il2CppSequencePoint *seqPoint = NULL);
static NORETURN void RaiseNullReferenceException(Il2CppSequencePoint *seqPoint = NULL);
static NORETURN void RaiseNullReferenceException(const utils::StringView<Il2CppChar>& msg, Il2CppSequencePoint *seqPoint = NULL);
static NORETURN void RaiseDivideByZeroException(Il2CppSequencePoint *seqPoint = NULL);
static NORETURN void RaiseOverflowException(Il2CppSequencePoint *seqPoint = NULL);
static NORETURN void RaiseArgumentOutOfRangeException(const char* msg, Il2CppSequencePoint *seqPoint = NULL);
static NORETURN void Raise(il2cpp_hresult_t hresult, bool defaultToCOMException, Il2CppSequencePoint *seqPoint = NULL);
inline static void RaiseIfFailed(il2cpp_hresult_t hresult, bool defaultToCOMException, Il2CppSequencePoint *seqPoint = NULL)
{
if (IL2CPP_HR_FAILED(hresult))
Raise(hresult, defaultToCOMException, seqPoint);
}
////TODO: rename to NewFromClassNameAndMessage
static Il2CppException* FromNameMsg(const Il2CppImage* image, const char* name_space, const char* name, const char* msg);
static Il2CppException* FromNameMsg(const Il2CppImage* image, const char* name_space, const char* name, const utils::StringView<Il2CppChar>& msg);
static Il2CppException* FromNameMsg(const Il2CppImage* image, const char* name_space, const char* name, const utils::StringView<Il2CppChar>& msg, il2cpp_hresult_t hresult);
public:
////TODO: rename all of these to NewXXX
static Il2CppException* GetArgumentException(const char *arg, const char *msg);
static Il2CppException* GetArgumentException(const utils::StringView<Il2CppChar>& arg, const utils::StringView<Il2CppChar>& msg);
static Il2CppException* GetArgumentNullException(const char *arg);
static Il2CppException* GetArgumentOutOfRangeException(const char *arg);
static Il2CppException* GetTypeInitializationException(const char *msg, Il2CppException* innerException);
static Il2CppException* GetIndexOutOfRangeException();
static Il2CppException* GetIndexOutOfRangeException(const utils::StringView<Il2CppChar>& msg);
static Il2CppException* GetNullReferenceException(const utils::StringView<Il2CppChar>& msg);
static Il2CppException* GetInvalidCastException(const char* msg);
static Il2CppException* GetInvalidCastException(const utils::StringView<Il2CppChar>& msg);
static Il2CppException* GetTypeLoadException();
static Il2CppException* GetTypeLoadException(const TypeNameParseInfo& typeNameParseInfo);
static Il2CppException* GetTypeLoadException(const utils::StringView<char>& namespaze, const utils::StringView<char>& typeName, const utils::StringView<char>& assemblyName);
static Il2CppException* GetTypeLoadExceptionForWindowsRuntimeType(const utils::StringView<char>& namespaze, const utils::StringView<char>& typeName);
static Il2CppException* GetOutOfMemoryException(const utils::StringView<Il2CppChar>& msg);
static Il2CppException* GetOverflowException();
static Il2CppException* GetOverflowException(const char* msg);
static Il2CppException* GetFormatException(const char* msg);
static Il2CppException* GetSystemException();
static Il2CppException* GetNotSupportedException(const char* msg);
static Il2CppException* GetArrayTypeMismatchException();
static Il2CppException* GetTypeLoadException(const char* msg);
static Il2CppException* GetEntryPointNotFoundException(const char* msg);
static Il2CppException* GetDllNotFoundException(const char* msg);
static Il2CppException* GetInvalidOperationException(const char* msg);
static Il2CppException* GetThreadInterruptedException();
static Il2CppException* GetThreadAbortException();
static Il2CppException* GetThreadStateException(const char* msg);
static Il2CppException* GetSynchronizationLockException(const char* msg);
static Il2CppException* GetMissingMethodException(const char* msg);
static Il2CppException* GetMarshalDirectiveException(const char* msg);
static Il2CppException* GetTargetException(const char* msg);
static Il2CppException* GetExecutionEngineException(const char* msg);
static Il2CppException* GetMethodAccessException(const char* msg);
static Il2CppException* GetUnauthorizedAccessException(const utils::StringView<Il2CppChar>& msg);
static Il2CppException* GetDivideByZeroException();
static Il2CppException* GetPlatformNotSupportedException(const utils::StringView<Il2CppChar>& msg);
static Il2CppException* GetFileLoadException(const char* msg);
static Il2CppException* GetMaxmimumNestedGenericsException();
static void StoreExceptionInfo(Il2CppException* ex, Il2CppString* exceptionString);
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,51 @@
#pragma once
#include <stdint.h>
#include "il2cpp-config.h"
struct FieldInfo;
struct Il2CppType;
struct Il2CppClass;
struct Il2CppObject;
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API Field
{
public:
// exported
static const Il2CppType* GetType(FieldInfo *field);
static Il2CppClass* GetParent(FieldInfo *field);
static int GetFlags(FieldInfo *field);
static const char* GetName(FieldInfo *field);
static size_t GetOffset(FieldInfo *field);
static void GetValue(Il2CppObject *obj, FieldInfo *field, void *value);
static uint32_t GetToken(const FieldInfo *field);
static Il2CppObject* GetValueObject(FieldInfo *field, Il2CppObject *obj);
static Il2CppObject* GetValueObjectForThread(FieldInfo *field, Il2CppObject *obj, Il2CppThread *thread);
static bool HasAttribute(FieldInfo *field, Il2CppClass *attr_class);
static bool IsDeleted(FieldInfo *field);
static void SetValue(Il2CppObject *obj, const FieldInfo *field, void *value);
static void StaticGetValue(FieldInfo *field, void *value);
static void StaticGetValueInternal(FieldInfo *field, void *value, void *threadStaticData);
#if NET_4_0
static void StaticGetValueForThread(FieldInfo *field, void *value, Il2CppInternalThread *thread);
#endif
static void StaticSetValue(FieldInfo *field, void *value);
static void StaticSetValueForThread(FieldInfo *field, void *value, Il2CppThread *thread);
static void SetInstanceFieldValueObject(Il2CppObject* objectInstance, FieldInfo* field, Il2CppObject* value);
public:
// internal
static const char* GetData(FieldInfo *field);
static void GetDefaultFieldValue(FieldInfo *field, void *value);
static bool IsInstance(FieldInfo* field);
static bool IsNormalStatic(FieldInfo* field);
static bool IsThreadStatic(FieldInfo* field);
static void SetValueRaw(const Il2CppType *type, void *dest, void *value, bool deref_pointer);
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,32 @@
#pragma once
#include <stdint.h>
#include "il2cpp-config.h"
struct Il2CppClass;
struct Il2CppGenericClass;
struct Il2CppGenericContext;
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API GenericClass
{
public:
// exported
public:
//internal
static Il2CppClass* GetClass(Il2CppGenericClass *gclass);
static Il2CppGenericContext* GetContext(Il2CppGenericClass *gclass);
static Il2CppClass* GetTypeDefinition(Il2CppGenericClass *gclass);
static bool IsEnum(Il2CppGenericClass *gclass);
static bool IsValueType(Il2CppGenericClass *gclass);
static void SetupEvents(Il2CppClass* genericInstanceType);
static void SetupFields(Il2CppClass* genericInstanceType);
static void SetupMethods(Il2CppClass* genericInstanceType);
static void SetupProperties(Il2CppClass* genericInstanceType);
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,26 @@
#pragma once
#include <stdint.h>
#include "il2cpp-config.h"
#include "il2cpp-metadata.h"
struct Il2CppClass;
struct Il2CppGenericContainer;
struct Il2CppGenericParameter;
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API GenericContainer
{
public:
// exported
public:
//internal
static Il2CppClass* GetDeclaringType(const Il2CppGenericContainer* genericContainer);
static const Il2CppGenericParameter* GetGenericParameter(const Il2CppGenericContainer* genericContainer, uint16_t index);
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,77 @@
#pragma once
#include <stdint.h>
#include <string>
#include <vector>
#include "il2cpp-config.h"
struct Il2CppClass;
struct MethodInfo;
struct Il2CppAssembly;
struct Il2CppDelegate;
struct Il2CppImage;
struct Il2CppType;
struct Il2CppGenericContext;
struct Il2CppGenericContainer;
struct Il2CppReflectionAssembly;
struct Il2CppArray;
class AssemblyVector;
namespace il2cpp
{
namespace vm
{
typedef std::vector<const Il2CppClass*> TypeVector;
class TypeNameParseInfo;
struct EmbeddedResourceRecord
{
EmbeddedResourceRecord(const Il2CppImage* image, const std::string& name, uint32_t offset, uint32_t size)
: image(image), name(name), offset(offset), size(size)
{}
const Il2CppImage* image;
std::string name;
uint32_t offset;
uint32_t size;
};
class LIBIL2CPP_CODEGEN_API Image
{
// exported
public:
static Il2CppImage* GetCorlib();
public:
static const char * GetName(const Il2CppImage* image);
static const char * GetFileName(const Il2CppImage* image);
static const Il2CppAssembly* GetAssembly(const Il2CppImage* image);
static const MethodInfo* GetEntryPoint(const Il2CppImage* image);
static const Il2CppImage* GetExecutingImage();
static const Il2CppImage* GetCallingImage();
static size_t GetNumTypes(const Il2CppImage* image);
static const Il2CppClass* GetType(const Il2CppImage* image, size_t index);
static Il2CppClass* FromTypeNameParseInfo(const Il2CppImage* image, const TypeNameParseInfo &info, bool ignoreCase);
static Il2CppClass* ClassFromName(const Il2CppImage* image, const char* namespaze, const char *name);
static void GetTypes(const Il2CppImage* image, bool exportedOnly, TypeVector* target);
struct EmbeddedResourceData
{
EmbeddedResourceData(EmbeddedResourceRecord record, void* data)
: record(record), data(data)
{}
EmbeddedResourceRecord record;
void* data;
};
static void CacheMemoryMappedResourceFile(Il2CppReflectionAssembly* assembly, void* memoryMappedFile);
static void* GetCachedMemoryMappedResourceFile(Il2CppReflectionAssembly* assembly);
static void CacheResourceData(EmbeddedResourceRecord record, void* data);
static void* GetCachedResourceData(const Il2CppImage* image, const std::string& name);
static void ClearCachedResourceData();
static void InitNestedTypes(const Il2CppImage *image);
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,17 @@
#pragma once
#include "il2cpp-config.h"
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API InternalCalls
{
public:
static void Init();
static void Add(const char* name, Il2CppMethodPointer method);
static Il2CppMethodPointer Resolve(const char* name);
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,22 @@
#pragma once
#include <stdint.h>
#include "il2cpp-config.h"
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API LastError
{
public:
static uint32_t GetLastError();
static void StoreLastError();
static void InitializeLastErrorThreadStatic();
private:
static int32_t s_LastErrorThreadLocalStorageOffset;
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,19 @@
#pragma once
#include "il2cpp-config.h"
#include "utils/StringView.h"
struct PInvokeArguments;
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API LibraryLoader
{
public:
static void* LoadLibrary(il2cpp::utils::StringView<Il2CppNativeChar> nativeDynamicLibrary);
static void SetFindPluginCallback(Il2CppSetFindPlugInCallback method);
};
} /* namespace vm */
} /* namespace il2cpp*/
@@ -0,0 +1,26 @@
#pragma once
#include <stdint.h>
#include "il2cpp-config.h"
struct Il2CppClass;
struct Il2CppObject;
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API Liveness
{
public:
typedef void (*register_object_callback)(Il2CppObject** arr, int size, void* userdata);
typedef void (*WorldChangedCallback)();
static void* Begin(Il2CppClass* filter, int max_object_count, register_object_callback callback, void* userdata, WorldChangedCallback onWorldStarted, WorldChangedCallback onWorldStopped);
static void End(void* state);
static void FromRoot(Il2CppObject* root, void* state);
static void FromStatics(void* state);
static void StopWorld(WorldChangedCallback onWorldStopped);
static void StartWorld(WorldChangedCallback onWorldStarted);
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,32 @@
#pragma once
#include "il2cpp-config.h"
#if _DEBUG
#include <map>
#include "os/Mutex.h"
#endif
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API MarshalAlloc
{
public:
static void* Allocate(size_t size);
static void* ReAlloc(void* ptr, size_t size);
static void Free(void* ptr);
static void* AllocateHGlobal(size_t size);
static void* ReAllocHGlobal(void* ptr, size_t size);
static void FreeHGlobal(void* ptr);
#if _DEBUG
static void PushAllocationFrame();
static void PopAllocationFrame();
static bool HasUnfreedAllocations();
static void ClearAllTrackedAllocations();
#endif
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,106 @@
#pragma once
#include "il2cpp-config.h"
struct Il2CppMetadataField
{
uint32_t offset;
uint32_t typeIndex;
const char* name;
bool isStatic;
};
enum Il2CppMetadataTypeFlags
{
kNone = 0,
kValueType = 1 << 0,
kArray = 1 << 1,
kArrayRankMask = 0xFFFF0000
};
struct Il2CppMetadataType
{
Il2CppMetadataTypeFlags flags; // If it's an array, rank is encoded in the upper 2 bytes
Il2CppMetadataField* fields;
uint32_t fieldCount;
uint32_t staticsSize;
uint8_t* statics;
uint32_t baseOrElementTypeIndex;
char* name;
const char* assemblyName;
uint64_t typeInfoAddress;
uint32_t size;
};
struct Il2CppMetadataSnapshot
{
uint32_t typeCount;
Il2CppMetadataType* types;
};
struct Il2CppManagedMemorySection
{
uint64_t sectionStartAddress;
uint32_t sectionSize;
uint8_t* sectionBytes;
};
struct Il2CppManagedHeap
{
uint32_t sectionCount;
Il2CppManagedMemorySection* sections;
};
struct Il2CppStacks
{
uint32_t stackCount;
Il2CppManagedMemorySection* stacks;
};
struct NativeObject
{
uint32_t gcHandleIndex;
uint32_t size;
uint32_t instanceId;
uint32_t classId;
uint32_t referencedNativeObjectIndicesCount;
uint32_t* referencedNativeObjectIndices;
};
struct Il2CppGCHandles
{
uint32_t trackedObjectCount;
uint64_t* pointersToObjects;
};
struct Il2CppRuntimeInformation
{
uint32_t pointerSize;
uint32_t objectHeaderSize;
uint32_t arrayHeaderSize;
uint32_t arrayBoundsOffsetInHeader;
uint32_t arraySizeOffsetInHeader;
uint32_t allocationGranularity;
};
struct Il2CppManagedMemorySnapshot
{
Il2CppManagedHeap heap;
Il2CppStacks stacks;
Il2CppMetadataSnapshot metadata;
Il2CppGCHandles gcHandles;
Il2CppRuntimeInformation runtimeInformation;
void* additionalUserInformation;
};
namespace il2cpp
{
namespace vm
{
namespace MemoryInformation
{
Il2CppManagedMemorySnapshot* CaptureManagedMemorySnapshot();
void FreeCapturedManagedMemorySnapshot(Il2CppManagedMemorySnapshot* snapshot);
}
}
}
@@ -0,0 +1,20 @@
#pragma once
#include "il2cpp-config.h"
struct Il2CppGenericClass;
struct Il2CppGenericMethod;
namespace il2cpp
{
namespace vm
{
void MetadataAllocInitialize();
void MetadataAllocCleanup();
// These allocators assume the g_MetadataLock lock is held
void* MetadataMalloc(size_t size);
void* MetadataCalloc(size_t count, size_t size);
// These metadata structures have their own locks, since they do lightweight initialization
Il2CppGenericClass* MetadataAllocGenericClass();
Il2CppGenericMethod* MetadataAllocGenericMethod();
} // namespace vm
} // namespace il2cpp
@@ -0,0 +1,128 @@
#pragma once
#include <stdint.h>
#include <vector>
#include "il2cpp-config.h"
#include "Assembly.h"
#include "metadata/Il2CppTypeVector.h"
#include "il2cpp-class-internals.h"
#include "utils/dynamic_array.h"
#include "os/Mutex.h"
#define THREAD_LOCAL_STATIC_MASK (int32_t)0x80000000
struct MethodInfo;
struct Il2CppClass;
struct Il2CppGenericContainer;
struct Il2CppGenericContext;
struct Il2CppGenericInst;
struct Il2CppGenericMethod;
struct Il2CppType;
struct Il2CppString;
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API MetadataCache
{
public:
static void Register(const Il2CppCodeRegistration * const codeRegistration, const Il2CppMetadataRegistration * const metadataRegistration, const Il2CppCodeGenOptions* const codeGenOptions);
static void Initialize();
static void InitializeGCSafe();
static void InitializeAllMethodMetadata();
static Il2CppClass* GetGenericInstanceType(Il2CppClass* genericTypeDefinition, const il2cpp::metadata::Il2CppTypeVector& genericArgumentTypes);
static const MethodInfo* GetGenericInstanceMethod(const MethodInfo* genericMethodDefinition, const Il2CppGenericContext* context);
static const MethodInfo* GetGenericInstanceMethod(const MethodInfo* genericMethodDefinition, const il2cpp::metadata::Il2CppTypeVector& genericArgumentTypes);
static const Il2CppGenericContext* GetMethodGenericContext(const MethodInfo* method);
static const Il2CppGenericContainer* GetMethodGenericContainer(const MethodInfo* method);
static const MethodInfo* GetGenericMethodDefinition(const MethodInfo* method);
static Il2CppClass* GetPointerType(Il2CppClass* type);
static Il2CppClass* GetWindowsRuntimeClass(const std::string& fullName);
static const char* GetWindowsRuntimeClassName(const Il2CppClass* klass);
static void AddPointerType(Il2CppClass* type, Il2CppClass* pointerType);
static const Il2CppGenericInst* GetGenericInst(const Il2CppType* const* types, uint32_t typeCount);
static const Il2CppGenericInst* GetGenericInst(const il2cpp::metadata::Il2CppTypeVector& types);
static const Il2CppGenericMethod* GetGenericMethod(const MethodInfo* methodDefinition, const Il2CppGenericInst* classInst, const Il2CppGenericInst* methodInst);
static InvokerMethod GetInvokerMethodPointer(const MethodInfo* methodDefinition, const Il2CppGenericContext* context);
static Il2CppMethodPointer GetMethodPointer(const MethodInfo* methodDefinition, const Il2CppGenericContext* context);
static Il2CppClass* GetTypeInfoFromTypeIndex(TypeIndex index);
static const Il2CppType* GetIl2CppTypeFromIndex(TypeIndex index);
static const MethodInfo* GetMethodInfoFromIndex(EncodedMethodIndex index);
static const Il2CppGenericMethod* GetGenericMethodFromIndex(GenericMethodIndex index);
static Il2CppString* GetStringLiteralFromIndex(StringLiteralIndex index);
static const char* GetStringFromIndex(StringIndex index);
static FieldInfo* GetFieldInfoFromIndex(EncodedMethodIndex index);
static void InitializeMethodMetadata(uint32_t index);
static Il2CppMethodPointer GetMethodPointerFromIndex(MethodIndex index);
static InvokerMethod GetMethodInvokerFromIndex(MethodIndex index);
static const Il2CppInteropData* GetInteropDataForType(const Il2CppType* type);
static Il2CppMethodPointer GetReversePInvokeWrapperFromIndex(MethodIndex index);
static Il2CppMethodPointer GetUnresolvedVirtualCallStub(const MethodInfo* method);
static const Il2CppAssembly* GetAssemblyFromIndex(AssemblyIndex index);
static const Il2CppAssembly* GetAssemblyByName(const std::string& name);
static Il2CppImage* GetImageFromIndex(ImageIndex index);
static Il2CppClass* GetTypeInfoFromTypeDefinitionIndex(TypeDefinitionIndex index);
static const Il2CppTypeDefinition* GetTypeDefinitionFromIndex(TypeDefinitionIndex index);
static TypeDefinitionIndex GetExportedTypeFromIndex(TypeDefinitionIndex index);
static const Il2CppGenericContainer* GetGenericContainerFromIndex(GenericContainerIndex index);
static const Il2CppGenericParameter* GetGenericParameterFromIndex(GenericParameterIndex index);
static const Il2CppType* GetGenericParameterConstraintFromIndex(GenericParameterConstraintIndex index);
static Il2CppClass* GetNestedTypeFromIndex(NestedTypeIndex index);
static const Il2CppType* GetInterfaceFromIndex(InterfacesIndex index);
static EncodedMethodIndex GetVTableMethodFromIndex(VTableIndex index);
static Il2CppInterfaceOffsetPair GetInterfaceOffsetIndex(InterfaceOffsetIndex index);
static const Il2CppRGCTXDefinition* GetRGCTXDefinitionFromIndex(RGCTXIndex index);
static const Il2CppEventDefinition* GetEventDefinitionFromIndex(EventIndex index);
static const Il2CppFieldDefinition* GetFieldDefinitionFromIndex(FieldIndex index);
static const Il2CppFieldDefaultValue* GetFieldDefaultValueFromIndex(FieldIndex index);
static const uint8_t* GetFieldDefaultValueDataFromIndex(FieldIndex index);
static const Il2CppFieldDefaultValue* GetFieldDefaultValueForField(const FieldInfo* field);
static const uint8_t* GetParameterDefaultValueDataFromIndex(ParameterIndex index);
static const Il2CppParameterDefaultValue* GetParameterDefaultValueForParameter(const MethodInfo* method, const ParameterInfo* parameter);
static int GetFieldMarshaledSizeForField(const FieldInfo* field);
static const Il2CppMethodDefinition* GetMethodDefinitionFromIndex(MethodIndex index);
static const MethodInfo* GetMethodInfoFromMethodDefinitionIndex(MethodIndex index);
static const Il2CppPropertyDefinition* GetPropertyDefinitionFromIndex(PropertyIndex index);
static const Il2CppParameterDefinition* GetParameterDefinitionFromIndex(ParameterIndex index);
// returns the compiler computer field offset for type definition fields
static int32_t GetFieldOffsetFromIndexLocked(TypeIndex typeIndex, int32_t fieldIndexInType, FieldInfo* field, const il2cpp::os::FastAutoLock& lock);
static int32_t GetThreadLocalStaticOffsetForField(FieldInfo* field);
static void AddThreadLocalStaticOffsetForFieldLocked(FieldInfo* field, int32_t offset, const il2cpp::os::FastAutoLock& lock);
static int32_t GetReferenceAssemblyIndexIntoAssemblyTable(int32_t referencedAssemblyTableIndex);
static const TypeDefinitionIndex GetIndexForTypeDefinition(const Il2CppClass* typeDefinition);
static const GenericParameterIndex GetIndexForGenericParameter(const Il2CppGenericParameter* genericParameter);
static const MethodIndex GetIndexForMethodDefinition(const MethodInfo* method);
static CustomAttributeIndex GetCustomAttributeIndex(const Il2CppImage* image, uint32_t token);
static CustomAttributesCache* GenerateCustomAttributesCache(CustomAttributeIndex index);
static CustomAttributesCache* GenerateCustomAttributesCache(const Il2CppImage* image, uint32_t token);
static bool HasAttribute(CustomAttributeIndex index, Il2CppClass* attribute);
static bool HasAttribute(const Il2CppImage* image, uint32_t token, Il2CppClass* attribute);
typedef void(*WalkTypesCallback)(Il2CppClass* type, void* context);
static void WalkPointerTypes(WalkTypesCallback callback, void* context);
private:
static void InitializeUnresolvedSignatureTable();
static void InitializeStringLiteralTable();
static void InitializeGenericMethodTable();
static void InitializeWindowsRuntimeTypeNamesTables();
static void IntializeMethodMetadataRange(uint32_t start, uint32_t count, const utils::dynamic_array<Il2CppMetadataUsage>& expectedUsages);
};
} // namespace vm
} // namespace il2cpp
@@ -0,0 +1,14 @@
#pragma once
#include "il2cpp-config.h"
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API MetadataLoader
{
public:
static void* LoadMetadataFile(const char* fileName);
};
} // namespace vm
} // namespace il2cpp
@@ -0,0 +1,12 @@
#pragma once
#include "il2cpp-config.h"
#include "os/Mutex.h"
namespace il2cpp
{
namespace vm
{
extern il2cpp::os::FastMutex g_MetadataLock;
} // namespace vm
} // namespace il2cpp
@@ -0,0 +1,46 @@
#pragma once
#include <stdint.h>
#include <string>
#include "il2cpp-config.h"
struct MethodInfo;
struct PropertyInfo;
struct ParameterInfo;
struct Il2CppString;
struct Il2CppType;
struct Il2CppClass;
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API Method
{
public:
static const Il2CppType* GetReturnType(const MethodInfo* method);
static const char* GetName(const MethodInfo *method);
static std::string GetNameWithGenericTypes(const MethodInfo* method);
static std::string GetFullName(const MethodInfo* method);
static bool IsGeneric(const MethodInfo *method);
static bool IsInflated(const MethodInfo *method);
static bool IsInstance(const MethodInfo *method);
static bool IsGenericInstance(const MethodInfo *method);
static uint32_t GetParamCount(const MethodInfo *method);
static uint32_t GetGenericParamCount(const MethodInfo *method);
static const Il2CppType* GetParam(const MethodInfo *method, uint32_t index);
static Il2CppClass* GetClass(const MethodInfo *method);
static bool HasAttribute(const MethodInfo *method, Il2CppClass *attr_class);
static Il2CppClass *GetDeclaringType(const MethodInfo* method);
static uint32_t GetImplementationFlags(const MethodInfo *method);
static uint32_t GetFlags(const MethodInfo *method);
static uint32_t GetToken(const MethodInfo *method);
static const char* GetParamName(const MethodInfo *method, uint32_t index);
static bool IsSameOverloadSignature(const MethodInfo* method1, const MethodInfo* method2);
static bool IsSameOverloadSignature(const PropertyInfo* property1, const PropertyInfo* property2);
static int CompareOverloadSignature(const PropertyInfo* property1, const PropertyInfo* property2);
static const char* GetParameterDefaultValue(const MethodInfo *method, const ParameterInfo* parameter, const Il2CppType** type, bool* isExplicitySetNullDefaultValue);
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,19 @@
#pragma once
#include <stdint.h>
#include "il2cpp-config.h"
struct Il2CppImage;
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API Module
{
public:
// exported
static uint32_t GetToken(const Il2CppImage *image);
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,61 @@
#pragma once
#include "il2cpp-config.h"
struct Il2CppObject;
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API Monitor
{
public:
static void Enter(Il2CppObject* object);
static bool TryEnter(Il2CppObject* object, uint32_t timeout);
static void Exit(Il2CppObject* object);
static void Pulse(Il2CppObject* object);
static void PulseAll(Il2CppObject* object);
static void Wait(Il2CppObject* object);
static bool TryWait(Il2CppObject* object, uint32_t timeout);
static bool IsAcquired(Il2CppObject* object);
};
#if !IL2CPP_SUPPORT_THREADS
inline void Monitor::Enter(Il2CppObject* object)
{
}
inline bool Monitor::TryEnter(Il2CppObject* object, uint32_t timeout)
{
return true;
}
inline void Monitor::Exit(Il2CppObject* object)
{
}
inline void Monitor::Pulse(Il2CppObject* object)
{
}
inline void Monitor::PulseAll(Il2CppObject* object)
{
}
inline void Monitor::Wait(Il2CppObject* object)
{
}
inline bool Monitor::TryWait(Il2CppObject* object, uint32_t timeout)
{
return true;
}
inline bool Monitor::IsAcquired(Il2CppObject* object)
{
return true;
}
#endif
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,67 @@
#pragma once
#include "gc/GCHandle.h"
#include "vm/ComObjectBase.h"
#include "utils/TemplateUtils.h"
namespace il2cpp
{
namespace vm
{
template<typename TDerived>
struct NOVTABLE NonCachedCCWBase : ComObjectBase
{
private:
volatile uint32_t m_RefCount;
uint32_t m_GCHandle;
public:
inline NonCachedCCWBase(Il2CppObject* obj) :
ComObjectBase(obj),
m_RefCount(1) // We start with a ref count of 1
{
m_GCHandle = gc::GCHandle::New(GetManagedObjectInline(), false);
IL2CPP_ASSERT(m_GCHandle != 0);
Il2CppStaticAssert(utils::TemplateUtils::IsBaseOf<NonCachedCCWBase<TDerived>, TDerived>::value);
}
inline ~NonCachedCCWBase()
{
IL2CPP_ASSERT(m_GCHandle != 0);
gc::GCHandle::Free(m_GCHandle);
m_GCHandle = 0;
}
FORCE_INLINE uint32_t AddRefImpl()
{
return Atomic::Increment(&m_RefCount);
}
FORCE_INLINE uint32_t ReleaseImpl()
{
const uint32_t count = Atomic::Decrement(&m_RefCount);
if (count == 0)
Destroy();
return count;
}
FORCE_INLINE static TDerived* __CreateInstance(Il2CppObject* obj)
{
void* memory = utils::Memory::Malloc(sizeof(TDerived));
if (memory == NULL)
Exception::RaiseOutOfMemoryException();
return new(memory)TDerived(obj);
}
virtual void STDCALL Destroy() IL2CPP_FINAL IL2CPP_OVERRIDE
{
IL2CPP_ASSERT(m_RefCount == 0);
TDerived* instance = static_cast<TDerived*>(this);
instance->~TDerived();
utils::Memory::Free(instance);
}
};
}
}
@@ -0,0 +1,47 @@
#pragma once
#include <stdint.h>
#include "il2cpp-config.h"
struct Il2CppString;
struct Il2CppObject;
struct Il2CppClass;
struct MethodInfo;
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API Object
{
public:
static Il2CppObject* Box(Il2CppClass *klass, void* data);
static Il2CppClass* GetClass(Il2CppObject* obj);
static int32_t GetHash(Il2CppObject* obj);
static uint32_t GetSize(Il2CppObject* obj);
static const MethodInfo* GetVirtualMethod(Il2CppObject *obj, const MethodInfo *method);
static Il2CppObject * IsInst(Il2CppObject *obj, Il2CppClass *klass);
static Il2CppObject* New(Il2CppClass *klass);
static void* Unbox(Il2CppObject* obj);
static void UnboxNullable(Il2CppObject* obj, Il2CppClass* nullableArgumentClass, void* storage);
static Il2CppObject * Clone(Il2CppObject *obj);
static Il2CppObject* NewPinned(Il2CppClass *klass);
static void NullableInit(uint8_t* buf, Il2CppObject* value, Il2CppClass* klass);
private:
static Il2CppObject * NewAllocSpecific(Il2CppClass *klass);
static Il2CppObject* NewPtrFree(Il2CppClass *klass);
static Il2CppObject* Allocate(size_t size, Il2CppClass *typeInfo);
static Il2CppObject* AllocatePtrFree(size_t size, Il2CppClass *typeInfo);
static Il2CppObject* AllocateSpec(size_t size, Il2CppClass *typeInfo);
friend class Array;
friend class RCW;
friend class String;
};
} /* namespace vm */
} /* namespace il2cpp */
#define IL2CPP_OBJECT_SETREF(obj, fieldname, value) do {\
il2cpp_gc_wbarrier_set_field((Il2CppObject *)(obj), (void**)&(obj)->fieldname, (value));\
} while (0)
@@ -0,0 +1,18 @@
#pragma once
#include "il2cpp-config.h"
struct ParameterInfo;
struct Il2CppObject;
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API Parameter
{
public:
// internal
static Il2CppObject* GetDefaultParameterValueObject(const MethodInfo* method, const ParameterInfo* parameter, bool* isExplicitySetNullDefaultValue);
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,17 @@
#pragma once
#include "il2cpp-config.h"
#include <string>
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API Path
{
public:
static void SetTempPath(const char* path);
static std::string GetTempPath();
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,68 @@
#pragma once
#include "il2cpp-config.h"
#include "il2cpp-blob.h"
#include "il2cpp-runtime-metadata.h"
#include "il2cpp-object-internals.h"
#include "vm/Array.h"
#include "vm/Class.h"
#include "vm/MarshalAlloc.h"
#include "vm/Object.h"
#include "vm/String.h"
#include "utils/StringView.h"
struct Il2CppString;
struct Il2CppStringBuilder;
struct PInvokeArguments
{
const il2cpp::utils::StringView<Il2CppNativeChar> moduleName;
const il2cpp::utils::StringView<char> entryPoint;
Il2CppCallConvention callingConvention;
Il2CppCharSet charSet;
int parameterSize;
bool isNoMangle; // Says whether P/Invoke should append to function name 'A'/'W' according to charSet.
};
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API PlatformInvoke
{
public:
static void SetFindPluginCallback(Il2CppSetFindPlugInCallback method);
static Il2CppMethodPointer Resolve(const PInvokeArguments& pinvokeArgs);
static void MarshalFree(void* ptr);
static char* MarshalCSharpStringToCppString(Il2CppString* managedString);
static void MarshalCSharpStringToCppStringFixed(Il2CppString* managedString, char* buffer, int numberOfCharacters);
static Il2CppChar* MarshalCSharpStringToCppWString(Il2CppString* managedString);
static void MarshalCSharpStringToCppWStringFixed(Il2CppString* managedString, Il2CppChar* buffer, int numberOfCharacters);
static il2cpp_hresult_t MarshalCSharpStringToCppBStringNoThrow(Il2CppString* managedString, Il2CppChar** bstr);
static Il2CppChar* MarshalCSharpStringToCppBString(Il2CppString* managedString);
static Il2CppString* MarshalCppStringToCSharpStringResult(const char* value);
static Il2CppString* MarshalCppWStringToCSharpStringResult(const Il2CppChar* value);
static Il2CppString* MarshalCppBStringToCSharpStringResult(const Il2CppChar* value);
static void MarshalFreeBString(Il2CppChar* value);
static char* MarshalStringBuilder(Il2CppStringBuilder* stringBuilder);
static Il2CppChar* MarshalWStringBuilder(Il2CppStringBuilder* stringBuilder);
static void MarshalStringBuilderResult(Il2CppStringBuilder* stringBuilder, char* buffer);
static void MarshalWStringBuilderResult(Il2CppStringBuilder* stringBuilder, Il2CppChar* buffer);
static intptr_t MarshalDelegate(Il2CppDelegate* d);
static Il2CppDelegate* MarshalFunctionPointerToDelegate(void* functionPtr, Il2CppClass* delegateType);
template<typename T>
static T* MarshalAllocateStringBuffer(size_t numberOfCharacters)
{
return (T*)MarshalAlloc::Allocate(numberOfCharacters * sizeof(T));
}
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,55 @@
#pragma once
#include <stdint.h>
#include "il2cpp-config.h"
namespace il2cpp
{
namespace vm
{
#if IL2CPP_ENABLE_PROFILER
class LIBIL2CPP_CODEGEN_API Profiler
{
// exported
public:
static void Install(Il2CppProfiler *prof, Il2CppProfileFunc shutdownCallback);
static void SetEvents(Il2CppProfileFlags events);
static void InstallEnterLeave(Il2CppProfileMethodFunc enter, Il2CppProfileMethodFunc fleave);
static void InstallAllocation(Il2CppProfileAllocFunc callback);
static void InstallGC(Il2CppProfileGCFunc callback, Il2CppProfileGCResizeFunc heap_resize_callback);
static void InstallFileIO(Il2CppProfileFileIOFunc callback);
static void InstallThread(Il2CppProfileThreadFunc start, Il2CppProfileThreadFunc end);
// internal
public:
static void Allocation(Il2CppObject *obj, Il2CppClass *klass);
static void MethodEnter(const MethodInfo *method);
static void MethodExit(const MethodInfo *method);
static void GCEvent(Il2CppGCEvent eventType);
static void GCHeapResize(int64_t newSize);
static void FileIO(Il2CppProfileFileIOKind kind, int count);
static void ThreadStart(unsigned long tid);
static void ThreadEnd(unsigned long tid);
static Il2CppProfileFlags s_profilerEvents;
static inline bool ProfileAllocations()
{
return (s_profilerEvents & IL2CPP_PROFILE_ALLOCATIONS) != 0;
}
static inline bool ProfileFileIO()
{
return (s_profilerEvents & IL2CPP_PROFILE_FILEIO) != 0;
}
static void Shutdown();
private:
};
#endif
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,26 @@
#pragma once
#include <stdint.h>
#include "il2cpp-config.h"
struct MethodInfo;
struct PropertyInfo;
struct Il2CppClass;
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API Property
{
public:
// exported
static uint32_t GetFlags(const PropertyInfo* prop);
static const MethodInfo* GetGetMethod(const PropertyInfo* prop);
static const MethodInfo* GetSetMethod(const PropertyInfo* prop);
static const char* GetName(const PropertyInfo* prop);
static Il2CppClass* GetParent(const PropertyInfo* prop);
static uint32_t GetToken(const PropertyInfo* prop);
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,44 @@
#pragma once
#include "il2cpp-config.h"
#include "il2cpp-object-internals.h"
struct Il2CppComObject;
struct Il2CppGuid;
struct Il2CppIUnknown;
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API RCW
{
public:
static void Register(Il2CppComObject* rcw);
static Il2CppObject* GetOrCreateFromIUnknown(Il2CppIUnknown* unknown, Il2CppClass* fallbackClass);
static Il2CppObject* GetOrCreateFromIInspectable(Il2CppIInspectable* inspectable, Il2CppClass* fallbackClass);
static Il2CppObject* GetOrCreateForSealedClass(Il2CppIUnknown* unknown, Il2CppClass* objectClass);
static void Cleanup(Il2CppComObject* rcw);
template<bool throwOnError>
inline static Il2CppIUnknown* QueryInterface(Il2CppComObject* rcw, const Il2CppGuid& iid)
{
IL2CPP_ASSERT(rcw);
IL2CPP_ASSERT(rcw->identity);
Il2CppIUnknown* result;
const il2cpp_hresult_t hr = rcw->identity->QueryInterface(iid, reinterpret_cast<void**>(&result));
if (IL2CPP_HR_FAILED(hr))
{
if (throwOnError)
Exception::Raise(hr, true);
return NULL;
}
IL2CPP_ASSERT(result);
return result;
}
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,19 @@
#pragma once
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API Random
{
public:
static bool Open();
static void* Create();
static void Free(void* handle);
static bool TryGetBytes(void** handle, unsigned char *buffer, int buffer_size);
static bool TryGetUnsignedInt32(void** handle, uint32_t *val, uint32_t min, uint32_t max);
static uint32_t Next(void** handle, uint32_t min, uint32_t max);
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,91 @@
#pragma once
#include <stdint.h>
#include "il2cpp-config.h"
#include "il2cpp-metadata.h"
struct Il2CppString;
struct Il2CppArray;
struct Il2CppReflectionAssembly;
struct Il2CppReflectionAssemblyName;
struct Il2CppReflectionField;
struct Il2CppReflectionMethod;
struct Il2CppReflectionModule;
struct Il2CppReflectionProperty;
struct Il2CppReflectionEvent;
struct Il2CppReflectionType;
struct Il2CppReflectionParameter;
struct Il2CppClass;
struct FieldInfo;
struct MethodInfo;
struct PropertyInfo;
struct EventInfo;
struct Il2CppClass;
struct CustomAttributesCache;
struct CustomAttributeTypeCache;
struct Il2CppAssembly;
struct Il2CppAssemblyName;
struct Il2CppImage;
struct Il2CppType;
struct Il2CppObject;
struct MonoGenericParameterInfo;
struct Il2CppGenericParameter;
struct Il2CppMonoAssemblyName;
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API Reflection
{
// exported
public:
static Il2CppReflectionAssembly* GetAssemblyObject(const Il2CppAssembly *assembly);
static Il2CppReflectionAssemblyName* GetAssemblyNameObject(const Il2CppAssemblyName *assemblyName);
static Il2CppReflectionField* GetFieldObject(Il2CppClass *klass, FieldInfo *field);
static Il2CppReflectionProperty* GetPropertyObject(Il2CppClass *klass, const PropertyInfo *property);
static Il2CppReflectionEvent* GetEventObject(Il2CppClass *klass, const EventInfo *event);
static Il2CppReflectionMethod* GetMethodObject(const MethodInfo *method, Il2CppClass *refclass);
static const MethodInfo* GetMethod(const Il2CppReflectionMethod* method);
static Il2CppReflectionModule* GetModuleObject(const Il2CppImage *image);
static Il2CppReflectionType* GetTypeObject(const Il2CppType *type);
static Il2CppArray* GetParamObjects(const MethodInfo *method, Il2CppClass *refclass);
static CustomAttributesCache* GetCustomAttrsInfo(Il2CppObject *obj);
static const MonoGenericParameterInfo* GetMonoGenericParameterInfo(const Il2CppGenericParameter *param);
static void SetMonoGenericParameterInfo(const Il2CppGenericParameter *param, const MonoGenericParameterInfo *monoParam);
static const Il2CppMonoAssemblyName* GetMonoAssemblyName(const Il2CppAssembly *assembly);
static void SetMonoAssemblyName(const Il2CppAssembly *assembly, const Il2CppMonoAssemblyName *aname);
static bool HasAttribute(Il2CppObject *obj, Il2CppClass *attribute);
static bool HasAttribute(FieldInfo *field, Il2CppClass *attribute);
static bool HasAttribute(const MethodInfo *method, Il2CppClass *attribute);
static bool HasAttribute(Il2CppClass *klass, Il2CppClass *attribute);
static bool IsType(Il2CppObject *obj);
static bool IsField(Il2CppObject *obj);
static bool IsAnyMethod(Il2CppObject *obj);
static bool IsProperty(Il2CppObject *obj);
static bool IsEvent(Il2CppObject *obj);
// internal
public:
static void Initialize();
static Il2CppClass* TypeGetHandle(Il2CppReflectionType* ref);
static Il2CppObject* GetDBNullObject();
static Il2CppObject* GetCustomAttribute(CustomAttributeIndex index, Il2CppClass* attribute);
static Il2CppArray* ConstructCustomAttributes(CustomAttributeIndex index);
static CustomAttributesCache* GetCustomAttributesCacheFor(Il2CppClass *klass);
static CustomAttributesCache* GetCustomAttributesCacheFor(const MethodInfo *method);
private:
static bool HasAttribute(Il2CppReflectionParameter *parameter, Il2CppClass* attribute);
static CustomAttributesCache* GetCustomAttributesCacheFor(const PropertyInfo *property);
static CustomAttributesCache* GetCustomAttributesCacheFor(FieldInfo *field);
static CustomAttributesCache* GetCustomAttributesCacheFor(const EventInfo *event);
static CustomAttributesCache* GetCustomAttributesCacheFor(Il2CppReflectionParameter *param);
static CustomAttributesCache* GetCustomAttributesCacheFor(const Il2CppAssembly *assembly);
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,82 @@
#pragma once
#include <stdint.h>
#include <vector>
#include <string>
#include "il2cpp-config.h"
#include "il2cpp-metadata.h"
#include "il2cpp-object-internals.h"
#include "metadata/GenericMethod.h"
#include "vm/Exception.h"
#include "vm/Class.h"
#include "vm/MetadataCache.h"
#include "utils/StringUtils.h"
struct Il2CppArray;
struct Il2CppDelegate;
struct Il2CppObject;
struct MethodInfo;
struct Il2CppClass;
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API Runtime
{
public:
static void Init(const char* filename, const char *runtime_version);
static void Shutdown();
static bool IsShuttingDown();
static void SetConfigDir(const char *path);
static void SetConfigUtf16(const Il2CppChar* executablePath);
static void SetConfig(const char* executablePath);
static void SetUnityTlsInterface(const void* unitytlsInterface);
static std::string GetConfigDir();
static const void* GetUnityTlsInterface();
static const char *GetFrameworkVersion();
static const MethodInfo* GetDelegateInvoke(Il2CppClass* klass);
static Il2CppObject* DelegateInvoke(Il2CppDelegate *obj, void **params, Il2CppException **exc);
static Il2CppObject* Invoke(const MethodInfo *method, void *obj, void **params, Il2CppException **exc);
static Il2CppObject* InvokeWithThrow(const MethodInfo *method, void *obj, void **params);
static Il2CppObject* InvokeConvertArgs(const MethodInfo *method, void *obj, Il2CppObject **params, int paramCount, Il2CppException **exc);
static Il2CppObject* InvokeArray(const MethodInfo *method, void *obj, Il2CppArray *params, Il2CppException **exc);
static void ObjectInit(Il2CppObject* object);
static void ObjectInitException(Il2CppObject* object, Il2CppException **exc);
static void SetUnhandledExceptionPolicy(Il2CppRuntimeUnhandledExceptionPolicy value);
static const MethodInfo* GetGenericVirtualMethod(const MethodInfo* methodDefinition, const MethodInfo* inflatedMethod);
static void RaiseExecutionEngineExceptionIfMethodIsNotFound(const MethodInfo* method);
static void AlwaysRaiseExecutionEngineException(const MethodInfo* method);
public:
// internal
static Il2CppRuntimeUnhandledExceptionPolicy GetUnhandledExceptionPolicy();
static void UnhandledException(Il2CppException* exc);
static void ClassInit(Il2CppClass *klass);
static const char *GetBundledMachineConfig();
static void RegisterBundledMachineConfig(const char *config_xml);
static int32_t GetExitCode();
static void SetExitCode(int32_t value);
private:
static void CallUnhandledExceptionDelegate(Il2CppDomain* domain, Il2CppDelegate* delegate, Il2CppException* exc);
static Il2CppObject* CreateUnhandledExceptionEventArgs(Il2CppException* exc);
static void VerifyApiVersion();
static inline void RaiseExecutionEngineExceptionIfMethodIsNotFound(const MethodInfo* method, const Il2CppGenericMethod* genericMethod)
{
if (method->methodPointer == NULL)
RaiseExecutionEngineException(metadata::GenericMethod::GetFullName(genericMethod).c_str());
}
static inline void RaiseExecutionEngineException(const char* methodFullName)
{
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()));
}
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,20 @@
#pragma once
#include "vm/Domain.h"
#include "vm/Thread.h"
namespace il2cpp
{
namespace vm
{
class ScopedThreadAttacher
{
public:
ScopedThreadAttacher();
~ScopedThreadAttacher();
private:
Il2CppThread* m_AttachedThread;
};
}
}
@@ -0,0 +1,46 @@
#pragma once
#include <stdint.h>
#include <vector>
#include "il2cpp-config.h"
#include "il2cpp-metadata.h"
#if IL2CPP_ENABLE_NATIVE_STACKTRACES
struct MethodDefinitionKey
{
Il2CppMethodPointer method;
MethodIndex methodIndex;
};
#endif
namespace il2cpp
{
namespace vm
{
typedef std::vector<Il2CppStackFrameInfo> StackFrames;
class LIBIL2CPP_CODEGEN_API StackTrace
{
public:
static void InitializeStackTracesForCurrentThread();
static void CleanupStackTracesForCurrentThread();
// Current thread functions
static const StackFrames* GetStackFrames();
static bool GetStackFrameAt(int32_t depth, Il2CppStackFrameInfo& frame);
static void WalkFrameStack(Il2CppFrameWalkFunc callback, void* context);
inline static size_t GetStackDepth() { return GetStackFrames()->size(); }
inline static bool GetTopStackFrame(Il2CppStackFrameInfo& frame) { return GetStackFrameAt(0, frame); }
static void PushFrame(Il2CppStackFrameInfo& frame);
static void PopFrame();
// Remote thread functions
static bool GetThreadStackFrameAt(Il2CppThread* thread, int32_t depth, Il2CppStackFrameInfo& frame);
static void WalkThreadFrameStack(Il2CppThread* thread, Il2CppFrameWalkFunc callback, void* context);
static int32_t GetThreadStackDepth(Il2CppThread* thread);
static bool GetThreadTopStackFrame(Il2CppThread* thread, Il2CppStackFrameInfo& frame);
};
}
}
@@ -0,0 +1,34 @@
#pragma once
#include <stdint.h>
#include "il2cpp-config.h"
#include "utils/StringView.h"
struct Il2CppString;
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API String
{
public:
//exported
static Il2CppString* Empty();
static int32_t GetLength(Il2CppString* str);
static int32_t GetHash(Il2CppString* str);
static Il2CppString* New(const char* str);
static Il2CppString* NewWrapper(const char* str);
static Il2CppString* NewLen(const char* str, uint32_t length);
static Il2CppString* NewSize(int32_t len);
static Il2CppString* NewUtf16(const Il2CppChar *text, int32_t len);
static Il2CppString* NewUtf16(const utils::StringView<Il2CppChar>& text);
public:
static void InitializeEmptyString(Il2CppClass* stringClass);
static void CleanupEmptyString();
static Il2CppString* Intern(Il2CppString* str);
static Il2CppString* IsInterned(Il2CppString* str);
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,158 @@
#pragma once
#include <stdint.h>
#include <vector>
#include <string>
#include "il2cpp-config.h"
#include "utils/NonCopyable.h"
struct MethodInfo;
struct Il2CppArray;
struct Il2CppDomain;
struct Il2CppObject;
struct Il2CppThread;
struct Il2CppInternalThread;
struct Il2CppString;
namespace il2cpp
{
namespace vm
{
// System.Threading.ThreadState
enum ThreadState
{
kThreadStateRunning = 0x00000000,
kThreadStateStopRequested = 0x00000001,
kThreadStateSuspendRequested = 0x00000002,
kThreadStateBackground = 0x00000004,
kThreadStateUnstarted = 0x00000008,
kThreadStateStopped = 0x00000010,
kThreadStateWaitSleepJoin = 0x00000020,
kThreadStateSuspended = 0x00000040,
kThreadStateAbortRequested = 0x00000080,
kThreadStateAborted = 0x00000100
};
// System.Threading.ApartmentState
enum ThreadApartmentState
{
kThreadApartmentStateSTA = 0x00000000,
kThreadApartmentStateMTA = 0x00000001,
kThreadApartmentStateUnknown = 0x00000002
};
class LIBIL2CPP_CODEGEN_API Thread
{
public:
#if NET_4_0
static std::string GetName(Il2CppInternalThread* thread);
#endif
static void SetName(Il2CppThread* thread, Il2CppString* name);
static void SetName(Il2CppInternalThread* thread, Il2CppString* name);
static Il2CppThread* Current();
static Il2CppThread* Attach(Il2CppDomain *domain);
static void Detach(Il2CppThread *thread);
static void WalkFrameStack(Il2CppThread *thread, Il2CppFrameWalkFunc func, void *user_data);
static Il2CppThread** GetAllAttachedThreads(size_t &size);
static void KillAllBackgroundThreadsAndWaitForForegroundThreads();
static Il2CppThread* Main();
static bool IsVmThread(Il2CppThread *thread);
static uint64_t GetId(Il2CppThread *thread);
#if NET_4_0
static uint64_t GetId(Il2CppInternalThread* thread);
#endif
static void RequestInterrupt(Il2CppThread* thread);
static void CheckCurrentThreadForInterruptAndThrowIfNecessary();
static bool RequestAbort(Il2CppThread* thread);
static void CheckCurrentThreadForAbortAndThrowIfNecessary();
static void ResetAbort(Il2CppThread* thread);
#if NET_4_0
static bool RequestAbort(Il2CppInternalThread* thread);
static void ResetAbort(Il2CppInternalThread* thread);
static void SetPriority(Il2CppThread* thread, int32_t priority);
static int32_t GetPriority(Il2CppThread* thread);
#endif
struct NativeThreadAbortException {};
public:
// internal
static void Initialize();
static void UnInitialize();
static void AdjustStaticData();
static int32_t AllocThreadStaticData(int32_t size);
static void FreeThreadStaticData(Il2CppThread *thread);
static void* GetThreadStaticData(int32_t offset);
static void* GetThreadStaticDataForThread(int32_t offset, Il2CppThread* thread);
#if NET_4_0
static void* GetThreadStaticDataForThread(int32_t offset, Il2CppInternalThread* thread);
#endif
static void Register(Il2CppThread *thread);
static void Unregister(Il2CppThread *thread);
static void Setup(Il2CppThread* thread);
/// Initialize and register thread.
/// NOTE: Must be called on thread!
static void Initialize(Il2CppThread *thread, Il2CppDomain* domain);
static void Uninitialize(Il2CppThread *thread);
static void SetMain(Il2CppThread* thread);
static void SetState(Il2CppThread *thread, ThreadState value);
static ThreadState GetState(Il2CppThread *thread);
static void ClrState(Il2CppThread* thread, ThreadState clr);
static void FullMemoryBarrier();
static int32_t GetNewManagedId();
#if NET_4_0
static Il2CppInternalThread* CurrentInternal();
static void ClrState(Il2CppInternalThread* thread, ThreadState clr);
static void SetState(Il2CppInternalThread *thread, ThreadState value);
static ThreadState GetState(Il2CppInternalThread *thread);
static bool TestState(Il2CppInternalThread* thread, ThreadState value);
static Il2CppInternalThread* CreateInternal(void(*func)(void*), void* arg, bool threadpool_thread, uint32_t stack_size);
static void Stop(Il2CppInternalThread* thread);
static void Sleep(uint32_t ms);
static bool YieldInternal();
#endif
private:
static Il2CppThread* s_MainThread;
};
class ThreadStateSetter : il2cpp::utils::NonCopyable
{
public:
ThreadStateSetter(ThreadState state) : m_State(state)
{
m_Thread = il2cpp::vm::Thread::Current();
Thread::SetState(m_Thread, m_State);
}
~ThreadStateSetter()
{
Thread::ClrState(m_Thread, m_State);
}
private:
ThreadState m_State;
Il2CppThread* m_Thread;
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,68 @@
#pragma once
#include "il2cpp-config.h"
struct Il2CppObject;
struct Il2CppDelegate;
struct Il2CppAsyncResult;
#if NET_4_0
/* Keep in sync with System.IOOperation in mcs/class/System/System/IOSelector.cs */
enum Il2CppIOOperation
{
EVENT_IN = 1 << 0,
EVENT_OUT = 1 << 1,
EVENT_ERR = 1 << 2, /* not in managed */
};
#endif
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API ThreadPool
{
public:
struct Configuration
{
int minThreads;
int maxThreads;
int minAsyncIOThreads;
int maxAsyncIOThreads;
// These are read-only.
int availableThreads;
int availableAsyncIOThreads;
};
#if NET_4_0
typedef struct
{
bool(*init)(int wakeup_pipe_fd);
void(*register_fd)(int fd, int events, bool is_new);
void(*remove_fd)(int fd);
int(*event_wait)(void(*callback)(int fd, int events, void* user_data), void* user_data);
} ThreadPoolIOBackend;
#endif
static void Initialize();
static void Shutdown();
/// On a thread, call the given delegate with 'params' as arguments. Upon completion,
/// call 'asyncCallback'.
static Il2CppAsyncResult* Queue(Il2CppDelegate* delegate, void** params, Il2CppDelegate* asyncCallback, Il2CppObject* state);
/// Wait for the execution of the given asynchronous call to have completed and return
/// the value returned by the delegate wrapped in the call (or null if the delegate has
/// a void return type).
/// NOTE: Any AsyncResult can only be waited on once! Repeated or concurrent calls to Wait() on the same AsyncResult
/// will throw InvalidOperationExceptions.
static Il2CppObject* Wait(Il2CppAsyncResult* asyncResult, void** outArgs);
static Configuration GetConfiguration();
static void SetConfiguration(const Configuration& configuration);
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,25 @@
#pragma once
#if NET_4_0
#include "il2cpp-config.h"
#include "il2cpp-object-internals.h"
#include "il2cpp-class-internals.h"
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API ThreadPoolMs
{
public:
static Il2CppAsyncResult* DelegateBeginInvoke(Il2CppDelegate* delegate, void** params, Il2CppDelegate* asyncCallback, Il2CppObject* state);
static Il2CppObject* DelegateEndInvoke(Il2CppAsyncResult* asyncResult, void **out_args);
static Il2CppObject* MessageInvoke(Il2CppObject *target, Il2CppMethodMessage *msg, Il2CppObject **exc, Il2CppArray **out_args);
static void Suspend();
static void Resume();
};
} /* namespace vm */
} /* namespace il2cpp */
#endif
@@ -0,0 +1,245 @@
#pragma once
#include <stdint.h>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include "il2cpp-config.h"
#include "il2cpp-class-internals.h"
#ifdef major
# undef major
# undef minor
#endif
struct FieldInfo;
struct Il2CppType;
struct Il2CppClass;
struct Il2CppGenericParameter;
struct Il2CppString;
namespace il2cpp
{
namespace vm
{
static const int32_t kPublicKeyTokenLength = 17;
class TypeNameParseInfo
{
public:
struct AssemblyName
{
std::string name;
std::string culture;
std::string hash_value;
std::string public_key;
char public_key_token[kPublicKeyTokenLength];
uint32_t hash_alg;
uint32_t hash_len;
uint32_t flags;
uint16_t major;
uint16_t minor;
uint16_t build;
uint16_t revision;
AssemblyName() :
hash_alg(0),
hash_len(0),
flags(0),
major(0),
minor(0),
build(0),
revision(0)
{
memset(public_key_token, 0, kPublicKeyTokenLength);
}
};
TypeNameParseInfo();
~TypeNameParseInfo();
inline const std::string &ns() const
{
return _namespace;
}
inline const std::string &name() const
{
return _name;
}
inline const AssemblyName &assembly_name() const
{
return _assembly_name;
}
inline const std::vector<int> &modifiers() const
{
return _modifiers;
}
inline const std::vector<TypeNameParseInfo> &type_arguments() const
{
return _type_arguments;
}
inline const std::vector<std::string> &nested() const
{
return _nested;
}
inline bool is_byref() const
{
return std::find(_modifiers.begin(), _modifiers.end(), 0) != _modifiers.end();
}
inline bool has_generic_arguments() const
{
return _type_arguments.size() > 0;
}
inline bool is_pointer() const
{
return std::find(_modifiers.begin(), _modifiers.end(), -1) != _modifiers.end();
}
inline bool is_bounded() const
{
return std::find(_modifiers.begin(), _modifiers.end(), -2) != _modifiers.end();
}
inline bool is_array() const
{
std::vector<int32_t>::const_iterator it = _modifiers.begin();
while (it != _modifiers.end())
{
if (*it > 0)
return true;
++it;
}
return false;
}
void SetAssemblyName(const AssemblyName& assemblyName)
{
_assembly_name = assemblyName;
}
private:
std::string _namespace;
std::string _name;
AssemblyName _assembly_name;
std::vector<int32_t> _modifiers;
std::vector<TypeNameParseInfo> _type_arguments;
std::vector<std::string> _nested;
friend class TypeNameParser;
};
class TypeNameParser
{
public:
TypeNameParser(const std::string &name, TypeNameParseInfo &info, bool is_nested);
TypeNameParser(std::string::const_iterator &begin, std::string::const_iterator &end, TypeNameParseInfo &info, bool is_nested);
bool Parse(bool acceptAssemblyName = true);
bool ParseAssembly();
private:
inline bool IsEOL() const
{
return _p >= _end;
}
inline bool CurrentIs(char v) const
{
if (IsEOL())
return false;
return *_p == v;
}
inline bool Next(bool skipWhites = false)
{
++_p;
if (skipWhites)
SkipWhites();
return !IsEOL();
}
bool NextWillBe(char v, bool skipWhites = false) const;
void InitializeParser();
void SkipWhites();
void ConsumeIdentifier();
void ConsumeAssemblyIdentifier();
void ConsumePropertyIdentifier();
void ConsumePropertyValue();
bool ConsumeNumber(int32_t &value);
bool ParseTypeName(int32_t &arity);
bool ParseNestedTypeOptional(int32_t &arity);
bool ParseTypeArgumentsOptional(int32_t &arity);
bool ParseAssemblyNameOptional();
bool ParseAssemblyName();
bool ParsePropertiesOptional();
bool ParseArrayModifierOptional();
bool ParsePointerModifiersOptional();
bool ParseByRefModifiersOptional();
static bool ParseVersion(const std::string& version, uint16_t& major, uint16_t& minor, uint16_t& build, uint16_t& revision);
TypeNameParseInfo &_info;
bool _is_nested;
bool _accept_assembly_name;
std::string::const_iterator _p;
std::string::const_iterator _end;
};
class LIBIL2CPP_CODEGEN_API Type
{
public:
// exported
static std::string GetName(const Il2CppType *type, Il2CppTypeNameFormat format);
static int GetType(const Il2CppType *type);
static Il2CppClass* GetClassOrElementClass(const Il2CppType *type);
static const Il2CppType* GetUnderlyingType(const Il2CppType *type);
static uint32_t GetToken(const Il2CppType *type);
static bool IsGenericInstance(const Il2CppType *type);
static Il2CppReflectionType* GetDeclaringType(const Il2CppType* type);
static Il2CppArray* GetGenericArgumentsInternal(Il2CppReflectionType* type, bool runtimeArray);
static bool IsEqualToType(const Il2CppType *type, const Il2CppType *otherType);
public:
// internal
static void GetNameInternal(std::string &oss, const Il2CppType *type, Il2CppTypeNameFormat format, bool is_nested);
static bool IsReference(const Il2CppType* type);
static bool IsStruct(const Il2CppType* type);
static bool GenericInstIsValuetype(const Il2CppType* type);
static bool IsEnum(const Il2CppType *type);
static bool IsValueType(const Il2CppType *type);
static bool IsEmptyType(const Il2CppType *type);
static bool IsSystemDBNull(const Il2CppType *type);
static bool IsSystemDateTime(const Il2CppType *type);
static bool IsSystemDecimal(const Il2CppType *type);
static Il2CppClass* GetClass(const Il2CppType *type);
static const Il2CppGenericParameter* GetGenericParameter(const Il2CppType *type);
static void ConstructDelegate(Il2CppDelegate* delegate, Il2CppObject* target, Il2CppMethodPointer addr, const MethodInfo* method);
static Il2CppString* AppendAssemblyNameIfNecessary(Il2CppString* typeName, const char* assemblyName);
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,19 @@
#pragma once
struct Il2CppWaitHandle;
namespace il2cpp
{ namespace os
{ class Handle; } }
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API WaitHandle
{
public:
static Il2CppWaitHandle* NewManualResetEvent(bool initialState);
static os::Handle* GetPlatformHandle(Il2CppWaitHandle* waitHandle);
};
} /* namespace vm */
} /* namespace il2cpp */
@@ -0,0 +1,25 @@
#pragma once
#include "il2cpp-object-internals.h"
namespace il2cpp
{
namespace vm
{
struct WeakReference IL2CPP_FINAL : Il2CppIWeakReference
{
static il2cpp_hresult_t Create(Il2CppObject* managedObject, Il2CppIWeakReference** result);
WeakReference(Il2CppObject * managedObject);
virtual il2cpp_hresult_t STDCALL QueryInterface(const Il2CppGuid& iid, void** object) IL2CPP_FINAL IL2CPP_OVERRIDE;
virtual uint32_t STDCALL AddRef() IL2CPP_FINAL IL2CPP_OVERRIDE;
virtual uint32_t STDCALL Release() IL2CPP_FINAL IL2CPP_OVERRIDE;
virtual il2cpp_hresult_t STDCALL Resolve(const Il2CppGuid& iid, Il2CppIInspectable** object) IL2CPP_FINAL IL2CPP_OVERRIDE;
private:
uint32_t m_GCHandle;
uint32_t m_RefCount;
};
}
}
@@ -0,0 +1,82 @@
#pragma once
#include "il2cpp-vm-support.h"
#include "os/WindowsRuntime.h"
#include "vm/Exception.h"
#include "utils/StringView.h"
struct Il2CppIActivationFactory;
namespace il2cpp
{
namespace vm
{
class LIBIL2CPP_CODEGEN_API WindowsRuntime
{
public:
static Il2CppIActivationFactory* GetActivationFactory(const utils::StringView<Il2CppNativeChar>& runtimeClassName);
static inline void CreateHStringReference(const utils::StringView<Il2CppNativeChar>& str, Il2CppHStringHeader* header, Il2CppHString* hstring)
{
il2cpp_hresult_t hr = os::WindowsRuntime::CreateHStringReference(str, header, hstring);
IL2CPP_VM_RAISE_IF_FAILED(hr, false);
}
static inline Il2CppHString CreateHString(Il2CppString* str)
{
Il2CppHString result;
il2cpp_hresult_t hr = os::WindowsRuntime::CreateHString(utils::StringView<Il2CppChar>(str->chars, str->length), &result);
IL2CPP_VM_RAISE_IF_FAILED(hr, false);
return result;
}
static inline Il2CppHString CreateHString(const utils::StringView<Il2CppNativeChar>& str)
{
Il2CppHString result;
il2cpp_hresult_t hr = os::WindowsRuntime::CreateHString(str, &result);
IL2CPP_VM_RAISE_IF_FAILED(hr, false);
return result;
}
static inline void DeleteHString(Il2CppHString hstring)
{
il2cpp_hresult_t hr = os::WindowsRuntime::DeleteHString(hstring);
IL2CPP_VM_RAISE_IF_FAILED(hr, false);
}
static inline Il2CppString* HStringToManagedString(Il2CppHString hstring)
{
return os::WindowsRuntime::HStringToManagedString(hstring);
}
static inline void* PreallocateHStringBuffer(uint32_t length, Il2CppNativeChar** buffer)
{
void* bufferHandle;
il2cpp_hresult_t hr = os::WindowsRuntime::PreallocateHStringBuffer(length, buffer, &bufferHandle);
IL2CPP_VM_RAISE_IF_FAILED(hr, false);
return bufferHandle;
}
static inline Il2CppHString PromoteHStringBuffer(void* bufferHandle)
{
Il2CppHString hstring;
il2cpp_hresult_t hr = os::WindowsRuntime::PromoteHStringBuffer(bufferHandle, &hstring);
if (IL2CPP_HR_FAILED(hr))
{
// Prevent memory leaks by deleting the hstring buffer that was supposed to be promoted before raising an exception
os::WindowsRuntime::DeleteHStringBuffer(bufferHandle);
IL2CPP_VM_RAISE_COM_EXCEPTION(hr, false);
}
return hstring;
}
static void MarshalTypeToNative(const Il2CppType* type, Il2CppWindowsRuntimeTypeName& nativeType);
static const Il2CppType* MarshalTypeFromNative(Il2CppWindowsRuntimeTypeName& nativeType);
static inline void DeleteNativeType(Il2CppWindowsRuntimeTypeName& nativeType)
{
DeleteHString(nativeType.typeName);
}
};
}
}