/* -*-C-*-
-$Id: nttrap.c,v 1.5 1993/08/21 03:48:49 gjr Exp $
+$Id: nttrap.c,v 1.6 1993/09/08 04:41:06 gjr Exp $
Copyright (c) 1992-1993 Massachusetts Institute of Technology
}
#endif /* W32_TRAP_DEBUG */
\f
+#ifndef PAGE_SIZE
+# define PAGE_SIZE 0x1000
+#endif
+
+extern void EXFUN (winnt_stack_reset, (void));
+extern void EXFUN (winnt_protect_stack, (void));
+extern void EXFUN (winnt_unprotect_stack, (void));
+
+static Boolean stack_protected = FALSE;
+unsigned long protected_stack_base;
+unsigned long protected_stack_end;
+
+void
+DEFUN_VOID (winnt_unprotect_stack)
+{
+ DWORD old_protection;
+
+ if ((stack_protected)
+ && (VirtualProtect (((LPVOID) protected_stack_base),
+ PAGE_SIZE,
+ PAGE_READWRITE,
+ &old_protection)))
+ stack_protected = FALSE;
+ return;
+}
+
+void
+DEFUN_VOID (winnt_protect_stack)
+{
+ DWORD old_protection;
+
+ if ((! stack_protected)
+ && (VirtualProtect (((LPVOID) protected_stack_base),
+ PAGE_SIZE,
+ (PAGE_GUARD | PAGE_READWRITE),
+ &old_protection)))
+ stack_protected = TRUE;
+ return;
+}
+
+void
+DEFUN_VOID (winnt_stack_reset)
+{
+ unsigned long boundary;
+
+ /* This presumes that the distance between Absolute_Stack_Base and
+ Stack_Guard is at least a page.
+ */
+
+ boundary = (((unsigned long) Stack_Guard)
+ & (~ ((unsigned long) (PAGE_SIZE - 1))));
+ if (stack_protected && (protected_stack_base == boundary))
+ return;
+ winnt_unprotect_stack ();
+ protected_stack_base = boundary;
+ protected_stack_end = (boundary + PAGE_SIZE);
+ winnt_protect_stack ();
+ return;
+}
+\f
+#define EXCEPTION_CODE_GUARDED_PAGE_ACCESS 0x80000001L
+
static int
DEFUN (WinntException, (code, info),
DWORD code AND LPEXCEPTION_POINTERS info)
MB_OK);
trap_immediate_termination ();
}
+ else if ((code == EXCEPTION_CODE_GUARDED_PAGE_ACCESS)
+ && stack_protected
+ && (context->Esp >= protected_stack_base)
+ && (context->Esp <= protected_stack_end))
+ {
+ stack_protected = FALSE;
+ REQUEST_INTERRUPT (INT_Stack_Overflow);
+ return (EXCEPTION_CONTINUE_EXECUTION);
+ }
else
{
#ifdef W32_TRAP_DEBUG
/* -*-C-*-
-$Id: stack.h,v 9.34 1993/06/24 06:22:52 gjr Exp $
+$Id: stack.h,v 9.35 1993/09/08 04:38:21 gjr Exp $
Copyright (c) 1987-1993 Massachusetts Institute of Technology
/* This file contains macros for manipulating stacks and stacklets. */
\f
#ifdef DOS386
+ extern void EXFUN (dos386_stack_reset, (void));
+# define STACK_RESET() dos386_stack_reset()
+#endif /* DOS386 */
-extern void EXFUN (dos386_stack_reset, (void));
-#define STACK_RESET() dos386_stack_reset()
+#ifdef WINNT
+ extern void EXFUN (winnt_stack_reset, (void));
+# define STACK_RESET() winnt_stack_reset()
+#endif /* WINNT */
-#else
+#ifndef STACK_RESET
+# define STACK_RESET() do {} while (0)
+#endif /* STACK_RESET */
-#define STACK_RESET() do \
-{ \
-} while (0)
-
-#endif
#ifdef USE_STACKLETS