[add] first

This commit is contained in:
2023-10-08 10:24:48 +08:00
commit b1ae0510a9
1048 changed files with 3254361 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
#pragma once
#include "il2cpp-class-internals.h"
#include "../il2cpp-blob.h"
namespace il2cpp
{
namespace utils
{
class BlobReader
{
public:
// internal
static bool GetConstantValueFromBlob(const Il2CppImage* image, Il2CppTypeEnum type, const char *blob, void *value);
// This overload move the blob pointer as it reads
static bool GetConstantValueFromBlob(const Il2CppImage* image, Il2CppTypeEnum type, const char **blob, void *value, bool deserializeManagedObjects);
// Reads an encoded Il2CppTypeEnum
// For IL2CPP_TYPE_ENUM, the underlying Il2CppTypeEnum will be returned and klass will be the actual enum class
// For IL2CPP_TYPE_SZARRAY, klass will just be System.Array
// For all other Il2CppTypeEnum klass will the the correct Il2CppClass
static Il2CppTypeEnum ReadEncodedTypeEnum(const Il2CppImage* image, const char** blob, Il2CppClass** klass);
};
} /* utils */
} /* il2cpp */

View File

@@ -0,0 +1,23 @@
#pragma once
#include <cstdint>
namespace il2cpp
{
namespace utils
{
struct SourceLocation
{
const char* filePath;
uint32_t lineNumber;
};
class DebugSymbolReader
{
public:
static bool LoadDebugSymbols();
static bool GetSourceLocation(void* nativeInsturctionPointer, SourceLocation& sourceLocation);
static bool DebugSymbolsAvailable();
};
} /* namespace utils */
} /* namespace il2cpp */

View File

