Deleted Added
full compact
UnwindLevel1.c (288151) UnwindLevel1.c (302450)
1//===------------------------- UnwindLevel1.c -----------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//

--- 19 unchanged lines hidden (view full) ---

28
29#include "libunwind.h"
30#include "unwind.h"
31#include "config.h"
32
33#if !_LIBUNWIND_ARM_EHABI
34
35static _Unwind_Reason_Code
1//===------------------------- UnwindLevel1.c -----------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//

--- 19 unchanged lines hidden (view full) ---

28
29#include "libunwind.h"
30#include "unwind.h"
31#include "config.h"
32
33#if !_LIBUNWIND_ARM_EHABI
34
35static _Unwind_Reason_Code
36unwind_phase1(unw_context_t *uc, _Unwind_Exception *exception_object) {
37 unw_cursor_t cursor1;
38 unw_init_local(&cursor1, uc);
36unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *exception_object) {
37 unw_init_local(cursor, uc);
39
40 // Walk each frame looking for a place to stop.
41 bool handlerNotFound = true;
42 while (handlerNotFound) {
43 // Ask libuwind to get next frame (skip over first which is
44 // _Unwind_RaiseException).
38
39 // Walk each frame looking for a place to stop.
40 bool handlerNotFound = true;
41 while (handlerNotFound) {
42 // Ask libuwind to get next frame (skip over first which is
43 // _Unwind_RaiseException).
45 int stepResult = unw_step(&cursor1);
44 int stepResult = unw_step(cursor);
46 if (stepResult == 0) {
47 _LIBUNWIND_TRACE_UNWINDING("unwind_phase1(ex_ojb=%p): unw_step() reached "
48 "bottom => _URC_END_OF_STACK\n",
49 (void *)exception_object);
50 return _URC_END_OF_STACK;
51 } else if (stepResult < 0) {
52 _LIBUNWIND_TRACE_UNWINDING("unwind_phase1(ex_ojb=%p): unw_step failed => "
53 "_URC_FATAL_PHASE1_ERROR\n",
54 (void *)exception_object);
55 return _URC_FATAL_PHASE1_ERROR;
56 }
57
58 // See if frame has code to run (has personality routine).
59 unw_proc_info_t frameInfo;
60 unw_word_t sp;
45 if (stepResult == 0) {
46 _LIBUNWIND_TRACE_UNWINDING("unwind_phase1(ex_ojb=%p): unw_step() reached "
47 "bottom => _URC_END_OF_STACK\n",
48 (void *)exception_object);
49 return _URC_END_OF_STACK;
50 } else if (stepResult < 0) {
51 _LIBUNWIND_TRACE_UNWINDING("unwind_phase1(ex_ojb=%p): unw_step failed => "
52 "_URC_FATAL_PHASE1_ERROR\n",
53 (void *)exception_object);
54 return _URC_FATAL_PHASE1_ERROR;
55 }
56
57 // See if frame has code to run (has personality routine).
58 unw_proc_info_t frameInfo;
59 unw_word_t sp;
61 if (unw_get_proc_info(&cursor1, &frameInfo) != UNW_ESUCCESS) {
60 if (unw_get_proc_info(cursor, &frameInfo) != UNW_ESUCCESS) {
62 _LIBUNWIND_TRACE_UNWINDING("unwind_phase1(ex_ojb=%p): unw_get_proc_info "
63 "failed => _URC_FATAL_PHASE1_ERROR\n",
64 (void *)exception_object);
65 return _URC_FATAL_PHASE1_ERROR;
66 }
67
68 // When tracing, print state information.
69 if (_LIBUNWIND_TRACING_UNWINDING) {
70 char functionBuf[512];
71 const char *functionName = functionBuf;
72 unw_word_t offset;
61 _LIBUNWIND_TRACE_UNWINDING("unwind_phase1(ex_ojb=%p): unw_get_proc_info "
62 "failed => _URC_FATAL_PHASE1_ERROR\n",
63 (void *)exception_object);
64 return _URC_FATAL_PHASE1_ERROR;
65 }
66
67 // When tracing, print state information.
68 if (_LIBUNWIND_TRACING_UNWINDING) {
69 char functionBuf[512];
70 const char *functionName = functionBuf;
71 unw_word_t offset;
73 if ((unw_get_proc_name(&cursor1, functionBuf, sizeof(functionBuf),
72 if ((unw_get_proc_name(cursor, functionBuf, sizeof(functionBuf),
74 &offset) != UNW_ESUCCESS) ||
75 (frameInfo.start_ip + offset > frameInfo.end_ip))
76 functionName = ".anonymous.";
77 unw_word_t pc;
73 &offset) != UNW_ESUCCESS) ||
74 (frameInfo.start_ip + offset > frameInfo.end_ip))
75 functionName = ".anonymous.";
76 unw_word_t pc;
78 unw_get_reg(&cursor1, UNW_REG_IP, &pc);
77 unw_get_reg(cursor, UNW_REG_IP, &pc);
79 _LIBUNWIND_TRACE_UNWINDING(
80 "unwind_phase1(ex_ojb=%p): pc=0x%" PRIx64 ", start_ip=0x%" PRIx64
81 ", func=%s, lsda=0x%" PRIx64 ", personality=0x%" PRIx64 "\n",
82 (void *)exception_object, pc, frameInfo.start_ip, functionName,
83 frameInfo.lsda, frameInfo.handler);
84 }
85
86 // If there is a personality routine, ask it if it will want to stop at
87 // this frame.
88 if (frameInfo.handler != 0) {
89 __personality_routine p =
90 (__personality_routine)(long)(frameInfo.handler);
91 _LIBUNWIND_TRACE_UNWINDING(
92 "unwind_phase1(ex_ojb=%p): calling personality function %p\n",
93 (void *)exception_object, (void *)(uintptr_t)p);
94 _Unwind_Reason_Code personalityResult =
95 (*p)(1, _UA_SEARCH_PHASE, exception_object->exception_class,
78 _LIBUNWIND_TRACE_UNWINDING(
79 "unwind_phase1(ex_ojb=%p): pc=0x%" PRIx64 ", start_ip=0x%" PRIx64
80 ", func=%s, lsda=0x%" PRIx64 ", personality=0x%" PRIx64 "\n",
81 (void *)exception_object, pc, frameInfo.start_ip, functionName,
82 frameInfo.lsda, frameInfo.handler);
83 }
84
85 // If there is a personality routine, ask it if it will want to stop at
86 // this frame.
87 if (frameInfo.handler != 0) {
88 __personality_routine p =
89 (__personality_routine)(long)(frameInfo.handler);
90 _LIBUNWIND_TRACE_UNWINDING(
91 "unwind_phase1(ex_ojb=%p): calling personality function %p\n",
92 (void *)exception_object, (void *)(uintptr_t)p);
93 _Unwind_Reason_Code personalityResult =
94 (*p)(1, _UA_SEARCH_PHASE, exception_object->exception_class,
96 exception_object, (struct _Unwind_Context *)(&cursor1));
95 exception_object, (struct _Unwind_Context *)(cursor));
97 switch (personalityResult) {
98 case _URC_HANDLER_FOUND:
99 // found a catch clause or locals that need destructing in this frame
100 // stop search and remember stack pointer at the frame
101 handlerNotFound = false;
96 switch (personalityResult) {
97 case _URC_HANDLER_FOUND:
98 // found a catch clause or locals that need destructing in this frame
99 // stop search and remember stack pointer at the frame
100 handlerNotFound = false;
102 unw_get_reg(&cursor1, UNW_REG_SP, &sp);
101 unw_get_reg(cursor, UNW_REG_SP, &sp);
103 exception_object->private_2 = (uintptr_t)sp;
104 _LIBUNWIND_TRACE_UNWINDING(
105 "unwind_phase1(ex_ojb=%p): _URC_HANDLER_FOUND \n",
106 (void *)exception_object);
107 return _URC_NO_REASON;
108
109 case _URC_CONTINUE_UNWIND:
110 _LIBUNWIND_TRACE_UNWINDING(

--- 11 unchanged lines hidden (view full) ---

122 }
123 }
124 }
125 return _URC_NO_REASON;
126}
127
128
129static _Unwind_Reason_Code
102 exception_object->private_2 = (uintptr_t)sp;
103 _LIBUNWIND_TRACE_UNWINDING(
104 "unwind_phase1(ex_ojb=%p): _URC_HANDLER_FOUND \n",
105 (void *)exception_object);
106 return _URC_NO_REASON;
107
108 case _URC_CONTINUE_UNWIND:
109 _LIBUNWIND_TRACE_UNWINDING(

--- 11 unchanged lines hidden (view full) ---

121 }
122 }
123 }
124 return _URC_NO_REASON;
125}
126
127
128static _Unwind_Reason_Code
130unwind_phase2(unw_context_t *uc, _Unwind_Exception *exception_object) {
131 unw_cursor_t cursor2;
132 unw_init_local(&cursor2, uc);
129unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *exception_object) {
130 unw_init_local(cursor, uc);
133
134 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p)\n",
135 (void *)exception_object);
136
137 // Walk each frame until we reach where search phase said to stop.
138 while (true) {
139
140 // Ask libuwind to get next frame (skip over first which is
141 // _Unwind_RaiseException).
131
132 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p)\n",
133 (void *)exception_object);
134
135 // Walk each frame until we reach where search phase said to stop.
136 while (true) {
137
138 // Ask libuwind to get next frame (skip over first which is
139 // _Unwind_RaiseException).
142 int stepResult = unw_step(&cursor2);
140 int stepResult = unw_step(cursor);
143 if (stepResult == 0) {
144 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p): unw_step() reached "
145 "bottom => _URC_END_OF_STACK\n",
146 (void *)exception_object);
147 return _URC_END_OF_STACK;
148 } else if (stepResult < 0) {
149 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p): unw_step failed => "
150 "_URC_FATAL_PHASE1_ERROR\n",
151 (void *)exception_object);
152 return _URC_FATAL_PHASE2_ERROR;
153 }
154
155 // Get info about this frame.
156 unw_word_t sp;
157 unw_proc_info_t frameInfo;
141 if (stepResult == 0) {
142 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p): unw_step() reached "
143 "bottom => _URC_END_OF_STACK\n",
144 (void *)exception_object);
145 return _URC_END_OF_STACK;
146 } else if (stepResult < 0) {
147 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p): unw_step failed => "
148 "_URC_FATAL_PHASE1_ERROR\n",
149 (void *)exception_object);
150 return _URC_FATAL_PHASE2_ERROR;
151 }
152
153 // Get info about this frame.
154 unw_word_t sp;
155 unw_proc_info_t frameInfo;
158 unw_get_reg(&cursor2, UNW_REG_SP, &sp);
159 if (unw_get_proc_info(&cursor2, &frameInfo) != UNW_ESUCCESS) {
156 unw_get_reg(cursor, UNW_REG_SP, &sp);
157 if (unw_get_proc_info(cursor, &frameInfo) != UNW_ESUCCESS) {
160 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p): unw_get_proc_info "
161 "failed => _URC_FATAL_PHASE1_ERROR\n",
162 (void *)exception_object);
163 return _URC_FATAL_PHASE2_ERROR;
164 }
165
166 // When tracing, print state information.
167 if (_LIBUNWIND_TRACING_UNWINDING) {
168 char functionBuf[512];
169 const char *functionName = functionBuf;
170 unw_word_t offset;
158 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p): unw_get_proc_info "
159 "failed => _URC_FATAL_PHASE1_ERROR\n",
160 (void *)exception_object);
161 return _URC_FATAL_PHASE2_ERROR;
162 }
163
164 // When tracing, print state information.
165 if (_LIBUNWIND_TRACING_UNWINDING) {
166 char functionBuf[512];
167 const char *functionName = functionBuf;
168 unw_word_t offset;
171 if ((unw_get_proc_name(&cursor2, functionBuf, sizeof(functionBuf),
169 if ((unw_get_proc_name(cursor, functionBuf, sizeof(functionBuf),
172 &offset) != UNW_ESUCCESS) ||
173 (frameInfo.start_ip + offset > frameInfo.end_ip))
174 functionName = ".anonymous.";
175 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p): start_ip=0x%" PRIx64
176 ", func=%s, sp=0x%" PRIx64 ", lsda=0x%" PRIx64
177 ", personality=0x%" PRIx64 "\n",
178 (void *)exception_object, frameInfo.start_ip,
179 functionName, sp, frameInfo.lsda,

--- 6 unchanged lines hidden (view full) ---

186 (__personality_routine)(long)(frameInfo.handler);
187 _Unwind_Action action = _UA_CLEANUP_PHASE;
188 if (sp == exception_object->private_2) {
189 // Tell personality this was the frame it marked in phase 1.
190 action = (_Unwind_Action)(_UA_CLEANUP_PHASE | _UA_HANDLER_FRAME);
191 }
192 _Unwind_Reason_Code personalityResult =
193 (*p)(1, action, exception_object->exception_class, exception_object,
170 &offset) != UNW_ESUCCESS) ||
171 (frameInfo.start_ip + offset > frameInfo.end_ip))
172 functionName = ".anonymous.";
173 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p): start_ip=0x%" PRIx64
174 ", func=%s, sp=0x%" PRIx64 ", lsda=0x%" PRIx64
175 ", personality=0x%" PRIx64 "\n",
176 (void *)exception_object, frameInfo.start_ip,
177 functionName, sp, frameInfo.lsda,

