Changeset 9640813


Ignore:
Timestamp:
Mar 20, 2020, 4:40:54 PM (19 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
arm-eh, jacob/cs343-translation, master, new-ast, new-ast-unique-expr
Children:
7a0f1d2
Parents:
8ef95679
Message:

Clean-up in exception.c. Moved platform checks to the top of the file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/exception.c

    r8ef95679 r9640813  
    1414//
    1515
     16// Normally we would get this from the CFA prelude.
    1617#include <stddef.h> // for size_t
    1718
    1819#include "exception.h"
    1920
    20 // Implementation of the secret header.
     21// Implementation of the secret header is hardware dependent.
     22#if !( defined( __x86_64 ) || defined( __i386 ) )
     23#error Exception Handling: No known architecture detected.
     24#endif
    2125
    2226#include <stdlib.h>
     
    6872//}
    6973
    70 
    71 // This macro should be the only thing that needs to change across machines.
    72 // Used in the personality function, way down in termination.
    73 // struct _Unwind_Context * -> _Unwind_Reason_Code(*)(exception_t *)
    74 #if defined( __x86_64 )
    75 #define MATCHER_FROM_CONTEXT(ptr_to_context) \
    76         (*(_Unwind_Reason_Code(**)(exception_t *))(_Unwind_GetCFA(ptr_to_context) + 8))
    77 #elif defined( __i386 )
    78 #define MATCHER_FROM_CONTEXT(ptr_to_context) \
    79         (*(_Unwind_Reason_Code(**)(exception_t *))(_Unwind_GetCFA(ptr_to_context) + 24))
    80 #endif
    8174
    8275// RESUMPTION ================================================================
     
    354347                                        cur_ptr = read_uleb128(cur_ptr, &imatcher);
    355348
    356                                         _Unwind_Reason_Code (*matcher)(exception_t *) =
    357                                                 MATCHER_FROM_CONTEXT(context);
     349#                                       if defined( __x86_64 )
     350                                        _Unwind_Word match_pos = _Unwind_GetCFA(context) + 8;
     351#                                       elif defined( __i386 )
     352                                        _Unwind_Word match_pos = _Unwind_GetCFA(context) + 24;
     353#                                       endif
     354                                        int (*matcher)(exception_t *) = *(int(**)(exception_t *))match_pos;
     355
    358356                                        int index = matcher(shared_stack.current_exception);
    359357                                        _Unwind_Reason_Code ret = (0 == index)
     
    468466
    469467#ifdef __PIC__
    470 #if defined( __i386 ) || defined( __x86_64 )
    471468asm (
    472469        // HEADER
     
    514511#endif
    515512);
    516 #else
    517 #error Exception Handling: unknown architecture for position independent code.
    518 #endif // __i386 || __x86_64
    519513#else // __PIC__
    520 #if defined( __i386 ) || defined( __x86_64 )
    521514asm (
    522515        // HEADER
     
    547540        "       .section        .note.GNU-stack,\"x\",@progbits\n"
    548541);
    549 #else
    550 #error Exception Handling: unknown architecture for position dependent code.
    551 #endif // __i386 || __x86_64
    552542#endif // __PIC__
    553543
Note: See TracChangeset for help on using the changeset viewer.