Fix infrequent hangs in test-runner. (#16793)
[mono-project.git] / mcs / class / referencesource / System / services / monitoring / system / diagnosticts / ProcessModule.cs
blobdebc0745e991d350f43d4fb2d57d5d3ba77158e0
1 //------------------------------------------------------------------------------
2 // <copyright file="ProcessModule.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 // </copyright>
5 //------------------------------------------------------------------------------
7 namespace System.Diagnostics {
8 using System.Diagnostics;
9 using System;
10 using System.Collections;
11 using System.IO;
12 using Microsoft.Win32;
13 using System.ComponentModel;
14 using System.Globalization;
15 using System.Security.Permissions;
16 // using System.Windows.Forms;
17 using System.Runtime.Versioning;
19 /// <devdoc>
20 /// A process module component represents a DLL or EXE loaded into
21 /// a particular process. Using this component, you can determine
22 /// information about the module.
23 /// </devdoc>
24 [Designer("System.Diagnostics.Design.ProcessModuleDesigner, " + AssemblyRef.SystemDesign)]
25 [PermissionSet(SecurityAction.LinkDemand, Name="FullTrust")]
26 [PermissionSet(SecurityAction.InheritanceDemand, Name="FullTrust")]
27 public class ProcessModule : Component {
28 internal ModuleInfo moduleInfo;
29 FileVersionInfo fileVersionInfo;
31 /// <devdoc>
32 /// Initialize the module.
33 /// </devdoc>
34 /// <internalonly/>
35 internal ProcessModule(ModuleInfo moduleInfo) {
36 this.moduleInfo = moduleInfo;
37 GC.SuppressFinalize(this);
40 /// <devdoc>
41 /// Make sure we are running on NT.
42 /// </devdoc>
43 /// <internalonly/>
44 internal void EnsureNtProcessInfo() {
45 if (Environment.OSVersion.Platform != PlatformID.Win32NT)
46 throw new PlatformNotSupportedException(SR.GetString(SR.WinNTRequired));
49 /// <devdoc>
50 /// Returns the name of the Module.
51 /// </devdoc>
52 [MonitoringDescription(SR.ProcModModuleName)]
53 public string ModuleName {
54 get {
55 return moduleInfo.baseName;
59 /// <devdoc>
60 /// Returns the full file path for the location of the module.
61 /// </devdoc>
62 [MonitoringDescription(SR.ProcModFileName)]
63 public string FileName {
64 [ResourceExposure(ResourceScope.Machine)]
65 get {
66 return moduleInfo.fileName;
70 /// <devdoc>
71 /// Returns the memory address that the module was loaded at.
72 /// </devdoc>
73 [MonitoringDescription(SR.ProcModBaseAddress)]
74 public IntPtr BaseAddress {
75 [ResourceExposure(ResourceScope.Process)]
76 get {
77 return moduleInfo.baseOfDll;
81 /// <devdoc>
82 /// Returns the amount of memory required to load the module. This does
83 /// not include any additional memory allocations made by the module once
84 /// it is running; it only includes the size of the static code and data
85 /// in the module file.
86 /// </devdoc>
87 [MonitoringDescription(SR.ProcModModuleMemorySize)]
88 public int ModuleMemorySize {
89 get {
90 return moduleInfo.sizeOfImage;
94 /// <devdoc>
95 /// Returns the memory address for function that runs when the module is
96 /// loaded and run.
97 /// </devdoc>
98 [MonitoringDescription(SR.ProcModEntryPointAddress)]
99 public IntPtr EntryPointAddress {
100 get {
101 EnsureNtProcessInfo();
102 return moduleInfo.entryPoint;
106 /// <devdoc>
107 /// Returns version information about the module.
108 /// </devdoc>
109 [Browsable(false)]
110 public FileVersionInfo FileVersionInfo {
111 [ResourceExposure(ResourceScope.Machine)] // Let's review callers - why do they want this?
112 [ResourceConsumption(ResourceScope.Machine)]
113 get {
114 if (fileVersionInfo == null)
115 fileVersionInfo = FileVersionInfo.GetVersionInfo(FileName);
116 return fileVersionInfo;
120 public override string ToString() {
121 return String.Format(CultureInfo.CurrentCulture, "{0} ({1})", base.ToString(), this.ModuleName);