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 ***************************************************************/
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 if(VectoredHandler(&ExceptionInfo
) == EXCEPTION_CONTINUE_EXECUTION
)
56 RtlLeaveCriticalSection(&RtlpVectoredExceptionLock
);
57 return ExceptionContinueSearch
;
60 RtlLeaveCriticalSection(&RtlpVectoredExceptionLock
);
63 return ExceptionContinueExecution
;
67 RtlpInitializeVectoredExceptionHandling(VOID
)
69 InitializeListHead(&RtlpVectoredExceptionHead
);
70 RtlInitializeCriticalSection(&RtlpVectoredExceptionLock
);
78 RtlAddVectoredExceptionHandler(IN ULONG FirstHandler
,
79 IN PVECTORED_EXCEPTION_HANDLER VectoredHandler
)
81 PRTL_VECTORED_EXCEPTION_HANDLER veh
;
83 veh
= RtlAllocateHeap(RtlGetProcessHeap(),
85 sizeof(RTL_VECTORED_EXCEPTION_HANDLER
));
88 veh
->VectoredHandler
= RtlEncodePointer(VectoredHandler
);
89 RtlEnterCriticalSection(&RtlpVectoredExceptionLock
);
92 InsertHeadList(&RtlpVectoredExceptionHead
,
97 InsertTailList(&RtlpVectoredExceptionHead
,
100 RtlLeaveCriticalSection(&RtlpVectoredExceptionLock
);
111 RtlRemoveVectoredExceptionHandler(IN PVOID VectoredHandlerHandle
)
113 PLIST_ENTRY CurrentEntry
;
114 PRTL_VECTORED_EXCEPTION_HANDLER veh
= NULL
;
115 ULONG Removed
= FALSE
;
117 RtlEnterCriticalSection(&RtlpVectoredExceptionLock
);
118 for(CurrentEntry
= RtlpVectoredExceptionHead
.Flink
;
119 CurrentEntry
!= &RtlpVectoredExceptionHead
;
120 CurrentEntry
= CurrentEntry
->Flink
)
122 veh
= CONTAINING_RECORD(CurrentEntry
,
123 RTL_VECTORED_EXCEPTION_HANDLER
,
125 if(veh
== VectoredHandlerHandle
)
127 RemoveEntryList(&veh
->ListEntry
);
132 RtlLeaveCriticalSection(&RtlpVectoredExceptionLock
);
136 RtlFreeHeap(RtlGetProcessHeap(),