Skip to content

Commit db69a9a

Browse files
committed
[RTL][NDK] Improve RtlUnhandledExceptionFilter(2) (reactos#8353)
- Reimplement `RtlUnhandledExceptionFilter()` by just calling `RtlUnhandledExceptionFilter2()`. - Return an adequate exception filter value `EXCEPTION_CONTINUE_SEARCH` from `RtlUnhandledExceptionFilter2()`, instead of some random error. If `ExceptionCode` is `STATUS_POSSIBLE_DEADLOCK` however, return `EXCEPTION_CONTINUE_EXECUTION` instead, as shown by a test from Whindmar Saksit. - The second parameter of `RtlUnhandledExceptionFilter2()` is not a flag, but a pointer to string `PCSTR` ! See https://skanthak.hier-im-netz.de/download/NTDLL.H who is the only one online who has the correct definition, whose usage I've double-checked on Win7 ntdll.dll. This is used in the `<function_name>` slot in the displayed debugger message: ``` *** An Access Violation occurred in <program_command_line>:<function_name> The instruction at <address> tried to write to a NULL pointer ``` For example, see: https://community.osr.com/t/access-violation/33435
1 parent 92f680d commit db69a9a

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

sdk/include/ndk/rtlfuncs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ NTSYSAPI
676676
LONG
677677
NTAPI
678678
RtlUnhandledExceptionFilter(
679-
_In_ struct _EXCEPTION_POINTERS* ExceptionInfo
679+
_In_ PEXCEPTION_POINTERS ExceptionInfo
680680
);
681681

682682
__analysis_noreturn

sdk/lib/rtl/exception.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ RtlRaiseStatus(IN NTSTATUS Status)
8787
EXCEPTION_RECORD ExceptionRecord;
8888
CONTEXT Context;
8989

90-
/* Capture the context */
90+
/* Capture the context */
9191
RtlCaptureContext(&Context);
9292

9393
/* Create an exception record */
@@ -234,14 +234,14 @@ static VOID
234234
}
235235

236236
static VOID
237-
PrintStackTrace(struct _EXCEPTION_POINTERS *ExceptionInfo)
237+
PrintStackTrace(struct _EXCEPTION_POINTERS *ExceptionInfo)
238238
{
239239
PVOID StartAddr;
240240
CHAR szMod[128] = "";
241241
PEXCEPTION_RECORD ExceptionRecord = ExceptionInfo->ExceptionRecord;
242242
PCONTEXT ContextRecord = ExceptionInfo->ContextRecord;
243243

244-
/* Print a stack trace. */
244+
/* Print a stack trace */
245245
DbgPrint("Unhandled exception\n");
246246
DbgPrint("ExceptionCode: %8x\n", ExceptionRecord->ExceptionCode);
247247

@@ -310,12 +310,10 @@ static VOID
310310
*/
311311
LONG
312312
NTAPI
313-
RtlUnhandledExceptionFilter(IN struct _EXCEPTION_POINTERS* ExceptionInfo)
313+
RtlUnhandledExceptionFilter(
314+
_In_ PEXCEPTION_POINTERS ExceptionInfo)
314315
{
315-
/* This is used by the security cookie checks, and also called externally */
316-
UNIMPLEMENTED;
317-
PrintStackTrace(ExceptionInfo);
318-
return ERROR_CALL_NOT_IMPLEMENTED;
316+
return RtlUnhandledExceptionFilter2(ExceptionInfo, "");
319317
}
320318

321319
/*
@@ -325,12 +323,17 @@ LONG
325323
NTAPI
326324
RtlUnhandledExceptionFilter2(
327325
_In_ PEXCEPTION_POINTERS ExceptionInfo,
328-
_In_ ULONG Flags)
326+
_In_ PCSTR Function)
329327
{
330328
/* This is used by the security cookie checks, and also called externally */
331329
UNIMPLEMENTED;
330+
ASSERT(ExceptionInfo && ExceptionInfo->ExceptionRecord);
331+
332332
PrintStackTrace(ExceptionInfo);
333-
return ERROR_CALL_NOT_IMPLEMENTED;
333+
334+
if (ExceptionInfo->ExceptionRecord->ExceptionCode == STATUS_POSSIBLE_DEADLOCK)
335+
return EXCEPTION_CONTINUE_EXECUTION;
336+
return EXCEPTION_CONTINUE_SEARCH;
334337
}
335338

336339
/*

0 commit comments

Comments
 (0)