Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(538)

Side by Side Diff: chrome_frame/exception_barrier.h

Issue 1733021: Add an ExceptionBarrier around outbound calls to patched methods in IE. In so... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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 // A class to make it easy to tag exception propagation boundaries and
6 // get crash reports of exceptions that pass over same.
7 #ifndef CHROME_FRAME_EXCEPTION_BARRIER_H_
8 #define CHROME_FRAME_EXCEPTION_BARRIER_H_
9
10 #include <windows.h>
11
12 /// This is the type dictated for an exception handler by the platform ABI
13 /// @see _except_handler in excpt.h
14 typedef EXCEPTION_DISPOSITION (__cdecl *ExceptionHandlerFunc)(
15 struct _EXCEPTION_RECORD *exception_record,
16 void * establisher_frame,
17 struct _CONTEXT *context,
18 void * reserved);
19
20 /// The type of an exception record in the exception handler chain
21 struct EXCEPTION_REGISTRATION {
22 EXCEPTION_REGISTRATION *prev;
23 ExceptionHandlerFunc handler;
24 };
25
26 /// This is our raw exception handler, it must be declared extern "C" to
27 /// match up with the SAFESEH declaration in our corresponding ASM file
28 extern "C" EXCEPTION_DISPOSITION __cdecl
29 ExceptionBarrierHandler(struct _EXCEPTION_RECORD *exception_record,
30 void * establisher_frame,
31 struct _CONTEXT *context,
32 void * reserved);
33
34 /// An exception barrier is used to report exceptions that pass through
35 /// a boundary where exceptions shouldn't pass, such as e.g. COM interface
36 /// boundaries.
37 /// This is handy for any kind of plugin code, where if the exception passes
38 /// through unhindered, it'll either be swallowed by an SEH exception handler
39 /// above us on the stack, or be reported as an unhandled exception for
40 /// the application hosting the plugin code.
41 ///
42 /// To use this class, simply instantiate an ExceptionBarrier just inside
43 /// the code boundary, like this:
44 /// @code
45 /// HRESULT SomeObject::SomeCOMMethod(...) {
46 /// ExceptionBarrier report_crashes;
47 ///
48 /// ... other code here ...
49 /// }
50 /// @endcode
51 class ExceptionBarrier {
52 public:
53 /// Register the barrier in the SEH chain
54 ExceptionBarrier();
55
56 /// And unregister on destruction
57 ~ExceptionBarrier();
58
59 /// Signature of the handler function which gets notified when
60 /// an exception propagates through a barrier.
61 typedef void (CALLBACK *ExceptionHandler)(EXCEPTION_POINTERS *ptrs);
62
63 /// @name Accessors
64 /// @{
65 static void set_handler(ExceptionHandler handler) { s_handler_ = handler; }
66 static ExceptionHandler handler() { return s_handler_; }
67 /// @}
68
69 private:
70 /// Our SEH frame
71 EXCEPTION_REGISTRATION registration_;
72
73 /// The function that gets invoked if an exception
74 /// propagates through a barrier
75 static ExceptionHandler s_handler_;
76 };
77
78 /// @name These are implemented in the associated .asm file
79 /// @{
80 extern "C" void WINAPI RegisterExceptionRecord(
81 EXCEPTION_REGISTRATION *registration,
82 ExceptionHandlerFunc func);
83 extern "C" void WINAPI UnregisterExceptionRecord(
84 EXCEPTION_REGISTRATION *registration);
85 /// @}
86
87
88 inline ExceptionBarrier::ExceptionBarrier() {
89 RegisterExceptionRecord(&registration_, ExceptionBarrierHandler);
90 }
91
92 inline ExceptionBarrier::~ExceptionBarrier() {
93 UnregisterExceptionRecord(&registration_);
94 }
95
96 #endif // CHROME_FRAME_EXCEPTION_BARRIER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698