1/* libunwind - a platform-independent unwind library 2 Copyright (C) 2003-2004 Hewlett-Packard Co 3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com> 4 5This file is part of libunwind. 6 7Permission is hereby granted, free of charge, to any person obtaining 8a copy of this software and associated documentation files (the 9"Software"), to deal in the Software without restriction, including 10without limitation the rights to use, copy, modify, merge, publish, 11distribute, sublicense, and/or sell copies of the Software, and to 12permit persons to whom the Software is furnished to do so, subject to 13the following conditions: 14 15The above copyright notice and this permission notice shall be 16included in all copies or substantial portions of the Software. 17 18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 24WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 25 26#include "unwind-internal.h" 27 28/* ANDROID support update. */ 29PROTECTED _Unwind_Reason_Code 30_Unwind_RaiseException (struct _Unwind_Exception *exception_object) 31{ 32 uint64_t exception_class = exception_object->exception_class; 33 _Unwind_Personality_Fn personality; 34 struct _Unwind_Context context; 35 _Unwind_Reason_Code reason; 36 unw_proc_info_t pi; 37 unw_context_t uc; 38 unw_word_t ip; 39 int ret; 40 int destroy_map = 1; 41 42 Debug (1, "(exception_object=%p)\n", exception_object); 43 44 unw_map_local_create (); 45 46 if (_Unwind_InitContext (&context, &uc) < 0) 47 { 48 ret = _URC_FATAL_PHASE1_ERROR; 49 goto done; 50 } 51 52 /* Phase 1 (search phase) */ 53 54 while (1) 55 { 56 if (unw_step (&context.cursor) <= 0) 57 { 58 Debug (1, "no handler found\n"); 59 ret = _URC_END_OF_STACK; 60 goto done; 61 } 62 63 if (unw_get_proc_info (&context.cursor, &pi) < 0) 64 { 65 ret = _URC_FATAL_PHASE1_ERROR; 66 goto done; 67 } 68 69 personality = (_Unwind_Personality_Fn) (uintptr_t) pi.handler; 70 if (personality) 71 { 72 reason = (*personality) (_U_VERSION, _UA_SEARCH_PHASE, 73 exception_class, exception_object, 74 &context); 75 if (reason != _URC_CONTINUE_UNWIND) 76 { 77 if (reason == _URC_HANDLER_FOUND) 78 break; 79 else 80 { 81 Debug (1, "personality returned %d\n", reason); 82 ret = _URC_FATAL_PHASE1_ERROR; 83 goto done; 84 } 85 } 86 } 87 } 88 89 /* Exceptions are associated with IP-ranges. If a given exception 90 is handled at a particular IP, it will _always_ be handled at 91 that IP. If this weren't true, we'd have to track the tuple 92 (IP,SP,BSP) to uniquely identify the stack frame that's handling 93 the exception. */ 94 if (unw_get_reg (&context.cursor, UNW_REG_IP, &ip) < 0) 95 ret = _URC_FATAL_PHASE1_ERROR; 96 else 97 { 98 exception_object->private_1 = 0; /* clear "stop" pointer */ 99 exception_object->private_2 = ip; /* save frame marker */ 100 101 Debug (1, "found handler for IP=%lx; entering cleanup phase\n", (long) ip); 102 103 /* Reset the cursor to the first frame: */ 104 if (unw_init_local (&context.cursor, &uc) < 0) 105 ret = _URC_FATAL_PHASE1_ERROR; 106 else 107 ret = _Unwind_Phase2 (exception_object, &context, &destroy_map); 108 } 109 110done: 111 if (destroy_map) 112 unw_map_local_destroy (); 113 114 return ret; 115} 116/* End ANDROID support. */ 117 118_Unwind_Reason_Code 119__libunwind_Unwind_RaiseException (struct _Unwind_Exception *) 120 ALIAS (_Unwind_RaiseException); 121