Exemple #1
0
        /// <summary>
        /// This thunk is used to lazily resolve Finalizer calls
        /// </summary>
        /// <param name="obj">Object to be finalized</param>
        private static void FinalizeThunk(object obj)
        {
            RuntimeTypeHandle rthType = RuntimeAugments.GetRuntimeTypeHandleFromObjectReference(obj);
            TypeSystemContext context = TypeSystemContextFactory.Create();
            TypeDesc          type    = context.ResolveRuntimeTypeHandle(rthType);

            MethodDesc finalizer = type.GetFinalizer();
            IntPtr     fnPtrFinalizer;

            if (!TryGetVTableCallableAddress(finalizer, out fnPtrFinalizer))
            {
                Environment.FailFast("Method address lookup failed for: " + finalizer.ToString());
            }

            TypeSystemContextFactory.Recycle(context);

            unsafe
            {
                rthType.ToEETypePtr()->FinalizerCode = fnPtrFinalizer;
            }

            // Call the finalizer directly. No need to play tricks with tail calling, as this is rare enough, it shouldn't happen much

            // Here we take advantage of the detail that the calling convention abi for a static function
            // that returns no values, and takes a single object parameter matches that of a
            // instance function that takes no parameters
            Intrinsics.Call(fnPtrFinalizer, obj);
        }
 private static void CctorHelper()
 {
     s_resolveCallOnReferenceTypeFuncPtr       = Intrinsics.AddrOf((ResolveCallOnReferenceTypeDel)ResolveCallOnReferenceType);
     s_resolveCallOnValueTypeFuncPtr           = Intrinsics.AddrOf((ResolveCallOnValueTypeDel)ResolveCallOnValueType);
     s_resolveCallOnReferenceTypeCacheMissFunc = RuntimeAugments.RegisterResolutionFunctionWithRuntimeCache(
         Intrinsics.AddrOf((RuntimeCacheFuncSignatureDel)ResolveCallOnReferenceTypeCacheMiss));
 }
Exemple #3
0
 /// <summary>
 /// Get the thunk that can represent all finalizers of metadata represented objects.
 /// </summary>
 public static IntPtr GetFinalizerThunk()
 {
     // Here we take advantage of the detail that the calling convention abi for a static function
     // that returns no values, and takes a single object parameter matches that of a
     // instance function that takes no parameters
     return(Intrinsics.AddrOf(new Action <object>(FinalizeThunk)));
 }
Exemple #4
0
        /// <summary>
        /// Initialize module info and construct per-module metadata reader.
        /// </summary>
        /// <param name="moduleHandle">Handle (address) of module to initialize</param>
        internal ModuleInfo(TypeManagerHandle moduleHandle, ModuleType moduleType)
        {
            Handle     = moduleHandle;
            ModuleType = moduleType;

            DynamicModule *dynamicModulePtr = (DynamicModule *)MemoryHelpers.AllocateMemory(sizeof(DynamicModule));

            dynamicModulePtr->CbSize = DynamicModule.DynamicModuleSize;
            Debug.Assert(sizeof(DynamicModule) >= dynamicModulePtr->CbSize);

            if ((moduleType == ModuleType.ReadyToRun) || (moduleType == ModuleType.Ecma))
            {
                // Dynamic type load modules utilize dynamic type resolution
                dynamicModulePtr->DynamicTypeSlotDispatchResolve = Intrinsics.AddrOf(
                    (Func <IntPtr, IntPtr, ushort, IntPtr>)ResolveTypeSlotDispatch);
            }
            else
            {
                Debug.Assert(moduleType == ModuleType.Eager);
                // Pre-generated modules do not
                dynamicModulePtr->DynamicTypeSlotDispatchResolve = IntPtr.Zero;
            }

            dynamicModulePtr->GetRuntimeException = Intrinsics.AddrOf(
                (Func <ExceptionIDs, Exception>)RuntimeExceptionHelpers.GetRuntimeException);

            DynamicModulePtr = dynamicModulePtr;
        }
 private static void CctorHelper()
 {
     s_resolveCallOnReferenceTypeFuncPtr   = Intrinsics.AddrOf((ResolveCallOnReferenceTypeDel)ResolveCallOnReferenceType);
     s_resolveCallOnValueTypeFuncPtr       = Intrinsics.AddrOf((ResolveCallOnValueTypeDel)ResolveCallOnValueType);
     s_resolveDirectConstrainedCallFuncPtr = Intrinsics.AddrOf((Func <IntPtr, IntPtr, IntPtr>)ResolveDirectConstrainedCall);
     s_boxAndToStringFuncPtr    = Intrinsics.AddrOf((BoxAndCallDel <string>)BoxAndToString);
     s_boxAndGetHashCodeFuncPtr = Intrinsics.AddrOf((BoxAndCallDel <int>)BoxAndGetHashCode);
     s_boxAndEqualsFuncPtr      = Intrinsics.AddrOf((BoxAndCallDel2 <bool>)BoxAndEquals);
 }
 private static void CctorHelper()
 {
     s_resolveCallOnReferenceTypeFuncPtr   = Intrinsics.AddrOf((ResolveCallOnReferenceTypeDel)ResolveCallOnReferenceType);
     s_resolveCallOnValueTypeFuncPtr       = Intrinsics.AddrOf((ResolveCallOnValueTypeDel)ResolveCallOnValueType);
     s_resolveDirectConstrainedCallFuncPtr = Intrinsics.AddrOf((Func <IntPtr, IntPtr, IntPtr>)ResolveDirectConstrainedCall);
     s_boxAndToStringFuncPtr    = Intrinsics.AddrOf((BoxAndCallDel <string>)BoxAndToString);
     s_boxAndGetHashCodeFuncPtr = Intrinsics.AddrOf((BoxAndCallDel <int>)BoxAndGetHashCode);
     s_boxAndEqualsFuncPtr      = Intrinsics.AddrOf((BoxAndCallDel2 <bool>)BoxAndEquals);
     s_resolveCallOnReferenceTypeCacheMissFunc = RuntimeAugments.RegisterResolutionFunctionWithRuntimeCache(
         Intrinsics.AddrOf((RuntimeCacheFuncSignatureDel)ResolveCallOnReferenceTypeCacheMiss));
 }
