From 0d887c7d51e28455da610a730f20631eaa0533b6 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 5 May 2012 11:40:31 +0300 Subject: [PATCH] Fix failures in starting subprocesses on Windows 7. src/w32proc.c (new_child): Force Windows to reserve only 64KB of stack for each reader_thread, instead of defaulting to 8MB determined by the linker. This avoids failures in creating subprocesses on Windows 7, see the discussion in this thread: http://lists.gnu.org/archive/html/emacs-devel/2012-03/msg00119.html. --- src/ChangeLog | 8 ++++++++ src/w32proc.c | 20 +++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/ChangeLog b/src/ChangeLog index 8aa1707cd30..1e6af943fb4 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2012-05-05 Eli Zaretskii + + * w32proc.c (new_child): Force Windows to reserve only 64KB of + stack for each reader_thread, instead of defaulting to 8MB + determined by the linker. This avoids failures in creating + subprocesses on Windows 7, see the discussion in this thread: + http://lists.gnu.org/archive/html/emacs-devel/2012-03/msg00119.html. + 2012-05-02 Jim Meyering * w32font.c (fill_in_logfont): NUL-terminate a string (Bug#11372). diff --git a/src/w32proc.c b/src/w32proc.c index 28591f90128..5bdeba25958 100644 --- a/src/w32proc.c +++ b/src/w32proc.c @@ -141,7 +141,25 @@ new_child (void) cp->char_consumed = CreateEvent (NULL, FALSE, FALSE, NULL); if (cp->char_consumed) { - cp->thrd = CreateThread (NULL, 1024, reader_thread, cp, 0, &id); + /* The 0x00010000 flag is STACK_SIZE_PARAM_IS_A_RESERVATION. + It means that the 64K stack we are requesting in the 2nd + argument is how much memory should be reserved for the + stack. If we don't use this flag, the memory requested + by the 2nd argument is the amount actually _committed_, + but Windows reserves 8MB of memory for each thread's + stack. (The 8MB figure comes from the -stack + command-line argument we pass to the linker when building + Emacs, but that's because we need a large stack for + Emacs's main thread.) Since we request 2GB of reserved + memory at startup (see w32heap.c), which is close to the + maximum memory available for a 32-bit process on Windows, + the 8MB reservation for each thread causes failures in + starting subprocesses, because we create a thread running + reader_thread for each subprocess. As 8MB of stack is + way too much for reader_thread, forcing Windows to + reserve less wins the day. */ + cp->thrd = CreateThread (NULL, 64 * 1024, reader_thread, cp, + 0x00010000, &id); if (cp->thrd) return cp; } -- 2.39.2