public static tAsyncCall *get_IsGenericType(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue) { tMD_TypeDef *pType = ((tRuntimeType *)pThis_)->pTypeDef; *(uint *)pReturnValue = (MetaData.TYPE_ISGENERICINSTANCE(pType) || pType->isGenericDefinition != 0) ? (uint)1 : (uint)0; return(null); }
public static tAsyncCall *Internal_GetInfo(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue) { tMD_TypeDef * pEnumType = System_RuntimeType.DeRef((byte *)((tMD_TypeDef **)pParams)[0]); uint i, retIndex; /*HEAP_PTR*/ byte *names, values; // An enum type always has just one non-literal field, with all other fields being the values. names = System_Array.NewVector(Type.types[Type.TYPE_SYSTEM_ARRAY_STRING], pEnumType->numFields - 1); values = System_Array.NewVector(Type.types[Type.TYPE_SYSTEM_ARRAY_INT32], pEnumType->numFields - 1); for (i = 0, retIndex = 0; i < pEnumType->numFields; i++) { tMD_FieldDef * pField = pEnumType->ppFields[i]; tSystemString *name; int value; if (!MetaData.FIELD_ISLITERAL(pField)) { continue; } name = System_String.FromCharPtrASCII(pField->name); System_Array.StoreElement(names, retIndex, (byte *)&name); MetaData.GetConstant(pField->pMetaData, pField->tableIndex, (byte *)&value); System_Array.StoreElement(values, retIndex, (byte *)&value); retIndex++; } *(((/*HEAP_PTR*/ byte ***)pParams)[1]) = names; *(((/*HEAP_PTR*/ byte ***)pParams)[2]) = values; return(null); }
public static tAsyncCall *GetGenericArguments(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue) { tMD_TypeDef * pType = ((tRuntimeType *)pThis_)->pTypeDef; tMD_TypeDef * pCoreType; uint i, argCount = 0; /*HEAP_PTR*/ byte *ret; pCoreType = pType->pGenericDefinition; if (pCoreType != null) { // Find the core instantiation of this type tGenericInstance *pInst = pCoreType->pGenericInstances; while (pInst != null) { if (pInst->pInstanceTypeDef == pType) { // Found it! argCount = pInst->numTypeArgs; } pInst = pInst->pNext; } } ret = System_Array.NewVector(Type.types[Type.TYPE_SYSTEM_ARRAY_TYPE], argCount); // Allocate to return value straight away, so it cannot be GCed *(/*HEAP_PTR*/ byte **)pReturnValue = ret; for (i = 0; i < argCount; i++) { /*HEAP_PTR*/ byte *argType = Type.GetTypeObject(pType->ppClassTypeArgs[i]); System_Array.StoreElement(ret, i, (byte *)&argType); } return(null); }
public static void WrapMonoAssembly(tMetaData *pMetaData, System.Reflection.Assembly assembly) { System.Type[] types = assembly.GetTypes(); pMetaData->tables.numRows[MetaDataTable.MD_TABLE_TYPEDEF] = (uint)types.Length; tMD_TypeDef *pTypeDefs = (tMD_TypeDef *)Mem.malloc((SIZE_T)(sizeof(tMD_TypeDef) * types.Length)); Mem.memset(pTypeDefs, 0, (SIZE_T)(sizeof(tMD_TypeDef) * types.Length)); for (int i = 0; i < types.Length; i++) { tMD_TypeDef *pTypeDef = &pTypeDefs[i]; System.Type monoType = types[i]; pTypeDef->pMetaData = pMetaData; pTypeDef->name = new S(monoType.Name); pTypeDef->nameSpace = new S(monoType.Namespace); pTypeDef->monoType = new H(monoType); pTypeDef->flags = (monoType.IsInterface ? TYPEATTRIBUTES_INTERFACE : 0); pTypeDef->isValueType = (byte)(monoType.IsValueType ? 1 : 0); pTypeDef->isGenericDefinition = (byte)(types[i].IsGenericTypeDefinition ? 1 : 0); MonoType.monoTypes[monoType] = (PTR)pTypeDef; } pMetaData->tables.data[MetaDataTable.MD_TABLE_TYPEDEF] = (PTR)pTypeDefs; }
public static tAsyncCall *GetTypeFromHandle(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue) { tMD_TypeDef *pTypeDef = *(tMD_TypeDef **)pParams; *(/*HEAP_PTR*/ byte **)pReturnValue = Type.GetTypeObject(pTypeDef); return(null); }
public static /*HEAP_PTR*/ byte *AllocMonoObject(tMD_TypeDef *pTypeDef, object monoObject) { byte * pMem = AllocType(pTypeDef); void **ppMonoHandle = (void **)pMem; *ppMonoHandle = H.Alloc(monoObject); return(pMem); }
public static /*HEAP_PTR*/ byte *AllocMonoObject(tMD_TypeDef *pTypeDef, object monoObject) { byte * pMem = AllocType(pTypeDef); void **ppGCHandle = (void **)pMem; *ppGCHandle = (void *)(System.IntPtr)GCHandle.Alloc(monoObject); return(pMem); }
public static /*HEAP_PTR*/ byte *Box(tMD_TypeDef *pType, byte *pMem) { /*HEAP_PTR*/ byte *boxed; boxed = AllocType(pType); Mem.memcpy((void *)boxed, (void *)pMem, pType->instanceMemSize); return(boxed); }
public static tAsyncCall *CreateInstance(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue) { tRuntimeType *pRuntimeType = (*((tRuntimeType **)(pParams + 0))); tMD_TypeDef * pElementType = System_RuntimeType.DeRef((byte *)pRuntimeType); tMD_TypeDef * pArrayType = Type.GetArrayTypeDef(pElementType, null, null); uint length = (*((uint *)(pParams + Sys.S_PTR))); Sys.INTERNALCALL_RESULT_PTR(pReturnValue, System_Array.NewVector(pArrayType, length)); return(null); }
public static /*HEAP_PTR*/ byte *NewVector(tMD_TypeDef *pArrayTypeDef, uint length) { uint heapSize; tSystemArray *pArray; heapSize = (uint)(sizeof(tSystemArray) + length * pArrayTypeDef->pArrayElementType->arrayElementSize); pArray = (tSystemArray *)Heap.Alloc(pArrayTypeDef, heapSize); pArray->length = length; return((/*HEAP_PTR*/ byte *)pArray); }
/// <summary> /// Call to a DNA method given it's method def. /// </summary> /// <param name="methodDef">The method def</param> /// <param name="args">The arguments to pass (or null for no arguments)</param> /// <returns>The value returned by the method.</returns> public object Call(ulong methodDef, object[] args = null) { if (dnaPtr == null) { throw new System.NullReferenceException(); } tMD_TypeDef *pTypeDef = Heap.GetType(dnaPtr); return(Dna.Call(methodDef, this, args)); }
public static /*HEAP_PTR*/ byte *New(tMD_TypeDef *pTypeDef) { tRuntimeType *pRuntimeType; pRuntimeType = (tRuntimeType *)Heap.AllocType(Type.types[Type.TYPE_SYSTEM_RUNTIMETYPE]); Heap.MakeUndeletable((/*HEAP_PTR*/ byte *)pRuntimeType); pRuntimeType->pTypeDef = pTypeDef; return((/*HEAP_PTR*/ byte *)pRuntimeType); }
/// <summary> /// Call a method on a DNA type with a typedef and method name. /// </summary> /// <param name="typeDef">Pointer to the type def</param> /// <param name="methodName">The name of the method</param> /// <param name="argTypes">The argument types</param> /// <param name="args">The arguments to pass (or null for no arguments)</param> /// <returns>The value returned by the method.</returns> public object Call(string methodName, System.Type[] argTypes = null, object[] args = null) { if (dnaPtr == null) { throw new System.NullReferenceException(); } tMD_TypeDef *pTypeDef = Heap.GetType(dnaPtr); return(Dna.Call((ulong)pTypeDef, methodName, argTypes, this, args)); }
public static tAsyncCall *get_IsEnum(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue) { tMD_TypeDef *pType = ((tRuntimeType *)pThis_)->pTypeDef; uint isEnum = (pType->pParent == Type.types[Type.TYPE_SYSTEM_ENUM]) ? (uint)1 : (uint)0; *(uint *)pReturnValue = isEnum; return(null); }
/// <summary> /// Returns a method def given method name and argument types for this object. /// </summary> /// <param name="methodName"></param> /// <param name="argTypes"></param> /// <returns></returns> public ulong FindMethod(string methodName, System.Type[] argTypes) { if (dnaPtr == null) { throw new System.NullReferenceException(); } tMD_TypeDef *pTypeDef = Heap.GetType(dnaPtr); return(Dna.FindMethod((ulong)pTypeDef, methodName, argTypes)); }
public static void Fill_Defer(tMD_TypeDef *pTypeDef, tMD_TypeDef **ppClassTypeArgs, tMD_TypeDef **ppMethodTypeArgs) { if (typesToFill != null && pTypeDef->fillState < Type.TYPE_FILL_ALL && !typesToFill.ContainsKey((PTR)pTypeDef)) { typesToFill.Add((PTR)pTypeDef, new FillState { pTypeDef = pTypeDef, ppClassTypeArgs = ppClassTypeArgs, ppMethodTypeArgs = ppMethodTypeArgs }); } }
// Get the size of a heap entry, NOT including the header // This works by returning the size of the type, unless the type is an array or a string, // which are the only two type that can have variable sizes static uint GetSize(tHeapEntry *pHeapEntry) { tMD_TypeDef *pType = pHeapEntry->pTypeDef; if (MetaData.TYPE_ISARRAY(pType)) { // If it's an array, return the array length * array element size return(System_Array.GetNumBytes(null /* This is ok */, (/*HEAP_PTR*/ byte *)(pHeapEntry + 1), pType->pArrayElementType)); } // If it's not array, just return the instance memory size return(pType->instanceMemSize); }
public static void Fill_FieldDef(tMD_TypeDef *pParentType, FieldInfo fieldInfo, tMD_FieldDef *pFieldDef, uint memOffset, uint *pAlignment, tMD_TypeDef **ppClassTypeArgs) { tMetaData *pMetaData; uint fieldSize; uint fieldAlignment; if (pFieldDef->isFilled == 1) { return; } pFieldDef->isFilled = 1; pFieldDef->pParentType = pParentType; pFieldDef->pType = MonoType.GetTypeForMonoType(fieldInfo.FieldType, ppClassTypeArgs, null); if (pFieldDef->pType == null) { // If the field is a core generic type definition, then we can't do anything more return; } if (pFieldDef->pType->fillState < Type.TYPE_FILL_LAYOUT) { MetaData.Fill_TypeDef(pFieldDef->pType, null, null); } else if (pFieldDef->pType->fillState < Type.TYPE_FILL_ALL) { MetaData.Fill_Defer(pFieldDef->pType, null, null); } if (pFieldDef->pType->isValueType != 0) { fieldSize = pFieldDef->pType->instanceMemSize; fieldAlignment = (pFieldDef->pType->isValueType == 0 || pFieldDef->pType->alignment == 0) ? sizeof(PTR) : pFieldDef->pType->alignment; } else { fieldSize = fieldAlignment = sizeof(PTR); } if (pAlignment != null && *pAlignment < fieldAlignment) { *pAlignment = fieldAlignment; } pFieldDef->memOffset = (memOffset + fieldAlignment - 1) & ~(fieldAlignment - 1); pFieldDef->memSize = fieldSize; pFieldDef->pFieldDef = pFieldDef; pFieldDef->monoFieldInfo = new H(fieldInfo); pFieldDef->monoGetter = new H(GetFieldTrampoline); pFieldDef->monoSetter = new H(SetFieldTrampoline); pMetaData = pFieldDef->pMetaData; }
public static tAsyncCall *Internal_GetGenericTypeDefinition(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue) { tMD_TypeDef *pType = ((tRuntimeType *)pThis_)->pTypeDef; if (MetaData.TYPE_ISGENERICINSTANCE(pType)) { pType = pType->pGenericDefinition; } *(/*HEAP_PTR*/ byte **)pReturnValue = Type.GetTypeObject(pType); return(null); }
public static void Fill_GetDeferredTypeArgs(tMD_TypeDef *pTypeDef, ref tMD_TypeDef **ppClassTypeArgs, ref tMD_TypeDef **ppMethodTypeArgs) { FillState state = new FillState(); if (typesToFill != null) { if (typesToFill.TryGetValue((PTR)pTypeDef, out state)) { ppClassTypeArgs = state.ppClassTypeArgs; ppMethodTypeArgs = state.ppMethodTypeArgs; } } }
public static /*HEAP_PTR*/ byte *AllocType(tMD_TypeDef *pTypeDef) { //printf("Heap.AllocType('%s')\n", pTypeDef->name); byte *pInst = Alloc(pTypeDef, pTypeDef->instanceMemSize); if (pTypeDef->hasMonoBase != 0) { tHeapEntry *pHeapEntry = (tHeapEntry *)((byte *)pInst - sizeof(tHeapEntry)); pHeapEntry->monoHandle = 1; } return(pInst); }
public static void GetHeapRoots(tHeapRoots *pHeapRoots, tMD_TypeDef *pTypeDef) { tGenericInstance *pInst = pTypeDef->pGenericInstances; while (pInst != null) { tMD_TypeDef *pInstTypeDef = pInst->pInstanceTypeDef; if (pInstTypeDef->staticFieldSize > 0) { Heap.SetRoots(pHeapRoots, pInstTypeDef->pStaticFields, pInstTypeDef->staticFieldSize); } pInst = pInst->pNext; } }
public static tMD_MethodDef *GetMethodDefFromCoreMethod(tMD_MethodDef *pCoreMethod, tMD_TypeDef *pParentType, uint numTypeArgs, tMD_TypeDef **ppTypeArgs, HashSet <PTR> resolveTypes = null) { tGenericMethodInstance *pInst; tMD_MethodDef * pMethod; int i; Mem.heapcheck(); // See if we already have an instance with the given type args pInst = pCoreMethod->pGenericMethodInstances; while (pInst != null) { if (pInst->numTypeArgs == numTypeArgs && Mem.memcmp(pInst->ppTypeArgs, ppTypeArgs, (SIZE_T)(numTypeArgs * sizeof(tMD_TypeDef *))) == 0) { return(pInst->pInstanceMethodDef); } pInst = pInst->pNext; } // We don't have an instance so create one now. pInst = (tGenericMethodInstance *)Mem.mallocForever((SIZE_T)(sizeof(tGenericMethodInstance))); pInst->pNext = pCoreMethod->pGenericMethodInstances; pCoreMethod->pGenericMethodInstances = pInst; pInst->numTypeArgs = numTypeArgs; pInst->ppTypeArgs = (tMD_TypeDef **)Mem.malloc((SIZE_T)(numTypeArgs * sizeof(tMD_TypeDef *))); Mem.memcpy(pInst->ppTypeArgs, ppTypeArgs, (SIZE_T)(numTypeArgs * sizeof(tMD_TypeDef *))); pInst->pInstanceMethodDef = pMethod = ((tMD_MethodDef *)Mem.mallocForever((SIZE_T)sizeof(tMD_MethodDef))); Mem.memset(pMethod, 0, (SIZE_T)sizeof(tMD_MethodDef)); pMethod->pMethodDef = pMethod; pMethod->pMetaData = pCoreMethod->pMetaData; pMethod->pCIL = pCoreMethod->pCIL; pMethod->implFlags = pCoreMethod->implFlags; pMethod->flags = pCoreMethod->flags; pMethod->name = pCoreMethod->name; pMethod->signature = pCoreMethod->signature; pMethod->vTableOfs = pCoreMethod->vTableOfs; pMethod->ppMethodTypeArgs = pInst->ppTypeArgs; MetaData.Fill_MethodDef(pParentType, pMethod, pParentType->ppClassTypeArgs, pInst->ppTypeArgs); Mem.heapcheck(); return(pMethod); }
/// <summary> /// Returns a DNA TypeDef for a given type. /// </summary> /// <param name="type">The fully qualified name of the type (namespace and type name)</param> /// <returns>The TypeDef or 0 if no type by that name was found</returns> public static ulong FindType(string type) { byte *className = stackalloc byte[128]; byte *nameSpace = stackalloc byte[128]; if (!_isInitialized) { Init(); } string[] split = type.Split('.'); if (split.Length < 1) { throw new System.ArgumentException("Type must have at least a type name"); } if (split.Length > 1) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); for (int i = 0; i < split.Length - 1; i++) { if (i > 0) { sb.Append('.'); } sb.Append(split[i]); } S.strncpy(nameSpace, sb.ToString(), 128); } else { nameSpace[0] = 0; } S.strncpy(className, split[split.Length - 1], 128); // Find any overload of the named method; assume it's the right one. // Specifying it exactly (type generic args, method generic args, arguments themselves, picking the // inherited methods if needed), is complex and not required at the moment. tMD_TypeDef *pTypeDef = CLIFile.FindTypeInAllLoadedAssemblies(nameSpace, className); if (pTypeDef->fillState < Type.TYPE_FILL_ALL) { MetaData.Fill_TypeDef(pTypeDef, null, null); } return((ulong)pTypeDef); }
public static tAsyncCall *GetElementType(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue) { tMD_TypeDef *pType = ((tRuntimeType *)pThis_)->pTypeDef; tMD_TypeDef *pElementTypeDef = pType->pArrayElementType; if (pElementTypeDef != null) { *(/*HEAP_PTR*/ byte **)pReturnValue = Type.GetTypeObject(pElementTypeDef); } else { *(/*HEAP_PTR*/ byte **)pReturnValue = null; } return(null); }
public static DnaObject CreateInstance(tMD_TypeDef *pTypeDef, object monoBaseObject = null) { Mem.heapcheck(); byte *pPtr = null; if (monoBaseObject != null) { pPtr = Heap.AllocMonoObject(pTypeDef, monoBaseObject); } else { pPtr = Heap.AllocType(pTypeDef); } Mem.heapcheck(); return(WrapObject(pPtr)); }
// TODO: This is not the most efficient way of doing this, as it has to search through all the // entries in the GenericParams table for all lookups. This can be improved. static tMD_GenericParam *FindGenericParam(tMD_TypeDef *pCoreType, uint typeArgIndex) { tMD_GenericParam *pGenericParam; uint i; pGenericParam = (tMD_GenericParam *)MetaData.GetTableRow(pCoreType->pMetaData, MetaData.MAKE_TABLE_INDEX(MetaDataTable.MD_TABLE_GENERICPARAM, 1)); for (i = 0; i < pCoreType->pMetaData->tables.numRows[MetaDataTable.MD_TABLE_GENERICPARAM]; i++, pGenericParam++) { if (pGenericParam->owner == pCoreType->tableIndex && pGenericParam->number == typeArgIndex) { return(pGenericParam); } } return(null); }
public static tAsyncCall *get_BaseType(tJITCallNative *pCallNative, byte *pThis_, byte *pParams, byte *pReturnValue) { tRuntimeType *pRuntimeType = (tRuntimeType *)pThis_; tMD_TypeDef * pBaseType = pRuntimeType->pTypeDef->pParent; if (pBaseType == null) { *(/*HEAP_PTR*/ byte **)pReturnValue = null; } else { *(/*HEAP_PTR*/ byte **)pReturnValue = Type.GetTypeObject(pBaseType); } return(null); }
public static bool TYPE_IMPLEMENTS(tMD_TypeDef *pTypeDef, tMD_TypeDef *pInterfaceDef) { for (int i = 0; i < pTypeDef->numInterfaces; i++) { tMD_TypeDef *pTypeInterfaceDef = pTypeDef->pInterfaceMaps[i].pInterface; while (pTypeInterfaceDef != null) { if (pTypeInterfaceDef == pInterfaceDef) { return(true); } pTypeInterfaceDef = pTypeInterfaceDef->pParent; } } return(false); }
static tMD_FieldDef *FindFieldInType(tMD_TypeDef *pTypeDef, /*STRING*/ byte *name) { uint i; MetaData.Fill_TypeDef(pTypeDef, null, null, Type.TYPE_FILL_LAYOUT); for (i = 0; i < pTypeDef->numFields; i++) { if (S.strcmp(pTypeDef->ppFields[i]->name, name) == 0) { return(pTypeDef->ppFields[i]); } } Sys.Crash("FindFieldInType(): Cannot find field '%s' in type %s.%s", (PTR)name, (PTR)pTypeDef->nameSpace, (PTR)pTypeDef->name); return(null); }