/* * private static TypedReference ClrMakeTypedReference(Object target, * FieldInfo[] flds); */ ILTypedRef _IL_TypedReference_ClrMakeTypedReference(ILExecThread *_thread, ILObject *target, System_Array *flds) { ILClass *classInfo; ILInt32 index; ILUInt32 offset; ILTypedRef ref; ILField *field; /* Get the initial class and offset */ classInfo = GetObjectClass(target); offset = 0; /* Resolve the fields within the object, level by level */ for(index = 0; index < ArrayLength(flds); ++index) { field = *((ILField **)(((ILObject **)(ArrayToBuffer(flds)))[index])); if(!field) { ILExecThreadThrowSystem (_thread, "System.ArgumentException", "Arg_MakeTypedRefFields"); ref.type = 0; ref.value = 0; return ref; } offset += field->offset; classInfo = ILClassFromType (ILContextNextImage(_thread->process->context, 0), 0, ILField_Type(field), 0); classInfo = ILClassResolve(classInfo); if(!classInfo || (index < (ArrayLength(flds) - 1) && !ILClassIsValueType(classInfo))) { ILExecThreadThrowSystem (_thread, "System.ArgumentException", "Arg_MakeTypedRefFields"); ref.type = 0; ref.value = 0; return ref; } } /* Populate the typed reference */ ref.type = (void *)classInfo; ref.value = (void *)(((unsigned char *)target) + offset); return ref; }
/* * private static Assembly[] GetAssembliesInternal(Object appDomain); */ System_Array *_IL_AppDomain_GetAssembliesInternal(ILExecThread *thread, ILObject *appDomain) { if(!IsAppDomainUnloaded(thread, (ILExecProcess *)appDomain)) { ILContext *context; ILImage *image; ILInt32 num; System_Array *array; ILObject **buffer; ILImage **images; ILImage **ptr; IL_METADATA_RDLOCK((ILExecProcess *)appDomain); context = ((ILExecProcess *)appDomain)->context; /* count out the number of images */ image = 0; num = 0; while((image = ILContextNextImage(context, image)) != 0) { ++num; } /* create the image array */ if (!(images = (ILImage **)ILMalloc(sizeof(ILImage *)*num))) { IL_METADATA_UNLOCK((ILExecProcess *)appDomain); ILExecThreadThrowOutOfMemory(thread); return 0; } /* fill the image array */ image = 0; ptr = images; while((image = ILContextNextImage(context, image)) != 0) { *ptr = image; ++ptr; } IL_METADATA_UNLOCK((ILExecProcess *)appDomain); /* create the assembly array */ array = (System_Array *)ILExecThreadNew(thread, "[oSystem.Reflection.Assembly;", "(Ti)V", (ILVaInt)num); if(!array) { ILExecThreadThrowOutOfMemory(thread); return 0; } /* fill the assembly array */ ptr = images; buffer = (ILObject **)(ArrayToBuffer(array)); while(num > 0) { *buffer = ImageToAssembly(thread, *ptr); ++buffer; ++ptr; --num; } /* cleanup */ ILFree(images); /* return the assembly array */ return array; } return (System_Array *)0; }