https://git.reactos.org/?p=reactos.git;a=commitdiff;h=2913ef5c9300fe1028de0…
commit 2913ef5c9300fe1028de07f238dcb2ed39174edf
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Sat Sep 7 23:33:48 2024 +0300
Commit: Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Thu Sep 12 17:07:59 2024 +0300
[NTOS:KE/x64] Fix exception information on page faults
Pass a proper write/execute flag in the ExceptionInformation[0] field of the exception record instead of the raw fault code. This fixes comdlg:filedlg wine test, which writes to a write protected resource section, which needs to be handled by kernel32 UnhandledExceptionFilter, which relies on this parameter to be correct.
---
ntoskrnl/ke/amd64/trap.S | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/ntoskrnl/ke/amd64/trap.S b/ntoskrnl/ke/amd64/trap.S
index 03e71bf9bc3..34b7c906104 100644
--- a/ntoskrnl/ke/amd64/trap.S
+++ b/ntoskrnl/ke/amd64/trap.S
@@ -461,8 +461,11 @@ IntsDisabled:
PageFaultError:
- /* Set parameter 1 to error code */
+ /* Set parameter 1 to write/execute flag.
+ See https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-exceptio… */
mov r9d, [rbp + KTRAP_FRAME_ErrorCode]
+ shr r9d, 1
+ and r9d, 9
/* Set parameter 2 to faulting address */
mov r10, cr2 // Param2 = faulting address
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=5eab2ddb2eb362eb2d5c3…
commit 5eab2ddb2eb362eb2d5c327003d5193e071c573a
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Sat Sep 7 22:10:28 2024 +0300
Commit: Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Thu Sep 12 17:07:59 2024 +0300
[RTL/x64] Do not overwrite the original context during exception handling
This fixes ExceptionContinueExecution cases, where we want to continue execution on the original context (or as modified by the handler), not on some halfway unwinded one.
---
sdk/lib/rtl/amd64/unwind.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/sdk/lib/rtl/amd64/unwind.c b/sdk/lib/rtl/amd64/unwind.c
index 4a5903361b9..ee7313bc62f 100644
--- a/sdk/lib/rtl/amd64/unwind.c
+++ b/sdk/lib/rtl/amd64/unwind.c
@@ -679,7 +679,7 @@ RtlpUnwindInternal(
ULONG64 ImageBase, EstablisherFrame;
CONTEXT UnwindContext;
- /* Get the current stack limits and registration frame */
+ /* Get the current stack limits */
RtlpGetStackLimits(&StackLow, &StackHigh);
/* If we have a target frame, then this is our high limit */
@@ -708,8 +708,11 @@ RtlpUnwindInternal(
UnwindContext.Rip = *(DWORD64*)UnwindContext.Rsp;
UnwindContext.Rsp += sizeof(DWORD64);
- /* Copy the context back for the next iteration */
- *ContextRecord = UnwindContext;
+ if (HandlerType == UNW_FLAG_UHANDLER)
+ {
+ /* Copy the context back for the next iteration */
+ *ContextRecord = UnwindContext;
+ }
continue;
}
@@ -756,7 +759,7 @@ RtlpUnwindInternal(
/* Log the exception if it's enabled */
RtlpCheckLogException(ExceptionRecord,
- ContextRecord,
+ &UnwindContext,
&DispatcherContext,
sizeof(DispatcherContext));
@@ -844,8 +847,11 @@ RtlpUnwindInternal(
break;
}
- /* We have successfully unwound a frame. Copy the unwind context back. */
- *ContextRecord = UnwindContext;
+ if (HandlerType == UNW_FLAG_UHANDLER)
+ {
+ /* We have successfully unwound a frame. Copy the unwind context back. */
+ *ContextRecord = UnwindContext;
+ }
}
if (ExceptionRecord->ExceptionCode != STATUS_UNWIND_CONSOLIDATE)