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
;
18 static volatile LONG RtlpVectoredExceptionsInstalled
;
20 typedef struct _RTL_VECTORED_EXCEPTION_HANDLER
23 PVECTORED_EXCEPTION_HANDLER VectoredHandler
;
26 } RTL_VECTORED_EXCEPTION_HANDLER
, *PRTL_VECTORED_EXCEPTION_HANDLER
;
28 /* FUNCTIONS ***************************************************************/
32 RtlCallVectoredExceptionHandlers(IN PEXCEPTION_RECORD ExceptionRecord
,
35 PLIST_ENTRY CurrentEntry
;
36 PRTL_VECTORED_EXCEPTION_HANDLER veh
= NULL
;
37 PVECTORED_EXCEPTION_HANDLER VectoredHandler
;
38 EXCEPTION_POINTERS ExceptionInfo
;
39 BOOLEAN Remove
= FALSE
;
42 ExceptionInfo
.ExceptionRecord
= ExceptionRecord
;
43 ExceptionInfo
.ContextRecord
= Context
;
45 if(RtlpVectoredExceptionsInstalled
)
47 RtlEnterCriticalSection(&RtlpVectoredExceptionLock
);
48 CurrentEntry
= RtlpVectoredExceptionHead
.Flink
;
49 while (CurrentEntry
!= &RtlpVectoredExceptionHead
)
51 veh
= CONTAINING_RECORD(CurrentEntry
,
52 RTL_VECTORED_EXCEPTION_HANDLER
,
55 RtlLeaveCriticalSection(&RtlpVectoredExceptionLock
);
57 VectoredHandler
= RtlDecodePointer(veh
->VectoredHandler
);
58 if(VectoredHandler(&ExceptionInfo
) == EXCEPTION_CONTINUE_EXECUTION
)
60 RtlEnterCriticalSection(&RtlpVectoredExceptionLock
);
63 RemoveEntryList (&veh
->ListEntry
);
64 InterlockedDecrement (&RtlpVectoredExceptionsInstalled
);
71 RtlEnterCriticalSection(&RtlpVectoredExceptionLock
);
75 CurrentEntry
= veh
->ListEntry
.Flink
;
76 RemoveEntryList (&veh
->ListEntry
);
77 InterlockedDecrement (&RtlpVectoredExceptionsInstalled
);
78 RtlLeaveCriticalSection(&RtlpVectoredExceptionLock
);
80 RtlFreeHeap(RtlGetProcessHeap(),
83 RtlEnterCriticalSection(&RtlpVectoredExceptionLock
);
86 CurrentEntry
= CurrentEntry
->Flink
;
89 RtlLeaveCriticalSection(&RtlpVectoredExceptionLock
);
94 RtlFreeHeap(RtlGetProcessHeap(),
103 RtlpInitializeVectoredExceptionHandling(VOID
)
105 InitializeListHead(&RtlpVectoredExceptionHead
);
106 RtlInitializeCriticalSection(&RtlpVectoredExceptionLock
);
107 RtlpVectoredExceptionsInstalled
= 0;
115 RtlAddVectoredExceptionHandler(IN ULONG FirstHandler
,
116 IN PVECTORED_EXCEPTION_HANDLER VectoredHandler
)
118 PRTL_VECTORED_EXCEPTION_HANDLER veh
;
120 veh
= RtlAllocateHeap(RtlGetProcessHeap(),
122 sizeof(RTL_VECTORED_EXCEPTION_HANDLER
));
125 veh
->VectoredHandler
= RtlEncodePointer(VectoredHandler
);
127 veh
->Deleted
= FALSE
;
128 RtlEnterCriticalSection(&RtlpVectoredExceptionLock
);
129 if(FirstHandler
!= 0)
131 InsertHeadList(&RtlpVectoredExceptionHead
,
136 InsertTailList(&RtlpVectoredExceptionHead
,
139 InterlockedIncrement (&RtlpVectoredExceptionsInstalled
);
140 RtlLeaveCriticalSection(&RtlpVectoredExceptionLock
);
151 RtlRemoveVectoredExceptionHandler(IN PVOID VectoredHandlerHandle
)
153 PLIST_ENTRY CurrentEntry
;
154 PRTL_VECTORED_EXCEPTION_HANDLER veh
= NULL
;
155 BOOLEAN Remove
= FALSE
;
158 RtlEnterCriticalSection(&RtlpVectoredExceptionLock
);
159 for(CurrentEntry
= RtlpVectoredExceptionHead
.Flink
;
160 CurrentEntry
!= &RtlpVectoredExceptionHead
;
161 CurrentEntry
= CurrentEntry
->Flink
)
163 veh
= CONTAINING_RECORD(CurrentEntry
,
164 RTL_VECTORED_EXCEPTION_HANDLER
,
166 if(veh
== VectoredHandlerHandle
)
170 if (--veh
->Refs
== 0)
172 RemoveEntryList (&veh
->ListEntry
);
181 RtlLeaveCriticalSection(&RtlpVectoredExceptionLock
);
185 RtlFreeHeap(RtlGetProcessHeap(),
195 RtlAddVectoredContinueHandler(
196 IN ULONG FirstHandler
,
197 IN PVECTORED_EXCEPTION_HANDLER VectoredHandler
)
205 RtlRemoveVectoredContinueHandler(
206 IN PVOID VectoredHandlerHandle
)