[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,74 @@
#pragma once
#include <stdint.h>
#include "os/Mutex.h"
#include "il2cpp-class-internals.h"
namespace il2cpp
{
namespace metadata
{
class ArrayMetadata
{
public:
static Il2CppClass* GetBoundedArrayClass(Il2CppClass* elementClass, uint32_t rank, bool bounded);
typedef void(*ArrayTypeWalkCallback)(Il2CppClass* type, void* context);
static void WalkSZArrays(ArrayTypeWalkCallback callback, void* context);
static void WalkArrays(ArrayTypeWalkCallback callback, void* context);
// called as part of Class::Init with lock held
static void SetupArrayInterfaces(Il2CppClass* klass, const il2cpp::os::FastAutoLock& lock);
static void SetupArrayVTable(Il2CppClass* klass, const il2cpp::os::FastAutoLock& lock);
static void Clear();
/* From ECMA-335, I.8.7 Assignment compatibility:
The reduced type of a type T is the following:
1. If the underlying type of T is:
a. int8, or unsigned int8, then its reduced type is int8.
b. int16, or unsigned int16, then its reduced type is int16.
c. int32, or unsigned int32, then its reduced type is int32.
d. int64, or unsigned int64, then its reduced type is int64.
e. native int, or unsigned native int, then its reduced type is native int.
(NOTE: In NetFW/Mono (but not CoreCLR) implementations the reduced type is int32 or int64)
2. Otherwise, the reduced type is itself.
AND... enums are converted to their underlying type
*/
static inline Il2CppClass* GetArrayVarianceReducedType(Il2CppClass* type)
{
// Using castClass to handle reducing enum types - for enums castClass is the underling type
switch (type->castClass->byval_arg.type)
{
case IL2CPP_TYPE_I1:
case IL2CPP_TYPE_U1:
return il2cpp_defaults.sbyte_class;
case IL2CPP_TYPE_I2:
case IL2CPP_TYPE_U2:
return il2cpp_defaults.int16_class;
case IL2CPP_TYPE_I4:
case IL2CPP_TYPE_U4:
return il2cpp_defaults.int32_class;
case IL2CPP_TYPE_I8:
case IL2CPP_TYPE_U8:
return il2cpp_defaults.int64_class;
case IL2CPP_TYPE_I:
case IL2CPP_TYPE_U:
#if IL2CPP_SIZEOF_VOID_P == 8
return il2cpp_defaults.int64_class;
#else
return il2cpp_defaults.int32_class;
#endif
default:
return type;
}
}
};
} /* namespace vm */
} /* namespace il2cpp */

View File

@@ -0,0 +1,36 @@
#pragma once
#include "metadata/CustomAttributeDataReader.h"
#include "il2cpp-object-internals.h"
#include "vm-utils/VmThreadUtils.h"
namespace il2cpp
{
namespace metadata
{
class CustomAttributeCreator : public CustomAttributeReaderVisitor
{
private:
Il2CppObject* attr;
Il2CppException* exc;
public:
CustomAttributeCreator() : attr(NULL), exc(NULL)
{
// As currently implemented CustomAttributeCreator must be stack allocated
// It directly stores managed objects attr & exc so it must be either on the stack
// or in GC allocated memory
IL2CPP_ASSERT_STACK_PTR(this);
}
virtual void VisitCtor(const MethodInfo* ctor, CustomAttributeArgument args[], uint32_t argumentCount);
virtual void VisitField(const CustomAttributeFieldArgument& field, uint32_t index);
virtual void VisitProperty(const CustomAttributePropertyArgument& prop, uint32_t index);
Il2CppObject* GetAttribute(Il2CppException** exc);
private:
};
} /* namespace vm */
} /* namespace il2cpp */

View File

@@ -0,0 +1,144 @@
#pragma once
#include <stdint.h>
#include <vector>
#include "il2cpp-object-internals.h"
#include "gc/Allocator.h"
namespace il2cpp
{
namespace metadata
{
// This union is large enough to store any type
// that can be serialized by an attribute argument
// bool, byte, char, double, float, int, long, sbyte, short, string, uint, ulong, ushort, System.Object, System.Type, or an enum
// Or an szarray/vector of the previous types
union CustomAttributeDataStorage
{
Il2CppObject* obj;
int64_t i;
double d;
};
struct CustomAttributeArgument
{
Il2CppClass* klass;
CustomAttributeDataStorage data;
};
struct CustomAttributeFieldArgument
{
CustomAttributeArgument arg;
const FieldInfo* field;
};
struct CustomAttributePropertyArgument
{
CustomAttributeArgument arg;
const PropertyInfo* prop;
};
struct LazyCustomAttributeData
{
const MethodInfo* ctor;
const void* dataStart;
uint32_t dataLength;
};
struct CustomAttributeData
{
const MethodInfo* ctor;
};
class CustomAttributeReaderVisitor
{
public:
// This Visitor methods will be called in the defined order
virtual void VisitArgumentSizes(uint32_t argumentCount, uint32_t fieldCount, uint32_t propertyCount) {}
virtual void VisitArgument(const CustomAttributeArgument& argument, uint32_t index) {}
virtual void VisitCtor(const MethodInfo* ctor, CustomAttributeArgument args[], uint32_t argumentCount) {}
virtual void VisitField(const CustomAttributeFieldArgument& field, uint32_t index) {}
virtual void VisitProperty(const CustomAttributePropertyArgument& prop, uint32_t index) {}
};
class CustomAttributeDataIterator;
class CustomAttributeCtorIterator
{
private:
CustomAttributeCtorIterator(const char* ctorBuffer) : ctorBuffer(ctorBuffer)
{}
const char* ctorBuffer;
friend class CustomAttributeDataReader;
friend class CustomAttributeDataIterator;
};
class CustomAttributeDataIterator
{
private:
CustomAttributeDataIterator(const char* ctorBuffer, const char* dataBuffer) : dataBuffer(dataBuffer), ctorIter(ctorBuffer)
{}
const char* dataBuffer;
CustomAttributeCtorIterator ctorIter;
friend class CustomAttributeDataReader;
};
class CustomAttributeDataReader
{
public:
// Creates a CustomAttributeDataReader pointing into the metadata buffer start and end
// This range must be for a single metadata member
CustomAttributeDataReader(const void* buffer, const void* bufferEnd);
// Returns the number of custom attributes stored for the member
uint32_t GetCount();
// Iterate through all of the custom attribute constructors
// Call GetCtorIterator to get the iterator and call this method until it returns false
bool IterateAttributeCtors(const Il2CppImage* image, const MethodInfo** attributeCtor, CustomAttributeCtorIterator* iter);
// Iterate through all of the custom attribute data, but only return the attribute type and data range.
// This method does not allocate
// On each call LazyCustomAttributeData will be filled with new custom attribute data
// Call GetDataIterator to get the iterator and call this method until it returns false
// Call the static VisitCustomAttributeData function to get the attribute arguments from the LazyCustomAttributeData
// If this function returns false *exc may be non-null if an exception occured
bool ReadLazyCustomAttributeData(const Il2CppImage* image, LazyCustomAttributeData* data, CustomAttributeDataIterator* iter, Il2CppException** exc);
// Iterate through all of the custom attribute data and get all of the custom attriubte ctor arguments, fields, and parameter info
// On each call the CustomAttributeReaderVisitor will be called with the information for the current custom attribute
// If any of the arguments are managed types (e.g. string, object, arrays) this method will allocate them on the GC heap
// Call GetDataIterator to get the iterator and call this function until it returns false
// If this function returns false *exc may be non-null if an exception occured
bool VisitCustomAttributeData(const Il2CppImage* image, CustomAttributeDataIterator* iter, CustomAttributeReaderVisitor* visitor, Il2CppException** exc);
// Get the custom attribute ctor arguments, fields, and parameter info for a single custom attribute
// The CustomAttributeReaderVisitor will be called with the information for this custom attribute
// Call ReadLazyCustomAttributeData to get the dataStart & dataLength parameters
// If any of the arguments are managed types (e.g. string, object, arrays) this method will allocate them on the GC heap
// This method returns false on error
// If this function returns false *exc may be non-null if an exception occured
static bool VisitCustomAttributeData(const Il2CppImage* image, const MethodInfo* ctor, const void* dataStart, uint32_t dataLength, CustomAttributeReaderVisitor* visitor, Il2CppException** exc);
CustomAttributeCtorIterator GetCtorIterator();
CustomAttributeDataIterator GetDataIterator();
private:
const char* GetDataBufferStart();
CustomAttributeDataReader(const char* dataStart, uint32_t dataLength);
bool VisitCustomAttributeDataImpl(const Il2CppImage* image, const MethodInfo* ctor, CustomAttributeDataIterator* iter, CustomAttributeReaderVisitor* visitor, Il2CppException** exc, bool deserializedManagedObjects);
const char* bufferStart;
const char* bufferEnd;
uint32_t count;
};
} /* namespace vm */
} /* namespace il2cpp */

View File

@@ -0,0 +1,35 @@
#pragma once
#include <stdint.h>
#include <vector>
typedef bool (FieldInfoFilter)(FieldInfo*);
namespace il2cpp
{
namespace metadata
{
struct SizeAndAlignment
{
size_t size;
uint8_t alignment;
uint8_t naturalAlignment;
};
class FieldLayout
{
public:
struct FieldLayoutData
{
std::vector<size_t> FieldOffsets;
size_t classSize;
size_t actualClassSize;
uint8_t minimumAlignment;
uint8_t naturalAlignment;
};
static void LayoutFields(const Il2CppClass* klass, FieldInfoFilter filter, size_t parentSize, size_t actualParentSize, size_t parentAlignment, uint8_t packing, FieldLayoutData& data);
static SizeAndAlignment GetTypeSizeAndAlignment(const Il2CppType* type);
};
} /* namespace metadata */
} /* namespace il2cpp */

View File

@@ -0,0 +1,54 @@
#pragma once
#include <stdint.h>
#include "il2cpp-metadata.h"
#include "os/Mutex.h"
struct Il2CppGenericClass;
struct Il2CppGenericContext;
struct Il2CppGenericInst;
struct Il2CppGenericMethod;
union Il2CppRGCTXData;
struct Il2CppRGCTXDefinition;
struct Il2CppType;
struct MethodInfo;
struct ParameterInfo;
struct Il2CppClass;
namespace il2cpp
{
namespace metadata
{
class GenericMetadata
{
public:
static const Il2CppType** InflateParameters(const Il2CppType**, uint8_t parameterCount, const Il2CppGenericContext* context, bool inflateMethodVars);
static Il2CppGenericClass* GetGenericClass(const Il2CppClass* genericTypeDefinition, const Il2CppGenericInst* inst);
static Il2CppGenericClass* GetGenericClass(const Il2CppType* genericTypeDefinition, const Il2CppGenericInst* inst);
static const MethodInfo* Inflate(const MethodInfo* methodDefinition, const Il2CppGenericContext* context);
static const Il2CppGenericMethod* Inflate(const Il2CppGenericMethod* genericMethod, const Il2CppGenericContext* context);
static const Il2CppGenericInst* GetInflatedGenericIntance(const Il2CppGenericInst* inst, const Il2CppGenericContext* context, bool inflatMethodVars);
static Il2CppRGCTXData* InflateRGCTXLocked(const Il2CppImage* image, uint32_t token, const Il2CppGenericContext* context, const il2cpp::os::FastAutoLock& lock);
static void RegisterGenericClasses(Il2CppGenericClass* const* genericClasses, int32_t genericClassesCount);
static bool ContainsGenericParameters(const Il2CppClass* klass);
static bool ContainsGenericParameters(const MethodInfo* method);
static bool ContainsGenericParameters(const Il2CppGenericInst* inst);
static bool ContainsGenericParameters(const Il2CppType* type);
static const Il2CppType* InflateIfNeeded(const Il2CppType* type, const Il2CppGenericContext* context, bool inflateMethodVars);
typedef void(*GenericClassWalkCallback)(Il2CppClass* type, void* context);
static void WalkAllGenericClasses(GenericClassWalkCallback callback, void* context);
static int GetMaximumRuntimeGenericDepth();
static void SetMaximumRuntimeGenericDepth(int depth);
static int GetGenericVirtualIterations();
static void SetGenericVirtualIterations(int iterations);
static void Clear();
};
} /* namespace vm */
} /* namespace il2cpp */

View File

@@ -0,0 +1,42 @@
#pragma once
#include <string>
#include "il2cpp-class-internals.h"
#include "os/Mutex.h"
struct MethodInfo;
struct Il2CppGenericMethod;
struct Il2CppGenericContext;
struct Il2CppGenericInst;
namespace il2cpp
{
namespace metadata
{
class GenericMethod
{
public:
// exported
public:
//internal
static const MethodInfo* GetGenericVirtualMethod(const MethodInfo* vtableSlotMethod, const MethodInfo* genericVirtualMethod);
static const MethodInfo* GetMethod(const MethodInfo* methodDefinition, const Il2CppGenericInst* classInst, const Il2CppGenericInst* methodInst);
static const MethodInfo* GetMethod(const Il2CppGenericMethod* gmethod);
static MethodInfo* AllocateNewMethodInfo(const MethodInfo* methodDefinition, const Il2CppGenericInst* classInst, const Il2CppGenericInst* methodInst);
static bool IsGenericAmbiguousMethodInfo(const MethodInfo* method);
static Il2CppMethodPointer GetVirtualCallMethodPointer(const MethodInfo* method);
static const Il2CppGenericContext* GetContext(const Il2CppGenericMethod* gmethod);
static std::string GetFullName(const Il2CppGenericMethod* gmethod);
static void ClearStatics();
static const Il2CppRGCTXData* InflateRGCTX(const MethodInfo* method);
private:
static const MethodInfo* GetMethod(const Il2CppGenericMethod* gmethod, bool copyMethodPtr);
static const MethodInfo* CreateMethodLocked(const Il2CppGenericMethod* gmethod, bool copyMethodPtr);
static const Il2CppRGCTXData* InflateRGCTXLocked(const Il2CppGenericMethod* gmethod, const il2cpp::os::FastAutoLock& lock);
};
} /* namespace vm */
} /* namespace il2cpp */

View File

@@ -0,0 +1,17 @@
#pragma once
struct Il2CppGenericClass;
struct Il2CppGenericMethod;
namespace il2cpp
{
namespace metadata
{
class GenericSharing
{
public:
static bool IsShareable(Il2CppGenericClass* gclass);
static bool IsShareable(Il2CppGenericMethod* gmethod);
};
} /* namespace metadata */
} /* namespace il2cpp */

View File

@@ -0,0 +1,18 @@
#pragma once
#include "utils/KeyWrapper.h"
struct Il2CppGenericClass;
namespace il2cpp
{
namespace metadata
{
class Il2CppGenericClassCompare
{
public:
bool operator()(const Il2CppGenericClass* t1, const Il2CppGenericClass* t2) const;
static bool Compare(const Il2CppGenericClass* t1, const Il2CppGenericClass* t2);
};
} /* namespace vm */
} /* namespace il2cpp */

View File

@@ -0,0 +1,16 @@
#pragma once
struct Il2CppGenericClass;
namespace il2cpp
{
namespace metadata
{
class Il2CppGenericClassHash
{
public:
size_t operator()(const Il2CppGenericClass* ea) const;
static size_t Hash(const Il2CppGenericClass* t1);
};
} /* namespace vm */
} /* namespace il2cpp */

View File

@@ -0,0 +1,16 @@
#pragma once
struct Il2CppGenericContext;
namespace il2cpp
{
namespace metadata
{
class Il2CppGenericContextCompare
{
public:
bool operator()(const Il2CppGenericContext* t1, const Il2CppGenericContext* t2) const;
static bool Compare(const Il2CppGenericContext* t1, const Il2CppGenericContext* t2);
};
} /* namespace vm */
} /* namespace il2cpp */

View File

@@ -0,0 +1,16 @@
#pragma once
struct Il2CppGenericContext;
namespace il2cpp
{
namespace metadata
{
class Il2CppGenericContextHash
{
public:
size_t operator()(const Il2CppGenericContext* ea) const;
static size_t Hash(const Il2CppGenericContext* t1);
};
} /* namespace vm */
} /* namespace il2cpp */

View File

@@ -0,0 +1,19 @@
#pragma once
#include "utils/KeyWrapper.h"
struct Il2CppGenericInst;
namespace il2cpp
{
namespace metadata
{
class Il2CppGenericInstCompare
{
public:
bool operator()(const KeyWrapper<const Il2CppGenericInst*>& t1, const KeyWrapper<const Il2CppGenericInst*>& t2) const;
static bool Compare(const KeyWrapper<const Il2CppGenericInst*>& t1, const KeyWrapper<const Il2CppGenericInst*>& t2);
static bool AreEqual(const Il2CppGenericInst* left, const Il2CppGenericInst* right);
};
} /* namespace vm */
} /* namespace il2cpp */

View File

@@ -0,0 +1,16 @@
#pragma once
struct Il2CppGenericInst;
namespace il2cpp
{
namespace metadata
{
class Il2CppGenericInstHash
{
public:
size_t operator()(const Il2CppGenericInst* ea) const;
static size_t Hash(const Il2CppGenericInst* t1);
};
} /* namespace vm */
} /* namespace il2cpp */

View File

@@ -0,0 +1,17 @@
#pragma once
#include "utils/KeyWrapper.h"
struct Il2CppGenericMethod;
namespace il2cpp
{
namespace metadata
{
struct Il2CppGenericMethodCompare
{
bool operator()(const Il2CppGenericMethod* m1, const Il2CppGenericMethod* m2) const;
static bool Equals(const Il2CppGenericMethod* m1, const Il2CppGenericMethod* m2);
};
} /* namespace metadata */
} /* namespace il2cpp */

View File

@@ -0,0 +1,16 @@
#pragma once
struct Il2CppGenericMethod;
namespace il2cpp
{
namespace metadata
{
struct Il2CppGenericMethodHash
{
public:
size_t operator()(const Il2CppGenericMethod* method) const;
static size_t Hash(const Il2CppGenericMethod* method);
};
} /* namespace metadata */
} /* namespace il2cpp */

View File

@@ -0,0 +1,28 @@
#pragma once
struct Il2CppType;
namespace il2cpp
{
namespace metadata
{
struct Il2CppSignature
{
size_t Count;
const Il2CppType** Types;
};
struct Il2CppSignatureHash
{
public:
size_t operator()(const Il2CppSignature& signature) const;
static size_t Hash(const Il2CppSignature& signature);
};
struct Il2CppSignatureCompare
{
bool operator()(const Il2CppSignature& s1, const Il2CppSignature& s2) const;
static bool Equals(const Il2CppSignature& s1, const Il2CppSignature& s2);
};
} /* namespace metadata */
} /* namespace il2cpp */

View File

@@ -0,0 +1,24 @@
#pragma once
#include "utils/KeyWrapper.h"
struct Il2CppType;
namespace il2cpp
{
namespace metadata
{
class Il2CppTypeEqualityComparer
{
public:
bool operator()(const Il2CppType* t1, const Il2CppType* t2) const { return AreEqual(t1, t2); }
static bool AreEqual(const Il2CppType* t1, const Il2CppType* t2);
};
class Il2CppTypeLess
{
public:
bool operator()(const Il2CppType* t1, const Il2CppType* t2) const;
};
} /* namespace vm */
} /* namespace il2cpp */

View File

@@ -0,0 +1,16 @@
#pragma once
struct Il2CppType;
namespace il2cpp
{
namespace metadata
{
class Il2CppTypeHash
{
public:
size_t operator()(const Il2CppType* t1) const;
static size_t Hash(const Il2CppType* t1);
};
} /* namespace vm */
} /* namespace il2cpp */