示例#1
0
 /// <summary>
 /// Given module handle, locate the metadata reader. Return null when not found.
 /// </summary>
 /// <param name="moduleHandle">Handle of module to look up</param>
 /// <returns>Reader for the embedded metadata blob in the module, null when not found</returns>
 public MetadataReader GetMetadataReaderForModule(IntPtr moduleHandle)
 {
     ModuleMap moduleMap = _loadedModuleMap;
     int moduleIndex;
     if (moduleMap.HandleToModuleIndex.TryGetValue(moduleHandle, out moduleIndex))
     {
         return moduleMap.Modules[moduleIndex].MetadataReader;
     }
     return null;
 }
示例#2
0
 /// <summary>
 /// Try to Locate module info for a given module. Returns false when not found.
 /// gets initialized.
 /// </summary>
 /// <param name="moduleHandle">Handle of module to look up</param>
 public bool TryGetModuleInfoByHandle(IntPtr moduleHandle, out ModuleInfo moduleInfo)
 {
     ModuleMap moduleMap = _loadedModuleMap;
     int moduleIndex;
     if (moduleMap.HandleToModuleIndex.TryGetValue(moduleHandle, out moduleIndex))
     {
         moduleInfo = moduleMap.Modules[moduleIndex];
         return true;
     }
     moduleInfo = null;
     return false;
 }
示例#3
0
        /// <summary>
        /// Initialize the module enumerator state machine and locate the preferred module index.
        /// </summary>
        /// <param name="moduleMap">Module map to enumerate</param>
        /// <param name="preferredModuleHandle">Optional module handle to enumerate first</param>
        internal NativeFormatModuleInfoEnumerator(ModuleMap moduleMap, TypeManagerHandle preferredModuleHandle)
        {
            _modules        = moduleMap.Modules;
            _preferredIndex = -1;
            _iterationIndex = -1;
            _currentModule  = null;

            if (!preferredModuleHandle.IsNull &&
                !moduleMap.HandleToModuleIndex.TryGetValue(preferredModuleHandle, out _preferredIndex))
            {
                Environment.FailFast("Invalid module requested in enumeration: " + preferredModuleHandle.LowLevelToString());
            }
        }
示例#4
0
        /// <summary>
        /// Try to Locate module info for a given module. Returns false when not found.
        /// gets initialized.
        /// </summary>
        /// <param name="moduleHandle">Handle of module to look up</param>
        /// <param name="moduleInfo">Found module info</param>
        public bool TryGetModuleInfoByHandle(TypeManagerHandle moduleHandle, out ModuleInfo moduleInfo)
        {
            ModuleMap moduleMap = _loadedModuleMap;
            int       moduleIndex;

            if (moduleMap.HandleToModuleIndex.TryGetValue(moduleHandle, out moduleIndex))
            {
                moduleInfo = moduleMap.Modules[moduleIndex];
                return(true);
            }
            moduleInfo = null;
            return(false);
        }
示例#5
0
        /// <summary>
        /// Initialize the module enumerator state machine and locate the preferred module index.
        /// </summary>
        /// <param name="moduleMap">Module map to enumerate</param>
        /// <param name="preferredModuleHandle">Optional module handle to enumerate first</param>
        internal ModuleInfoEnumerator(ModuleMap moduleMap, IntPtr preferredModuleHandle)
        {
            _modules        = moduleMap.Modules;
            _preferredIndex = -1;
            _iterationIndex = -1;
            _currentModule  = null;

            if (preferredModuleHandle != default(IntPtr) &&
                !moduleMap.HandleToModuleIndex.TryGetValue(preferredModuleHandle, out _preferredIndex))
            {
                Environment.FailFast("Invalid module requested in enumeration: " + preferredModuleHandle.LowLevelToString());
            }
        }
