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,359 @@
#pragma once
#include "il2cpp-config.h"
#include <cassert>
#include <cstdlib>
#include <limits>
#include <string>
#include <math.h>
#include <vector>
#include "il2cpp-object-internals.h"
#include "il2cpp-class-internals.h"
#include "il2cpp-tabledefs.h"
#include "gc/GarbageCollector.h"
#include "vm/PlatformInvoke.h"
#include "vm/StackTrace.h"
#include "vm/PlatformInvoke.h"
#include "vm/StackTrace.h"
#include "vm-utils/Debugger.h"
#include "utils/StringUtils.h"
#include "utils/StringView.h"
#include "utils/Exception.h"
#include "utils/Output.h"
#include "utils/Runtime.h"
REAL_NORETURN IL2CPP_NO_INLINE void il2cpp_codegen_no_return();
#if IL2CPP_COMPILER_MSVC
#define DEFAULT_CALL STDCALL
#else
#define DEFAULT_CALL
#endif
#if defined(__ARMCC_VERSION)
inline double bankers_round(double x)
{
return __builtin_round(x);
}
inline float bankers_roundf(float x)
{
return __builtin_roundf(x);
}
#else
inline double bankers_round(double x)
{
double integerPart;
if (x >= 0.0)
{
if (modf(x, &integerPart) == 0.5)
return (int64_t)integerPart % 2 == 0 ? integerPart : integerPart + 1.0;
return floor(x + 0.5);
}
else
{
if (modf(x, &integerPart) == -0.5)
return (int64_t)integerPart % 2 == 0 ? integerPart : integerPart - 1.0;
return ceil(x - 0.5);
}
}
inline float bankers_roundf(float x)
{
double integerPart;
if (x >= 0.0f)
{
if (modf(x, &integerPart) == 0.5)
return (int64_t)integerPart % 2 == 0 ? (float)integerPart : (float)integerPart + 1.0f;
return floorf(x + 0.5f);
}
else
{
if (modf(x, &integerPart) == -0.5)
return (int64_t)integerPart % 2 == 0 ? (float)integerPart : (float)integerPart - 1.0f;
return ceilf(x - 0.5f);
}
}
#endif
// returns true if overflow occurs
inline bool il2cpp_codegen_check_mul_overflow_i64(int64_t a, int64_t b, int64_t imin, int64_t imax)
{
// TODO: use a better algorithm without division
uint64_t ua = (uint64_t)llabs(a);
uint64_t ub = (uint64_t)llabs(b);
uint64_t c;
if ((a > 0 && b > 0) || (a <= 0 && b <= 0))
c = (uint64_t)llabs(imax);
else
c = (uint64_t)llabs(imin);
return ua != 0 && ub > c / ua;
}
inline bool il2cpp_codegen_check_mul_oveflow_u64(uint64_t a, uint64_t b)
{
return b != 0 && (a * b) / b != a;
}
inline int32_t il2cpp_codegen_abs(uint32_t value)
{
return abs(static_cast<int32_t>(value));
}
inline int32_t il2cpp_codegen_abs(int32_t value)
{
return abs(value);
}
inline int64_t il2cpp_codegen_abs(uint64_t value)
{
return llabs(static_cast<int64_t>(value));
}
inline int64_t il2cpp_codegen_abs(int64_t value)
{
return llabs(value);
}
// Exception support macros
#define IL2CPP_LEAVE(Offset, Target) \
__leave_target = Offset; \
goto Target;
#define IL2CPP_END_FINALLY(Id) \
goto __CLEANUP_ ## Id;
#define IL2CPP_CLEANUP(Id) \
__CLEANUP_ ## Id:
#define IL2CPP_RETHROW_IF_UNHANDLED(ExcType) \
if(__last_unhandled_exception) { \
ExcType _tmp_exception_local = __last_unhandled_exception; \
__last_unhandled_exception = 0; \
il2cpp_codegen_raise_exception(_tmp_exception_local); \
}
#define IL2CPP_JUMP_TBL(Offset, Target) \
if(__leave_target == Offset) { \
__leave_target = 0; \
goto Target; \
}
#define IL2CPP_END_CLEANUP(Offset, Target) \
if(__leave_target == Offset) \
goto Target;
#if IL2CPP_MONO_DEBUGGER
#define IL2CPP_RAISE_MANAGED_EXCEPTION(message, seqPoint, lastManagedFrame) \
do {\
il2cpp_codegen_raise_exception((Exception_t*)message, seqPoint, (MethodInfo*)lastManagedFrame);\
il2cpp_codegen_no_return();\
} while (0)
#else
#define IL2CPP_RAISE_MANAGED_EXCEPTION(message, seqPoint, lastManagedFrame) \
do {\
il2cpp_codegen_raise_exception((Exception_t*)message, NULL, (MethodInfo*)lastManagedFrame);\
il2cpp_codegen_no_return();\
} while (0)
#endif
template<typename T>
inline void Il2CppCodeGenWriteBarrier(T** targetAddress, T* object)
{
il2cpp::gc::GarbageCollector::SetWriteBarrier((void**)targetAddress);
}
void il2cpp_codegen_memory_barrier();
template<typename T>
inline T VolatileRead(T* location)
{
T result = *location;
il2cpp_codegen_memory_barrier();
return result;
}
template<typename T>
inline void VolatileWrite(T** location, T* value)
{
il2cpp_codegen_memory_barrier();
*location = value;
Il2CppCodeGenWriteBarrier(location, value);
}
template<typename T>
inline void VolatileWrite(T* location, T value)
{
il2cpp_codegen_memory_barrier();
*location = value;
}
inline void il2cpp_codegen_write_to_stdout(const char* str)
{
il2cpp::utils::Output::WriteToStdout(str);
}
inline void il2cpp_codegen_write_to_stderr(const char* str)
{
il2cpp::utils::Output::WriteToStderr(str);
}
inline REAL_NORETURN void il2cpp_codegen_abort()
{
il2cpp::utils::Runtime::Abort();
il2cpp_codegen_no_return();
}
inline bool il2cpp_codegen_check_add_overflow(int64_t left, int64_t right)
{
return (right >= 0 && left > kIl2CppInt64Max - right) ||
(left < 0 && right < kIl2CppInt64Min - left);
}
inline bool il2cpp_codegen_check_sub_overflow(int64_t left, int64_t right)
{
return (right >= 0 && left < kIl2CppInt64Min + right) ||
(right < 0 && left > kIl2CppInt64Max + right);
}
template<bool, class T, class U>
struct pick_first;
template<class T, class U>
struct pick_first<true, T, U>
{
typedef T type;
};
template<class T, class U>
struct pick_first<false, T, U>
{
typedef U type;
};
template<class T, class U>
struct pick_bigger
{
typedef typename pick_first<(sizeof(T) >= sizeof(U)), T, U>::type type;
};
template<typename T, typename U>
inline typename pick_bigger<T, U>::type il2cpp_codegen_multiply(T left, U right)
{
return left * right;
}
template<typename T, typename U>
inline typename pick_bigger<T, U>::type il2cpp_codegen_add(T left, U right)
{
return left + right;
}
template<typename T, typename U>
inline typename pick_bigger<T, U>::type il2cpp_codegen_subtract(T left, U right)
{
return left - right;
}
inline void il2cpp_codegen_memcpy(void* dest, const void* src, size_t count)
{
memcpy(dest, src, count);
}
inline void il2cpp_codegen_memset(void* ptr, int value, size_t num)
{
memset(ptr, value, num);
}
#if IL2CPP_MONO_DEBUGGER
extern volatile uint32_t g_Il2CppDebuggerCheckPointEnabled;
#endif
inline void il2cpp_codegen_register_debugger_data(const Il2CppDebuggerMetadataRegistration *data)
{
#if IL2CPP_MONO_DEBUGGER
il2cpp::utils::Debugger::RegisterSequencePointCheck(&g_Il2CppDebuggerCheckPointEnabled);
il2cpp::utils::Debugger::RegisterMetadata(data);
#endif
}
inline void il2cpp_codegen_check_sequence_point(Il2CppSequencePointExecutionContext* executionContext, size_t seqPointId)
{
#if IL2CPP_MONO_DEBUGGER
if (g_Il2CppDebuggerCheckPointEnabled)
il2cpp::utils::Debugger::CheckSequencePoint(executionContext, seqPointId);
#endif
}
inline void il2cpp_codegen_check_pause_point()
{
#if IL2CPP_MONO_DEBUGGER
if (g_Il2CppDebuggerCheckPointEnabled)
il2cpp::utils::Debugger::CheckPausePoint();
#endif
}
inline Il2CppSequencePoint* il2cpp_codegen_get_sequence_point(size_t id)
{
#if IL2CPP_MONO_DEBUGGER
return il2cpp::utils::Debugger::GetSequencePoint(id);
#else
return NULL;
#endif
}
class MethodExitSequencePointChecker
{
private:
size_t m_pSeqPoint;
Il2CppSequencePointExecutionContext* m_seqPointStorage;
public:
MethodExitSequencePointChecker(Il2CppSequencePointExecutionContext* seqPointStorage, size_t seqPointId) :
m_seqPointStorage(seqPointStorage), m_pSeqPoint(seqPointId)
{
}
~MethodExitSequencePointChecker()
{
#if IL2CPP_MONO_DEBUGGER
il2cpp_codegen_check_sequence_point(m_seqPointStorage, m_pSeqPoint);
#endif
}
};
#ifdef _MSC_VER
#define IL2CPP_DISABLE_OPTIMIZATIONS __pragma(optimize("", off))
#define IL2CPP_ENABLE_OPTIMIZATIONS __pragma(optimize("", on))
#else
#define IL2CPP_DISABLE_OPTIMIZATIONS __attribute__ ((optnone))
#define IL2CPP_ENABLE_OPTIMIZATIONS
#endif
// NativeArray macros
#define IL2CPP_NATIVEARRAY_GET_ITEM(TElementType, TTField, TIndex) \
*(reinterpret_cast<TElementType*>(TTField) + TIndex)
#define IL2CPP_NATIVEARRAY_SET_ITEM(TElementType, TTField, TIndex, TValue) \
*(reinterpret_cast<TElementType*>(TTField) + TIndex) = TValue;
#define IL2CPP_NATIVEARRAY_GET_LENGTH(TLengthField) \
(TLengthField)
// Array Unsafe
#define IL2CPP_ARRAY_UNSAFE_LOAD(TArray, TIndex) \
(TArray)->GetAtUnchecked(static_cast<il2cpp_array_size_t>(TIndex))
inline bool il2cpp_codegen_object_reference_equals(const RuntimeObject *obj1, const RuntimeObject *obj2)
{
return obj1 == obj2;
}
@@ -0,0 +1,995 @@
#pragma once
#include "il2cpp-codegen-common.h"
#include "il2cpp-mono-support.h"
#include "mono-api.h"
struct ProfilerMethodSentry
{
ProfilerMethodSentry(const RuntimeMethod* method)
#if IL2CPP_ENABLE_PROFILER
: m_method(method)
#endif
{
IL2CPP_NOT_IMPLEMENTED("Unity profiler hooks are not implemented yet for the libmonoruntime backend.");
}
~ProfilerMethodSentry()
{
IL2CPP_NOT_IMPLEMENTED("Unity profiler hooks are not implemented yet for the libmonoruntime backend.");
}
private:
const RuntimeMethod* m_method;
};
struct StackTraceSentry
{
StackTraceSentry(RuntimeMethod* method) : m_method(method)
{
MonoStackFrameInfo frame_info;
frame_info.method = method;
frame_info.actual_method = method;
frame_info.type = FRAME_TYPE_MANAGED;
frame_info.managed = 1;
frame_info.il_offset = 0;
frame_info.native_offset = 0;
frame_info.ji = (MonoJitInfo*)(void*)-1;
mono::vm::StackTrace::PushFrame(frame_info);
}
~StackTraceSentry()
{
mono::vm::StackTrace::PopFrame();
}
private:
const RuntimeMethod* m_method;
};
#define IL2CPP_FAKE_BOX_SENTRY (MonoThreadsSync*)UINTPTR_MAX
template<typename T>
struct Il2CppFakeBox : RuntimeObject
{
T m_Value;
Il2CppFakeBox(RuntimeClass* boxedType, T* value)
{
vtable = il2cpp_mono_class_vtable(g_MonoDomain, boxedType);
synchronisation = IL2CPP_FAKE_BOX_SENTRY;
m_Value = *value;
}
};
inline bool il2cpp_codegen_is_fake_boxed_object(RuntimeObject* object)
{
return object->synchronisation == IL2CPP_FAKE_BOX_SENTRY;
}
// TODO: This file should contain all the functions and type declarations needed for the generated code.
// Hopefully, we stop including everything in the generated code and know exactly what dependencies we have.
// Note that all parameter and return types should match the generated types not the runtime types.
// type registration
inline String_t* il2cpp_codegen_string_new_utf16(const il2cpp::utils::StringView<Il2CppChar>& str)
{
return (String_t*)mono_string_new_utf16(g_MonoDomain, (const mono_unichar2*)str.Str(), (int32_t)str.Length());
}
inline NORETURN void il2cpp_codegen_raise_exception(Exception_t *ex, Il2CppSequencePoint *seqPoint = NULL, MethodInfo* lastManagedFrame = NULL)
{
mono_raise_exception((RuntimeException*)ex);
il2cpp_codegen_no_return();
}
inline void il2cpp_codegen_raise_execution_engine_exception_if_method_is_not_found(const RuntimeMethod* method)
{
il2cpp_mono_raise_execution_engine_exception_if_method_is_not_found(const_cast<RuntimeMethod*>(method));
}
inline void il2cpp_codegen_raise_execution_engine_exception(const RuntimeMethod* method)
{
mono_raise_exception(mono_get_exception_execution_engine(mono_unity_method_get_name(method)));
}
inline Exception_t* il2cpp_codegen_get_argument_exception(const char* param, const char* msg)
{
return (Exception_t*)mono_get_exception_argument(param, msg);
}
inline Exception_t* il2cpp_codegen_get_argument_null_exception(const char* param)
{
return (Exception_t*)mono_get_exception_argument_null(param);
}
inline Exception_t* il2cpp_codegen_get_overflow_exception()
{
return (Exception_t*)mono_get_exception_overflow();
}
inline Exception_t* il2cpp_codegen_get_not_supported_exception(const char* msg)
{
return (Exception_t*)mono_get_exception_not_supported(msg);
}
inline Exception_t* il2cpp_codegen_get_array_type_mismatch_exception()
{
return (Exception_t*)mono_get_exception_array_type_mismatch();
}
inline Exception_t* il2cpp_codegen_get_invalid_operation_exception(const char* msg)
{
return (Exception_t*)mono_get_exception_invalid_operation(msg);
}
inline Exception_t* il2cpp_codegen_get_marshal_directive_exception(const char* msg)
{
return (Exception_t*)mono_unity_exception_get_marshal_directive(msg);
}
inline Exception_t* il2cpp_codegen_get_missing_method_exception(const char* msg)
{
return (Exception_t*)mono_get_exception_missing_method(msg, "ctor");
}
inline Exception_t* il2cpp_codegen_get_maximum_nested_generics_exception()
{
return (Exception_t*)mono_get_exception_not_supported(MAXIMUM_NESTED_GENERICS_EXCEPTION_MESSAGE);
}
inline RuntimeClass* il2cpp_codegen_object_class(RuntimeObject* obj)
{
return mono_object_get_class(obj);
}
// OpCode.IsInst
inline RuntimeObject* IsInst(RuntimeObject *obj, RuntimeClass* targetType)
{
return mono_object_isinst(obj, targetType);
}
inline RuntimeObject* IsInstSealed(RuntimeObject *obj, RuntimeClass* targetType)
{
if (!obj)
return NULL;
// optimized version to compare sealed classes
return mono_unity_object_isinst_sealed(obj, targetType);
}
inline RuntimeObject* IsInstClass(RuntimeObject *obj, RuntimeClass* targetType)
{
if (!obj)
return NULL;
return mono_unity_class_has_parent_unsafe(mono_object_get_class(obj), targetType) ? obj : NULL;
}
// OpCode.Castclass
inline RuntimeObject* Castclass(RuntimeObject *obj, RuntimeClass* targetType)
{
if (!obj)
return NULL;
RuntimeObject* result = mono_object_isinst(obj, targetType);
if (result)
return result;
mono_raise_exception(mono_get_exception_invalid_cast());
return NULL;
}
inline RuntimeObject* CastclassSealed(RuntimeObject *obj, RuntimeClass* targetType)
{
if (!obj)
return NULL;
RuntimeObject* result = IsInstSealed(obj, targetType);
if (result)
return result;
mono_raise_exception(mono_get_exception_invalid_cast());
return NULL;
}
inline RuntimeObject* CastclassClass(RuntimeObject *obj, RuntimeClass* targetType)
{
if (!obj)
return NULL;
RuntimeObject* result = IsInstClass(obj, targetType);
if (result)
return result;
mono_raise_exception(mono_get_exception_invalid_cast());
return NULL;
}
// OpCode.Box
inline RuntimeObject* Box(RuntimeClass* type, void* data)
{
return mono_value_box(g_MonoDomain, type, data);
}
// OpCode.UnBox
inline void* UnBox(RuntimeObject* obj)
{
if (!obj)
{
mono_raise_exception(mono_get_exception_null_reference());
il2cpp_codegen_no_return();
}
return mono_object_unbox(obj);
}
inline void* UnBox(RuntimeObject* obj, RuntimeClass* klass)
{
if (!obj)
{
mono_raise_exception(mono_get_exception_null_reference());
il2cpp_codegen_no_return();
}
if (!mono_unity_object_check_box_cast(obj, klass))
{
mono_raise_exception(mono_get_exception_invalid_cast());
il2cpp_codegen_no_return();
}
return mono_object_unbox(obj);
}
inline void UnBoxNullable(RuntimeObject* obj, RuntimeClass* klass, void* storage)
{
mono_unity_object_unbox_nullable(obj, klass, storage);
}
inline uint32_t il2cpp_codegen_sizeof(RuntimeClass* klass)
{
if (!mono_class_is_valuetype(klass))
return sizeof(void*);
return mono_class_instance_size(klass) - sizeof(RuntimeObject);
}
inline bool il2cpp_codegen_method_is_virtual(RuntimeMethod* method)
{
return method->slot != -1;
}
inline bool il2cpp_codegen_object_is_of_sealed_type(RuntimeObject* obj)
{
return obj != NULL && mono_class_is_sealed(mono_object_get_class(obj));
}
inline bool il2cpp_codegen_method_is_generic_instance(RuntimeMethod* method)
{
return unity_mono_method_is_generic(method);
}
inline bool il2cpp_codegen_method_is_interface_method(RuntimeMethod* method)
{
return MONO_CLASS_IS_INTERFACE(mono_method_get_class(method));
}
inline uint16_t il2cpp_codegen_method_get_slot(RuntimeMethod* method)
{
return method->slot;
}
inline RuntimeClass* il2cpp_codegen_method_get_declaring_type(RuntimeMethod* method)
{
return mono_method_get_class(method);
}
FORCE_INLINE const VirtualInvokeData il2cpp_codegen_get_virtual_invoke_data(RuntimeMethod* method, void* obj)
{
VirtualInvokeData invokeData;
il2cpp_mono_get_virtual_invoke_data(method, obj, &invokeData);
return invokeData;
}
FORCE_INLINE const VirtualInvokeData il2cpp_codegen_get_interface_invoke_data(RuntimeMethod* method, void* obj, RuntimeClass* declaringInterface)
{
VirtualInvokeData invokeData;
il2cpp_mono_get_interface_invoke_data(method, obj, &invokeData);
return invokeData;
}
FORCE_INLINE const RuntimeMethod* il2cpp_codegen_get_generic_virtual_method(const RuntimeMethod* method, const RuntimeObject* obj)
{
return il2cpp_mono_get_virtual_target_method(const_cast<RuntimeMethod*>(method), const_cast<RuntimeObject*>(obj));
}
FORCE_INLINE void il2cpp_codegen_get_generic_virtual_invoke_data(const RuntimeMethod* method, void* obj, VirtualInvokeData* invokeData)
{
il2cpp_mono_get_invoke_data(const_cast<RuntimeMethod*>(method), obj, invokeData);
}
FORCE_INLINE const RuntimeMethod* il2cpp_codegen_get_generic_interface_method(const RuntimeMethod* method, const RuntimeObject* obj)
{
return il2cpp_mono_get_virtual_target_method(const_cast<RuntimeMethod*>(method), const_cast<RuntimeObject*>(obj));
}
FORCE_INLINE void il2cpp_codegen_get_generic_interface_invoke_data(RuntimeMethod* method, void* obj, VirtualInvokeData* invokeData)
{
il2cpp_mono_get_invoke_data(method, obj, invokeData);
}
FORCE_INLINE void il2cpp_codegen_get_generic_interface_invoke_data(const RuntimeMethod* method, void* obj, VirtualInvokeData* invokeData)
{
il2cpp_codegen_get_generic_interface_invoke_data(const_cast<RuntimeMethod*>(method), obj, invokeData);
}
// OpCode.Ldtoken
inline RuntimeClass* il2cpp_codegen_class_from_type(RuntimeType* type)
{
return mono_class_from_mono_type(type);
}
inline RuntimeClass* il2cpp_codegen_class_from_type(const RuntimeType *type)
{
return il2cpp_codegen_class_from_type(const_cast<RuntimeType*>(type));
}
template<typename T>
inline T InterlockedCompareExchangeImpl(T* location, T value, T comparand)
{
return (T)mono_unity_object_compare_exchange((RuntimeObject**)location, (RuntimeObject*)value, (RuntimeObject*)comparand);
}
template<typename T>
inline T InterlockedExchangeImpl(T* location, T value)
{
return (T)mono_unity_object_exchange((RuntimeObject**)location, (RuntimeObject*)value);
}
inline void ArrayGetGenericValueImpl(RuntimeArray* __this, int32_t pos, void* value)
{
int elementSize = mono_unity_array_get_element_size(__this);
memcpy(value, mono_array_addr_with_size(__this, elementSize, pos), elementSize);
}
inline void ArraySetGenericValueImpl(RuntimeArray * __this, int32_t pos, void* value)
{
int elementSize = mono_unity_array_get_element_size(__this);
memcpy(mono_array_addr_with_size(__this, elementSize, pos), value, elementSize);
}
inline RuntimeArray* SZArrayNew(RuntimeClass* arrayType, uint32_t length)
{
mono_class_init(arrayType);
MonoError error;
RuntimeArray *retVal = mono_array_new_specific_checked(il2cpp_mono_class_vtable(g_MonoDomain, arrayType), length, &error);
RuntimeException *exc = mono_error_convert_to_exception(&error);
if (exc)
mono_raise_exception(exc);
return retVal;
}
inline RuntimeArray* GenArrayNew(RuntimeClass* arrayType, il2cpp_array_size_t* dimensions)
{
MonoError error;
RuntimeArray *retVal = mono_array_new_full_checked(g_MonoDomain, arrayType, dimensions, NULL, &error);
RuntimeException *exc = mono_error_convert_to_exception(&error);
if (exc)
mono_raise_exception(exc);
return retVal;
}
// Performance optimization as detailed here: http://blogs.msdn.com/b/clrcodegeneration/archive/2009/08/13/array-bounds-check-elimination-in-the-clr.aspx
// Since array size is a signed int32_t, a single unsigned check can be performed to determine if index is less than array size.
// Negative indices will map to a unsigned number greater than or equal to 2^31 which is larger than allowed for a valid array.
#define IL2CPP_ARRAY_BOUNDS_CHECK(index, length) \
do { \
if (((uint32_t)(index)) >= ((uint32_t)length)) mono_raise_exception(mono_get_exception_index_out_of_range()); \
} while (0)
inline bool il2cpp_codegen_class_is_assignable_from(RuntimeClass *klass, RuntimeClass *oklass)
{
return mono_class_is_assignable_from(klass, oklass);
}
inline RuntimeObject* il2cpp_codegen_object_new(RuntimeClass *klass)
{
return mono_object_new(g_MonoDomain, klass);
}
inline Il2CppMethodPointer il2cpp_codegen_resolve_icall(const RuntimeMethod* icallMethod)
{
return (Il2CppMethodPointer)mono_lookup_internal_call(const_cast<RuntimeMethod*>(icallMethod));
}
template<typename FunctionPointerType>
inline FunctionPointerType il2cpp_codegen_resolve_pinvoke(const RuntimeMethod* pinvokeMethod)
{
const char *exc_class, *exc_arg;
FunctionPointerType result = reinterpret_cast<FunctionPointerType>(mono_lookup_pinvoke_call(const_cast<RuntimeMethod*>(pinvokeMethod), &exc_class, &exc_arg));
if (exc_class)
{
mono_raise_exception(mono_exception_from_name_msg(mono_unity_image_get_mscorlib(), "System", exc_class, exc_arg));
il2cpp_codegen_no_return();
}
return result;
}
template<typename T>
inline T* il2cpp_codegen_marshal_allocate_array(size_t length)
{
MonoError unused;
return (T*)mono_marshal_alloc((il2cpp_array_size_t)(sizeof(T) * length), &unused);
}
template<typename T>
inline T* il2cpp_codegen_marshal_allocate()
{
MonoError unused;
return (T*)mono_marshal_alloc(sizeof(T), &unused);
}
inline char* il2cpp_codegen_marshal_string(String_t* string)
{
return mono::vm::PlatformInvoke::MarshalCSharpStringToCppString((RuntimeString*)string);
}
inline void il2cpp_codegen_marshal_string_fixed(String_t* string, char* buffer, int numberOfCharacters)
{
return mono::vm::PlatformInvoke::MarshalCSharpStringToCppStringFixed((RuntimeString*)string, buffer, numberOfCharacters);
}
inline Il2CppChar* il2cpp_codegen_marshal_wstring(String_t* string)
{
return (Il2CppChar*)mono::vm::PlatformInvoke::MarshalCSharpStringToCppWString((RuntimeString*)string);
}
inline void il2cpp_codegen_marshal_wstring_fixed(String_t* string, Il2CppChar* buffer, int numberOfCharacters)
{
return mono::vm::PlatformInvoke::MarshalCSharpStringToCppWStringFixed((RuntimeString*)string, (mono_unichar2*)buffer, numberOfCharacters);
}
inline Il2CppChar* il2cpp_codegen_marshal_bstring(String_t* string)
{
IL2CPP_NOT_IMPLEMENTED("COM is not yet supported with the libmonoruntime backend.");
return NULL;
}
inline String_t* il2cpp_codegen_marshal_string_result(const char* value)
{
return (String_t*)mono::vm::PlatformInvoke::MarshalCppStringToCSharpStringResult(value);
}
inline String_t* il2cpp_codegen_marshal_wstring_result(const Il2CppChar* value)
{
return (String_t*)mono::vm::PlatformInvoke::MarshalCppWStringToCSharpStringResult((const mono_unichar2*)value);
}
inline String_t* il2cpp_codegen_marshal_bstring_result(const Il2CppChar* value)
{
IL2CPP_NOT_IMPLEMENTED("COM is not yet supported with the libmonoruntime backend.");
return NULL;
}
inline void il2cpp_codegen_marshal_free_bstring(Il2CppChar* value)
{
IL2CPP_NOT_IMPLEMENTED("COM is not yet supported with the libmonoruntime backend.");
}
inline char* il2cpp_codegen_marshal_string_builder(StringBuilder_t* stringBuilder)
{
return mono::vm::PlatformInvoke::MarshalStringBuilder((RuntimeStringBuilder*)stringBuilder);
}
inline Il2CppChar* il2cpp_codegen_marshal_wstring_builder(StringBuilder_t* stringBuilder)
{
return (Il2CppChar*)mono::vm::PlatformInvoke::MarshalWStringBuilder((RuntimeStringBuilder*)stringBuilder);
}
inline void il2cpp_codegen_marshal_string_builder_result(StringBuilder_t* stringBuilder, char* buffer)
{
mono::vm::PlatformInvoke::MarshalStringBuilderResult((RuntimeStringBuilder*)stringBuilder, buffer);
}
inline void il2cpp_codegen_marshal_wstring_builder_result(StringBuilder_t* stringBuilder, Il2CppChar* buffer)
{
mono::vm::PlatformInvoke::MarshalWStringBuilderResult((RuntimeStringBuilder*)stringBuilder, (mono_unichar2*)buffer);
}
inline Il2CppHString il2cpp_codegen_create_hstring(String_t* str)
{
IL2CPP_NOT_IMPLEMENTED("COM is not yet supported with the libmonoruntime backend.");
return NULL;
}
inline String_t* il2cpp_codegen_marshal_hstring_result(Il2CppHString hstring)
{
IL2CPP_NOT_IMPLEMENTED("COM is not yet supported with the libmonoruntime backend.");
return NULL;
}
inline void il2cpp_codegen_marshal_free_hstring(Il2CppHString hstring)
{
IL2CPP_NOT_IMPLEMENTED("COM is not yet supported with the libmonoruntime backend.");
}
inline void il2cpp_codegen_marshal_free(void* ptr)
{
mono_marshal_free(ptr);
}
inline Il2CppMethodPointer il2cpp_codegen_marshal_delegate(MulticastDelegate_t* d)
{
return (Il2CppMethodPointer)mono::vm::PlatformInvoke::MarshalDelegate((RuntimeDelegate*)d);
}
template<typename T>
inline T* il2cpp_codegen_marshal_function_ptr_to_delegate(Il2CppMethodPointer functionPtr, RuntimeClass* delegateType)
{
return (T*)mono::vm::PlatformInvoke::MarshalFunctionPointerToDelegate(reinterpret_cast<void*>(functionPtr), delegateType);
}
inline void il2cpp_codegen_marshal_store_last_error()
{
mono_marshal_set_last_error();
}
namespace il2cpp
{
namespace vm
{
class ScopedThreadAttacher
{
public:
ScopedThreadAttacher() :
_threadWasAttached(false)
{
if (!mono_thread_is_attached())
{
mono_thread_attach(mono_get_root_domain());
_threadWasAttached = true;
}
}
~ScopedThreadAttacher()
{
if (_threadWasAttached)
mono_thread_detach(mono_thread_current());
}
private:
bool _threadWasAttached;
bool mono_thread_is_attached()
{
return mono_domain_get() != NULL;
}
};
}
}
#if _DEBUG
struct ScopedMarshallingAllocationCheck
{
};
struct ScopedMarshalingAllocationClearer
{
};
#endif
inline void NullCheck(void* this_ptr)
{
if (this_ptr != NULL)
return;
mono_raise_exception(mono_get_exception_null_reference());
}
inline void DivideByZeroCheck(int64_t denominator)
{
if (denominator != 0)
return;
mono_raise_exception(mono_get_exception_divide_by_zero());
}
inline void il2cpp_codegen_initobj(void* value, size_t size)
{
memset(value, 0, size);
}
inline bool MethodIsStatic(const RuntimeMethod* method)
{
return mono_unity_method_is_static(const_cast<RuntimeMethod*>(method));
}
inline bool MethodHasParameters(const RuntimeMethod* method)
{
return mono_signature_get_param_count(mono_method_signature(const_cast<RuntimeMethod*>(method))) != 0;
}
//#define IL2CPP_RUNTIME_CLASS_INIT(klass) do { if((klass)->has_cctor && !(klass)->cctor_finished) il2cpp::vm::Runtime::ClassInit ((klass)); } while (0)
#define IL2CPP_RUNTIME_CLASS_INIT(klass) RuntimeInit(klass)
inline void* il2cpp_codegen_mono_class_rgctx(RuntimeClass* klass, Il2CppRGCTXDataType rgctxType, int rgctxIndex, bool useSharedVersion)
{
return il2cpp_mono_class_rgctx(klass, rgctxType, rgctxIndex, useSharedVersion);
}
inline void* il2cpp_codegen_mono_method_rgctx(RuntimeMethod* method, Il2CppRGCTXDataType rgctxType, int rgctxIndex, bool useSharedVersion)
{
return il2cpp_mono_method_rgctx(method, rgctxType, rgctxIndex, useSharedVersion);
}
inline void ArrayElementTypeCheck(RuntimeArray* array, void* value)
{
if (!value)
return;
RuntimeClass *aclass = mono_unity_array_get_class(array);
RuntimeClass *eclass = mono_unity_class_get_element_class(aclass);
RuntimeClass *oclass = mono_unity_object_get_class((RuntimeObject*)value);
if (!mono_class_is_assignable_from(eclass, oclass))
mono_raise_exception(mono_get_exception_array_type_mismatch());
}
inline const RuntimeMethod* GetVirtualMethodInfo(RuntimeObject* pThis, const RuntimeMethod* method)
{
if (!pThis)
mono_raise_exception(mono_get_exception_null_reference());
return mono_object_get_virtual_method(pThis, const_cast<RuntimeMethod*>(method));
}
inline const RuntimeMethod* GetInterfaceMethodInfo(RuntimeObject* pThis, RuntimeMethod *slot, RuntimeClass* declaringInterface)
{
if (!pThis)
mono_raise_exception(mono_get_exception_null_reference());
return mono_object_get_virtual_method(pThis, slot);
}
inline void il2cpp_codegen_memory_barrier()
{
mono_unity_memory_barrier();
}
inline void il2cpp_codegen_initialize_method(uint32_t index)
{
il2cpp_mono_initialize_method_metadata(index);
}
inline bool il2cpp_codegen_type_implements_virtual_method(RuntimeClass* type, RuntimeMethod *slot)
{
return mono_unity_method_get_class(slot) == type;
}
inline MethodBase_t* il2cpp_codegen_get_method_object(const RuntimeMethod* method)
{
if (unity_mono_method_is_inflated(const_cast<RuntimeMethod*>(method)))
method = mono_unity_method_get_generic_definition(const_cast<RuntimeMethod*>(method));
return (MethodBase_t*)mono_unity_method_get_object(const_cast<RuntimeMethod*>(method));
}
inline Type_t* il2cpp_codegen_get_type(Il2CppMethodPointer getTypeFunction, String_t* typeName, const char* assemblyName)
{
typedef Type_t* (*getTypeFuncType)(String_t*, const RuntimeMethod*);
MonoString* assemblyQualifiedTypeName = mono_unity_string_append_assembly_name_if_necessary((MonoString*)typeName, assemblyName);
// Try to find the type using a hint about about calling assembly. If it is not found, fall back to calling GetType without the hint.
Type_t* type = ((getTypeFuncType)getTypeFunction)((String_t*)assemblyQualifiedTypeName, NULL);
if (type == NULL)
return ((getTypeFuncType)getTypeFunction)(typeName, NULL);
return type;
}
inline Type_t* il2cpp_codegen_get_type(Il2CppMethodPointer getTypeFunction, String_t* typeName, bool throwOnError, const char* assemblyName)
{
typedef Type_t* (*getTypeFuncType)(String_t*, bool, const RuntimeMethod*);
MonoString* assemblyQualifiedTypeName = mono_unity_string_append_assembly_name_if_necessary((MonoString*)typeName, assemblyName);
// Try to find the type using a hint about about calling assembly. If it is not found, fall back to calling GetType without the hint.
Type_t* type = ((getTypeFuncType)getTypeFunction)((String_t*)assemblyQualifiedTypeName, throwOnError, NULL);
if (type == NULL)
return ((getTypeFuncType)getTypeFunction)(typeName, throwOnError, NULL);
return type;
}
inline Type_t* il2cpp_codegen_get_type(Il2CppMethodPointer getTypeFunction, String_t* typeName, bool throwOnError, bool ignoreCase, const char* assemblyName)
{
typedef Type_t* (*getTypeFuncType)(String_t*, bool, bool, const RuntimeMethod*);
MonoString* assemblyQualifiedTypeName = mono_unity_string_append_assembly_name_if_necessary((MonoString*)typeName, assemblyName);
// Try to find the type using a hint about about calling assembly. If it is not found, fall back to calling GetType without the hint.
Type_t* type = ((getTypeFuncType)getTypeFunction)((String_t*)assemblyQualifiedTypeName, throwOnError, ignoreCase, NULL);
if (type == NULL)
return ((getTypeFuncType)getTypeFunction)(typeName, throwOnError, ignoreCase, NULL);
return type;
}
inline Assembly_t* il2cpp_codegen_get_executing_assembly(const RuntimeMethod* method)
{
return (Assembly_t*)mono_assembly_get_object(g_MonoDomain, mono_unity_class_get_assembly(mono_unity_method_get_class(method)));
}
// Atomic
inline void* il2cpp_codegen_atomic_compare_exchange_pointer(void* volatile* dest, void* exchange, void* comparand)
{
IL2CPP_NOT_IMPLEMENTED("COM is not yet supported with the libmonoruntime backend.");
return NULL;
}
template<typename T>
inline T* il2cpp_codegen_atomic_compare_exchange_pointer(T* volatile* dest, T* newValue, T* oldValue)
{
IL2CPP_NOT_IMPLEMENTED("COM is not yet supported with the libmonoruntime backend.");
return NULL;
}
// COM
inline void il2cpp_codegen_com_marshal_variant(RuntimeObject* obj, Il2CppVariant* variant)
{
IL2CPP_NOT_IMPLEMENTED("COM is not yet supported with the libmonoruntime backend.");
}
inline RuntimeObject* il2cpp_codegen_com_marshal_variant_result(Il2CppVariant* variant)
{
IL2CPP_NOT_IMPLEMENTED("COM is not yet supported with the libmonoruntime backend.");
return NULL;
}
inline void il2cpp_codegen_com_destroy_variant(Il2CppVariant* variant)
{
IL2CPP_NOT_IMPLEMENTED("COM is not yet supported with the libmonoruntime backend.");
}
inline Il2CppSafeArray* il2cpp_codegen_com_marshal_safe_array(Il2CppChar type, RuntimeArray* managedArray)
{
IL2CPP_NOT_IMPLEMENTED("COM is not yet supported with the libmonoruntime backend.");
return NULL;
}
inline RuntimeArray* il2cpp_codegen_com_marshal_safe_array_result(Il2CppChar variantType, RuntimeClass* type, Il2CppSafeArray* safeArray)
{
IL2CPP_NOT_IMPLEMENTED("COM is not yet supported with the libmonoruntime backend.");
return NULL;
}
inline Il2CppSafeArray* il2cpp_codegen_com_marshal_safe_array_bstring(RuntimeArray* managedArray)
{
IL2CPP_NOT_IMPLEMENTED("COM is not yet supported with the libmonoruntime backend.");
return NULL;
}
inline RuntimeArray* il2cpp_codegen_com_marshal_safe_array_bstring_result(RuntimeClass* type, Il2CppSafeArray* safeArray)
{
IL2CPP_NOT_IMPLEMENTED("COM is not yet supported with the libmonoruntime backend.");
return NULL;
}
inline void il2cpp_codegen_com_destroy_safe_array(Il2CppSafeArray* safeArray)
{
IL2CPP_NOT_IMPLEMENTED("COM is not yet supported with the libmonoruntime backend.");
}
inline void il2cpp_codegen_com_create_instance(const Il2CppGuid& clsid, Il2CppIUnknown** identity)
{
IL2CPP_NOT_IMPLEMENTED("COM is not yet supported with the libmonoruntime backend.");
}
inline void il2cpp_codegen_com_register_rcw(Il2CppComObject* rcw)
{
IL2CPP_NOT_IMPLEMENTED("COM is not yet supported with the libmonoruntime backend.");
}
template<typename T>
inline T* il2cpp_codegen_com_get_or_create_rcw_from_iunknown(Il2CppIUnknown* unknown, RuntimeClass* fallbackClass)
{
IL2CPP_NOT_IMPLEMENTED("COM is not yet supported with the libmonoruntime backend.");
return NULL;
}
template<typename T>
inline T* il2cpp_codegen_com_get_or_create_rcw_from_iinspectable(Il2CppIInspectable* unknown, RuntimeClass* fallbackClass)
{
IL2CPP_NOT_IMPLEMENTED("COM is not yet supported with the libmonoruntime backend.");
return NULL;
}
template<typename T>
inline T* il2cpp_codegen_com_get_or_create_rcw_for_sealed_class(Il2CppIUnknown* unknown, RuntimeClass* objectClass)
{
IL2CPP_NOT_IMPLEMENTED("COM is not yet supported with the libmonoruntime backend.");
return NULL;
}
inline void il2cpp_codegen_il2cpp_com_object_cleanup(Il2CppComObject* rcw)
{
IL2CPP_NOT_IMPLEMENTED("COM is not yet supported with the libmonoruntime backend.");
}
template<typename InterfaceType>
inline InterfaceType* il2cpp_codegen_com_get_or_create_ccw(RuntimeObject* obj)
{
IL2CPP_NOT_IMPLEMENTED("COM is not yet supported with the libmonoruntime backend.");
return NULL;
}
inline intptr_t il2cpp_codegen_com_get_iunknown_for_object(RuntimeObject* obj)
{
IL2CPP_NOT_IMPLEMENTED("COM is not yet supported with the libmonoruntime backend.");
return 0;
}
inline void il2cpp_codegen_com_raise_exception(il2cpp_hresult_t hr)
{
IL2CPP_NOT_IMPLEMENTED("COM is not yet supported with the libmonoruntime backend.");
}
inline void il2cpp_codegen_com_raise_exception_if_failed(il2cpp_hresult_t hr, bool defaultToCOMException)
{
IL2CPP_NOT_IMPLEMENTED("COM is not yet supported with the libmonoruntime backend.");
}
inline RuntimeException* il2cpp_codegen_com_get_exception(il2cpp_hresult_t hr, bool defaultToCOMException)
{
IL2CPP_NOT_IMPLEMENTED("Not implemented yet.");
return NULL;
}
inline RuntimeException* il2cpp_codegen_com_get_exception_for_invalid_iproperty_cast(RuntimeObject* value, const char* a, const char* b)
{
IL2CPP_NOT_IMPLEMENTED("COM is not yet supported with the libmonoruntime backend.");
return NULL;
}
inline Il2CppIActivationFactory* il2cpp_codegen_windows_runtime_get_activation_factory(const il2cpp::utils::StringView<Il2CppNativeChar>& runtimeClassName)
{
IL2CPP_NOT_IMPLEMENTED("COM is not yet supported with the libmonoruntime backend.");
return NULL;
}
// delegate
inline Il2CppAsyncResult* il2cpp_codegen_delegate_begin_invoke(RuntimeDelegate* delegate, void** params, RuntimeDelegate* asyncCallback, RuntimeObject* state)
{
return il2cpp_mono_delegate_begin_invoke(delegate, params, asyncCallback, state);
}
inline RuntimeObject* il2cpp_codegen_delegate_end_invoke(Il2CppAsyncResult* asyncResult, void **out_args)
{
return il2cpp_mono_delegate_end_invoke(asyncResult, out_args);
}
inline const Il2CppGenericInst* il2cpp_codegen_get_generic_class_inst(RuntimeClass* genericClass)
{
IL2CPP_NOT_IMPLEMENTED("Windows runtime is not yet supported with the libmonoruntime backend.");
return NULL;
}
inline RuntimeClass* il2cpp_codegen_inflate_generic_class(RuntimeClass* genericClassDefinition, const Il2CppGenericInst* genericInst)
{
//return il2cpp::vm::Class::GetInflatedGenericInstanceClass(genericClassDefinition, genericInst);
IL2CPP_NOT_IMPLEMENTED("Windows runtime is not yet supported with the libmonoruntime backend.");
return NULL;
}
inline RuntimeAssembly* il2cpp_codegen_mono_corlib()
{
return mono_unity_assembly_get_mscorlib();
}
inline RuntimeClass* il2cpp_codegen_mono_class(AssemblyIndex assemblyIndex, uint32_t classToken)
{
return mono_class_get(mono_assembly_get_image(il2cpp_mono_assembly_from_index(assemblyIndex)), classToken);
}
inline RuntimeClass* il2cpp_codegen_mono_class(RuntimeAssembly* assembly, uint32_t classToken)
{
return mono_class_get(mono_assembly_get_image(assembly), classToken);
}
inline RuntimeMethod* il2cpp_codegen_mono_method(AssemblyIndex index, uint32_t methodToken)
{
return mono_get_method(mono_assembly_get_image(il2cpp_mono_assembly_from_index(index)), methodToken, NULL);
}
inline RuntimeMethod* il2cpp_codegen_mono_method(RuntimeAssembly* assembly, uint32_t methodToken)
{
return mono_get_method(mono_assembly_get_image(assembly), methodToken, NULL);
}
inline void* il2cpp_codegen_mono_get_static_field_address(RuntimeClass* klass, RuntimeField* field)
{
return il2cpp_mono_get_static_field_address(klass, field);
}
inline void* il2cpp_codegen_mono_get_thread_static_field_address(RuntimeClass* klass, RuntimeField* field)
{
return il2cpp_mono_get_thread_static_field_address(klass, field);
}
inline RuntimeField* il2cpp_codegen_mono_class_get_field(RuntimeClass* klass, uint32_t fieldToken)
{
return mono_class_get_field(klass, fieldToken);
}
inline Il2CppMethodPointer il2cpp_codegen_get_method_pointer(const RuntimeMethod* method)
{
MonoError unused;
il2cpp_mono_method_initialize_function_pointers(const_cast<RuntimeMethod*>(method), &unused);
return (Il2CppMethodPointer)mono_unity_method_get_method_pointer(const_cast<RuntimeMethod*>(method));
}
inline RuntimeType* il2cpp_codegen_method_return_type(const RuntimeMethod* method)
{
return mono_signature_get_return_type(mono_method_signature(const_cast<RuntimeMethod*>(method)));
}
inline int il2cpp_codegen_method_parameter_count(const RuntimeMethod* method)
{
return mono_signature_get_param_count(mono_method_signature(const_cast<RuntimeMethod*>(method)));
}
template<class T>
T il2cpp_mono_cast_nullable_method_param(const RuntimeMethod *method, int index, void *value)
{
if (value)
return *((T*)value);
T retVal;
RuntimeClass *klass = mono_unity_signature_get_class_for_param(mono_method_signature(const_cast<RuntimeMethod*>(method)), index);
mono_nullable_init((uint8_t*)&retVal, NULL, klass);
return retVal;
}
inline const RuntimeMethod* il2cpp_codegen_vtable_slot_method(const RuntimeClass* klass, RuntimeMethod* slot)
{
return slot;
}
inline Il2CppMethodPointer il2cpp_codegen_vtable_slot_method_pointer(const RuntimeClass* klass, RuntimeMethod* slot)
{
MonoError unused;
il2cpp_mono_method_initialize_function_pointers(slot, &unused);
return (Il2CppMethodPointer)mono_unity_method_get_method_pointer(slot);
}
inline bool il2cpp_codegen_is_import_or_windows_runtime(const RuntimeObject *object)
{
assert(0 && "Not implemented yet.");
return false;
}
inline std::string il2cpp_codegen_format_exception(const RuntimeException* ex)
{
return il2cpp_mono_format_exception(ex);
}
inline intptr_t il2cpp_codegen_get_com_interface_for_object(RuntimeObject* object, Type_t* type)
{
assert(0 && "Not implemented yet.");
return 0;
}
inline NORETURN void il2cpp_codegen_raise_profile_exception(const RuntimeMethod* method)
{
il2cpp_codegen_raise_exception(il2cpp_codegen_get_not_supported_exception(mono_unity_method_get_name(method)));
}
@@ -0,0 +1,55 @@
#pragma once
struct String_t;
struct Type_t;
struct Exception_t;
struct StringBuilder_t;
struct MulticastDelegate_t;
struct MethodBase_t;
struct Assembly_t;
#if RUNTIME_MONO
extern "C"
{
#include <mono/metadata/class.h>
#include <mono/metadata/image.h>
#include <mono/metadata/metadata.h>
#include <mono/metadata/object.h>
#include <mono/metadata/object-internals.h>
}
typedef MonoClass RuntimeClass;
typedef MonoMethod RuntimeMethod;
typedef MonoClassField RuntimeField;
typedef MonoType RuntimeType;
typedef MonoObject RuntimeObject;
typedef MonoImage RuntimeImage;
typedef MonoException RuntimeException;
typedef MonoArray RuntimeArray;
typedef MonoAssembly RuntimeAssembly;
typedef MonoString RuntimeString;
typedef MonoStringBuilder RuntimeStringBuilder;
typedef MonoDelegate RuntimeDelegate;
#include "il2cpp-codegen-mono.h"
#else
struct TypeInfo;
struct MethodInfo;
struct FieldInfo;
struct Il2CppType;
typedef Il2CppClass RuntimeClass;
typedef MethodInfo RuntimeMethod;
typedef FieldInfo RuntimeField;
typedef Il2CppType RuntimeType;
typedef Il2CppObject RuntimeObject;
typedef Il2CppImage RuntimeImage;
typedef Il2CppException RuntimeException;
typedef Il2CppArray RuntimeArray;
typedef Il2CppAssembly RuntimeAssembly;
typedef Il2CppString RuntimeString;
struct Il2CppStringBuilder;
typedef Il2CppStringBuilder RuntimeStringBuilder;
typedef Il2CppDelegate RuntimeDelegate;
#include "il2cpp-codegen-il2cpp.h"
#endif