ReactOS  0.4.15-dev-3173-g40ee59d
except.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Run-Time Library
3  * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE: User-mode exception support for AMD64
5  * COPYRIGHT: Copyright 2018-2021 Timo Kreuzer <timo.kreuzer@reactos.org>
6  */
7 
8 /* INCLUDES *****************************************************************/
9 
10 #include <rtl.h>
11 #define NDEBUG
12 #include <debug.h>
13 
14 /* PUBLIC FUNCTIONS **********************************************************/
15 
16 VOID
17 NTAPI
19 {
22 
23  /* Capture the current context */
25 
26  /* Fix up Context.Rip for the caller */
28 
29  /* Fix up Context.Rsp for the caller */
31 
32  /* Save the exception address */
33  ExceptionRecord->ExceptionAddress = (PVOID)Context.Rip;
34 
35  /* Check if user mode debugger is active */
37  {
38  /* Raise an exception immediately */
39  Status = ZwRaiseException(ExceptionRecord, &Context, TRUE);
40  }
41  else
42  {
43  /* Dispatch the exception and check if we should continue */
44  if (!RtlDispatchException(ExceptionRecord, &Context))
45  {
46  /* Raise the exception */
47  Status = ZwRaiseException(ExceptionRecord, &Context, FALSE);
48  }
49  else
50  {
51  /* Continue, go back to previous context */
53  }
54  }
55 
56  /* If we returned, raise a status */
58 }
59 
60 /*
61 * @unimplemented
62 */
63 PVOID
64 NTAPI
66 {
68  return NULL;
69 }
70 
71 BOOLEAN
72 NTAPI
74  _In_opt_ PVOID TargetFrame,
75  _In_opt_ PVOID TargetIp,
76  _In_ PEXCEPTION_RECORD ExceptionRecord,
79  _In_opt_ struct _UNWIND_HISTORY_TABLE *HistoryTable,
80  _In_ ULONG Flags);
81 
82 /*
83  * @unimplemented
84  */
85 BOOLEAN
86 NTAPI
88  _In_ PEXCEPTION_RECORD ExceptionRecord,
90 {
92 
93  /* Perform vectored exception handling for user mode */
94  if (RtlCallVectoredExceptionHandlers(ExceptionRecord, ContextRecord))
95  {
96  /* Exception handled, now call vectored continue handlers */
98 
99  /* Continue execution */
100  return TRUE;
101  }
102 
103  /* Call the internal unwind routine */
104  Handled = RtlpUnwindInternal(NULL, // TargetFrame
105  NULL, // TargetIp
106  ExceptionRecord,
107  0, // ReturnValue
109  NULL, // HistoryTable
111 
112  /* In user mode, call any registered vectored continue handlers */
114 
115  return Handled;
116 }
#define IN
Definition: typedefs.h:39
DECLSPEC_NORETURN NTSYSAPI VOID NTAPI RtlRaiseStatus(_In_ NTSTATUS Status)
#define _In_opt_
Definition: ms_sal.h:309
VOID NTAPI RtlRaiseException(IN PEXCEPTION_RECORD ExceptionRecord)
Definition: except.c:18
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI NTSTATUS NTAPI ZwRaiseException(_In_ PEXCEPTION_RECORD ExceptionRecord, _In_ PCONTEXT Context, _In_ BOOLEAN SearchFrames)
void * _AddressOfReturnAddress(void)
BOOLEAN NTAPI RtlpUnwindInternal(_In_opt_ PVOID TargetFrame, _In_opt_ PVOID TargetIp, _In_ PEXCEPTION_RECORD ExceptionRecord, _In_ PVOID ReturnValue, _In_ PCONTEXT ContextRecord, _In_opt_ struct _UNWIND_HISTORY_TABLE *HistoryTable, _In_ ULONG Flags)
Definition: unwind.c:686
if(dx==0 &&dy==0)
Definition: linetemp.h:174
NTSYSAPI VOID NTAPI RtlCaptureContext(_Out_ PCONTEXT ContextRecord)
NTSYSAPI NTSTATUS NTAPI ZwContinue(_In_ PCONTEXT Context, _In_ BOOLEAN TestAlert)
PVOID NTAPI RtlpGetExceptionAddress(VOID)
Definition: except.c:65
UINT32 void void ** ReturnValue
Definition: acevents.h:214
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
#define STATUS_INVALID_DISPOSITION
Definition: ntstatus.h:275
unsigned char BOOLEAN
#define _In_
Definition: ms_sal.h:308
void * PVOID
Definition: retypes.h:9
Status
Definition: gdiplustypes.h:24
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
_In_ BOOLEAN Handled
Definition: ketypes.h:337
BOOLEAN NTAPI RtlCallVectoredExceptionHandlers(_In_ PEXCEPTION_RECORD ExceptionRecord, _In_ PCONTEXT Context)
Definition: libsupp.c:817
_IRQL_requires_same_ _In_ PVOID _Inout_ struct _CONTEXT * ContextRecord
Definition: ntbasedef.h:654
unsigned __int64 ULONG64
Definition: imports.h:198
BOOLEAN NTAPI RtlpCheckForActiveDebugger(VOID)
Definition: libsupp.c:25
#define NULL
Definition: types.h:112
void * _ReturnAddress(void)
struct tagContext Context
Definition: acpixf.h:1034
VOID NTAPI RtlCallVectoredContinueHandlers(_In_ PEXCEPTION_RECORD ExceptionRecord, _In_ PCONTEXT Context)
Definition: libsupp.c:826
BOOLEAN NTAPI RtlDispatchException(_In_ PEXCEPTION_RECORD ExceptionRecord, _In_ PCONTEXT ContextRecord)
Definition: except.c:87
unsigned int ULONG
Definition: retypes.h:1
#define UNIMPLEMENTED
Definition: debug.h:115