Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions patches/tinycc/tccrun.c.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
--- tccrun.c
+++ tccrun.c
@@ -130,8 +130,15 @@
//printf("map %p %p %p\n", ptr, prw, (void*)ptr_diff);
size *= 2;
#else
+# ifdef _WIN32
+ /* Generated code is page-protected below; avoid changing CRT heap pages. */
+ ptr = VirtualAlloc(NULL, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
+# else
ptr = tcc_malloc(size += PAGESIZE); /* one extra page to align malloc memory */
+# endif
#endif
+ if (!ptr)
+ return tcc_error_noabort("tccrun: could not allocate memory");
s1->run_ptr = ptr;
s1->run_size = size;
return ptr_diff;
@@ -188,12 +195,20 @@
#ifdef CONFIG_SELINUX
munmap(ptr, size);
#else
+# ifdef _WIN32
+ (void)size;
+# ifdef _WIN64
+ win64_del_function_table(s1->run_function_table);
+# endif
+ VirtualFree(ptr, 0, MEM_RELEASE);
+# else
/* unprotect memory to make it usable for malloc again */
protect_pages((void*)PAGEALIGN(ptr), size - PAGESIZE, 2 /*rw*/);
# ifdef _WIN64
win64_del_function_table(s1->run_function_table);
# endif
tcc_free(ptr);
+# endif
#endif
}

@@ -414,7 +429,11 @@
}
if (protect_pages((void*)addr, n, f) < 0)
return tcc_error_noabort(
+#ifdef _WIN32
+ "VirtualProtect failed");
+#else
"mprotect failed (did you mean to configure --with-selinux?)");
+#endif
}
}

@@ -487,11 +506,14 @@
void *p = NULL;
if (s1->uw_pdata) {
p = (void*)s1->uw_pdata->sh_addr;
- RtlAddFunctionTable(
+ if (!RtlAddFunctionTable(
(RUNTIME_FUNCTION*)p,
s1->uw_pdata->data_offset / sizeof (RUNTIME_FUNCTION),
s1->pe_imagebase
- );
+ )) {
+ tcc_error_noabort("RtlAddFunctionTable failed");
+ p = NULL;
+ }
s1->uw_pdata = NULL;
}
return p;
8 changes: 7 additions & 1 deletion scripts/build/deps/tinycc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ export const tinycc: Dependency = {
commit: TINYCC_COMMIT,
}),

patches: ["patches/tinycc/tcc.h.patch"],
patches: [
"patches/tinycc/tcc.h.patch",
// Backport of upstream tinycc mob 6728a64f1b (win32: VirtualAlloc for run
// memory) and 601a088214 (win32 tccrun diagnostics); the pinned fork
// predates both. Drop once TINYCC_COMMIT advances past a merge of those.
"patches/tinycc/tccrun.c.patch",
],

build: cfg => {
const sources = ["libtcc.c", "tccpp.c", "tccgen.c", "tccdbg.c", "tccelf.c", "tccasm.c", "tccrun.c"];
Expand Down
Loading