2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS sysem libraries
4 * PURPOSE: Vectored Exception Handling
5 * FILE: lib/rtl/vectoreh.c
6 * PROGRAMERS: Thomas Weidenmueller
9 /* INCLUDES *****************************************************************/
16 static RTL_CRITICAL_SECTION RtlpVectoredExceptionLock
;
17 static LIST_ENTRY RtlpVectoredExceptionHead
;
19 typedef struct _RTL_VECTORED_EXCEPTION_HANDLER
22 PVECTORED_EXCEPTION_HANDLER VectoredHandler
;
23 } RTL_VECTORED_EXCEPTION_HANDLER
, *PRTL_VECTORED_EXCEPTION_HANDLER
;
25 /* FIXME - stupid ld won't resolve RtlDecodePointer! Since their implementation
26 is the same just use RtlEncodePointer for now! */
27 #define RtlDecodePointer RtlEncodePointer
29 /* FUNCTIONS ***************************************************************/
31 EXCEPTION_DISPOSITION NTAPI
32 RtlpExecuteVectoredExceptionHandlers(IN PEXCEPTION_RECORD ExceptionRecord
,
35 PLIST_ENTRY CurrentEntry
;
36 PRTL_VECTORED_EXCEPTION_HANDLER veh
;
37 PVECTORED_EXCEPTION_HANDLER VectoredHandler
;
38 EXCEPTION_POINTERS ExceptionInfo
;
40 ExceptionInfo
.ExceptionRecord
= ExceptionRecord
;
41 ExceptionInfo
.ContextRecord
= Context
;
43 if(RtlpVectoredExceptionHead
.Flink
!= &RtlpVectoredExceptionHead
)
45 RtlEnterCriticalSection(&RtlpVectoredExceptionLock
);
46 for(CurrentEntry
= RtlpVectoredExceptionHead
.Flink
;
47 CurrentEntry
!= &RtlpVectoredExceptionHead
;
48 CurrentEntry
= CurrentEntry
->Flink
)
50 veh
= CONTAINING_RECORD(CurrentEntry
,
51 RTL_VECTORED_EXCEPTION_HANDLER
,
53 VectoredHandler
= RtlDecodePointer(veh
->VectoredHandler
);
54 RtlLeaveCriticalSection(&RtlpVectoredExceptionLock
);
56 if(VectoredHandler(&ExceptionInfo
) == EXCEPTION_CONTINUE_EXECUTION
)
58 return ExceptionContinueSearch
;
61 RtlEnterCriticalSection(&RtlpVectoredExceptionLock
);
63 RtlLeaveCriticalSection(&RtlpVectoredExceptionLock
);
66 return ExceptionContinueExecution
;
70 RtlpInitializeVectoredExceptionHandling(VOID
)
72 InitializeListHead(&RtlpVectoredExceptionHead
);
73 RtlInitializeCriticalSection(&RtlpVectoredExceptionLock
);
81 RtlAddVectoredExceptionHandler(IN ULONG FirstHandler
,
82 IN PVECTORED_EXCEPTION_HANDLER VectoredHandler
)
84 PRTL_VECTORED_EXCEPTION_HANDLER veh
;
86 veh
= RtlAllocateHeap(RtlGetProcessHeap(),
88 sizeof(RTL_VECTORED_EXCEPTION_HANDLER
));
91 veh
->VectoredHandler
= RtlEncodePointer(VectoredHandler
);
92 RtlEnterCriticalSection(&RtlpVectoredExceptionLock
);
95 InsertHeadList(&RtlpVectoredExceptionHead
,
100 InsertTailList(&RtlpVectoredExceptionHead
,
103 RtlLeaveCriticalSection(&RtlpVectoredExceptionLock
);
114 RtlRemoveVectoredExceptionHandler(IN PVOID VectoredHandlerHandle
)
116 PLIST_ENTRY CurrentEntry
;
117 PRTL_VECTORED_EXCEPTION_HANDLER veh
= NULL
;
118 ULONG Removed
= FALSE
;
120 RtlEnterCriticalSection(&RtlpVectoredExceptionLock
);
121 for(CurrentEntry
= RtlpVectoredExceptionHead
.Flink
;
122 CurrentEntry
!= &RtlpVectoredExceptionHead
;
123 CurrentEntry
= CurrentEntry
->Flink
)
125 veh
= CONTAINING_RECORD(CurrentEntry
,
126 RTL_VECTORED_EXCEPTION_HANDLER
,
128 if(veh
== VectoredHandlerHandle
)
130 RemoveEntryList(&veh
->ListEntry
);
135 RtlLeaveCriticalSection(&RtlpVectoredExceptionLock
);
139 RtlFreeHeap(RtlGetProcessHeap(),