@@ -0,0 +1,234 @@
#pragma once
#include "il2cpp-class-internals.h"
struct Il2CppSequencePoint;
struct Il2CppCatchPoint;
struct Il2CppSequencePointExecutionContext;
struct Il2CppThreadUnwindState;
typedef void(*DebugInfoInitialization)();
typedef void(*ThreadCallback)(void*, uintptr_t);
typedef struct Il2CppSequencePointExecutionContext
{
const MethodInfo* method;
void** thisArg;
void** params;
void** locals;
Il2CppSequencePoint* currentSequencePoint;
int32_t tryId;
#ifdef __cplusplus
Il2CppSequencePointExecutionContext(const MethodInfo* method, void** thisArg, void** params, void** locals);
~Il2CppSequencePointExecutionContext();
#endif //__cplusplus
} Il2CppSequencePointExecutionContext;
typedef struct Il2CppThreadUnwindState
{
Il2CppSequencePointExecutionContext** executionContexts;
uint32_t frameCount;
uint32_t frameCapacity;
} Il2CppThreadUnwindState;
typedef int32_t (*Il2CppMonoInternalStackWalk) (void /*MonoStackFrameInfo*/ *frame, void /*MonoContext*/ *ctx, void* data);
struct Il2CppMonoInterpCallbacks
{
void* (*create_method_pointer) (MethodInfo *method, void /*MonoError*/ *error);
Il2CppObject* (*runtime_invoke) (MethodInfo *method, void *obj, void **params, Il2CppObject **exc, void /*MonoError*/ *error);
void (*init_delegate) (Il2CppDelegate *del);
#ifndef DISABLE_REMOTING
void* (*get_remoting_invoke) (void* imethod, void /*MonoError*/ *error);
#endif
void* (*create_trampoline) (Il2CppDomain *domain, MethodInfo *method, void /*MonoError*/ *error);
void (*walk_stack_with_ctx) (Il2CppMonoInternalStackWalk func, void /*MonoContext*/ *ctx, int32_t /*MonoUnwindOptions*/ options, void *user_data);
void (*set_resume_state) (void /*MonoJitTlsData*/ *jit_tls, Il2CppException *ex, void /*MonoJitExceptionInfo*/ *ei, Il2CppSequencePointExecutionContext* interp_frame, void* handler_ip);
int32_t (*run_finally) (void /*MonoStackFrameInfo*/ *frame, int clause_index, void* handler_ip);
int32_t (*run_filter) (void /*MonoStackFrameInfo*/ *frame, Il2CppException *ex, int clause_index, void* handler_ip);
void (*frame_iter_init) (void /*MonoInterpStackIter*/ *iter, void* interp_exit_data);
int32_t (*frame_iter_next) (void /*MonoInterpStackIter*/ *iter, void /*MonoStackFrameInfo*/ *frame);
void* /*MonoJitInfo*/ (*find_jit_info) (Il2CppDomain *domain, MethodInfo *method);
void (*set_breakpoint) (void /*MonoJitInfo*/ *jinfo, void* ip);
void (*clear_breakpoint) (void /*MonoJitInfo*/ *jinfo, void* ip);
void* /*MonoJitInfo*/ (*frame_get_jit_info) (Il2CppSequencePointExecutionContext* frame);
void* (*frame_get_ip) (Il2CppSequencePointExecutionContext* frame);
void* (*frame_get_arg) (Il2CppSequencePointExecutionContext* frame, int pos);
void* (*frame_get_local) (Il2CppSequencePointExecutionContext* frame, int pos);
void* (*frame_get_this) (Il2CppSequencePointExecutionContext* frame);
Il2CppSequencePointExecutionContext* (*frame_get_parent) (Il2CppSequencePointExecutionContext* frame);
void (*start_single_stepping) ();
void (*stop_single_stepping) ();
};
#ifdef __cplusplus
extern "C"
{
int32_t unity_sequence_point_active_entry(Il2CppSequencePoint *seqPoint);
int32_t unity_sequence_point_active_exit(Il2CppSequencePoint *seqPoint);
extern int32_t g_unity_pause_point_active;
}
#include <stdint.h>
#include "os/Atomic.h"
#include "os/ThreadLocalValue.h"
#undef IsLoggingEnabled
extern il2cpp::os::ThreadLocalValue s_ExecutionContexts;
namespace il2cpp
{
namespace os
{
class Thread;
}
namespace utils
{
class Debugger
{
public:
static void RegisterMetadata(const Il2CppDebuggerMetadataRegistration *data);
static void SetAgentOptions(const char* options);
static void RegisterTransport(const Il2CppDebuggerTransport* transport);
static void Init();
static void Start();
static void StartDebuggerThread();
static inline void PushExecutionContext(Il2CppSequencePointExecutionContext* executionContext)
{
Il2CppThreadUnwindState* unwindState;
s_ExecutionContexts.GetValue(reinterpret_cast<void**>(&unwindState));
if (unwindState->frameCount == unwindState->frameCapacity)
GrowFrameCapacity(unwindState);
unwindState->executionContexts[unwindState->frameCount] = executionContext;
unwindState->frameCount++;
}
static inline void PopExecutionContext()
{
Il2CppThreadUnwindState* unwindState;
s_ExecutionContexts.GetValue(reinterpret_cast<void**>(&unwindState));
IL2CPP_ASSERT(unwindState->frameCount > 0);
unwindState->frameCount--;
}
typedef void(*OnBreakPointHitCallback) (Il2CppSequencePoint* sequencePoint);
typedef void (*OnPausePointHitCallback) ();
static void RegisterCallbacks(OnBreakPointHitCallback breakCallback, OnPausePointHitCallback pauseCallback);
static Il2CppThreadUnwindState* GetThreadStatePointer();
static void SaveThreadContext(Il2CppThreadUnwindState* context, int frameCountAdjust);
static void FreeThreadContext(Il2CppThreadUnwindState* context);
static void OnBreakPointHit(Il2CppSequencePoint *sequencePoint);
static void OnPausePointHit();
static bool IsGlobalBreakpointActive();
static bool GetIsDebuggerAttached();
static void SetIsDebuggerAttached(bool attached);
static bool IsDebuggerThread(os::Thread* thread);
static void AllocateThreadLocalData();
static void FreeThreadLocalData();
static Il2CppSequencePoint* GetSequencePoint(const Il2CppImage* image, size_t id);
static Il2CppSequencePoint* GetSequencePoints(const MethodInfo* method, void**iter);
static Il2CppSequencePoint* GetSequencePoint(const Il2CppImage* image, Il2CppCatchPoint* cp);
static Il2CppCatchPoint* GetCatchPoints(const MethodInfo* method, void**iter);
static Il2CppSequencePoint* GetAllSequencePoints(void* *iter);
static void HandleException(Il2CppException *exc);
static const char** GetTypeSourceFiles(const Il2CppClass *klass, int& count);
static void UserBreak();
static bool IsLoggingEnabled();
static void Log(int level, Il2CppString *category, Il2CppString *message);
static inline bool IsSequencePointActive(Il2CppSequencePoint *seqPoint)
{
return il2cpp::os::Atomic::LoadRelaxed(&seqPoint->isActive) || g_unity_pause_point_active;
}
static inline bool IsSequencePointActiveEntry(Il2CppSequencePoint *seqPoint)
{
return unity_sequence_point_active_entry(seqPoint);
}
static inline bool IsSequencePointActiveExit(Il2CppSequencePoint *seqPoint)
{
return unity_sequence_point_active_exit(seqPoint);
}
static bool IsPausePointActive();
static const MethodInfo* GetSequencePointMethod(const Il2CppImage* image, Il2CppSequencePoint *seqPoint);
static const MethodInfo* GetCatchPointMethod(const Il2CppImage* image, Il2CppCatchPoint *catchPoint);
static inline void CheckSequencePoint(Il2CppSequencePointExecutionContext* executionContext, Il2CppSequencePoint* seqPoint)
{
if (IsSequencePointActive(seqPoint))
{
executionContext->currentSequencePoint = seqPoint;
OnBreakPointHit(seqPoint);
}
}
static inline void CheckSequencePointEntry(Il2CppSequencePointExecutionContext* executionContext, Il2CppSequencePoint* seqPoint)
{
if (IsSequencePointActiveEntry(seqPoint))
{
executionContext->currentSequencePoint = seqPoint;
OnBreakPointHit(seqPoint);
}
}
static inline void CheckSequencePointExit(Il2CppSequencePointExecutionContext* executionContext, Il2CppSequencePoint* seqPoint)
{
if (IsSequencePointActiveExit(seqPoint))
{
executionContext->currentSequencePoint = seqPoint;
OnBreakPointHit(seqPoint);
}
}
static void CheckPausePoint();
static const char* GetLocalName(const MethodInfo* method, int32_t index);
static const Il2CppMethodScope* GetLocalScope(const MethodInfo* method, int32_t index);
static void GetMethodExecutionContextInfo(const MethodInfo* method, uint32_t* executionContextInfoCount, const Il2CppMethodExecutionContextInfo **executionContextInfo, const Il2CppMethodHeaderInfo **headerInfo, const Il2CppMethodScope **scopes);
// The context parameter here is really il2cpp::vm::StackFrames*. We don't want to include vm/StackTrace.h in this file,
// as this one is included in generated code.
static void GetStackFrames(void* context);
static void AcquireLoaderLock();
static void ReleaseLoaderLock();
static bool LoaderLockIsOwnedByThisThread();
static Il2CppMonoInterpCallbacks* GetInterpCallbacks();
private:
static os::ThreadLocalValue s_IsGlobalBreakpointActive;
static void InitializeMethodToSequencePointMap();
static void InitializeTypeSourceFileMap();
static void InitializeMethodToCatchPointMap();
static void GrowFrameCapacity(Il2CppThreadUnwindState* unwindState);
};
}
}
inline Il2CppSequencePointExecutionContext::Il2CppSequencePointExecutionContext(const MethodInfo* method, void** thisArg, void** params, void** locals)
: method(method),
thisArg(thisArg),
params(params),
locals(locals),
currentSequencePoint(NULL),
tryId(-1)
{
il2cpp::utils::Debugger::PushExecutionContext(this);
}
inline Il2CppSequencePointExecutionContext::~Il2CppSequencePointExecutionContext()
{
il2cpp::utils::Debugger::PopExecutionContext();
// il2cpp_save_current_thread_context_func_exit();
}
#endif //__cplusplus

