Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ption handling]
  • Loading branch information
jan.nijtmans committed Nov 27, 2024
1 parent f9e1f7c commit 0cdf923
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions win/MemoryModule.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,17 @@ PerformBaseRelocation(PMEMORYMODULE module, ptrdiff_t delta)
return TRUE;
}

#ifdef _WIN64
static BOOL
RegisterExceptionHandling(PMEMORYMODULE module)
{
PIMAGE_DATA_DIRECTORY pDir = GET_HEADER_DICTIONARY(module, IMAGE_DIRECTORY_ENTRY_EXCEPTION);
PRUNTIME_FUNCTION pEntry = (PRUNTIME_FUNCTION)(module->codeBase + pDir->VirtualAddress);
UINT count = (pDir->Size / sizeof(IMAGE_RUNTIME_FUNCTION_ENTRY)) - 1;
return RtlAddFunctionTable(pEntry, count, (DWORD64)module->codeBase);
}
#endif

static BOOL
BuildImportTable(PMEMORYMODULE module)
{
Expand Down Expand Up @@ -729,6 +740,12 @@ HMEMORYMODULE MemoryLoadLibraryEx(const void *data, size_t size,
goto error;
}

#ifdef _WIN64
if (!RegisterExceptionHandling(result)) {
goto error;
}
#endif

// mark memory pages depending on section headers and release
// sections that are marked as "discardable"
if (!FinalizeSections(result)) {
Expand Down

0 comments on commit 0cdf923

Please sign in to comment.