Alexandre Julliard : ntdll: Don't use a real guard page at the bottom of the stack.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Dec 19 03:22:36 CST 2005


Module: wine
Branch: refs/heads/master
Commit: efffa663308a9c2338dd1ed577fd40414e982f10
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=efffa663308a9c2338dd1ed577fd40414e982f10

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Sat Dec 17 18:47:03 2005 +0100

ntdll: Don't use a real guard page at the bottom of the stack.
A no-access page is enough, we can't properly raise an overflow
exception anyway.

---

 dlls/kernel/process.c |    2 +-
 dlls/ntdll/thread.c   |    3 +--
 dlls/ntdll/virtual.c  |    8 ++------
 3 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/dlls/kernel/process.c b/dlls/kernel/process.c
index 42c4033..e75fccb 100644
--- a/dlls/kernel/process.c
+++ b/dlls/kernel/process.c
@@ -994,7 +994,7 @@ static void *init_stack(void)
     NtCurrentTeb()->Tib.StackLimit    = (char *)base + page_size;
 
     /* setup guard page */
-    VirtualProtect( base, 1, PAGE_READWRITE | PAGE_GUARD, NULL );
+    VirtualProtect( base, page_size, PAGE_NOACCESS, NULL );
     return NtCurrentTeb()->Tib.StackBase;
 }
 
diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c
index 07cd08d..9896703 100644
--- a/dlls/ntdll/thread.c
+++ b/dlls/ntdll/thread.c
@@ -223,8 +223,7 @@ static void start_thread( struct wine_pt
 
     /* setup the guard page */
     size = page_size;
-    NtProtectVirtualMemory( NtCurrentProcess(), &teb->DeallocationStack, &size,
-                            PAGE_READWRITE | PAGE_GUARD, NULL );
+    NtProtectVirtualMemory( NtCurrentProcess(), &teb->DeallocationStack, &size, PAGE_NOACCESS, NULL );
     RtlFreeHeap( GetProcessHeap(), 0, info );
 
     RtlAcquirePebLock();
diff --git a/dlls/ntdll/virtual.c b/dlls/ntdll/virtual.c
index 3cd9fff..922c1b3 100644
--- a/dlls/ntdll/virtual.c
+++ b/dlls/ntdll/virtual.c
@@ -1178,17 +1178,13 @@ NTSTATUS VIRTUAL_HandleFault( LPCVOID ad
     RtlEnterCriticalSection( &csVirtual );
     if ((view = VIRTUAL_FindView( addr )))
     {
-        BYTE vprot = view->prot[((const char *)addr - (const char *)view->base) >> page_shift];
-        void *page = (void *)((UINT_PTR)addr & ~page_mask);
-        char *stack = NtCurrentTeb()->Tib.StackLimit;
+        void *page = ROUND_ADDR( addr, page_mask );
+        BYTE vprot = view->prot[((const char *)page - (const char *)view->base) >> page_shift];
         if (vprot & VPROT_GUARD)
         {
             VIRTUAL_SetProt( view, page, page_mask + 1, vprot & ~VPROT_GUARD );
             ret = STATUS_GUARD_PAGE_VIOLATION;
         }
-        /* is it inside the stack guard page? */
-        if (((const char *)addr >= stack - (page_mask + 1)) && ((const char *)addr < stack))
-            ret = STATUS_STACK_OVERFLOW;
     }
     RtlLeaveCriticalSection( &csVirtual );
     return ret;




More information about the wine-cvs mailing list