first pass at custom load-module exception (long term for JIT)

This commit is contained in:
Ryan Fleury
2026-07-23 20:22:54 -07:00
parent 16c447bb79
commit b0841ff2da
3 changed files with 67 additions and 0 deletions
+33
View File
@@ -38,6 +38,7 @@
# define raddbg_add_breakpoint(ptr, size, r, w, x) raddbg_add_or_remove_breakpoint__impl((ptr), (1), (size), (r), (w), (x)) # define raddbg_add_breakpoint(ptr, size, r, w, x) raddbg_add_or_remove_breakpoint__impl((ptr), (1), (size), (r), (w), (x))
# define raddbg_remove_breakpoint(ptr, size, r, w, x) raddbg_add_or_remove_breakpoint__impl((ptr), (0), (size), (r), (w), (x)) # define raddbg_remove_breakpoint(ptr, size, r, w, x) raddbg_add_or_remove_breakpoint__impl((ptr), (0), (size), (r), (w), (x))
# define raddbg_annotate_vaddr_range(ptr, size, ...) raddbg_annotate_vaddr_range__impl((ptr), (size), __VA_ARGS__) # define raddbg_annotate_vaddr_range(ptr, size, ...) raddbg_annotate_vaddr_range__impl((ptr), (size), __VA_ARGS__)
# define raddbg_load_module(ptr, size, name) raddbg_load_module__impl((ptr), (size), (name))
#else #else
# define raddbg_is_attached(...) (0) # define raddbg_is_attached(...) (0)
# define raddbg_thread_id(...) ((void)0) # define raddbg_thread_id(...) ((void)0)
@@ -57,6 +58,7 @@
# define raddbg_add_breakpoint(ptr, size, r, w, x) ((void)0) # define raddbg_add_breakpoint(ptr, size, r, w, x) ((void)0)
# define raddbg_remove_breakpoint(ptr, size, r, w, x) ((void)0) # define raddbg_remove_breakpoint(ptr, size, r, w, x) ((void)0)
# define raddbg_annotate_vaddr_range(ptr, size, ...) ((void)0) # define raddbg_annotate_vaddr_range(ptr, size, ...) ((void)0)
# define raddbg_load_module(ptr, size, name) ((void)0)
#endif #endif
//////////////////////////////// ////////////////////////////////
@@ -466,6 +468,37 @@ raddbg_annotate_vaddr_range__impl(void *ptr, unsigned __int64 size, char *fmt, .
} }
} }
void
raddbg_load_module__impl(void *ptr, unsigned __int64 size, char *name)
{
if(raddbg_is_attached())
{
#pragma pack(push, 8)
typedef struct RADDBG_LoadModuleInfo RADDBG_LoadModuleInfo;
struct RADDBG_LoadModuleInfo
{
unsigned __int64 vaddr;
unsigned __int64 size;
unsigned __int64 name_vaddr;
};
#pragma pack(pop)
RADDBG_LoadModuleInfo info;
info.vaddr = (unsigned __int64)ptr;
info.size = size;
info.name_vaddr= (unsigned __int64)name;
#pragma warning(push)
#pragma warning(disable: 6320 6322)
__try
{
RaiseException(0x00524157u, 0, sizeof(info) / sizeof(void *), (const ULONG_PTR *)&info);
}
__except(1)
{
}
#pragma warning(pop)
}
}
#endif // defined(RADDBG_MARKUP_IMPLEMENTATION) #endif // defined(RADDBG_MARKUP_IMPLEMENTATION)
#endif // defined(_WIN32) && !defined(RADDBG_MARKUP_STUBS) #endif // defined(_WIN32) && !defined(RADDBG_MARKUP_STUBS)
+33
View File
@@ -2773,6 +2773,39 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls)
e->string = str8(name_buffer, name_size); e->string = str8(name_buffer, name_size);
}break; }break;
//- rjf: fill load-library info
case W32_DMN_EXCEPTION_RADDBG_LOAD_MODULE:
{
// rjf: unpack parameters
U64 vaddr = exception->ExceptionInformation[0];
U64 size = exception->ExceptionInformation[1];
U64 name_vaddr = exception->ExceptionInformation[2];
// rjf: parse module info
W32_DMN_Entity *process = w32_dmn_entity_from_kind_id(W32_DMN_EntityKind_Process, evt.dwProcessId);
DMN_ModuleInfo *module_info = w32_dmn_module_info_from_process_module(arena, process->handle, 0, vaddr, name_vaddr, 0, 0);
// rjf: create module entity
W32_DMN_Entity *module = w32_dmn_entity_alloc(process, W32_DMN_EntityKind_Module, vaddr);
{
module->handle = 0;
module->arch = process->arch;
module->module.vaddr_range = r1u64(vaddr, vaddr + Max(module_info->vsize, size));
module->module.address_of_name_pointer = name_vaddr;
module->module.name_is_unicode = 0;
}
// rjf: fill event
e->kind = DMN_EventKind_LoadModule;
e->process = w32_dmn_handle_from_entity(process);
e->module = w32_dmn_handle_from_entity(module);
e->arch = module_info->arch;
e->address = vaddr;
e->size = Max(module_info->vsize, size);
e->string = module_info->module_path;
e->module_info = module_info;
}break;
//- rjf: unhandled exception case //- rjf: unhandled exception case
default: default:
{ {
+1
View File
@@ -59,6 +59,7 @@
#define W32_DMN_EXCEPTION_RADDBG_SET_THREAD_COLOR 0x00524144u #define W32_DMN_EXCEPTION_RADDBG_SET_THREAD_COLOR 0x00524144u
#define W32_DMN_EXCEPTION_RADDBG_SET_BREAKPOINT 0x00524145u #define W32_DMN_EXCEPTION_RADDBG_SET_BREAKPOINT 0x00524145u
#define W32_DMN_EXCEPTION_RADDBG_SET_VADDR_RANGE_NOTE 0x00524156u #define W32_DMN_EXCEPTION_RADDBG_SET_VADDR_RANGE_NOTE 0x00524156u
#define W32_DMN_EXCEPTION_RADDBG_LOAD_MODULE 0x00524157u
//////////////////////////////// ////////////////////////////////
//~ rjf: Win32 Exception ExceptionInformation Codes //~ rjf: Win32 Exception ExceptionInformation Codes