/* * 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 void UnloadAppDomain(Object appDomain); */ void _IL_AppDomain_UnloadAppDomain(ILExecThread *thread, ILObject *appDomain) { if(!IsAppDomainUnloaded(thread, (ILExecProcess *)appDomain)) { #ifdef IL_CONFIG_APPDOMAINS if (appDomain) { ILExecEngine *engine = ILExecEngineInstance(); if (engine) /* this should always be true */ { /* we aren't allowed to unload the default AppDomain */ if ((ILExecProcess *)appDomain == engine->defaultProcess) { /* bail out */ /* Throw an CannotUnloadAppDomainException */ ILExecThreadThrowSystem(thread, "System.CannotUnloadAppDomainException", (const char *)0); return; } /* if the current thread runs in the specified process */ /* we need to start an other thread to do the Unload */ if (thread->process == (ILExecProcess *)appDomain) { /* TODO */ } ILExecProcessUnload((ILExecProcess *)appDomain); } } #else /* we don't support multiple Appdomains so there is nothing to do */ #endif } }
ILObject *_IL_Object_GetType(ILExecThread *thread, ILObject *_this) { ILObject *obj; /* Check if _this is Null. */ if(_this == 0) { ILExecThreadThrowSystem(thread, "System.NullReferenceException", (const char *)0); return 0; } /* Does the class already have a "ClrType" instance? */ if(GetObjectClassPrivate(_this)->clrType) { return GetObjectClassPrivate(_this)->clrType; } /* Create a new "ClrType" instance for the "ILClass" structure */ obj = _ILGetClrType(thread, GetObjectClass(_this)); if(!obj) { return 0; } /* Return the object to the caller */ return obj; }
/* * public RuntimeTypeHandle GetNextArgType(); */ void _IL_ArgIterator_GetNextArgType(ILExecThread *_thread, void *_result, void *_this) { ArgIterator *iter = (ArgIterator *)_this; ILObject *object; if(iter->un.argIter.args && iter->un.argIter.posn < ArrayLength(iter->un.argIter.args)) { /* Extract the next object and determine its type */ object = ((ILObject **)ArrayToBuffer(iter->un.argIter.args)) [iter->un.argIter.posn]; if(object) { *((ILClass **)_result) = GetObjectClass(object); } else { /* Points at a "null" object reference */ *((ILClass **)_result) = _thread->process->objectClass; } } else { /* We've reached the end of the argument list */ ILExecThreadThrowSystem(_thread, "System.InvalidOperationException", "Invalid_BadEnumeratorPosition"); *((ILClass **)_result) = _thread->process->objectClass; } }
/* * Check if the ILExecProcess is unloaded. */ static ILBool IsAppDomainUnloaded(ILExecThread *thread, ILExecProcess *process) { if(process->state >= _IL_PROCESS_STATE_UNLOADING) { ILExecThreadThrowSystem(thread, "System.AppDomainUnloadedException", 0); return (ILBool)1; } return (ILBool)0; }
/* * Do the real delegate invokation. */ static void _DelegateInvoke(ILDelegateInvokeParams *params) { ILMethod *method; ILType *type; ILUInt32 size; PackDelegateUserData userData; /* If this is a multicast delegate, then execute "prev" first */ if(params->delegate->prev) { ILDelegateInvokeParams prevParams; prevParams.thread = params->thread; prevParams.cif = params->cif; prevParams.result = params->result; prevParams.args = params->args; prevParams.delegate = (System_Delegate *)(params->delegate->prev); ; _DelegateInvoke(&prevParams); if(_ILExecThreadHasException(params->thread)) { return; } } /* Extract the method from the delegate */ method = params->delegate->methodInfo; if(!method) { ILExecThreadThrowSystem(params->thread, "System.MissingMethodException", (const char *)0); return; } /* Call the method */ userData.args = params->args; userData.pinvokeInfo = (ILMethod *)ILTypeGetDelegateMethod (ILType_FromClass(GetObjectClass(params->delegate))); userData.needThis = 0; if(_ILCallMethod(params->thread, method, UnpackDelegateResult, params->result, 0, params->delegate->target, PackDelegateParams, &userData)) { /* An exception occurred, which is already stored in the thread */ type = ILMethod_Signature(method); type = ILTypeGetEnumType(ILTypeGetReturn(type)); if(type != ILType_Void) { /* Clear the native return value, because we cannot assume that the native caller knows how to handle exceptions */ size = ILSizeOfType(params->thread, type); ILMemZero(params->result, size); } } }
/* * public TypedReference GetNextArg(RuntimeTypeHandle type); * * Note: this version is typically used by unmanaged C++ code, where * it is expected that the next argument is of a particular type. * We check the type and return the value. This is a little stricter * than other implementations, but it is also a lot safer. */ ILTypedRef _IL_ArgIterator_GetNextArg_RuntimeTypeHandle(ILExecThread *_thread, void *_this, void *type) { void *actualType = *((void **)type); int actualTypePrim; ILTypedRef ref; /* Convert the actual type into its primitive form */ actualTypePrim = ArgTypeToPrimitive (ILClassToType((ILClass *)actualType)); /* Get the next reference from the argument list */ ref = _IL_ArgIterator_GetNextArg_(_thread, _this); if(!(ref.type)) { /* An exception was thrown at the end of the list */ return ref; } /* Convert the argument type into its primitive form and compare */ if(ArgTypeToPrimitive(ILClassToType((ILClass *)(ref.type))) != actualTypePrim || actualTypePrim == IL_META_ELEMTYPE_END) { ILExecThreadThrowSystem(_thread, "System.InvalidOperationException", "Invalid_BadEnumeratorPosition"); ref.type = 0; ref.value = 0; return ref; } if(actualTypePrim == IL_META_ELEMTYPE_VALUETYPE && ref.type != actualType) { ILExecThreadThrowSystem(_thread, "System.InvalidOperationException", "Invalid_BadEnumeratorPosition"); ref.type = 0; ref.value = 0; return ref; } /* Convert the typed reference into the requested type and return it */ ref.type = actualType; return ref; }
/* * public static String GetNetBIOSMachineName(); */ ILString *_IL_InfoMethods_GetNetBIOSMachineName(ILExecThread *thread) { char *env; env = getenv("COMPUTERNAME"); if(env && *env != '\0') { return ILStringCreate(thread, env); } #ifdef IL_CONFIG_NETWORKING return _IL_DnsMethods_InternalGetHostName(thread); #else ILExecThreadThrowSystem(thread, "System.NotSupportedException", "Exception_ThreadsNotSupported"); return 0; #endif /* IL_CONFIG_NETWORKING */ }
/* * public TypedReference GetNextArg(); */ ILTypedRef _IL_ArgIterator_GetNextArg_(ILExecThread *_thread, void *_this) { ArgIterator *iter = (ArgIterator *)_this; ILTypedRef ref; ILObject **object; ILClass *classInfo; if(iter->un.argIter.args && iter->un.argIter.posn < ArrayLength(iter->un.argIter.args)) { /* Extract the next object and unpack it */ object = &(((ILObject **)ArrayToBuffer(iter->un.argIter.args)) [(iter->un.argIter.posn)++]); if(*object) { /* Determine if this is an object or a value type */ classInfo = GetObjectClass(*object); if(!ILClassIsValueType(classInfo)) { /* Object reference */ ref.type = classInfo; ref.value = (void *)object; } else { /* Value type reference */ ref.type = classInfo; ref.value = (void *)(*object); } } else { /* Points at a "null" object reference */ ref.type = _thread->process->objectClass; ref.value = (void *)object; } } else { /* We've reached the end of the argument list */ ILExecThreadThrowSystem(_thread, "System.InvalidOperationException", "Invalid_BadEnumeratorPosition"); ref.type = 0; ref.value = 0; } return ref; }
/* * public static double Int64BitsToDouble(long value); */ ILDouble _IL_BitConverter_Int64BitsToDouble(ILExecThread *thread, ILInt64 value) { #ifdef IL_CONFIG_FP_SUPPORTED union { ILInt64 input; ILDouble output; } convert; convert.input = value; return convert.output; #else ILExecThreadThrowSystem(thread, "System.NotImplementedException", 0); return 0; #endif }
/* * public static int FloatToInt32Bits(float value); */ ILInt32 _IL_BitConverter_FloatToInt32Bits(ILExecThread *thread, ILFloat value) { #ifdef IL_CONFIG_FP_SUPPORTED union { ILFloat input; ILInt32 output; } convert; convert.input = value; return convert.output; #else ILExecThreadThrowSystem(thread, "System.NotImplementedException", 0); return 0; #endif }
/* * private static void CreateAppDomain(ref Object appDomain); */ void _IL_AppDomain_CreateAppDomain(ILExecThread *thread, ILObject **appDomain) { #ifdef IL_CONFIG_APPDOMAINS ILExecProcess *process = ILExecProcessCreate(0, 0); if (process) { int error; ILImage *corlibImage; /* load the same corlib assembly as the default appdomain */ /* first get the corlib image of the default appdomain */ ILImage *image = ILContextGetSystem(ILExecEngineInstance()->defaultProcess->context); if((error = ILImageLoadFromFile(ILImageGetFileName(image), process->context, &corlibImage, process->loadFlags, 0))) { ILExecThreadThrowSystem(thread, "System.IO.FileNotFoundException", 0); } else { _ILExecProcessLoadStandard(process, corlibImage); /* return the new process */ *appDomain = (ILObject *)process; } } else { ILExecThreadThrowOutOfMemory(thread); } #else /* we don't support multiple Appdomains so return the current process of the thread */ *appDomain = (ILNativeInt)((void *)thread->process); #endif }