win32: improve tccrun protection diagnostics

Report VirtualProtect failures with a Windows-specific -run diagnostic.
On Win64, also treat RtlAddFunctionTable failure as an error so unwind
registration problems are visible.
This commit is contained in:
Mounir IDRASSI 2026-05-15 19:03:01 +09:00
parent 1a54e47dda
commit 601a088214

View File

@ -427,7 +427,11 @@ redo:
} }
if (protect_pages((void*)addr, n, f) < 0) if (protect_pages((void*)addr, n, f) < 0)
return tcc_error_noabort( return tcc_error_noabort(
#ifdef _WIN32
"VirtualProtect failed");
#else
"mprotect failed (did you mean to configure --with-selinux?)"); "mprotect failed (did you mean to configure --with-selinux?)");
#endif
} }
} }
@ -502,11 +506,14 @@ static void *win64_add_function_table(TCCState *s1)
void *p = NULL; void *p = NULL;
if (s1->uw_pdata) { if (s1->uw_pdata) {
p = (void*)s1->uw_pdata->sh_addr; p = (void*)s1->uw_pdata->sh_addr;
RtlAddFunctionTable( if (!RtlAddFunctionTable(
(RUNTIME_FUNCTION*)p, (RUNTIME_FUNCTION*)p,
s1->uw_pdata->data_offset / sizeof (RUNTIME_FUNCTION), s1->uw_pdata->data_offset / sizeof (RUNTIME_FUNCTION),
s1->pe_imagebase s1->pe_imagebase
); )) {
tcc_error_noabort("RtlAddFunctionTable failed");
p = NULL;
}
s1->uw_pdata = NULL; s1->uw_pdata = NULL;
} }
return p; return p;