00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 static _Unwind_Reason_Code
00042 _Unwind_RaiseException_Phase2(struct _Unwind_Exception *exc,
00043 struct _Unwind_Context *context)
00044 {
00045 _Unwind_Reason_Code code;
00046
00047 while (1)
00048 {
00049 _Unwind_FrameState fs;
00050 int match_handler;
00051
00052 code = uw_frame_state_for (context, &fs);
00053
00054
00055 match_handler = (uw_identify_context (context) == exc->private_2
00056 ? _UA_HANDLER_FRAME : 0);
00057
00058 if (code != _URC_NO_REASON)
00059
00060
00061 return _URC_FATAL_PHASE2_ERROR;
00062
00063
00064 if (fs.personality)
00065 {
00066 code = (*fs.personality) (1, _UA_CLEANUP_PHASE | match_handler,
00067 exc->exception_class, exc, context);
00068 if (code == _URC_INSTALL_CONTEXT)
00069 break;
00070 if (code != _URC_CONTINUE_UNWIND)
00071 return _URC_FATAL_PHASE2_ERROR;
00072 }
00073
00074
00075 gcc_assert (!match_handler);
00076
00077 uw_update_context (context, &fs);
00078 }
00079
00080 return code;
00081 }
00082
00083
00084
00085 _Unwind_Reason_Code
00086 _Unwind_RaiseException(struct _Unwind_Exception *exc)
00087 {
00088 struct _Unwind_Context this_context, cur_context;
00089 _Unwind_Reason_Code code;
00090
00091
00092 uw_init_context (&this_context);
00093 cur_context = this_context;
00094
00095
00096
00097 while (1)
00098 {
00099 _Unwind_FrameState fs;
00100
00101
00102
00103 code = uw_frame_state_for (&cur_context, &fs);
00104
00105 if (code == _URC_END_OF_STACK)
00106
00107 return _URC_END_OF_STACK;
00108
00109 if (code != _URC_NO_REASON)
00110
00111
00112 return _URC_FATAL_PHASE1_ERROR;
00113
00114
00115 if (fs.personality)
00116 {
00117 code = (*fs.personality) (1, _UA_SEARCH_PHASE, exc->exception_class,
00118 exc, &cur_context);
00119 if (code == _URC_HANDLER_FOUND)
00120 break;
00121 else if (code != _URC_CONTINUE_UNWIND)
00122 return _URC_FATAL_PHASE1_ERROR;
00123 }
00124
00125
00126 uw_update_context (&cur_context, &fs);
00127 }
00128
00129
00130
00131 exc->private_1 = 0;
00132 exc->private_2 = uw_identify_context (&cur_context);
00133
00134 cur_context = this_context;
00135 code = _Unwind_RaiseException_Phase2 (exc, &cur_context);
00136 if (code != _URC_INSTALL_CONTEXT)
00137 return code;
00138
00139 uw_install_context (&this_context, &cur_context);
00140 }
00141
00142
00143
00144
00145 static _Unwind_Reason_Code
00146 _Unwind_ForcedUnwind_Phase2 (struct _Unwind_Exception *exc,
00147 struct _Unwind_Context *context)
00148 {
00149 _Unwind_Stop_Fn stop = (_Unwind_Stop_Fn) (_Unwind_Ptr) exc->private_1;
00150 void *stop_argument = (void *) (_Unwind_Ptr) exc->private_2;
00151 _Unwind_Reason_Code code, stop_code;
00152
00153 while (1)
00154 {
00155 _Unwind_FrameState fs;
00156 int action;
00157
00158
00159 code = uw_frame_state_for (context, &fs);
00160 if (code != _URC_NO_REASON && code != _URC_END_OF_STACK)
00161 return _URC_FATAL_PHASE2_ERROR;
00162
00163
00164 action = _UA_FORCE_UNWIND | _UA_CLEANUP_PHASE;
00165 if (code == _URC_END_OF_STACK)
00166 action |= _UA_END_OF_STACK;
00167 stop_code = (*stop) (1, action, exc->exception_class, exc,
00168 context, stop_argument);
00169 if (stop_code != _URC_NO_REASON)
00170 return _URC_FATAL_PHASE2_ERROR;
00171
00172
00173
00174 if (code == _URC_END_OF_STACK)
00175 break;
00176
00177 if (fs.personality)
00178 {
00179 code = (*fs.personality) (1, _UA_FORCE_UNWIND | _UA_CLEANUP_PHASE,
00180 exc->exception_class, exc, context);
00181 if (code == _URC_INSTALL_CONTEXT)
00182 break;
00183 if (code != _URC_CONTINUE_UNWIND)
00184 return _URC_FATAL_PHASE2_ERROR;
00185 }
00186
00187
00188
00189 uw_advance_context (context, &fs);
00190 }
00191
00192 return code;
00193 }
00194
00195
00196
00197
00198 _Unwind_Reason_Code
00199 _Unwind_ForcedUnwind (struct _Unwind_Exception *exc,
00200 _Unwind_Stop_Fn stop, void * stop_argument)
00201 {
00202 struct _Unwind_Context this_context, cur_context;
00203 _Unwind_Reason_Code code;
00204
00205 uw_init_context (&this_context);
00206 cur_context = this_context;
00207
00208 exc->private_1 = (_Unwind_Ptr) stop;
00209 exc->private_2 = (_Unwind_Ptr) stop_argument;
00210
00211 code = _Unwind_ForcedUnwind_Phase2 (exc, &cur_context);
00212 if (code != _URC_INSTALL_CONTEXT)
00213 return code;
00214
00215 uw_install_context (&this_context, &cur_context);
00216 }
00217
00218
00219
00220
00221
00222 void
00223 _Unwind_Resume (struct _Unwind_Exception *exc)
00224 {
00225 struct _Unwind_Context this_context, cur_context;
00226 _Unwind_Reason_Code code;
00227
00228 uw_init_context (&this_context);
00229 cur_context = this_context;
00230
00231
00232
00233 if (exc->private_1 == 0)
00234 code = _Unwind_RaiseException_Phase2 (exc, &cur_context);
00235 else
00236 code = _Unwind_ForcedUnwind_Phase2 (exc, &cur_context);
00237
00238 gcc_assert (code == _URC_INSTALL_CONTEXT);
00239
00240 uw_install_context (&this_context, &cur_context);
00241 }
00242
00243
00244
00245
00246
00247 _Unwind_Reason_Code
00248 _Unwind_Resume_or_Rethrow (struct _Unwind_Exception *exc)
00249 {
00250 struct _Unwind_Context this_context, cur_context;
00251 _Unwind_Reason_Code code;
00252
00253
00254
00255 if (exc->private_1 == 0)
00256 return _Unwind_RaiseException (exc);
00257
00258 uw_init_context (&this_context);
00259 cur_context = this_context;
00260
00261 code = _Unwind_ForcedUnwind_Phase2 (exc, &cur_context);
00262
00263 gcc_assert (code == _URC_INSTALL_CONTEXT);
00264
00265 uw_install_context (&this_context, &cur_context);
00266 }
00267
00268
00269
00270
00271 void
00272 _Unwind_DeleteException (struct _Unwind_Exception *exc)
00273 {
00274 if (exc->exception_cleanup)
00275 (*exc->exception_cleanup) (_URC_FOREIGN_EXCEPTION_CAUGHT, exc);
00276 }
00277
00278
00279
00280
00281 _Unwind_Reason_Code
00282 _Unwind_Backtrace(_Unwind_Trace_Fn trace, void * trace_argument)
00283 {
00284 struct _Unwind_Context context;
00285 _Unwind_Reason_Code code;
00286
00287 uw_init_context (&context);
00288
00289 while (1)
00290 {
00291 _Unwind_FrameState fs;
00292
00293
00294 code = uw_frame_state_for (&context, &fs);
00295 if (code != _URC_NO_REASON && code != _URC_END_OF_STACK)
00296 return _URC_FATAL_PHASE1_ERROR;
00297
00298
00299 if ((*trace) (&context, trace_argument) != _URC_NO_REASON)
00300 return _URC_FATAL_PHASE1_ERROR;
00301
00302
00303 if (code == _URC_END_OF_STACK)
00304 break;
00305
00306
00307 uw_update_context (&context, &fs);
00308 }
00309
00310 return code;
00311 }