--- 6 unchanged lines hidden (view full) ---

184 (__personality_routine)(long)(frameInfo.handler);
185 _Unwind_Action action = _UA_CLEANUP_PHASE;
186 if (sp == exception_object->private_2) {
187 // Tell personality this was the frame it marked in phase 1.
188 action = (_Unwind_Action)(_UA_CLEANUP_PHASE | _UA_HANDLER_FRAME);
189 }
190 _Unwind_Reason_Code personalityResult =
191 (*p)(1, action, exception_object->exception_class, exception_object,
194 (struct _Unwind_Context *)(&cursor2));
192 (struct _Unwind_Context *)(cursor));
195 switch (personalityResult) {
196 case _URC_CONTINUE_UNWIND:
197 // Continue unwinding
198 _LIBUNWIND_TRACE_UNWINDING(
199 "unwind_phase2(ex_ojb=%p): _URC_CONTINUE_UNWIND\n",
200 (void *)exception_object);
201 if (sp == exception_object->private_2) {
202 // Phase 1 said we would stop at this frame, but we did not...

--- 4 unchanged lines hidden (view full) ---

207 case _URC_INSTALL_CONTEXT:
208 _LIBUNWIND_TRACE_UNWINDING(
209 "unwind_phase2(ex_ojb=%p): _URC_INSTALL_CONTEXT\n",
210 (void *)exception_object);
211 // Personality routine says to transfer control to landing pad.
212 // We may get control back if landing pad calls _Unwind_Resume().
213 if (_LIBUNWIND_TRACING_UNWINDING) {
214 unw_word_t pc;
193 switch (personalityResult) {
194 case _URC_CONTINUE_UNWIND:
195 // Continue unwinding
196 _LIBUNWIND_TRACE_UNWINDING(
197 "unwind_phase2(ex_ojb=%p): _URC_CONTINUE_UNWIND\n",
198 (void *)exception_object);
199 if (sp == exception_object->private_2) {
200 // Phase 1 said we would stop at this frame, but we did not...

--- 4 unchanged lines hidden (view full) ---

205 case _URC_INSTALL_CONTEXT:
206 _LIBUNWIND_TRACE_UNWINDING(
207 "unwind_phase2(ex_ojb=%p): _URC_INSTALL_CONTEXT\n",
208 (void *)exception_object);
209 // Personality routine says to transfer control to landing pad.
210 // We may get control back if landing pad calls _Unwind_Resume().
211 if (_LIBUNWIND_TRACING_UNWINDING) {
212 unw_word_t pc;
215 unw_get_reg(&cursor2, UNW_REG_IP, &pc);
216 unw_get_reg(&cursor2, UNW_REG_SP, &sp);
213 unw_get_reg(cursor, UNW_REG_IP, &pc);
214 unw_get_reg(cursor, UNW_REG_SP, &sp);
217 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p): re-entering "
218 "user code with ip=0x%" PRIx64
219 ", sp=0x%" PRIx64 "\n",
220 (void *)exception_object, pc, sp);
221 }
215 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p): re-entering "
216 "user code with ip=0x%" PRIx64
217 ", sp=0x%" PRIx64 "\n",
218 (void *)exception_object, pc, sp);
219 }
222 unw_resume(&cursor2);
220 unw_resume(cursor);
223 // unw_resume() only returns if there was an error.
224 return _URC_FATAL_PHASE2_ERROR;
225 default:
226 // Personality routine returned an unknown result code.
227 _LIBUNWIND_DEBUG_LOG("personality function returned unknown result %d",
228 personalityResult);
229 return _URC_FATAL_PHASE2_ERROR;
230 }
231 }
232 }
233
234 // Clean up phase did not resume at the frame that the search phase
235 // said it would...
236 return _URC_FATAL_PHASE2_ERROR;
237}
238
239static _Unwind_Reason_Code
221 // unw_resume() only returns if there was an error.
222 return _URC_FATAL_PHASE2_ERROR;
223 default:
224 // Personality routine returned an unknown result code.
225 _LIBUNWIND_DEBUG_LOG("personality function returned unknown result %d",
226 personalityResult);
227 return _URC_FATAL_PHASE2_ERROR;
228 }
229 }
230 }
231
232 // Clean up phase did not resume at the frame that the search phase
233 // said it would...
234 return _URC_FATAL_PHASE2_ERROR;
235}
236
237static _Unwind_Reason_Code
240unwind_phase2_forced(unw_context_t *uc,
238unwind_phase2_forced(unw_context_t *uc, unw_cursor_t *cursor,
241 _Unwind_Exception *exception_object,
242 _Unwind_Stop_Fn stop, void *stop_parameter) {
239 _Unwind_Exception *exception_object,
240 _Unwind_Stop_Fn stop, void *stop_parameter) {
243 unw_cursor_t cursor2;
244 unw_init_local(&cursor2, uc);
241 unw_init_local(cursor, uc);
245
246 // Walk each frame until we reach where search phase said to stop
242
243 // Walk each frame until we reach where search phase said to stop
247 while (unw_step(&cursor2) > 0) {
244 while (unw_step(cursor) > 0) {
248
249 // Update info about this frame.
250 unw_proc_info_t frameInfo;
245
246 // Update info about this frame.
247 unw_proc_info_t frameInfo;
251 if (unw_get_proc_info(&cursor2, &frameInfo) != UNW_ESUCCESS) {
248 if (unw_get_proc_info(cursor, &frameInfo) != UNW_ESUCCESS) {
252 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): unw_step "
253 "failed => _URC_END_OF_STACK\n",
254 (void *)exception_object);
255 return _URC_FATAL_PHASE2_ERROR;
256 }
257
258 // When tracing, print state information.
259 if (_LIBUNWIND_TRACING_UNWINDING) {
260 char functionBuf[512];
261 const char *functionName = functionBuf;
262 unw_word_t offset;
249 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): unw_step "
250 "failed => _URC_END_OF_STACK\n",
251 (void *)exception_object);
252 return _URC_FATAL_PHASE2_ERROR;
253 }
254
255 // When tracing, print state information.
256 if (_LIBUNWIND_TRACING_UNWINDING) {
257 char functionBuf[512];
258 const char *functionName = functionBuf;
259 unw_word_t offset;
263 if ((unw_get_proc_name(&cursor2, functionBuf, sizeof(functionBuf),
260 if ((unw_get_proc_name(cursor, functionBuf, sizeof(functionBuf),
264 &offset) != UNW_ESUCCESS) ||
265 (frameInfo.start_ip + offset > frameInfo.end_ip))
266 functionName = ".anonymous.";
267 _LIBUNWIND_TRACE_UNWINDING(
268 "unwind_phase2_forced(ex_ojb=%p): start_ip=0x%" PRIx64
269 ", func=%s, lsda=0x%" PRIx64 ", personality=0x%" PRIx64 "\n",
270 (void *)exception_object, frameInfo.start_ip, functionName,
271 frameInfo.lsda, frameInfo.handler);
272 }
273
274 // Call stop function at each frame.
275 _Unwind_Action action =
276 (_Unwind_Action)(_UA_FORCE_UNWIND | _UA_CLEANUP_PHASE);
277 _Unwind_Reason_Code stopResult =
278 (*stop)(1, action, exception_object->exception_class, exception_object,
261 &offset) != UNW_ESUCCESS) ||
262 (frameInfo.start_ip + offset > frameInfo.end_ip))
263 functionName = ".anonymous.";
264 _LIBUNWIND_TRACE_UNWINDING(
265 "unwind_phase2_forced(ex_ojb=%p): start_ip=0x%" PRIx64
266 ", func=%s, lsda=0x%" PRIx64 ", personality=0x%" PRIx64 "\n",
267 (void *)exception_object, frameInfo.start_ip, functionName,
268 frameInfo.lsda, frameInfo.handler);
269 }
270
271 // Call stop function at each frame.
272 _Unwind_Action action =
273 (_Unwind_Action)(_UA_FORCE_UNWIND | _UA_CLEANUP_PHASE);
274 _Unwind_Reason_Code stopResult =
275 (*stop)(1, action, exception_object->exception_class, exception_object,
279 (struct _Unwind_Context *)(&cursor2), stop_parameter);
276 (struct _Unwind_Context *)(cursor), stop_parameter);
280 _LIBUNWIND_TRACE_UNWINDING(
281 "unwind_phase2_forced(ex_ojb=%p): stop function returned %d\n",
282 (void *)exception_object, stopResult);
283 if (stopResult != _URC_NO_REASON) {
284 _LIBUNWIND_TRACE_UNWINDING(
285 "unwind_phase2_forced(ex_ojb=%p): stopped by stop function\n",
286 (void *)exception_object);
287 return _URC_FATAL_PHASE2_ERROR;
288 }
289
290 // If there is a personality routine, tell it we are unwinding.
291 if (frameInfo.handler != 0) {
292 __personality_routine p =
293 (__personality_routine)(long)(frameInfo.handler);
294 _LIBUNWIND_TRACE_UNWINDING(
295 "unwind_phase2_forced(ex_ojb=%p): calling personality function %p\n",
296 (void *)exception_object, (void *)(uintptr_t)p);
297 _Unwind_Reason_Code personalityResult =
298 (*p)(1, action, exception_object->exception_class, exception_object,
277 _LIBUNWIND_TRACE_UNWINDING(
278 "unwind_phase2_forced(ex_ojb=%p): stop function returned %d\n",
279 (void *)exception_object, stopResult);
280 if (stopResult != _URC_NO_REASON) {
281 _LIBUNWIND_TRACE_UNWINDING(
282 "unwind_phase2_forced(ex_ojb=%p): stopped by stop function\n",
283 (void *)exception_object);
284 return _URC_FATAL_PHASE2_ERROR;
285 }
286
287 // If there is a personality routine, tell it we are unwinding.
288 if (frameInfo.handler != 0) {
289 __personality_routine p =
290 (__personality_routine)(long)(frameInfo.handler);
291 _LIBUNWIND_TRACE_UNWINDING(
292 "unwind_phase2_forced(ex_ojb=%p): calling personality function %p\n",
293 (void *)exception_object, (void *)(uintptr_t)p);
294 _Unwind_Reason_Code personalityResult =
295 (*p)(1, action, exception_object->exception_class, exception_object,
299 (struct _Unwind_Context *)(&cursor2));
296 (struct _Unwind_Context *)(cursor));
300 switch (personalityResult) {
301 case _URC_CONTINUE_UNWIND:
302 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): "
303 "personality returned "
304 "_URC_CONTINUE_UNWIND\n",
305 (void *)exception_object);
306 // Destructors called, continue unwinding
307 break;
308 case _URC_INSTALL_CONTEXT:
309 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): "
310 "personality returned "
311 "_URC_INSTALL_CONTEXT\n",
312 (void *)exception_object);
313 // We may get control back if landing pad calls _Unwind_Resume().
297 switch (personalityResult) {
298 case _URC_CONTINUE_UNWIND:
299 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): "
300 "personality returned "
301 "_URC_CONTINUE_UNWIND\n",
302 (void *)exception_object);
303 // Destructors called, continue unwinding
304 break;
305 case _URC_INSTALL_CONTEXT:
306 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): "
307 "personality returned "
308 "_URC_INSTALL_CONTEXT\n",
309 (void *)exception_object);
310 // We may get control back if landing pad calls _Unwind_Resume().
314 unw_resume(&cursor2);
311 unw_resume(cursor);
315 break;
316 default:
317 // Personality routine returned an unknown result code.
318 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): "
319 "personality returned %d, "
320 "_URC_FATAL_PHASE2_ERROR\n",
321 (void *)exception_object, personalityResult);
322 return _URC_FATAL_PHASE2_ERROR;

