| OLD | NEW |
| (Empty) |
| 1 // Copyright 2006-2009 Google Inc. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 // ======================================================================== | |
| 15 // | |
| 16 // A class to make it easy to tag exception propagation boundaries and | |
| 17 // get crash reports of exceptions that pass over same. | |
| 18 #include "omaha/base/exception_barrier.h" | |
| 19 | |
| 20 enum { | |
| 21 // Flag set by exception handling machinery when unwinding | |
| 22 EH_UNWINDING = 0x00000002 | |
| 23 }; | |
| 24 | |
| 25 // TODO(omaha): How to make this statically parameterizable? | |
| 26 ExceptionBarrier::ExceptionHandler ExceptionBarrier::s_handler_ = NULL; | |
| 27 | |
| 28 // This function must be extern "C" to match up with the SAFESEH | |
| 29 // declaration in our corresponding ASM file | |
| 30 extern "C" EXCEPTION_DISPOSITION __cdecl | |
| 31 ExceptionBarrierHandler(struct _EXCEPTION_RECORD *exception_record, | |
| 32 void * establisher_frame, | |
| 33 struct _CONTEXT *context, | |
| 34 void * reserved) { | |
| 35 establisher_frame; // unreferenced formal parameter | |
| 36 reserved; | |
| 37 if (!(exception_record->ExceptionFlags & EH_UNWINDING)) { | |
| 38 // When the exception is really propagating through us, we'd like to be | |
| 39 // called before the state of the program has been modified by the stack | |
| 40 // unwinding. In the absence of an exception handler, the unhandled | |
| 41 // exception filter gets called between the first chance and the second | |
| 42 // chance exceptions, so Windows pops either the JIT debugger or WER UI. | |
| 43 // This is not desirable in most of the cases. | |
| 44 ExceptionBarrier::ExceptionHandler handler = ExceptionBarrier::handler(); | |
| 45 if (handler) { | |
| 46 EXCEPTION_POINTERS ptrs = { exception_record, context }; | |
| 47 | |
| 48 handler(&ptrs); | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 return ExceptionContinueSearch; | |
| 53 } | |
| OLD | NEW |