From acce462995341bea8d9e8c0f2e58967972822ea2 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Mon, 21 Sep 2015 00:03:08 +0200 Subject: [PATCH] Delayed private heap allocation to after child the process started on windows --- src/compat/process.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/compat/process.c b/src/compat/process.c index cf2281d..8d69a79 100644 --- a/src/compat/process.c +++ b/src/compat/process.c @@ -169,8 +169,6 @@ static void CALLBACK handle_child_terminated(PVOID lpParameter, int resume_child(void) { #ifdef VANILLA_WIN32 - init_inheritable_heap(); - TCHAR mapping_name[128]; _sntprintf(mapping_name, 128, g_mapping_name, GetCurrentProcessId()); @@ -179,8 +177,10 @@ int resume_child(void) { FALSE, mapping_name); - if (sharedMem == NULL) + if (sharedMem == NULL) { + init_inheritable_heap(); return 0; + } struct full_context *ctx = (struct full_context *) MapViewOfFile(sharedMem, FILE_MAP_ALL_ACCESS, @@ -196,6 +196,20 @@ int resume_child(void) { local_ctx = *ctx; UnmapViewOfFile(ctx); + HANDLE self = GetCurrentThread(); + DuplicateHandle(GetCurrentProcess(), + self, + GetCurrentProcess(), + &self, + 0, + FALSE, + DUPLICATE_SAME_ACCESS); + + SetEvent(local_ctx.sync); + SuspendThread(self); + + init_inheritable_heap(); + struct test_single_param *param = NULL; if (local_ctx.param.size != 0) { ctx = (struct full_context*) MapViewOfFile(sharedMem, @@ -325,8 +339,6 @@ s_proc_handle *fork_process() { if (g_worker_context.suite->data) ctx->suite_data = *g_worker_context.suite->data; - inherit_heap(info.hProcess); - if (ResumeThread(info.hThread) == (DWORD) -1) goto failure; @@ -336,6 +348,11 @@ s_proc_handle *fork_process() { if (wres == WAIT_OBJECT_0) goto failure; + inherit_heap(info.hProcess); + + if (ResumeThread(info.hThread) == (DWORD) -1) + goto failure; + CloseHandle(info.hThread); UnmapViewOfFile(ctx);