--- 4 unchanged lines hidden (view full) ---

327 // Call stop function one last time and tell it we've reached the end
328 // of the stack.
329 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): calling stop "
330 "function with _UA_END_OF_STACK\n",
331 (void *)exception_object);
332 _Unwind_Action lastAction =
333 (_Unwind_Action)(_UA_FORCE_UNWIND | _UA_CLEANUP_PHASE | _UA_END_OF_STACK);
334 (*stop)(1, lastAction, exception_object->exception_class, exception_object,
312 break;
313 default:
314 // Personality routine returned an unknown result code.
315 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): "
316 "personality returned %d, "
317 "_URC_FATAL_PHASE2_ERROR\n",
318 (void *)exception_object, personalityResult);
319 return _URC_FATAL_PHASE2_ERROR;

--- 4 unchanged lines hidden (view full) ---

324 // Call stop function one last time and tell it we've reached the end
325 // of the stack.
326 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): calling stop "
327 "function with _UA_END_OF_STACK\n",
328 (void *)exception_object);
329 _Unwind_Action lastAction =
330 (_Unwind_Action)(_UA_FORCE_UNWIND | _UA_CLEANUP_PHASE | _UA_END_OF_STACK);
331 (*stop)(1, lastAction, exception_object->exception_class, exception_object,
335 (struct _Unwind_Context *)(&cursor2), stop_parameter);
332 (struct _Unwind_Context *)(cursor), stop_parameter);
336
337 // Clean up phase did not resume at the frame that the search phase said it
338 // would.
339 return _URC_FATAL_PHASE2_ERROR;
340}
341
342
343/// Called by __cxa_throw. Only returns if there is a fatal error.
344_LIBUNWIND_EXPORT _Unwind_Reason_Code
345_Unwind_RaiseException(_Unwind_Exception *exception_object) {
346 _LIBUNWIND_TRACE_API("_Unwind_RaiseException(ex_obj=%p)\n",
347 (void *)exception_object);
348 unw_context_t uc;
333
334 // Clean up phase did not resume at the frame that the search phase said it
335 // would.
336 return _URC_FATAL_PHASE2_ERROR;
337}
338
339
340/// Called by __cxa_throw. Only returns if there is a fatal error.
341_LIBUNWIND_EXPORT _Unwind_Reason_Code
342_Unwind_RaiseException(_Unwind_Exception *exception_object) {
343 _LIBUNWIND_TRACE_API("_Unwind_RaiseException(ex_obj=%p)\n",
344 (void *)exception_object);
345 unw_context_t uc;
346 unw_cursor_t cursor;
349 unw_getcontext(&uc);
350
351 // Mark that this is a non-forced unwind, so _Unwind_Resume()
352 // can do the right thing.
353 exception_object->private_1 = 0;
354 exception_object->private_2 = 0;
355
356 // phase 1: the search phase
347 unw_getcontext(&uc);
348
349 // Mark that this is a non-forced unwind, so _Unwind_Resume()
350 // can do the right thing.
351 exception_object->private_1 = 0;
352 exception_object->private_2 = 0;
353
354 // phase 1: the search phase
357 _Unwind_Reason_Code phase1 = unwind_phase1(&uc, exception_object);
355 _Unwind_Reason_Code phase1 = unwind_phase1(&uc, &cursor, exception_object);
358 if (phase1 != _URC_NO_REASON)
359 return phase1;
360
361 // phase 2: the clean up phase
356 if (phase1 != _URC_NO_REASON)
357 return phase1;
358
359 // phase 2: the clean up phase
362 return unwind_phase2(&uc, exception_object);
360 return unwind_phase2(&uc, &cursor, exception_object);
363}
364
365
366
367/// When _Unwind_RaiseException() is in phase2, it hands control
368/// to the personality function at each frame. The personality
369/// may force a jump to a landing pad in that function, the landing
370/// pad code may then call _Unwind_Resume() to continue with the
371/// unwinding. Note: the call to _Unwind_Resume() is from compiler
372/// geneated user code. All other _Unwind_* routines are called
373/// by the C++ runtime __cxa_* routines.
374///
375/// Note: re-throwing an exception (as opposed to continuing the unwind)
376/// is implemented by having the code call __cxa_rethrow() which
377/// in turn calls _Unwind_Resume_or_Rethrow().
378_LIBUNWIND_EXPORT void
379_Unwind_Resume(_Unwind_Exception *exception_object) {
380 _LIBUNWIND_TRACE_API("_Unwind_Resume(ex_obj=%p)\n", (void *)exception_object);
381 unw_context_t uc;
361}
362
363
364
365/// When _Unwind_RaiseException() is in phase2, it hands control
366/// to the personality function at each frame. The personality
367/// may force a jump to a landing pad in that function, the landing
368/// pad code may then call _Unwind_Resume() to continue with the
369/// unwinding. Note: the call to _Unwind_Resume() is from compiler
370/// geneated user code. All other _Unwind_* routines are called
371/// by the C++ runtime __cxa_* routines.
372///
373/// Note: re-throwing an exception (as opposed to continuing the unwind)
374/// is implemented by having the code call __cxa_rethrow() which
375/// in turn calls _Unwind_Resume_or_Rethrow().
376_LIBUNWIND_EXPORT void
377_Unwind_Resume(_Unwind_Exception *exception_object) {
378 _LIBUNWIND_TRACE_API("_Unwind_Resume(ex_obj=%p)\n", (void *)exception_object);
379 unw_context_t uc;
380 unw_cursor_t cursor;
382 unw_getcontext(&uc);
383
384 if (exception_object->private_1 != 0)
381 unw_getcontext(&uc);
382
383 if (exception_object->private_1 != 0)
385 unwind_phase2_forced(&uc, exception_object,
384 unwind_phase2_forced(&uc, &cursor, exception_object,
386 (_Unwind_Stop_Fn) exception_object->private_1,
387 (void *)exception_object->private_2);
388 else
385 (_Unwind_Stop_Fn) exception_object->private_1,
386 (void *)exception_object->private_2);
387 else
389 unwind_phase2(&uc, exception_object);
388 unwind_phase2(&uc, &cursor, exception_object);
390
391 // Clients assume _Unwind_Resume() does not return, so all we can do is abort.
392 _LIBUNWIND_ABORT("_Unwind_Resume() can't return");
393}
394
395
396
397/// Not used by C++.
398/// Unwinds stack, calling "stop" function at each frame.
399/// Could be used to implement longjmp().
400_LIBUNWIND_EXPORT _Unwind_Reason_Code
401_Unwind_ForcedUnwind(_Unwind_Exception *exception_object,
402 _Unwind_Stop_Fn stop, void *stop_parameter) {
403 _LIBUNWIND_TRACE_API("_Unwind_ForcedUnwind(ex_obj=%p, stop=%p)\n",
404 (void *)exception_object, (void *)(uintptr_t)stop);
405 unw_context_t uc;
389
390 // Clients assume _Unwind_Resume() does not return, so all we can do is abort.
391 _LIBUNWIND_ABORT("_Unwind_Resume() can't return");
392}
393
394
395
396/// Not used by C++.
397/// Unwinds stack, calling "stop" function at each frame.
398/// Could be used to implement longjmp().
399_LIBUNWIND_EXPORT _Unwind_Reason_Code
400_Unwind_ForcedUnwind(_Unwind_Exception *exception_object,
401 _Unwind_Stop_Fn stop, void *stop_parameter) {
402 _LIBUNWIND_TRACE_API("_Unwind_ForcedUnwind(ex_obj=%p, stop=%p)\n",
403 (void *)exception_object, (void *)(uintptr_t)stop);
404 unw_context_t uc;
405 unw_cursor_t cursor;
406 unw_getcontext(&uc);
407
408 // Mark that this is a forced unwind, so _Unwind_Resume() can do
409 // the right thing.
410 exception_object->private_1 = (uintptr_t) stop;
411 exception_object->private_2 = (uintptr_t) stop_parameter;
412
413 // do it
406 unw_getcontext(&uc);
407
408 // Mark that this is a forced unwind, so _Unwind_Resume() can do
409 // the right thing.
410 exception_object->private_1 = (uintptr_t) stop;
411 exception_object->private_2 = (uintptr_t) stop_parameter;
412
413 // do it
414 return unwind_phase2_forced(&uc, exception_object, stop, stop_parameter);
414 return unwind_phase2_forced(&uc, &cursor, exception_object, stop, stop_parameter);
415}
416
417
418/// Called by personality handler during phase 2 to get LSDA for current frame.
419_LIBUNWIND_EXPORT uintptr_t
420_Unwind_GetLanguageSpecificData(struct _Unwind_Context *context) {
421 unw_cursor_t *cursor = (unw_cursor_t *)context;
422 unw_proc_info_t frameInfo;

--- 84 unchanged lines hidden ---
415}
416
417
418/// Called by personality handler during phase 2 to get LSDA for current frame.
419_LIBUNWIND_EXPORT uintptr_t
420_Unwind_GetLanguageSpecificData(struct _Unwind_Context *context) {
421 unw_cursor_t *cursor = (unw_cursor_t *)context;
422 unw_proc_info_t frameInfo;

--- 84 unchanged lines hidden ---