View File

@@ -0,0 +1,75 @@
#pragma once
struct Il2CppException;
namespace il2cpp
{
namespace utils
{
NORETURN void RethrowException(Il2CppException* exception);
template<typename FinallyBlock, bool isFault>
struct FinallyHelper
{
public:
inline FinallyHelper(FinallyBlock&& finallyBlock) :
m_Exception(nullptr),
// static cast to rvalue reference simulates std::move, as we don't want to include <utility> for all generated code
m_FinallyBlock(static_cast<FinallyBlock &&>(finallyBlock))
{
}
FinallyHelper(const FinallyHelper<FinallyBlock, isFault>&) = delete;
FinallyHelper& operator=(const FinallyHelper<FinallyBlock, isFault>&) = delete;
inline FinallyHelper(FinallyHelper<FinallyBlock, isFault>&& other) :
m_FinallyBlock(static_cast<FinallyBlock &&>(other.m_FinallyBlock))
{
}
inline FinallyHelper& operator=(FinallyHelper<FinallyBlock, isFault>&& other)
{
m_FinallyBlock = static_cast<FinallyBlock &&>(other.m_FinallyBlock);
return *this;
}
inline ~FinallyHelper() noexcept(false)
{
if (isFault)
{
if (m_Exception != nullptr)
{
m_FinallyBlock();
RethrowException(m_Exception);
}
}
else
{
m_FinallyBlock();
if (m_Exception != nullptr)
RethrowException(m_Exception);
}
}
inline void StoreException(Il2CppException* exception)
{
m_Exception = exception;
}
private:
Il2CppException* m_Exception;
FinallyBlock m_FinallyBlock;
};
template<typename FinallyBlock>
inline FinallyHelper<FinallyBlock, false> Finally(FinallyBlock&& finallyBlock)
{
return FinallyHelper<FinallyBlock, false>(static_cast<FinallyBlock &&>(finallyBlock));
}
template<typename FinallyBlock>
inline FinallyHelper<FinallyBlock, true> Fault(FinallyBlock&& finallyBlock)
{
return FinallyHelper<FinallyBlock, true>(static_cast<FinallyBlock &&>(finallyBlock));
}
}
}