示例#6
0
        /// <summary>
        /// Register all modules which were added (Registered) to the runtime and are not already registered with the TypeLoader.
        /// </summary>
        /// <param name="moduleType">Type to assign to all new modules.</param>
        public void RegisterNewModules(ModuleType moduleType)
        {
            // prevent multiple threads from registering modules concurrently
            using (LockHolder.Hold(_moduleRegistrationLock))
            {
                // Fetch modules that have already been registered with the runtime
                int      loadedModuleCount        = RuntimeAugments.GetLoadedModules(null);
                IntPtr[] loadedModuleHandles      = new IntPtr[loadedModuleCount];
                int      loadedModuleCountUpdated = RuntimeAugments.GetLoadedModules(loadedModuleHandles);
                Debug.Assert(loadedModuleCount == loadedModuleCountUpdated);

                LowLevelList <IntPtr> newModuleHandles = new LowLevelList <IntPtr>(loadedModuleHandles.Length);
                foreach (IntPtr moduleHandle in loadedModuleHandles)
                {
                    // Skip already registered modules.
                    int oldModuleIndex;
                    if (_loadedModuleMap.HandleToModuleIndex.TryGetValue(moduleHandle, out oldModuleIndex))
                    {
                        continue;
                    }

                    newModuleHandles.Add(moduleHandle);
                }

                // Copy existing modules to new dictionary
                int          oldModuleCount = _loadedModuleMap.Modules.Length;
                ModuleInfo[] updatedModules = new ModuleInfo[oldModuleCount + newModuleHandles.Count];
                if (oldModuleCount > 0)
                {
                    Array.Copy(_loadedModuleMap.Modules, 0, updatedModules, 0, oldModuleCount);
                }

                for (int newModuleIndex = 0; newModuleIndex < newModuleHandles.Count; newModuleIndex++)
                {
                    ModuleInfo newModuleInfo = new ModuleInfo(newModuleHandles[newModuleIndex], moduleType);

                    updatedModules[oldModuleCount + newModuleIndex] = newModuleInfo;

                    if (_moduleRegistrationCallbacks != null)
                    {
                        _moduleRegistrationCallbacks(newModuleInfo);
                    }
                }

                // Atomically update the module map
                _loadedModuleMap = new ModuleMap(updatedModules);
            }
        }
示例#7
0
        /// <summary>
        /// Register initially (eagerly) loaded modules.
        /// </summary>
        internal ModuleList()
        {
            _loadedModuleMap = new ModuleMap(new ModuleInfo[0]);
            _moduleRegistrationCallbacks = default(Action<ModuleInfo>);
            _moduleRegistrationLock = new Lock();

            RegisterNewModules(ModuleType.Eager);

            IntPtr systemObjectModule = RuntimeAugments.GetModuleFromTypeHandle(RuntimeAugments.RuntimeTypeHandleOf<object>());
            foreach (ModuleInfo m in _loadedModuleMap.Modules)
            {
                if (m.Handle == systemObjectModule)
                {
                    _systemModule = m;
                    break;
                }
            }
        }
示例#8
0
        public void RegisterModule(ModuleInfo newModuleInfo)
        {
            // prevent multiple threads from registering modules concurrently
            using (LockHolder.Hold(_moduleRegistrationLock))
            {
                // Copy existing modules to new dictionary
                int          oldModuleCount = _loadedModuleMap.Modules.Length;
                ModuleInfo[] updatedModules = new ModuleInfo[oldModuleCount + 1];
                if (oldModuleCount > 0)
                {
                    Array.Copy(_loadedModuleMap.Modules, 0, updatedModules, 0, oldModuleCount);
                }
                updatedModules[oldModuleCount] = newModuleInfo;
                _moduleRegistrationCallbacks?.Invoke(newModuleInfo);

                // Atomically update the module map
                _loadedModuleMap = new ModuleMap(updatedModules);
            }
        }
示例#9
0
文件: ModuleList.cs 项目: wffy/corert
        /// <summary>
        /// Register initially (eagerly) loaded modules.
        /// </summary>
        internal ModuleList()
        {
            _loadedModuleMap             = new ModuleMap(new ModuleInfo[0]);
            _moduleRegistrationCallbacks = default(Action <ModuleInfo>);
            _moduleRegistrationLock      = new Lock();

            // Fetch modules that have already been registered with the runtime
            int loadedModuleCount = RuntimeAugments.GetLoadedModules(null);

            IntPtr[] loadedModuleHandles      = new IntPtr[loadedModuleCount];
            int      loadedModuleCountUpdated = RuntimeAugments.GetLoadedModules(loadedModuleHandles);

            Debug.Assert(loadedModuleCount == loadedModuleCountUpdated);

            foreach (IntPtr moduleHandle in loadedModuleHandles)
            {
                RegisterModule(moduleHandle);
            }
        }
