ReactOS 0.4.16-dev-1946-g52006dd
RtlUnhandledExceptionFilter.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API tests
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Tests for RtlUnhandledExceptionFilter(2)
5 * COPYRIGHT: Copyright 2025 Hermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
6 */
7
8#include "precomp.h"
9
11{
12/* Well-known exception codes, see include/psdk/minwinbase.h */
36/* Additional ones */
38};
39
41{
42 LONG (NTAPI* pRtlUnhandledExceptionFilter)(_In_ PEXCEPTION_POINTERS ExceptionInfo);
43 LONG (NTAPI* pRtlUnhandledExceptionFilter2)(_In_ PEXCEPTION_POINTERS ExceptionInfo, _In_ PCSTR Function);
45 CONTEXT ctx = {0};
46 EXCEPTION_RECORD er = {0};
47 EXCEPTION_POINTERS ep = {&er, &ctx};
48
49 /* Load functions */
50 HMODULE hNtDll = GetModuleHandleW(L"ntdll.dll");
51 if (!hNtDll)
52 {
53 skip("GetModuleHandleW(\"ntdll.dll\") failed with 0x%08lX\n", GetLastError());
54 return;
55 }
56 pRtlUnhandledExceptionFilter = (VOID*)GetProcAddress(hNtDll, "RtlUnhandledExceptionFilter");
57 pRtlUnhandledExceptionFilter2 = (VOID*)GetProcAddress(hNtDll, "RtlUnhandledExceptionFilter2");
58 if (!pRtlUnhandledExceptionFilter || !pRtlUnhandledExceptionFilter2)
59 {
60 skip("ntdll!RtlUnhandledExceptionFilter(2) not found\n");
61 return;
62 }
63
64 /* Build a dummy context/exception record. Not really valid on self, don't care. */
65 ctx.ContextFlags = CONTEXT_CONTROL;
67
68 /* Disable BeingDebugged so that RtlUnhandledExceptionFilter(2) doesn't
69 * unnecessarily break into the debugger with the debugging instructions.
70 * If you want to see them, comment the following line! */
72
73 /* Test the filter routine return value under different exception codes */
74 // for (er.ExceptionCode = 0; er.ExceptionCode != ~0; ++er.ExceptionCode)
75 for (UINT i = 0; i < _countof(KnownExceptionCodes); ++i)
76 {
78 BOOLEAN fail = TRUE;
80
81 /* Skip test if stack overflow code; the filter would invoke another crash handler */
83 continue;
84
86 {
88 {
89 r = pRtlUnhandledExceptionFilter2(&ep, __FUNCTION__);
90 fail = FALSE;
91 }
93 {
94 }
96 }
98 {
99 }
100 _SEH2_END;
101
102 // trace("%#x ret %lu\n", er.ExceptionCode, r);
105 else
107 if (fail)
108 trace("SEH on %#x\n", er.ExceptionCode);
109 }
110}
#define NtCurrentPeb()
Definition: FLS.c:22
unsigned char BOOLEAN
static NTSTATUS KnownExceptionCodes[]
#define ok_long(expression, result)
Definition: atltest.h:133
#define trace
Definition: atltest.h:70
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
LONG NTSTATUS
Definition: precomp.h:26
_In_ CDROM_SCAN_FOR_SPECIAL_INFO _In_ PCDROM_SCAN_FOR_SPECIAL_HANDLER Function
Definition: cdrom.h:1156
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcAddress(x, y)
Definition: compat.h:753
PPEB Peb
Definition: dllmain.c:27
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
BOOL WINAPI GetThreadContext(IN HANDLE hThread, OUT LPCONTEXT lpContext)
Definition: thread.c:501
#define L(x)
Definition: resources.c:13
#define __FUNCTION__
Definition: types.h:116
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
#define EXCEPTION_CONTINUE_SEARCH
Definition: excpt.h:91
#define EXCEPTION_CONTINUE_EXECUTION
Definition: excpt.h:92
#define EXCEPTION_SINGLE_STEP
Definition: minwinbase.h:47
#define EXCEPTION_NONCONTINUABLE_EXCEPTION
Definition: minwinbase.h:61
#define EXCEPTION_GUARD_PAGE
Definition: minwinbase.h:64
#define EXCEPTION_FLT_STACK_CHECK
Definition: minwinbase.h:54
#define EXCEPTION_STACK_OVERFLOW
Definition: minwinbase.h:62
#define EXCEPTION_POSSIBLE_DEADLOCK
Definition: minwinbase.h:66
#define EXCEPTION_INT_DIVIDE_BY_ZERO
Definition: minwinbase.h:56
#define EXCEPTION_IN_PAGE_ERROR
Definition: minwinbase.h:59
#define EXCEPTION_FLT_UNDERFLOW
Definition: minwinbase.h:55
#define EXCEPTION_INT_OVERFLOW
Definition: minwinbase.h:57
#define EXCEPTION_INVALID_HANDLE
Definition: minwinbase.h:65
#define EXCEPTION_INVALID_DISPOSITION
Definition: minwinbase.h:63
#define EXCEPTION_FLT_OVERFLOW
Definition: minwinbase.h:53
#define EXCEPTION_ARRAY_BOUNDS_EXCEEDED
Definition: minwinbase.h:48
#define EXCEPTION_DATATYPE_MISALIGNMENT
Definition: minwinbase.h:45
#define EXCEPTION_FLT_DENORMAL_OPERAND
Definition: minwinbase.h:49
#define EXCEPTION_FLT_INEXACT_RESULT
Definition: minwinbase.h:51
#define EXCEPTION_ILLEGAL_INSTRUCTION
Definition: minwinbase.h:60
#define EXCEPTION_ACCESS_VIOLATION
Definition: minwinbase.h:44
#define EXCEPTION_BREAKPOINT
Definition: minwinbase.h:46
#define EXCEPTION_FLT_INVALID_OPERATION
Definition: minwinbase.h:52
#define EXCEPTION_PRIV_INSTRUCTION
Definition: minwinbase.h:58
#define EXCEPTION_FLT_DIVIDE_BY_ZERO
Definition: minwinbase.h:50
unsigned int UINT
Definition: ndis.h:50
#define _In_
Definition: no_sal2.h:158
#define CONTEXT_CONTROL
Definition: nt_native.h:1372
#define STATUS_POSSIBLE_DEADLOCK
Definition: ntstatus.h:731
#define STATUS_STACK_BUFFER_OVERRUN
Definition: ntstatus.h:1078
long LONG
Definition: pedump.c:60
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:82
#define _SEH2_FINALLY
Definition: pseh2_64.h:130
#define _SEH2_END
Definition: pseh2_64.h:171
#define _SEH2_TRY
Definition: pseh2_64.h:71
LONG NTAPI RtlUnhandledExceptionFilter(_In_ PEXCEPTION_POINTERS ExceptionInfo)
Definition: exception.c:313
#define _countof(array)
Definition: sndvol32.h:70
DWORD ExceptionCode
Definition: compat.h:208
BYTE BeingDebugged
Definition: btrfs_drv.h:1909
#define NTAPI
Definition: typedefs.h:36
const char * PCSTR
Definition: typedefs.h:52
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
HANDLE WINAPI GetCurrentThread(void)
Definition: proc.c:1148