View File

@@ -0,0 +1,16 @@
#pragma once
#include "il2cpp-api-types.h"
#include "il2cpp-metadata.h"
#if IL2CPP_ENABLE_NATIVE_STACKTRACES
struct MethodDefinitionKey
{
Il2CppMethodPointer method;
#if IL2CPP_TINY_DEBUG_METADATA && !IL2CPP_TINY_DEBUGGER
int32_t methodIndex;
#else
Il2CppMetadataMethodDefinitionHandle methodHandle;
#endif
};
#endif

View File

@@ -0,0 +1,28 @@
#pragma once
#if !RUINTIME_TINY
#include "vm/MetadataCache.h"
#endif
#include "vm/StackTrace.h"
#include "vm-utils/MethodDefinitionKey.h"
#include "vm-utils/VmMethod.h"
#include <stdint.h>
#include <vector>
namespace il2cpp
{
namespace utils
{
class NativeSymbol
{
public:
#if (IL2CPP_ENABLE_NATIVE_STACKTRACES && (!RUNTIME_TINY || IL2CPP_TINY_DEBUG_METADATA))
static void RegisterMethods(const std::vector<MethodDefinitionKey>& managedMethods);
static const VmMethod* GetMethodFromNativeSymbol(Il2CppMethodPointer nativeMethod);
static bool GetMethodDebugInfo(const MethodInfo* method, Il2CppMethodDebugInfo* methodDebugInfo);
#endif
};
} /* namespace vm */
} /* namespace mono */

View File

@@ -0,0 +1,9 @@
#pragma once
#include "il2cpp-config.h"
#if RUNTIME_TINY
typedef TinyMethod VmMethod;
#else // Assume the libil2cpp runtime
typedef MethodInfo VmMethod;
#endif

View File

@@ -0,0 +1,36 @@
#pragma once
#include "il2cpp-config.h"
#include <string>
namespace il2cpp
{
namespace utils
{
class LIBIL2CPP_CODEGEN_API VmStringUtils
{
public:
static Il2CppChar Utf16ToLower(Il2CppChar c);
static bool CaseSensitiveEquals(Il2CppString* left, const char* right);
static bool CaseSensitiveEquals(const char* left, const char* right);
static bool CaseInsensitiveEquals(Il2CppString* left, const char* right);
static bool CaseInsensitiveEquals(const char* left, const char* right);
struct CaseSensitiveComparer
{
bool operator()(const std::string& left, const std::string& right) const;
bool operator()(const std::string& left, const char* right) const;
bool operator()(const char* left, const std::string& right) const;
bool operator()(const char* left, const char* right) const;
};
struct CaseInsensitiveComparer
{
bool operator()(const std::string& left, const std::string& right) const;
bool operator()(const std::string& left, const char* right) const;
bool operator()(const char* left, const std::string& right) const;
bool operator()(const char* left, const char* right) const;
};
};
} // namespace utils
} // namespace il2cpp

View File

@@ -0,0 +1,25 @@
#pragma once
#include "il2cpp-config.h"
enum Il2CppStackPointerResult
{
Il2CppStackPointerNotSupported = -1,
Il2CppStackPointerIsNotOnStack = 0,
Il2CppStackPointerIsOnStack = 1,
};
namespace il2cpp
{
namespace utils
{
class LIBIL2CPP_CODEGEN_API VmThreadUtils
{
public:
static Il2CppStackPointerResult PointerIsOnCurrentThreadStack(void* ptr);
};
} // namespace utils
} // namespace il2cpp
#define IL2CPP_ASSERT_STACK_PTR(ptr) IL2CPP_ASSERT(ptr != NULL && il2cpp::utils::VmThreadUtils::PointerIsOnCurrentThreadStack(ptr) != Il2CppStackPointerIsNotOnStack)