示例#10
0
        /// <summary>
        /// Given module handle, locate the metadata reader. Return null when not found.
        /// </summary>
        /// <param name="moduleHandle">Handle of module to look up</param>
        /// <returns>Reader for the embedded metadata blob in the module, null when not found</returns>
        public MetadataReader GetMetadataReaderForModule(TypeManagerHandle moduleHandle)
        {
            ModuleMap moduleMap = _loadedModuleMap;
            int       moduleIndex;

            if (moduleMap.HandleToModuleIndex.TryGetValue(moduleHandle, out moduleIndex))
            {
                NativeFormatModuleInfo moduleInfo = moduleMap.Modules[moduleIndex] as NativeFormatModuleInfo;
                if (moduleInfo != null)
                {
                    return(moduleInfo.MetadataReader);
                }
                else
                {
                    return(null);
                }
            }
            return(null);
        }
示例#11
0
 /// <summary>
 /// Construct the underlying module info enumerator used to iterate the module map
 /// </summary>
 /// <param name="moduleMap">Module map to enumerate</param>
 /// <param name="preferredModuleHandle">Optional module handle to enumerate first</param>
 internal MetadataReaderEnumerator(ModuleMap moduleMap, IntPtr preferredModuleHandle)
 {
     _moduleInfoEnumerator = new ModuleInfoEnumerator(moduleMap, preferredModuleHandle);
 }
示例#12
0
        /// <summary>
        /// Locate module info for a given module. Fail if not found or before the module registry
        /// gets initialized. Must only be called for modules described as native format (not the mrt module, or an ECMA module)
        /// </summary>
        /// <param name="moduleHandle">Handle of module to look up</param>
        public NativeFormatModuleInfo GetModuleInfoByHandle(TypeManagerHandle moduleHandle)
        {
            ModuleMap moduleMap = _loadedModuleMap;

            return((NativeFormatModuleInfo)moduleMap.Modules[moduleMap.HandleToModuleIndex[moduleHandle]]);
        }
示例#13
0
 /// <summary>
 /// Store module map and preferred module to pass to the enumerator upon construction.
 /// </summary>
 /// <param name="moduleMap">Module map to enumerate</param>
 /// <param name="preferredModuleHandle">Optional module handle to enumerate first</param>
 internal NativeFormatModuleInfoEnumerable(ModuleMap moduleMap, IntPtr preferredModuleHandle)
 {
     _moduleMap             = moduleMap;
     _preferredModuleHandle = preferredModuleHandle;
 }
示例#14
0
 /// <summary>
 /// Construct the underlying module info enumerator used to iterate the module map
 /// </summary>
 /// <param name="moduleMap">Module map to enumerate</param>
 /// <param name="preferredModuleHandle">Optional module handle to enumerate first</param>
 internal MetadataReaderEnumerator(ModuleMap moduleMap, TypeManagerHandle preferredModuleHandle)
 {
     _moduleInfoEnumerator = new NativeFormatModuleInfoEnumerator(moduleMap, preferredModuleHandle);
 }
