source: libcfa/src/exception.c@ c5cbc099

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since c5cbc099 was e67a82d, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago

fix conflicts

  • Property mode set to 100644
File size: 21.1 KB
RevLine 
[fa4805f]1//
2// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// exception.c --
8//
9// Author : Andrew Beach
10// Created On : Mon Jun 26 15:13:00 2017
[67ca73e]11// Last Modified By : Peter A. Buhr
[e67a82d]12// Last Modified On : Thu Aug 20 23:45:45 2020
13// Update Count : 27
[fa4805f]14//
15
[9640813]16// Normally we would get this from the CFA prelude.
[cbce272]17#include <stddef.h> // for size_t
18
[fa4805f]19#include "exception.h"
20
[9640813]21// Implementation of the secret header is hardware dependent.
22#if !( defined( __x86_64 ) || defined( __i386 ) )
[67ca73e]23#elif defined( __ARM_ARCH )
24#warning FIX ME: check if anything needed for ARM
25#else
26#warning Exception Handling: No known architecture detected.
[9640813]27#endif
[fa4805f]28
29#include <stdlib.h>
30#include <stdio.h>
31#include <unwind.h>
[73abe95]32#include <bits/debug.hfa>
[80ec409]33#include "concurrency/invoke.h"
[a201f7b]34#include "stdhdr/assert.h"
[fa4805f]35
[b947fb2]36// FIX ME: temporary hack to keep ARM build working
37#ifndef _URC_FATAL_PHASE1_ERROR
[73530d9]38#define _URC_FATAL_PHASE1_ERROR 3
[b947fb2]39#endif // ! _URC_FATAL_PHASE1_ERROR
40#ifndef _URC_FATAL_PHASE2_ERROR
41#define _URC_FATAL_PHASE2_ERROR 2
42#endif // ! _URC_FATAL_PHASE2_ERROR
43
[fa4805f]44#include "lsda.h"
45
[73530d9]46/* The exception class for our exceptions. Because of the vendor component
47 * its value would not be standard.
48 * Vendor: UWPL
49 * Language: CFA\0
50 */
51const _Unwind_Exception_Class __cfaehm_exception_class = 0x4c50575500414643;
[cbce272]52
53// Base exception vtable is abstract, you should not have base exceptions.
[3090127]54struct __cfaehm_base_exception_t_vtable
55 ___cfaehm_base_exception_t_vtable_instance = {
[cbce272]56 .parent = NULL,
57 .size = 0,
58 .copy = NULL,
59 .free = NULL,
60 .msg = NULL
61};
62
63
[86d5ba7c]64// Get the current exception context.
65// There can be a single global until multithreading occurs, then each stack
[5715d43]66// needs its own. We get this from libcfathreads (no weak attribute).
67__attribute__((weak)) struct exception_context_t * this_exception_context() {
68 static struct exception_context_t shared_stack = {NULL, NULL};
[86d5ba7c]69 return &shared_stack;
70}
[fa4805f]71
72
73// RESUMPTION ================================================================
74
[f1b6671]75static void reset_top_resume(struct __cfaehm_try_resume_node ** store) {
76 this_exception_context()->top_resume = *store;
77}
78
[046a890]79void __cfaehm_throw_resume(exception_t * except, void (*defaultHandler)(exception_t *)) {
[2a3b019]80 struct exception_context_t * context = this_exception_context();
[fa4805f]81
[851fd92]82 __cfadbg_print_safe(exception, "Throwing resumption exception\n");
[fa4805f]83
[381132b]84 {
85 __attribute__((cleanup(reset_top_resume)))
86 struct __cfaehm_try_resume_node * original_head = context->top_resume;
87 struct __cfaehm_try_resume_node * current = context->top_resume;
88
89 for ( ; current ; current = current->next) {
90 context->top_resume = current->next;
91 if (current->handler(except)) {
92 return;
93 }
[fa4805f]94 }
[381132b]95 } // End the search and return to the top of the stack.
[fa4805f]96
[046a890]97 // No handler found, fall back to the default operation.
[851fd92]98 __cfadbg_print_safe(exception, "Unhandled exception\n");
[046a890]99 defaultHandler(except);
[fa4805f]100}
101
[eb46fdf]102// Do we control where exceptions get thrown even with concurency?
103// If not these are not quite thread safe, the cleanup hook has to
104// be added after the node is built but before it is made the top node.
[b947fb2]105
[3090127]106void __cfaehm_try_resume_setup(struct __cfaehm_try_resume_node * node,
[0304215a]107 _Bool (*handler)(exception_t * except)) {
[2a3b019]108 struct exception_context_t * context = this_exception_context();
109 node->next = context->top_resume;
[307a732]110 node->handler = handler;
[2a3b019]111 context->top_resume = node;
[fa4805f]112}
113
[3090127]114void __cfaehm_try_resume_cleanup(struct __cfaehm_try_resume_node * node) {
[2a3b019]115 struct exception_context_t * context = this_exception_context();
116 context->top_resume = node->next;
[fa4805f]117}
118
119
[2922871]120// MEMORY MANAGEMENT =========================================================
[ff7ff14a]121
[980fb4e]122struct __cfaehm_node {
123 struct _Unwind_Exception unwind_exception;
124 struct __cfaehm_node * next;
125 int handler_index;
126};
127
128#define NODE_TO_EXCEPT(node) ((exception_t *)(1 + (node)))
129#define EXCEPT_TO_NODE(except) ((struct __cfaehm_node *)(except) - 1)
130#define UNWIND_TO_NODE(unwind) ((struct __cfaehm_node *)(unwind))
131#define NULL_MAP(map, ptr) ((ptr) ? (map(ptr)) : NULL)
132
[73530d9]133// How to clean up an exception in various situations.
134static void __cfaehm_exception_cleanup(
135 _Unwind_Reason_Code reason,
136 struct _Unwind_Exception * exception) {
137 switch (reason) {
138 case _URC_FOREIGN_EXCEPTION_CAUGHT:
139 // This one we could clean-up to allow cross-language exceptions.
140 case _URC_FATAL_PHASE1_ERROR:
141 case _URC_FATAL_PHASE2_ERROR:
142 default:
143 abort();
144 }
145}
146
[86d5ba7c]147// Creates a copy of the indicated exception and sets current_exception to it.
[3090127]148static void __cfaehm_allocate_exception( exception_t * except ) {
[86d5ba7c]149 struct exception_context_t * context = this_exception_context();
150
[ff7ff14a]151 // Allocate memory for the exception.
[3090127]152 struct __cfaehm_node * store = malloc(
153 sizeof( struct __cfaehm_node ) + except->virtual_table->size );
[ff7ff14a]154
155 if ( ! store ) {
156 // Failure: cannot allocate exception. Terminate thread.
157 abort(); // <- Although I think it might be the process.
[86d5ba7c]158 }
159
[980fb4e]160 // Initialize the node:
161 exception_t * except_store = NODE_TO_EXCEPT(store);
162 store->unwind_exception.exception_class = __cfaehm_exception_class;
163 store->unwind_exception.exception_cleanup = __cfaehm_exception_cleanup;
164 store->handler_index = 0;
165 except->virtual_table->copy( except_store, except );
[73530d9]166
[980fb4e]167 // Add the node to the list:
168 store->next = NULL_MAP(EXCEPT_TO_NODE, context->current_exception);
169 context->current_exception = except_store;
[86d5ba7c]170}
171
172// Delete the provided exception, unsetting current_exception if relivant.
[3090127]173static void __cfaehm_delete_exception( exception_t * except ) {
[86d5ba7c]174 struct exception_context_t * context = this_exception_context();
175
[851fd92]176 __cfadbg_print_safe(exception, "Deleting Exception\n");
[ff7ff14a]177
178 // Remove the exception from the list.
[3090127]179 struct __cfaehm_node * to_free = EXCEPT_TO_NODE(except);
180 struct __cfaehm_node * node;
[86d5ba7c]181
182 if ( context->current_exception == except ) {
[ff7ff14a]183 node = to_free->next;
[980fb4e]184 context->current_exception = NULL_MAP(NODE_TO_EXCEPT, node);
[86d5ba7c]185 } else {
[ff7ff14a]186 node = EXCEPT_TO_NODE(context->current_exception);
187 // It may always be in the first or second position.
[9cb89b87]188 while ( to_free != node->next ) {
[ff7ff14a]189 node = node->next;
190 }
191 node->next = to_free->next;
[86d5ba7c]192 }
[ff7ff14a]193
194 // Free the old exception node.
[cbce272]195 except->virtual_table->free( except );
[ff7ff14a]196 free( to_free );
[86d5ba7c]197}
198
[2922871]199// CANCELLATION ==============================================================
[fa4805f]200
201// Function needed by force unwind
202// It basically says to unwind the whole stack and then exit when we reach the end of the stack
203static _Unwind_Reason_Code _Stop_Fn(
204 int version,
205 _Unwind_Action actions,
[3090127]206 _Unwind_Exception_Class exception_class,
[fa4805f]207 struct _Unwind_Exception * unwind_exception,
[2a3b019]208 struct _Unwind_Context * unwind_context,
209 void * stop_param) {
[a201f7b]210 // Verify actions follow the rules we expect.
[851fd92]211 verify((actions & _UA_CLEANUP_PHASE) && (actions & _UA_FORCE_UNWIND));
[980fb4e]212 verify(!(actions & (_UA_SEARCH_PHASE | _UA_HANDLER_FRAME)));
[fa4805f]213
[a201f7b]214 if ( actions & _UA_END_OF_STACK ) {
215 exit(1);
216 } else {
217 return _URC_NO_REASON;
218 }
[fa4805f]219}
220
[980fb4e]221static struct _Unwind_Exception cancel_exception_storage;
222
[2922871]223// Cancel the current stack, prefroming approprate clean-up and messaging.
[979df46]224void __cfaehm_cancel_stack( exception_t * exception ) {
[2922871]225 // TODO: Detect current stack and pick a particular stop-function.
226 _Unwind_Reason_Code ret;
[980fb4e]227 ret = _Unwind_ForcedUnwind( &cancel_exception_storage, _Stop_Fn, (void*)0x22 );
[2922871]228 printf("UNWIND ERROR %d after force unwind\n", ret);
229 abort();
230}
231
232
233// TERMINATION ===============================================================
234
235// If this isn't a rethrow (*except==0), delete the provided exception.
236void __cfaehm_cleanup_terminate( void * except ) {
237 if ( *(void**)except ) __cfaehm_delete_exception( *(exception_t **)except );
238}
239
[8ad5752]240static void __cfaehm_cleanup_default( exception_t ** except ) {
241 __cfaehm_delete_exception( *except );
242 *except = NULL;
243}
244
[86d5ba7c]245// The exception that is being thrown must already be stored.
[046a890]246static void __cfaehm_begin_unwind(void(*defaultHandler)(exception_t *)) {
[8ad5752]247 struct exception_context_t * context = this_exception_context();
248 if ( NULL == context->current_exception ) {
[86d5ba7c]249 printf("UNWIND ERROR missing exception in begin unwind\n");
250 abort();
251 }
[980fb4e]252 struct _Unwind_Exception * storage =
253 &EXCEPT_TO_NODE(context->current_exception)->unwind_exception;
[fa4805f]254
255 // Call stdlibc to raise the exception
[8ad5752]256 __cfadbg_print_safe(exception, "Begin unwinding (storage &p, context %p)\n", storage, context);
257 _Unwind_Reason_Code ret = _Unwind_RaiseException( storage );
[fa4805f]258
[eb46fdf]259 // If we reach here it means something happened. For resumption to work we need to find a way
260 // to return back to here. Most of them will probably boil down to setting a global flag and
261 // making the phase 1 either stop or fail. Causing an error on purpose may help avoiding
262 // unnecessary work but it might have some weird side effects. If we just pretend no handler
263 // was found that would work but may be expensive for no reason since we will always search
264 // the whole stack.
[fa4805f]265
[8ad5752]266 // We did not simply reach the end of the stack without finding a handler. This is an error.
267 if ( ret != _URC_END_OF_STACK ) {
268 printf("UNWIND ERROR %d after raise exception\n", ret);
269 abort();
[fa4805f]270 }
271
[8ad5752]272 // No handler found, go to the default operation.
273 __cfadbg_print_safe(exception, "Uncaught exception %p\n", storage);
274
275 __attribute__((cleanup(__cfaehm_cleanup_default)))
276 exception_t * exception = context->current_exception;
277 defaultHandler( exception );
[fa4805f]278}
279
[046a890]280void __cfaehm_throw_terminate( exception_t * val, void (*defaultHandler)(exception_t *) ) {
[851fd92]281 __cfadbg_print_safe(exception, "Throwing termination exception\n");
[86d5ba7c]282
[3090127]283 __cfaehm_allocate_exception( val );
[046a890]284 __cfaehm_begin_unwind( defaultHandler );
285}
286
287static __attribute__((noreturn)) void __cfaehm_rethrow_adapter( exception_t * except ) {
288 // TODO: Print some error message.
289 (void)except;
290 abort();
[86d5ba7c]291}
292
[3090127]293void __cfaehm_rethrow_terminate(void) {
[851fd92]294 __cfadbg_print_safe(exception, "Rethrowing termination exception\n");
[fa4805f]295
[046a890]296 __cfaehm_begin_unwind( __cfaehm_rethrow_adapter );
297 abort();
[fa4805f]298}
[67ca73e]299#if 0
[eb46fdf]300// This is our personality routine. For every stack frame annotated with
301// ".cfi_personality 0x3,__gcfa_personality_v0" this function will be called twice when unwinding.
302// Once in the search phase and once in the cleanup phase.
[3090127]303_Unwind_Reason_Code __gcfa_personality_v0(
304 int version,
305 _Unwind_Action actions,
306 unsigned long long exception_class,
307 struct _Unwind_Exception * unwind_exception,
308 struct _Unwind_Context * unwind_context)
[fa4805f]309{
310
[851fd92]311 //__cfadbg_print_safe(exception, "CFA: 0x%lx\n", _Unwind_GetCFA(context));
312 __cfadbg_print_safe(exception, "Personality function (%d, %x, %llu, %p, %p):",
[3090127]313 version, actions, exception_class, unwind_exception, unwind_context);
[fa4805f]314
[a201f7b]315 // Verify that actions follow the rules we expect.
316 // This function should never be called at the end of the stack.
317 verify(!(actions & _UA_END_OF_STACK));
318 // Either only the search phase flag is set or...
[fa4805f]319 if (actions & _UA_SEARCH_PHASE) {
[a201f7b]320 verify(actions == _UA_SEARCH_PHASE);
[851fd92]321 __cfadbg_print_safe(exception, " lookup phase");
[a201f7b]322 // ... we are in clean-up phase.
323 } else {
324 verify(actions & _UA_CLEANUP_PHASE);
[851fd92]325 __cfadbg_print_safe(exception, " cleanup phase");
[a201f7b]326 // We shouldn't be the handler frame during forced unwind.
327 if (actions & _UA_HANDLER_FRAME) {
328 verify(!(actions & _UA_FORCE_UNWIND));
[851fd92]329 __cfadbg_print_safe(exception, " (handler frame)");
[a201f7b]330 } else if (actions & _UA_FORCE_UNWIND) {
[851fd92]331 __cfadbg_print_safe(exception, " (force unwind)");
[a201f7b]332 }
[fa4805f]333 }
334
335 // Get a pointer to the language specific data from which we will read what we need
[9cb89b87]336 const unsigned char * lsd = _Unwind_GetLanguageSpecificData( unwind_context );
[fa4805f]337
[9cb89b87]338 if ( !lsd ) { //Nothing to do, keep unwinding
[fa4805f]339 printf(" no LSD");
340 goto UNWIND;
341 }
342
343 // Get the instuction pointer and a reading pointer into the exception table
344 lsda_header_info lsd_info;
[2a3b019]345 const unsigned char * cur_ptr = parse_lsda_header(unwind_context, lsd, &lsd_info);
346 _Unwind_Ptr instruction_ptr = _Unwind_GetIP(unwind_context);
347
348 struct exception_context_t * context = this_exception_context();
[fa4805f]349
350 // Linearly search the table for stuff to do
[9cb89b87]351 while ( cur_ptr < lsd_info.action_table ) {
[fa4805f]352 _Unwind_Ptr callsite_start;
353 _Unwind_Ptr callsite_len;
354 _Unwind_Ptr callsite_landing_pad;
355 _uleb128_t callsite_action;
356
357 // Decode the common stuff we have in here
[eb46fdf]358 cur_ptr = read_encoded_value(0, lsd_info.call_site_encoding, cur_ptr, &callsite_start);
359 cur_ptr = read_encoded_value(0, lsd_info.call_site_encoding, cur_ptr, &callsite_len);
360 cur_ptr = read_encoded_value(0, lsd_info.call_site_encoding, cur_ptr, &callsite_landing_pad);
361 cur_ptr = read_uleb128(cur_ptr, &callsite_action);
[fa4805f]362
363 // Have we reach the correct frame info yet?
[9cb89b87]364 if ( lsd_info.Start + callsite_start + callsite_len < instruction_ptr ) {
[e9145a3]365#ifdef __CFA_DEBUG_PRINT__
[fa4805f]366 void * ls = (void*)lsd_info.Start;
367 void * cs = (void*)callsite_start;
368 void * cl = (void*)callsite_len;
369 void * bp = (void*)lsd_info.Start + callsite_start;
370 void * ep = (void*)lsd_info.Start + callsite_start + callsite_len;
371 void * ip = (void*)instruction_ptr;
[851fd92]372 __cfadbg_print_safe(exception, "\nfound %p - %p (%p, %p, %p), looking for %p\n",
[eb46fdf]373 bp, ep, ls, cs, cl, ip);
[e9145a3]374#endif // __CFA_DEBUG_PRINT__
[fa4805f]375 continue;
376 }
377
[eb46fdf]378 // Have we gone too far?
[9cb89b87]379 if ( lsd_info.Start + callsite_start > instruction_ptr ) {
[fa4805f]380 printf(" gone too far");
381 break;
382 }
383
[9cb89b87]384 // Check for what we must do:
[2a3b019]385 if ( 0 == callsite_landing_pad ) {
386 // Nothing to do, move along
[851fd92]387 __cfadbg_print_safe(exception, " no landing pad");
[9cb89b87]388 } else if (actions & _UA_SEARCH_PHASE) {
389 // In search phase, these means we found a potential handler we must check.
390
391 // We have arbitrarily decided that 0 means nothing to do and 1 means there is
392 // a potential handler. This doesn't seem to conflict the gcc default behavior.
393 if (callsite_action != 0) {
394 // Now we want to run some code to see if the handler matches
395 // This is the tricky part where we want to the power to run arbitrary code
396 // However, generating a new exception table entry and try routine every time
397 // is way more expansive than we might like
398 // The information we have is :
399 // - The GR (Series of registers)
400 // GR1=GP Global Pointer of frame ref by context
401 // - The instruction pointer
402 // - The instruction pointer info (???)
403 // - The CFA (Canonical Frame Address)
404 // - The BSP (Probably the base stack pointer)
405
406 // The current apprach uses one exception table entry per try block
407 _uleb128_t imatcher;
408 // Get the relative offset to the {...}?
409 cur_ptr = read_uleb128(cur_ptr, &imatcher);
410
[67ca73e]411 _Unwind_Word match_pos =
[9cb89b87]412# if defined( __x86_64 )
[67ca73e]413 _Unwind_GetCFA(unwind_context) + 8;
[9cb89b87]414# elif defined( __i386 )
[67ca73e]415 _Unwind_GetCFA(unwind_context) + 24;
416# elif defined( __ARM_ARCH )
417# warning FIX ME: check if anything needed for ARM
418 42;
[9cb89b87]419# endif
420 int (*matcher)(exception_t *) = *(int(**)(exception_t *))match_pos;
421
422 int index = matcher(context->current_exception);
423 _Unwind_Reason_Code ret = (0 == index)
424 ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
[980fb4e]425 UNWIND_TO_NODE(unwind_exception)->handler_index = index;
[9cb89b87]426
427 // Based on the return value, check if we matched the exception
428 if (ret == _URC_HANDLER_FOUND) {
[851fd92]429 __cfadbg_print_safe(exception, " handler found\n");
[9cb89b87]430 } else {
[980fb4e]431 // TODO: Continue the search if there is more in the table.
[851fd92]432 __cfadbg_print_safe(exception, " no handler\n");
[fa4805f]433 }
[9cb89b87]434 return ret;
[fa4805f]435 }
436
[9cb89b87]437 // This is only a cleanup handler, ignore it
[851fd92]438 __cfadbg_print_safe(exception, " no action");
[a201f7b]439 } else {
[9cb89b87]440 // In clean-up phase, no destructors here but this could be the handler.
441
442 if ( (callsite_action != 0) && !(actions & _UA_HANDLER_FRAME) ){
443 // If this is a potential exception handler
444 // but not the one that matched the exception in the seach phase,
445 // just ignore it
446 goto UNWIND;
447 }
[fa4805f]448
[9cb89b87]449 // We need to run some clean-up or a handler
450 // These statment do the right thing but I don't know any specifics at all
451 _Unwind_SetGR( unwind_context, __builtin_eh_return_data_regno(0),
452 (_Unwind_Ptr)unwind_exception );
453 _Unwind_SetGR( unwind_context, __builtin_eh_return_data_regno(1), 0 );
[fa4805f]454
[9cb89b87]455 // I assume this sets the instruction pointer to the adress of the landing pad
456 // It doesn't actually set it, it only state the value that needs to be set once we
457 // return _URC_INSTALL_CONTEXT
458 _Unwind_SetIP( unwind_context, ((lsd_info.LPStart) + (callsite_landing_pad)) );
[fa4805f]459
[851fd92]460 __cfadbg_print_safe(exception, " action\n");
[fa4805f]461
[9cb89b87]462 // Return have some action to run
463 return _URC_INSTALL_CONTEXT;
[fa4805f]464 }
465 }
466 // No handling found
[851fd92]467 __cfadbg_print_safe(exception, " table end reached");
[fa4805f]468
469 UNWIND:
[851fd92]470 __cfadbg_print_safe(exception, " unwind\n");
[fa4805f]471
472 // Keep unwinding the stack
473 return _URC_CONTINUE_UNWIND;
474}
475
[0f6ac828]476#pragma GCC push_options
[f017af6]477#pragma GCC optimize(0)
[0f6ac828]478
[eb46fdf]479// Try statements are hoisted out see comments for details. While this could probably be unique
480// and simply linked from libcfa but there is one problem left, see the exception table for details
[fa4805f]481__attribute__((noinline))
[3090127]482void __cfaehm_try_terminate(void (*try_block)(),
[0304215a]483 void (*catch_block)(int index, exception_t * except),
484 __attribute__((unused)) int (*match_block)(exception_t * except)) {
[fa4805f]485 //! volatile int xy = 0;
486 //! printf("%p %p %p %p\n", &try_block, &catch_block, &match_block, &xy);
487
[eb46fdf]488 // Setup the personality routine and exception table.
[9cb89b87]489 // Unforturnately these clobber gcc cancellation support which means we can't get access to
490 // the attribute cleanup tables at the same time. We would have to inspect the assembly to
491 // create a new set ourselves.
[3b9c674]492#ifdef __PIC__
493 asm volatile (".cfi_personality 0x9b,CFA.ref.__gcfa_personality_v0");
494 asm volatile (".cfi_lsda 0x1b, .LLSDACFA2");
495#else
[fa4805f]496 asm volatile (".cfi_personality 0x3,__gcfa_personality_v0");
497 asm volatile (".cfi_lsda 0x3, .LLSDACFA2");
[3b9c674]498#endif
[fa4805f]499
[b947fb2]500 // Label which defines the start of the area for which the handler is setup.
[fa4805f]501 asm volatile (".TRYSTART:");
502
503 // The actual statements of the try blocks
504 try_block();
505
506 // asm statement to prevent deadcode removal
507 asm volatile goto ("" : : : : CATCH );
508
[eb46fdf]509 // Normal return for when there is no throw.
[fa4805f]510 return;
511
512 // Exceptionnal path
513 CATCH : __attribute__(( unused ));
[b947fb2]514 // Label which defines the end of the area for which the handler is setup.
[fa4805f]515 asm volatile (".TRYEND:");
[9cb89b87]516 // Label which defines the start of the exception landing pad. Basically what is called when
517 // the exception is caught. Note, if multiple handlers are given, the multiplexing should be
518 // done by the generated code, not the exception runtime.
[fa4805f]519 asm volatile (".CATCH:");
520
521 // Exception handler
[2a3b019]522 // Note: Saving the exception context on the stack breaks termination exceptions.
[980fb4e]523 catch_block( EXCEPT_TO_NODE( this_exception_context()->current_exception )->handler_index,
[2a3b019]524 this_exception_context()->current_exception );
[fa4805f]525}
526
[eb46fdf]527// Exception table data we need to generate. While this is almost generic, the custom data refers
528// to {*}try_terminate, which is no way generic. Some more works need to be done if we want to
529// have a single call to the try routine.
[b947fb2]530
[3b9c674]531#ifdef __PIC__
532asm (
533 // HEADER
534 ".LFECFA1:\n"
535 " .globl __gcfa_personality_v0\n"
536 " .section .gcc_except_table,\"a\",@progbits\n"
537 // TABLE HEADER (important field is the BODY length at the end)
538 ".LLSDACFA2:\n"
539 " .byte 0xff\n"
540 " .byte 0xff\n"
541 " .byte 0x1\n"
542 " .uleb128 .LLSDACSECFA2-.LLSDACSBCFA2\n"
543 // BODY (language specific data)
544 // This uses language specific data and can be modified arbitrarily
545 // We use handled area offset, handled area length,
546 // handler landing pad offset and 1 (action code, gcc seems to use 0).
547 ".LLSDACSBCFA2:\n"
[3090127]548 " .uleb128 .TRYSTART-__cfaehm_try_terminate\n"
[3b9c674]549 " .uleb128 .TRYEND-.TRYSTART\n"
[3090127]550 " .uleb128 .CATCH-__cfaehm_try_terminate\n"
[3b9c674]551 " .uleb128 1\n"
552 ".LLSDACSECFA2:\n"
553 // TABLE FOOTER
554 " .text\n"
[3090127]555 " .size __cfaehm_try_terminate, .-__cfaehm_try_terminate\n"
[3b9c674]556);
557
558// Somehow this piece of helps with the resolution of debug symbols.
559__attribute__((unused)) static const int dummy = 0;
560
561asm (
562 // Add a hidden symbol which points at the function.
563 " .hidden CFA.ref.__gcfa_personality_v0\n"
564 " .weak CFA.ref.__gcfa_personality_v0\n"
565 // No clue what this does specifically
566 " .section .data.rel.local.CFA.ref.__gcfa_personality_v0,\"awG\",@progbits,CFA.ref.__gcfa_personality_v0,comdat\n"
567 " .align 8\n"
568 " .type CFA.ref.__gcfa_personality_v0, @object\n"
569 " .size CFA.ref.__gcfa_personality_v0, 8\n"
570 "CFA.ref.__gcfa_personality_v0:\n"
571#if defined( __x86_64 )
572 " .quad __gcfa_personality_v0\n"
573#else // then __i386
[e045590]574 " .long __gcfa_personality_v0\n"
[3b9c674]575#endif
576);
577#else // __PIC__
[fa4805f]578asm (
[eb46fdf]579 // HEADER
[fa4805f]580 ".LFECFA1:\n"
581 " .globl __gcfa_personality_v0\n"
582 " .section .gcc_except_table,\"a\",@progbits\n"
[eb46fdf]583 // TABLE HEADER (important field is the BODY length at the end)
584 ".LLSDACFA2:\n"
[fa4805f]585 " .byte 0xff\n"
586 " .byte 0xff\n"
587 " .byte 0x1\n"
[eb46fdf]588 " .uleb128 .LLSDACSECFA2-.LLSDACSBCFA2\n"
589 // BODY (language specific data)
590 ".LLSDACSBCFA2:\n"
591 // Handled area start (relative to start of function)
[3090127]592 " .uleb128 .TRYSTART-__cfaehm_try_terminate\n"
[eb46fdf]593 // Handled area length
594 " .uleb128 .TRYEND-.TRYSTART\n"
595 // Handler landing pad address (relative to start of function)
[3090127]596 " .uleb128 .CATCH-__cfaehm_try_terminate\n"
[eb46fdf]597 // Action code, gcc seems to always use 0.
598 " .uleb128 1\n"
599 // TABLE FOOTER
600 ".LLSDACSECFA2:\n"
601 " .text\n"
[3090127]602 " .size __cfaehm_try_terminate, .-__cfaehm_try_terminate\n"
[fa4805f]603 " .ident \"GCC: (Ubuntu 6.2.0-3ubuntu11~16.04) 6.2.0 20160901\"\n"
[3b9c674]604 " .section .note.GNU-stack,\"x\",@progbits\n"
[fa4805f]605);
[3b9c674]606#endif // __PIC__
607
608#pragma GCC pop_options
[67ca73e]609#endif // 0
Note: See TracBrowser for help on using the repository browser.