cs: support raco exe --embed-dlls on Windows

Uses a MemoryModule PR by @DaLynX to fix a setjmp/longjmp
interaction with embedded DLLs.
This commit is contained in:
Matthew Flatt 2020-05-01 19:59:20 -06:00
parent fffdeeddd2
commit 61cefe693a
2 changed files with 17 additions and 1 deletions

View File

@ -1563,7 +1563,6 @@
dest
mred?))))))
(define embed-dlls? (and (eq? 'windows (cross-system-type))
(eq? 'racket (cross-system-type 'vm))
(let ([m (assq 'embed-dlls? aux)])
(and m (cdr m)))))
(define embedded-dlls-box (and embed-dlls? (box null)))

View File

@ -435,6 +435,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);
PIMAGE_RUNTIME_FUNCTION_ENTRY pEntry = (PIMAGE_RUNTIME_FUNCTION_ENTRY)(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)
{
@ -725,6 +736,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)) {