diff --git a/patches/ntdll-Stack_Guard_Pages/0001-ntdll-Handle-stack-guard-pages-on-x86_64.patch b/patches/ntdll-Stack_Guard_Pages/0001-ntdll-Handle-stack-guard-pages-on-x86_64.patch new file mode 100644 index 00000000..0296ee91 --- /dev/null +++ b/patches/ntdll-Stack_Guard_Pages/0001-ntdll-Handle-stack-guard-pages-on-x86_64.patch @@ -0,0 +1,45 @@ +From d1f1c77ffb5eef8e440a9ba8a192cafde327227f Mon Sep 17 00:00:00 2001 +From: Sebastian Lackner +Date: Sat, 26 Mar 2016 22:26:43 +0100 +Subject: ntdll: Handle stack guard pages on x86_64. + +--- + dlls/ntdll/signal_x86_64.c | 20 +++++++++++++++++++- + 1 file changed, 19 insertions(+), 1 deletion(-) + +diff --git a/dlls/ntdll/signal_x86_64.c b/dlls/ntdll/signal_x86_64.c +index 1e88df3..e00132e 100644 +--- a/dlls/ntdll/signal_x86_64.c ++++ b/dlls/ntdll/signal_x86_64.c +@@ -2587,9 +2587,27 @@ static inline BOOL handle_interrupt( unsigned int interrupt, EXCEPTION_RECORD *r + */ + static void segv_handler( int signal, siginfo_t *siginfo, void *sigcontext ) + { +- EXCEPTION_RECORD *rec = setup_exception( sigcontext, raise_segv_exception ); ++ EXCEPTION_RECORD *rec; + ucontext_t *ucontext = sigcontext; + ++ /* check for page fault inside the thread stack */ ++ if (TRAP_sig(ucontext) == TRAP_x86_PAGEFLT && ++ (char *)siginfo->si_addr >= (char *)NtCurrentTeb()->DeallocationStack && ++ (char *)siginfo->si_addr < (char *)NtCurrentTeb()->Tib.StackBase && ++ virtual_handle_stack_fault( siginfo->si_addr )) ++ { ++ /* check if this was the last guard page */ ++ if ((char *)siginfo->si_addr < (char *)NtCurrentTeb()->DeallocationStack + 2*4096) ++ { ++ rec = setup_exception( sigcontext, raise_segv_exception ); ++ rec->ExceptionCode = EXCEPTION_STACK_OVERFLOW; ++ } ++ return; ++ } ++ ++ rec = setup_exception( sigcontext, raise_segv_exception ); ++ if (rec->ExceptionCode == EXCEPTION_STACK_OVERFLOW) return; ++ + switch(TRAP_sig(ucontext)) + { + case TRAP_x86_OFLOW: /* Overflow exception */ +-- +2.7.1 + diff --git a/patches/ntdll-Stack_Guard_Pages/definition b/patches/ntdll-Stack_Guard_Pages/definition new file mode 100644 index 00000000..d783c447 --- /dev/null +++ b/patches/ntdll-Stack_Guard_Pages/definition @@ -0,0 +1 @@ +Fixes: Handle stack guard pages on x86_64 diff --git a/patches/patchinstall.sh b/patches/patchinstall.sh index 9766bf0b..e11e7a48 100755 --- a/patches/patchinstall.sh +++ b/patches/patchinstall.sh @@ -233,6 +233,7 @@ patch_enable_all () enable_ntdll_RtlIpStringToAddress_Tests="$1" enable_ntdll_RtlQueryPackageIdentity="$1" enable_ntdll_Serial_Port_Detection="$1" + enable_ntdll_Stack_Guard_Pages="$1" enable_ntdll_Status_Mapping="$1" enable_ntdll_Syscall_Wrappers="$1" enable_ntdll_SystemInterruptInformation="$1" @@ -875,6 +876,9 @@ patch_enable () ntdll-Serial_Port_Detection) enable_ntdll_Serial_Port_Detection="$2" ;; + ntdll-Stack_Guard_Pages) + enable_ntdll_Stack_Guard_Pages="$2" + ;; ntdll-Status_Mapping) enable_ntdll_Status_Mapping="$2" ;; @@ -5176,6 +5180,18 @@ if test "$enable_ntdll_Serial_Port_Detection" -eq 1; then ) >> "$patchlist" fi +# Patchset ntdll-Stack_Guard_Pages +# | +# | Modified files: +# | * dlls/ntdll/signal_x86_64.c +# | +if test "$enable_ntdll_Stack_Guard_Pages" -eq 1; then + patch_apply ntdll-Stack_Guard_Pages/0001-ntdll-Handle-stack-guard-pages-on-x86_64.patch + ( + echo '+ { "Sebastian Lackner", "ntdll: Handle stack guard pages on x86_64.", 1 },'; + ) >> "$patchlist" +fi + # Patchset ntdll-Status_Mapping # | # | Modified files: