Stack guard page should be excluded from the stack size in TEB.

Vitaliy Margolen wine-patch at kievinfo.com
Sun Dec 4 10:51:50 CST 2005


Some programs like to clear stack after they are finished.
This patch stops stack overflow crashes and closer simulates what native
does.

ChangeLog:
Stack guard page should be excluded from the stack size in TEB.

 dlls/kernel/thread.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
-------------- next part --------------
2382d5fdd6eb08f200183de0dfed40a0818f691e
diff --git a/dlls/kernel/thread.c b/dlls/kernel/thread.c
index fd65b99..df2f0bd 100644
--- a/dlls/kernel/thread.c
+++ b/dlls/kernel/thread.c
@@ -63,12 +63,12 @@ TEB *THREAD_InitStack( TEB *teb, DWORD s
     stack_size = (stack_size + (page_size - 1)) & ~(page_size - 1);
     if (stack_size < 1024 * 1024) stack_size = 1024 * 1024;  /* Xlib needs a large stack */
 
-    if (!(base = VirtualAlloc( NULL, stack_size, MEM_COMMIT, PAGE_READWRITE )))
+    if (!(base = VirtualAlloc( NULL, stack_size + page_size, MEM_COMMIT, PAGE_READWRITE )))
         return NULL;
 
     teb->DeallocationStack = base;
     teb->Tib.StackBase     = (char *)base + stack_size;
-    teb->Tib.StackLimit    = base;  /* note: limit is lower than base since the stack grows down */
+    teb->Tib.StackLimit    = (char *)base + page_size;  /* note: limit is lower than base since the stack grows down */
 
     /* Setup guard pages */
 


More information about the wine-patches mailing list