View File

@@ -0,0 +1,52 @@
#pragma once
#include <stdint.h>
#include "il2cpp-config.h"
#include "il2cpp-object-internals.h"
#if RUNTIME_TINY
namespace tiny
#else
namespace il2cpp
#endif
{
namespace icalls
{
namespace mscorlib
{
namespace System
{
namespace Threading
{
class LIBIL2CPP_CODEGEN_API Interlocked
{
public:
static int32_t Add(int32_t* location1, int32_t value);
static int64_t Add64(int64_t* location1, int64_t value);
static int32_t CompareExchange(int32_t* location, int32_t value, int32_t comparand);
static int64_t CompareExchange64(int64_t* location1, int64_t value, int64_t comparand);
static double CompareExchangeDouble(double* location1, double value, double comparand);
static intptr_t CompareExchangeIntPtr(intptr_t* location, intptr_t value, intptr_t comparand);
static float CompareExchangeSingle(float* location1, float value, float comparand);
static void* CompareExchange_T(void** location, void* value, void* comparand);
static void CompareExchangeObject(void** location, void** value, void** comparand, void** res);
static int32_t Decrement(int32_t* location);
static int64_t Decrement64(int64_t* location);
static intptr_t ExchangeIntPtr(intptr_t* location, intptr_t value);
static int32_t Exchange(int32_t* location1, int32_t value);
static int64_t Exchange64(int64_t* location1, int64_t value);
static double ExchangeDouble(double* location1, double value);
static void* ExchangePointer(void** location1, void* value);
static void ExchangeObject(void** location1, void** value, void** res);
static float ExchangeSingle(float* location1, float value);
static int32_t Increment(int32_t* value);
static int64_t Increment64(int64_t* location);
static int64_t Read(int64_t* location);
static int32_t CompareExchange(int32_t* location1, int32_t value, int32_t comparand, bool* succeeded);
static void MemoryBarrierProcessWide();
};
} /* namespace Threading */
} /* namespace System */
} /* namespace mscorlib */
} /* namespace icalls */
} /* namespace tiny */

View File

@@ -0,0 +1,54 @@
#pragma once
#include "il2cpp-config.h"
#if RUNTIME_TINY
namespace tiny
#else
namespace il2cpp
#endif
{
namespace icalls
{
namespace mscorlib
{
namespace System
{
class LIBIL2CPP_CODEGEN_API Math
{
public:
static double Abs(double value);
static double Acos(double d);
static double Acosh(double d);
static double Asin(double d);
static double Asinh(double d);
static double Atan(double d);
static double Atan2(double y, double x);
static double Atanh(double d);
static double Cbrt(double d);
static double Ceiling(double a);
static double Cos(double d);
static double Cosh(double value);
static double Exp(double d);
static double Floor(double d);
static double FMod(double x, double y);
static double Log(double d);
static double Log10(double d);
static double ModF(double x, double* intptr);
static double Pow(double val, double exp);
static double Round(double x);
static double RoundDigits(double x, int32_t digits);
static double RoundMidpoint(double value, int32_t digits, bool away_from_zero);
static double Sin(double a);
static double Sinh(double value);
static double Sqrt(double d);
static double Tan(double a);
static double Tanh(double value);
static float Abs(float value);
#if IL2CPP_TINY
static double SplitFractionDouble(double* value);
#endif
};
} /* namespace System */
} /* namespace mscorlib */
} /* namespace icalls */
} /* namespace tiny */

View File

@@ -0,0 +1,41 @@
#pragma once
namespace il2cpp
{
namespace icalls
{
namespace mscorlib
{
namespace System
{
class LIBIL2CPP_CODEGEN_API MathF
{
public:
static float Acos(float x);
static float Acosh(float x);
static float Asin(float x);
static float Asinh(float x);
static float Atan(float x);
static float Atan2(float y, float x);
static float Atanh(float x);
static float Cbrt(float x);
static float Ceiling(float x);
static float Cos(float x);
static float Cosh(float x);
static float Exp(float x);
static float Floor(float x);
static float FMod(float x, float y);
static float Log(float x);
static float Log10(float x);
static float ModF(float x, float* intptr);
static float Pow(float x, float y);
static float Sin(float x);
static float Sinh(float x);
static float Sqrt(float x);
static float Tan(float x);
static float Tanh(float x);
};
} // namespace System
} // namespace mscorlib
} // namespace icalls
} // namespace il2cpp