Use expression-bodied members in more places (dotnet/coreclr#26500)
[mono-project.git] / mono / utils / mono-proclib.h
blob1a46eacad018146d691c7fdc6726c8f55cd08525
1 /**
2 * \file
3 */
5 #ifndef __MONO_PROC_LIB_H__
6 #define __MONO_PROC_LIB_H__
7 /*
8 * Utility functions to access processes information and other info about the system.
9 */
11 #include <glib.h>
12 #include <mono/utils/mono-compiler.h>
13 #include <mono/utils/mono-publib.h>
15 /* never remove or reorder these enums values: they are used in corlib/System */
17 typedef enum {
18 MONO_PROCESS_NUM_THREADS,
19 MONO_PROCESS_USER_TIME, /* milliseconds */
20 MONO_PROCESS_SYSTEM_TIME, /* milliseconds */
21 MONO_PROCESS_TOTAL_TIME, /* milliseconds */
22 MONO_PROCESS_WORKING_SET,
23 MONO_PROCESS_WORKING_SET_PEAK, /* 5 */
24 MONO_PROCESS_PRIVATE_BYTES,
25 MONO_PROCESS_VIRTUAL_BYTES,
26 MONO_PROCESS_VIRTUAL_BYTES_PEAK,
27 MONO_PROCESS_FAULTS,
28 MONO_PROCESS_ELAPSED, /* 10 */
29 MONO_PROCESS_PPID,
30 MONO_PROCESS_PAGED_BYTES,
31 MONO_PROCESS_END
32 } MonoProcessData;
34 typedef enum {
35 MONO_CPU_USER_TIME,
36 MONO_CPU_PRIV_TIME,
37 MONO_CPU_INTR_TIME,
38 MONO_CPU_DCP_TIME,
39 MONO_CPU_IDLE_TIME,
40 MONO_CPU_END
41 } MonoCpuData;
43 typedef enum {
44 MONO_PROCESS_ERROR_NONE, /* no error happened */
45 MONO_PROCESS_ERROR_NOT_FOUND, /* process not found */
46 MONO_PROCESS_ERROR_OTHER
47 } MonoProcessError;
49 typedef struct _MonoCpuUsageState MonoCpuUsageState;
50 #ifndef HOST_WIN32
51 struct _MonoCpuUsageState {
52 gint64 kernel_time;
53 gint64 user_time;
54 gint64 current_time;
56 #else
57 struct _MonoCpuUsageState {
58 guint64 kernel_time;
59 guint64 user_time;
60 guint64 idle_time;
62 #endif
64 gpointer* mono_process_list (int *size);
66 void mono_process_get_times (gpointer pid, gint64 *start_time, gint64 *user_time, gint64 *kernel_time);
68 char* mono_process_get_name (gpointer pid, char *buf, int len);
70 gint64 mono_process_get_data (gpointer pid, MonoProcessData data);
71 gint64 mono_process_get_data_with_error (gpointer pid, MonoProcessData data, MonoProcessError *error);
73 int mono_process_current_pid (void);
75 MONO_API int mono_cpu_count (void);
76 gint64 mono_cpu_get_data (int cpu_id, MonoCpuData data, MonoProcessError *error);
77 gint32 mono_cpu_usage (MonoCpuUsageState *prev);
79 int mono_atexit (void (*func)(void));
81 #ifndef HOST_WIN32
83 #include <sys/stat.h>
84 #include <unistd.h>
86 #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
88 #define IMAGE_DIRECTORY_ENTRY_EXPORT 0
89 #define IMAGE_DIRECTORY_ENTRY_IMPORT 1
90 #define IMAGE_DIRECTORY_ENTRY_RESOURCE 2
92 #define IMAGE_SIZEOF_SHORT_NAME 8
94 #if G_BYTE_ORDER != G_LITTLE_ENDIAN
95 #define IMAGE_DOS_SIGNATURE 0x4d5a
96 #define IMAGE_NT_SIGNATURE 0x50450000
97 #define IMAGE_NT_OPTIONAL_HDR32_MAGIC 0xb10
98 #define IMAGE_NT_OPTIONAL_HDR64_MAGIC 0xb20
99 #else
100 #define IMAGE_DOS_SIGNATURE 0x5a4d
101 #define IMAGE_NT_SIGNATURE 0x00004550
102 #define IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x10b
103 #define IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b
104 #endif
106 typedef struct {
107 guint16 e_magic;
108 guint16 e_cblp;
109 guint16 e_cp;
110 guint16 e_crlc;
111 guint16 e_cparhdr;
112 guint16 e_minalloc;
113 guint16 e_maxalloc;
114 guint16 e_ss;
115 guint16 e_sp;
116 guint16 e_csum;
117 guint16 e_ip;
118 guint16 e_cs;
119 guint16 e_lfarlc;
120 guint16 e_ovno;
121 guint16 e_res[4];
122 guint16 e_oemid;
123 guint16 e_oeminfo;
124 guint16 e_res2[10];
125 guint32 e_lfanew;
126 } IMAGE_DOS_HEADER;
128 typedef struct {
129 guint16 Machine;
130 guint16 NumberOfSections;
131 guint32 TimeDateStamp;
132 guint32 PointerToSymbolTable;
133 guint32 NumberOfSymbols;
134 guint16 SizeOfOptionalHeader;
135 guint16 Characteristics;
136 } IMAGE_FILE_HEADER;
138 typedef struct {
139 guint32 VirtualAddress;
140 guint32 Size;
141 } IMAGE_DATA_DIRECTORY;
143 typedef struct {
144 guint16 Magic;
145 guint8 MajorLinkerVersion;
146 guint8 MinorLinkerVersion;
147 guint32 SizeOfCode;
148 guint32 SizeOfInitializedData;
149 guint32 SizeOfUninitializedData;
150 guint32 AddressOfEntryPoint;
151 guint32 BaseOfCode;
152 guint32 BaseOfData;
153 guint32 ImageBase;
154 guint32 SectionAlignment;
155 guint32 FileAlignment;
156 guint16 MajorOperatingSystemVersion;
157 guint16 MinorOperatingSystemVersion;
158 guint16 MajorImageVersion;
159 guint16 MinorImageVersion;
160 guint16 MajorSubsystemVersion;
161 guint16 MinorSubsystemVersion;
162 guint32 Win32VersionValue;
163 guint32 SizeOfImage;
164 guint32 SizeOfHeaders;
165 guint32 CheckSum;
166 guint16 Subsystem;
167 guint16 DllCharacteristics;
168 guint32 SizeOfStackReserve;
169 guint32 SizeOfStackCommit;
170 guint32 SizeOfHeapReserve;
171 guint32 SizeOfHeapCommit;
172 guint32 LoaderFlags;
173 guint32 NumberOfRvaAndSizes;
174 IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
175 } IMAGE_OPTIONAL_HEADER32;
177 typedef struct {
178 guint16 Magic;
179 guint8 MajorLinkerVersion;
180 guint8 MinorLinkerVersion;
181 guint32 SizeOfCode;
182 guint32 SizeOfInitializedData;
183 guint32 SizeOfUninitializedData;
184 guint32 AddressOfEntryPoint;
185 guint32 BaseOfCode;
186 guint64 ImageBase;
187 guint32 SectionAlignment;
188 guint32 FileAlignment;
189 guint16 MajorOperatingSystemVersion;
190 guint16 MinorOperatingSystemVersion;
191 guint16 MajorImageVersion;
192 guint16 MinorImageVersion;
193 guint16 MajorSubsystemVersion;
194 guint16 MinorSubsystemVersion;
195 guint32 Win32VersionValue;
196 guint32 SizeOfImage;
197 guint32 SizeOfHeaders;
198 guint32 CheckSum;
199 guint16 Subsystem;
200 guint16 DllCharacteristics;
201 guint64 SizeOfStackReserve;
202 guint64 SizeOfStackCommit;
203 guint64 SizeOfHeapReserve;
204 guint64 SizeOfHeapCommit;
205 guint32 LoaderFlags;
206 guint32 NumberOfRvaAndSizes;
207 IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
208 } IMAGE_OPTIONAL_HEADER64;
210 #if SIZEOF_VOID_P == 8
211 typedef IMAGE_OPTIONAL_HEADER64 IMAGE_OPTIONAL_HEADER;
212 #else
213 typedef IMAGE_OPTIONAL_HEADER32 IMAGE_OPTIONAL_HEADER;
214 #endif
216 typedef struct {
217 guint32 Signature;
218 IMAGE_FILE_HEADER FileHeader;
219 IMAGE_OPTIONAL_HEADER32 OptionalHeader;
220 } IMAGE_NT_HEADERS32;
222 typedef struct {
223 guint32 Signature;
224 IMAGE_FILE_HEADER FileHeader;
225 IMAGE_OPTIONAL_HEADER64 OptionalHeader;
226 } IMAGE_NT_HEADERS64;
228 #if SIZEOF_VOID_P == 8
229 typedef IMAGE_NT_HEADERS64 IMAGE_NT_HEADERS;
230 #else
231 typedef IMAGE_NT_HEADERS32 IMAGE_NT_HEADERS;
232 #endif
234 typedef struct {
235 guint8 Name[IMAGE_SIZEOF_SHORT_NAME];
236 union {
237 guint32 PhysicalAddress;
238 guint32 VirtualSize;
239 } Misc;
240 guint32 VirtualAddress;
241 guint32 SizeOfRawData;
242 guint32 PointerToRawData;
243 guint32 PointerToRelocations;
244 guint32 PointerToLinenumbers;
245 guint16 NumberOfRelocations;
246 guint16 NumberOfLinenumbers;
247 guint32 Characteristics;
248 } IMAGE_SECTION_HEADER;
250 #define IMAGE_FIRST_SECTION32(header) ((IMAGE_SECTION_HEADER *)((gsize)(header) + G_STRUCT_OFFSET (IMAGE_NT_HEADERS32, OptionalHeader) + GUINT16_FROM_LE (((IMAGE_NT_HEADERS32 *)(header))->FileHeader.SizeOfOptionalHeader)))
252 #define RT_CURSOR 0x01
253 #define RT_BITMAP 0x02
254 #define RT_ICON 0x03
255 #define RT_MENU 0x04
256 #define RT_DIALOG 0x05
257 #define RT_STRING 0x06
258 #define RT_FONTDIR 0x07
259 #define RT_FONT 0x08
260 #define RT_ACCELERATOR 0x09
261 #define RT_RCDATA 0x0a
262 #define RT_MESSAGETABLE 0x0b
263 #define RT_GROUP_CURSOR 0x0c
264 #define RT_GROUP_ICON 0x0e
265 #define RT_VERSION 0x10
266 #define RT_DLGINCLUDE 0x11
267 #define RT_PLUGPLAY 0x13
268 #define RT_VXD 0x14
269 #define RT_ANICURSOR 0x15
270 #define RT_ANIICON 0x16
271 #define RT_HTML 0x17
272 #define RT_MANIFEST 0x18
274 typedef struct {
275 guint32 Characteristics;
276 guint32 TimeDateStamp;
277 guint16 MajorVersion;
278 guint16 MinorVersion;
279 guint16 NumberOfNamedEntries;
280 guint16 NumberOfIdEntries;
281 } IMAGE_RESOURCE_DIRECTORY;
283 typedef struct {
284 union {
285 struct {
286 #if G_BYTE_ORDER == G_BIG_ENDIAN
287 guint32 NameIsString:1;
288 guint32 NameOffset:31;
289 #else
290 guint32 NameOffset:31;
291 guint32 NameIsString:1;
292 #endif
294 guint32 Name;
295 #if G_BYTE_ORDER == G_BIG_ENDIAN
296 struct {
297 guint16 __wapi_big_endian_padding;
298 guint16 Id;
300 #else
301 guint16 Id;
302 #endif
304 union {
305 guint32 OffsetToData;
306 struct {
307 #if G_BYTE_ORDER == G_BIG_ENDIAN
308 guint32 DataIsDirectory:1;
309 guint32 OffsetToDirectory:31;
310 #else
311 guint32 OffsetToDirectory:31;
312 guint32 DataIsDirectory:1;
313 #endif
316 } IMAGE_RESOURCE_DIRECTORY_ENTRY;
318 typedef struct {
319 guint32 OffsetToData;
320 guint32 Size;
321 guint32 CodePage;
322 guint32 Reserved;
323 } IMAGE_RESOURCE_DATA_ENTRY;
327 gboolean
328 mono_pe_file_time_date_stamp (const gunichar2 *filename, guint32 *out);
330 gpointer
331 mono_pe_file_map (const gunichar2 *filename, gint32 *map_size, void **handle);
333 void
334 mono_pe_file_unmap (gpointer file_map, void *handle);
335 #endif /* HOST_WIN32 */
337 #endif /* __MONO_PROC_LIB_H__ */