示例#15
0
        /// <summary>
        /// Register all modules which were added (Registered) to the runtime and are not already registered with the TypeLoader.
        /// </summary>
        /// <param name="moduleType">Type to assign to all new modules.</param>
        public void RegisterNewModules(ModuleType moduleType)
        {
            // prevent multiple threads from registering modules concurrently
            using (LockHolder.Hold(_moduleRegistrationLock))
            {
                // Fetch modules that have already been registered with the runtime
                int loadedModuleCount = RuntimeAugments.GetLoadedModules(null);
                TypeManagerHandle[] loadedModuleHandles = new TypeManagerHandle[loadedModuleCount];
                int loadedModuleCountUpdated            = RuntimeAugments.GetLoadedModules(loadedModuleHandles);
                Debug.Assert(loadedModuleCount == loadedModuleCountUpdated);

                LowLevelList <TypeManagerHandle> newModuleHandles = new LowLevelList <TypeManagerHandle>(loadedModuleHandles.Length);
                foreach (TypeManagerHandle moduleHandle in loadedModuleHandles)
                {
                    // Skip already registered modules.
                    int oldModuleIndex;
                    if (_loadedModuleMap.HandleToModuleIndex.TryGetValue(moduleHandle, out oldModuleIndex))
                    {
                        continue;
                    }

                    newModuleHandles.Add(moduleHandle);
                }

                // Copy existing modules to new dictionary
                int          oldModuleCount = _loadedModuleMap.Modules.Length;
                ModuleInfo[] updatedModules = new ModuleInfo[oldModuleCount + newModuleHandles.Count];
                if (oldModuleCount > 0)
                {
                    Array.Copy(_loadedModuleMap.Modules, 0, updatedModules, 0, oldModuleCount);
                }

                for (int newModuleIndex = 0; newModuleIndex < newModuleHandles.Count; newModuleIndex++)
                {
                    ModuleInfo newModuleInfo;

                    unsafe
                    {
                        byte *pBlob;
                        uint  cbBlob;

                        if (RuntimeAugments.FindBlob(newModuleHandles[newModuleIndex], (int)ReflectionMapBlob.EmbeddedMetadata, new IntPtr(&pBlob), new IntPtr(&cbBlob)))
                        {
                            newModuleInfo = new NativeFormatModuleInfo(newModuleHandles[newModuleIndex], moduleType, (IntPtr)pBlob, (int)cbBlob);
                        }
                        else
                        {
                            newModuleInfo = new ModuleInfo(newModuleHandles[newModuleIndex], moduleType);
                        }
                    }

                    updatedModules[oldModuleCount + newModuleIndex] = newModuleInfo;

                    if (_moduleRegistrationCallbacks != null)
                    {
                        _moduleRegistrationCallbacks(newModuleInfo);
                    }
                }

                // Atomically update the module map
                _loadedModuleMap = new ModuleMap(updatedModules);
            }
        }
示例#16
0
 /// <summary>
 /// Construct the underlying module info enumerator used to iterate the module map
 /// </summary>
 /// <param name="moduleMap">Module map to enumerate</param>
 /// <param name="preferredModuleHandle">Optional module handle to enumerate first</param>
 internal ModuleHandleEnumerator(ModuleMap moduleMap, TypeManagerHandle preferredModuleHandle)
 {
     _moduleInfoEnumerator = new ModuleInfoEnumerator(moduleMap, preferredModuleHandle);
 }
示例#17
0
 /// <summary>
 /// Store module map and preferred module to pass to the enumerator upon construction.
 /// </summary>
 /// <param name="moduleMap">Module map to enumerate</param>
 /// <param name="preferredModuleHandle">Optional module handle to enumerate first</param>
 internal MetadataReaderEnumerable(ModuleMap moduleMap, TypeManagerHandle preferredModuleHandle)
 {
     _moduleMap             = moduleMap;
     _preferredModuleHandle = preferredModuleHandle;
 }
示例#18
0
        /// <summary>
        /// Register a new module. Call all module registration callbacks.
        /// </summary>
        /// <param name="moduleHandle">Module handle to register</param>
        public void RegisterModule(IntPtr newModuleHandle)
        {
            // prevent multiple threads from registering modules concurrently
            using (LockHolder.Hold(_moduleRegistrationLock))
            {
                // Don't allow double module registration
                int oldModuleIndex;
                if (_loadedModuleMap.HandleToModuleIndex.TryGetValue(newModuleHandle, out oldModuleIndex))
                {
                    Environment.FailFast("Module " + newModuleHandle.LowLevelToString() + " is being registered for the second time");
                }

                ModuleInfo newModuleInfo = new ModuleInfo(newModuleHandle);

                // Copy existing modules to new dictionary
                int oldModuleCount = _loadedModuleMap.Modules.Length;
                ModuleInfo[] updatedModules = new ModuleInfo[oldModuleCount + 1];
                if (oldModuleCount > 0)
                {
                    Array.Copy(_loadedModuleMap.Modules, 0, updatedModules, 0, oldModuleCount);
                }
                updatedModules[oldModuleCount] = newModuleInfo;

                // Atomically update the module map
                _loadedModuleMap = new ModuleMap(updatedModules);

                if (_moduleRegistrationCallbacks != null)
                {
                    _moduleRegistrationCallbacks(newModuleInfo);
                }
            }
        }
