[interp] Fix DEBUG_INTERP build (#16057)
[mono-project.git] / mono / mini / mini-windows-dlldac.c
blob0cdb9e0989f0c53c95ef73dedf042fcb698df277
1 #include <config.h>
3 #ifdef HOST_WIN32
4 #include <winsock2.h>
5 #include <windows.h>
6 #include <winnt.h>
8 #if defined(TARGET_AMD64) && !defined(DISABLE_JIT)
9 #include "mono/mini/mini.h"
10 #include "mono/mini/mini-amd64.h"
11 #include "mono/utils/mono-publib.h"
13 typedef enum _FUNCTION_TABLE_TYPE {
14 RF_SORTED,
15 RF_UNSORTED,
16 RF_CALLBACK
17 } FUNCTION_TABLE_TYPE;
19 typedef struct _DYNAMIC_FUNCTION_TABLE {
20 LIST_ENTRY Links;
21 PRUNTIME_FUNCTION FunctionTable;
22 LARGE_INTEGER TimeStamp;
23 ULONG64 MinimumAddress;
24 ULONG64 MaximumAddress;
25 ULONG64 BaseAddress;
26 PGET_RUNTIME_FUNCTION_CALLBACK Callback;
27 PVOID Context;
28 PWSTR OutOfProcessCallbackDll;
29 FUNCTION_TABLE_TYPE Type;
30 ULONG EntryCount;
31 } DYNAMIC_FUNCTION_TABLE, *PDYNAMIC_FUNCTION_TABLE;
33 typedef BOOL (ReadMemoryFunction)(PVOID user_context, LPCVOID base_address, PVOID buffer, SIZE_T size, SIZE_T *read);
35 BOOL
36 read_memory(PVOID user_context, LPCVOID base_address, PVOID buffer, SIZE_T size, SIZE_T* read)
38 return ReadProcessMemory ((HANDLE)user_context, base_address, buffer, size, read);
41 MONO_EXTERN_C
42 MONO_API_EXPORT DWORD
43 OutOfProcessFunctionTableCallbackEx (ReadMemoryFunction read_memory, PVOID user_context, PVOID table_address, PDWORD entries, PRUNTIME_FUNCTION *functions)
45 DYNAMIC_FUNCTION_TABLE func_table = { 0 };
46 DynamicFunctionTableEntry func_table_entry = { 0 };
47 PRUNTIME_FUNCTION rt_funcs = NULL;
48 size_t reads = 0;
49 DWORD result = 0xC0000001;
51 if (read_memory (user_context, table_address, &func_table, sizeof (func_table), &reads)) {
52 if (func_table.Context != NULL && read_memory (user_context, func_table.Context, &func_table_entry, sizeof (func_table_entry), &reads)) {
53 if (func_table_entry.rt_funcs_current_count != 0) {
54 rt_funcs = (PRUNTIME_FUNCTION)HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, func_table_entry.rt_funcs_current_count * sizeof (RUNTIME_FUNCTION));
55 if (rt_funcs) {
56 if (read_memory (user_context, func_table_entry.rt_funcs, rt_funcs, func_table_entry.rt_funcs_current_count * sizeof (RUNTIME_FUNCTION), &reads)) {
57 *entries = func_table_entry.rt_funcs_current_count;
58 *functions = rt_funcs;
59 result = 0x00000000;
66 return result;
69 MONO_EXTERN_C
70 MONO_API_EXPORT DWORD
71 OutOfProcessFunctionTableCallback (HANDLE process, PVOID table_address, PDWORD entries, PRUNTIME_FUNCTION *functions)
73 return OutOfProcessFunctionTableCallbackEx (&read_memory, process, table_address, entries, functions);
75 #endif /* defined(TARGET_AMD64) && !defined(DISABLE_JIT) */
77 #ifdef _MSC_VER
78 MONO_EXTERN_C
79 BOOL APIENTRY
80 DllMain (HMODULE module_handle, DWORD reason, LPVOID reserved)
82 return TRUE;
84 #endif
86 #else
88 MONO_EMPTY_SOURCE_FILE (mini_windows_dlldac);
89 #endif /* HOST_WIN32 */