Exemple #7
0
        /// <summary>
        /// Build initial array of vtable thunks. These thunks are the ones directly embedded in
        /// the typeloader codebase instead of being dynamically generated out of the thunk pool.
        /// </summary>
        private static IntPtr[] InitialThunks()
        {
            IntPtr firstResolverThunk;
            int    thunkCount;
            int    thunkSize = VTableResolver_Init(out firstResolverThunk,
                                                   Intrinsics.AddrOf(new Func <IntPtr, IntPtr, IntPtr>(VTableResolveThunk)),
                                                   RuntimeAugments.GetUniversalTransitionThunk(),
                                                   out thunkCount);

            IntPtr[] initialThunks = new IntPtr[thunkCount];
            for (int i = 0; i < thunkCount; i++)
            {
                unsafe
                {
                    initialThunks[i] = (IntPtr)(((byte *)firstResolverThunk) + (thunkSize * i));
                }
            }

            return(initialThunks);
        }
Exemple #8
0
        /// <summary>
        /// Initialize module info and construct per-module metadata reader.
        /// </summary>
        /// <param name="moduleHandle">Handle (address) of module to initialize</param>
        internal ModuleInfo(IntPtr moduleHandle, ModuleType moduleType)
        {
            Handle     = moduleHandle;
            ModuleType = moduleType;

            byte *pBlob;
            uint  cbBlob;

            if (RuntimeAugments.FindBlob(moduleHandle, (int)ReflectionMapBlob.EmbeddedMetadata, new IntPtr(&pBlob), new IntPtr(&cbBlob)))
            {
                MetadataReader = new MetadataReader((IntPtr)pBlob, (int)cbBlob);
            }

            DynamicModule *dynamicModulePtr = (DynamicModule *)MemoryHelpers.AllocateMemory(sizeof(DynamicModule));

            dynamicModulePtr->CbSize = DynamicModule.DynamicModuleSize;
            Debug.Assert(sizeof(DynamicModule) >= dynamicModulePtr->CbSize);

#if SUPPORTS_R2R_LOADING
            if (moduleType == ModuleType.ReadyToRun)
            {
                // ReadyToRun modules utilize dynamic type resolution
                dynamicModulePtr->DynamicTypeSlotDispatchResolve = Intrinsics.AddrOf(
                    (Func <IntPtr, IntPtr, ushort, IntPtr>)ReadyToRunCallbacks.ResolveTypeSlotDispatch);
            }
            else
#endif
            {
                Debug.Assert(moduleType == ModuleType.Eager);
                // Pre-generated modules do not
                dynamicModulePtr->DynamicTypeSlotDispatchResolve = IntPtr.Zero;
            }

            dynamicModulePtr->GetRuntimeException = Intrinsics.AddrOf(
                (Func <ExceptionIDs, Exception>)RuntimeExceptionHelpers.GetRuntimeException);

            DynamicModulePtr = dynamicModulePtr;
        }
 private static IntPtr SetupMethodEntrypoints()
 {
     return(MethodEntrypointStubs_SetupPointers(RuntimeAugments.GetUniversalTransitionThunk(),
                                                Intrinsics.AddrOf <Func <IntPtr, IntPtr, IntPtr> >(EntrypointThunk)));
 }
 private static void CctorHelper()
 {
     s_resolveCallOnReferenceTypeFuncPtr = Intrinsics.AddrOf((ResolveCallOnReferenceTypeDel)ResolveCallOnReferenceType);
     s_resolveCallOnValueTypeFuncPtr     = Intrinsics.AddrOf((ResolveCallOnValueTypeDel)ResolveCallOnValueType);
 }