| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 
|  | 2 // Use of this source code is governed by a BSD-style license that can be | 
|  | 3 // found in the LICENSE file. | 
|  | 4 | 
|  | 5 #ifndef CHROME_FRAME_VECTORED_HANDLER_H_ | 
|  | 6 #define CHROME_FRAME_VECTORED_HANDLER_H_ | 
|  | 7 | 
|  | 8 // Base class for VectoredHandlerT just to hold some members (independent of | 
|  | 9 // template parameter) | 
|  | 10 class VectoredHandlerBase { | 
|  | 11  public: | 
|  | 12   // For RtlCaptureStackBackTrace MSDN says: | 
|  | 13   // Windows Server 2003 and Windows XP:  The sum of the FramesToSkip and | 
|  | 14   // FramesToCapture parameters must be less than 64. | 
|  | 15   // In practice (on XPSP2) it has to be less than 63, hence leaving us with | 
|  | 16   // max back trace of 62. | 
|  | 17   static const DWORD max_back_trace = 62; | 
|  | 18   static unsigned long g_exceptions_seen; | 
|  | 19  protected: | 
|  | 20   static void* g_handler; | 
|  | 21 }; | 
|  | 22 | 
|  | 23 DECLSPEC_SELECTANY void* VectoredHandlerBase::g_handler; | 
|  | 24 DECLSPEC_SELECTANY unsigned long VectoredHandlerBase::g_exceptions_seen; | 
|  | 25 | 
|  | 26 // The E class is supposed to provide external/API functions. Using template | 
|  | 27 // make testability easier. It shall confirm the following concept/archetype: | 
|  | 28 // void* Register(PVECTORED_EXCEPTION_HANDLER, | 
|  | 29 //                const void* module_start, const void* module_end) | 
|  | 30 // Registers Vectored Exception Handler, non-unittest implementation shall call | 
|  | 31 // ::AddVectoredExceptionHandler Win32 API | 
|  | 32 // ULONG Unregister(void*) - ::RemoveVectoredExceptionHandler Win32 API | 
|  | 33 // int IsOurModule(const void* address) - | 
|  | 34 // void WriteDump(EXCEPTION_POINTERS*) - | 
|  | 35 // WORD RtlCaptureStackBackTrace(..) - same as Win32 API | 
|  | 36 // EXCEPTION_REGISTRATION_RECORD* RtlpGetExceptionList() - same as Win32 API | 
|  | 37 // You may want to derive own External class by deriving from | 
|  | 38 // VEHExternalBase helper (see below). | 
|  | 39 // Create dump policy: | 
|  | 40 // 1. Scan SEH chain, if there is a handler/filter that belongs to our | 
|  | 41 //    module - assume we expect this one and hence do nothing here. | 
|  | 42 // 2. If the address of the exception is in our module - create dump. | 
|  | 43 // 3. If our module is in somewhere in callstack - create dump. | 
|  | 44 template <class E> | 
|  | 45 class VectoredHandlerT : public VectoredHandlerBase { | 
|  | 46  public: | 
|  | 47   static void* Register(const void* module_start, const void* module_end) { | 
|  | 48     g_exceptions_seen = 0; | 
|  | 49     g_handler = E::Register(&VectoredHandler, module_start, module_end); | 
|  | 50     return g_handler; | 
|  | 51   } | 
|  | 52 | 
|  | 53   static ULONG Unregister() { | 
|  | 54     if (g_handler) | 
|  | 55       return E::Unregister(g_handler); | 
|  | 56     return 0; | 
|  | 57   } | 
|  | 58 | 
|  | 59   static LONG WINAPI VectoredHandler(EXCEPTION_POINTERS* exceptionInfo); | 
|  | 60  private: | 
|  | 61   static BOOL ModuleHasInstalledSEHFilter(); | 
|  | 62 }; | 
|  | 63 | 
|  | 64 // Handy class supposed to act as a base class for classes used as template | 
|  | 65 // parameter of VectoredHandlerT<E> | 
|  | 66 class VEHTraitsBase { | 
|  | 67  public: | 
|  | 68   static const void* g_module_start; | 
|  | 69   static const void* g_module_end; | 
|  | 70 | 
|  | 71   static inline int IsOurModule(const void* address) { | 
|  | 72     return (g_module_start <= address && address < g_module_end); | 
|  | 73   } | 
|  | 74 | 
|  | 75   static inline void SetModule(const void* module_start, | 
|  | 76                                const void* module_end) { | 
|  | 77     g_module_start = module_start; | 
|  | 78     g_module_end = module_end; | 
|  | 79   } | 
|  | 80 }; | 
|  | 81 | 
|  | 82 DECLSPEC_SELECTANY const void* VEHTraitsBase::g_module_start; | 
|  | 83 DECLSPEC_SELECTANY const void* VEHTraitsBase::g_module_end; | 
|  | 84 | 
|  | 85 class Win32VEHTraits; | 
|  | 86 typedef class VectoredHandlerT<Win32VEHTraits> VectoredHandler; | 
|  | 87 #endif  // CHROME_FRAME_VECTORED_HANDLER_H_ | 
| OLD | NEW | 
|---|