OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/mac/call_with_eh_frame.h" | 5 #include "base/mac/call_with_eh_frame.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <unwind.h> | 8 #include <unwind.h> |
9 | 9 |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 | 11 |
12 namespace base { | 12 namespace base { |
13 namespace mac { | 13 namespace mac { |
14 | 14 |
15 _Unwind_Reason_Code CxxPersonalityRoutine( | |
16 int version, | |
17 _Unwind_Action actions, | |
18 uint64_t exceptionClass, | |
19 struct _Unwind_Exception* exceptionObject, | |
20 struct _Unwind_Context* context) { | |
21 // Tell libunwind that this is the end of the stack. When it encounters the | |
22 // CallWithEHFrame, it will stop searching for an exception handler. The | |
23 // result is that no exception handler has been found higher on the stack, | |
24 // and any that are lower on the stack (e.g. in CFRunLoopRunSpecific), will | |
25 // now be skipped. Since this is reporting the end of the stack, and no | |
26 // exception handler will have been found, std::terminate() will be called. | |
27 return _URC_END_OF_STACK; | |
28 } | |
29 | |
30 #if defined(OS_IOS) | 15 #if defined(OS_IOS) |
31 // No iOS assembly implementation exists, so just call the block directly. | 16 // No iOS assembly implementation exists, so just call the block directly. |
32 void CallWithEHFrame(void (^block)(void)) { | 17 void CallWithEHFrame(void (^block)(void)) { |
33 block(); | 18 block(); |
34 } | 19 } |
35 #endif | 20 #else // OS_MACOSX |
| 21 extern "C" _Unwind_Reason_Code __gxx_personality_v0(int, |
| 22 _Unwind_Action, |
| 23 uint64_t, |
| 24 struct _Unwind_Exception*, |
| 25 struct _Unwind_Context*); |
| 26 |
| 27 _Unwind_Reason_Code CxxPersonalityRoutine( |
| 28 int version, |
| 29 _Unwind_Action actions, |
| 30 uint64_t exception_class, |
| 31 struct _Unwind_Exception* exception_object, |
| 32 struct _Unwind_Context* context) { |
| 33 // Unwinding is a two-phase process: phase one searches for an exception |
| 34 // handler, and phase two performs cleanup. For phase one, this custom |
| 35 // personality will terminate the search. For phase two, this should delegate |
| 36 // back to the standard personality routine. |
| 37 |
| 38 if ((actions & _UA_SEARCH_PHASE) != 0) { |
| 39 // Tell libunwind that this is the end of the stack. When it encounters the |
| 40 // CallWithEHFrame, it will stop searching for an exception handler. The |
| 41 // result is that no exception handler has been found higher on the stack, |
| 42 // and any that are lower on the stack (e.g. in CFRunLoopRunSpecific), will |
| 43 // now be skipped. Since this is reporting the end of the stack, and no |
| 44 // exception handler will have been found, std::terminate() will be called. |
| 45 return _URC_END_OF_STACK; |
| 46 } |
| 47 |
| 48 return __gxx_personality_v0(version, actions, exception_class, |
| 49 exception_object, context); |
| 50 } |
| 51 #endif // defined(OS_IOS) |
36 | 52 |
37 } // namespace mac | 53 } // namespace mac |
38 } // namespace base | 54 } // namespace base |
OLD | NEW |