示例#19
0
        /// <summary>
        /// Register initially (eagerly) loaded modules.
        /// </summary>
        internal ModuleList()
        {
            _loadedModuleMap = new ModuleMap(new ModuleInfo[0]);
            _moduleRegistrationCallbacks = default(Action<ModuleInfo>);
            _moduleRegistrationLock = new Lock();

            // Fetch modules that have already been registered with the runtime
            int loadedModuleCount = RuntimeAugments.GetLoadedModules(null);
            IntPtr[] loadedModuleHandles = new IntPtr[loadedModuleCount];
            int loadedModuleCountUpdated = RuntimeAugments.GetLoadedModules(loadedModuleHandles);
            Debug.Assert(loadedModuleCount == loadedModuleCountUpdated);

            foreach (IntPtr moduleHandle in loadedModuleHandles)
            {
                RegisterModule(moduleHandle);
            }
        }
示例#20
0
        /// <summary>
        /// Register initially (eagerly) loaded modules.
        /// </summary>
        internal ModuleList()
        {
            _loadedModuleMap = new ModuleMap(new ModuleInfo[0]);
            _moduleRegistrationCallbacks = default(Action<ModuleInfo>);
            _moduleRegistrationLock = new Lock();

            RegisterNewModules(ModuleType.Eager);
        }
示例#21
0
 /// <summary>
 /// Store module map and preferred module to pass to the enumerator upon construction.
 /// </summary>
 /// <param name="moduleMap">Module map to enumerate</param>
 /// <param name="preferredModuleHandle">Optional module handle to enumerate first</param>
 internal MetadataReaderEnumerable(ModuleMap moduleMap, IntPtr preferredModuleHandle)
 {
     _moduleMap = moduleMap;
     _preferredModuleHandle = preferredModuleHandle;
 }
示例#22
0
        /// <summary>
        /// Initialize the module enumerator state machine and locate the preferred module index.
        /// </summary>
        /// <param name="moduleMap">Module map to enumerate</param>
        /// <param name="preferredModuleHandle">Optional module handle to enumerate first</param>
        internal ModuleInfoEnumerator(ModuleMap moduleMap, IntPtr preferredModuleHandle)
        {
            _modules = moduleMap.Modules;
            _preferredIndex = -1;
            _iterationIndex = -1;
            _currentModule = null;

            if (preferredModuleHandle != default(IntPtr) &&
                !moduleMap.HandleToModuleIndex.TryGetValue(preferredModuleHandle, out _preferredIndex))
            {
                Environment.FailFast("Invalid module requested in enumeration: " + preferredModuleHandle.LowLevelToString());
            }
        }
示例#23
0
 /// <summary>
 /// Store module map and preferred module to pass to the enumerator upon construction.
 /// </summary>
 /// <param name="moduleMap">Module map to enumerate</param>
 /// <param name="preferredModuleHandle">Optional module handle to enumerate first</param>
 internal MetadataReaderEnumerable(ModuleMap moduleMap, IntPtr preferredModuleHandle)
 {
     _moduleMap             = moduleMap;
     _preferredModuleHandle = preferredModuleHandle;
 }
示例#24
0
 /// <summary>
 /// Store module map and preferred module to pass to the enumerator upon construction.
 /// </summary>
 /// <param name="moduleMap">Module map to enumerate</param>
 /// <param name="preferredModuleHandle">Optional module handle to enumerate first</param>
 internal ModuleHandleEnumerable(ModuleMap moduleMap, IntPtr preferredModuleHandle)
 {
     _moduleMap             = moduleMap;
     _preferredModuleHandle = preferredModuleHandle;
 }
示例#25
0
 /// <summary>
 /// Store module map and preferred module to pass to the enumerator upon construction.
 /// </summary>
 /// <param name="moduleMap">Module map to enumerate</param>
 /// <param name="preferredModuleHandle">Optional module handle to enumerate first</param>
 internal ModuleHandleEnumerable(ModuleMap moduleMap, IntPtr preferredModuleHandle)
 {
     _moduleMap = moduleMap;
     _preferredModuleHandle = preferredModuleHandle;
 }
示例#26
0
        /// <summary>
        /// Locate module info for a given module. Fail if not found or before the module registry
        /// gets initialized.
        /// </summary>
        /// <param name="moduleHandle">Handle of module to look up</param>
        public ModuleInfo GetModuleInfoByHandle(IntPtr moduleHandle)
        {
            ModuleMap moduleMap = _loadedModuleMap;

            return(moduleMap.Modules[moduleMap.HandleToModuleIndex[moduleHandle]]);
        }
示例#27
0
 /// <summary>
 /// Construct the underlying module info enumerator used to iterate the module map
 /// </summary>
 /// <param name="moduleMap">Module map to enumerate</param>
 /// <param name="preferredModuleHandle">Optional module handle to enumerate first</param>
 internal MetadataReaderEnumerator(ModuleMap moduleMap, IntPtr preferredModuleHandle)
 {
     _moduleInfoEnumerator = new ModuleInfoEnumerator(moduleMap, preferredModuleHandle);
 }
示例#28
0
 /// <summary>
 /// Store module map and preferred module to pass to the enumerator upon construction.
 /// </summary>
 /// <param name="moduleMap">Module map to enumerate</param>
 /// <param name="preferredModuleHandle">Optional module handle to enumerate first</param>
 internal NativeFormatModuleInfoEnumerable(ModuleMap moduleMap, TypeManagerHandle preferredModuleHandle)
 {
     _moduleMap             = moduleMap;
     _preferredModuleHandle = preferredModuleHandle;
 }
示例#29
0
        /// <summary>
        /// Register all modules which were added (Registered) to the runtime and are not already registered with the TypeLoader.
        /// </summary>
        /// <param name="moduleType">Type to assign to all new modules.</param>
        public void RegisterNewModules(ModuleType moduleType)
        {
            // prevent multiple threads from registering modules concurrently
            using (LockHolder.Hold(_moduleRegistrationLock))
            {
                // Fetch modules that have already been registered with the runtime
                int loadedModuleCount = RuntimeAugments.GetLoadedModules(null);
                IntPtr[] loadedModuleHandles = new IntPtr[loadedModuleCount];
                int loadedModuleCountUpdated = RuntimeAugments.GetLoadedModules(loadedModuleHandles);
                Debug.Assert(loadedModuleCount == loadedModuleCountUpdated);

                LowLevelList<IntPtr> newModuleHandles = new LowLevelList<IntPtr>(loadedModuleHandles.Length);
                foreach (IntPtr moduleHandle in loadedModuleHandles)
                {
                    // Skip already registered modules.
                    int oldModuleIndex;
                    if (_loadedModuleMap.HandleToModuleIndex.TryGetValue(moduleHandle, out oldModuleIndex))
                    {
                        continue;
                    }

                    newModuleHandles.Add(moduleHandle);
                }

                // Copy existing modules to new dictionary
                int oldModuleCount = _loadedModuleMap.Modules.Length;
                ModuleInfo[] updatedModules = new ModuleInfo[oldModuleCount + newModuleHandles.Count];
                if (oldModuleCount > 0)
                {
                    Array.Copy(_loadedModuleMap.Modules, 0, updatedModules, 0, oldModuleCount);
                }

                for (int newModuleIndex = 0; newModuleIndex < newModuleHandles.Count; newModuleIndex++)
                {
                    ModuleInfo newModuleInfo = new ModuleInfo(newModuleHandles[newModuleIndex], moduleType);

                    updatedModules[oldModuleCount + newModuleIndex] = newModuleInfo;

                    if (_moduleRegistrationCallbacks != null)
                    {
                        _moduleRegistrationCallbacks(newModuleInfo);
                    }
                }

                // Atomically update the module map
                _loadedModuleMap = new ModuleMap(updatedModules);
            }
        }
示例#30
0
        /// <summary>
        /// Register initially (eagerly) loaded modules.
        /// </summary>
        internal ModuleList()
        {
            _loadedModuleMap = new ModuleMap(new ModuleInfo[0]);
            _moduleRegistrationCallbacks = default(Action<ModuleInfo>);
            _moduleRegistrationLock = new Lock();

            RegisterNewModules(ModuleType.Eager);

            IntPtr systemObjectModule = RuntimeAugments.GetModuleFromTypeHandle(RuntimeAugments.RuntimeTypeHandleOf<object>());
            foreach (ModuleInfo m in _loadedModuleMap.Modules)
            {
                if (m.Handle == systemObjectModule)
                {
                    _systemModule = m;
                    break;
                }
            }
        }