Changes in / [77acd07d:396fd72]


Ignore:
Location:
src/libcfa
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/bits/defs.h

    r77acd07d r396fd72  
    1 //
     1// 
    22// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
    33//
    44// The contents of this file are covered under the licence agreement in the
    55// file "LICENCE" distributed with Cforall.
    6 //
    7 // defs.h --
    8 //
     6// 
     7// defs.h -- 
     8// 
    99// Author           : Thierry Delisle
    1010// Created On       : Thu Nov  9 13:24:10 2017
     
    1212// Last Modified On : Tue Jan  2 09:17:06 2018
    1313// Update Count     : 2
    14 //
     14// 
    1515
    1616#pragma once
     
    3434
    3535#ifdef __cforall
    36 #ifndef __NO_ABORT_OVERLOAD
    37 void abort ( const char fmt[], ... ) __attribute__ ((__nothrow__, __leaf__, __noreturn__));
    38 #endif
    3936extern "C" {
    4037#endif
  • src/libcfa/interpose.c

    r77acd07d r396fd72  
    2828}
    2929
    30 #define __NO_ABORT_OVERLOAD // no abort overload avoid ambiguities
    3130#include "bits/debug.h"
    3231#include "bits/defs.h"
    3332#include "bits/signal.h"
    3433#include "startup.h"
    35 
    36 //=============================================================================================
    37 // Interposing helpers
    38 //=============================================================================================
    3934
    4035typedef void (*generic_fptr_t)(void);
     
    7469}
    7570
     71
     72__typeof__( exit ) libc_exit __attribute__(( noreturn ));
     73__typeof__( abort ) libc_abort __attribute__(( noreturn ));
     74
    7675forall(dtype T)
    77 static inline void ptr_from_symbol( T** symbol_ptr, const char * symbol_name, const char * version) {
     76static inline void assign_ptr( T** symbol_ptr, const char * symbol_name, const char * version) {
    7877        union {
    7978                generic_fptr_t gp;
     
    8685}
    8786
    88 #define INTERPOSE_LIBC( x, ver ) ptr_from_symbol( (void**)&__cabi_libc.x, #x, ver)
    89 
    90 //=============================================================================================
    91 // Terminating Signals logic
    92 //=============================================================================================
     87#define INIT_REALRTN( x, ver ) assign_ptr( (void**)&libc_##x, #x, ver)
    9388
    9489void sigHandler_segv ( __CFA_SIGPARMS__ );
     
    9792void sigHandler_abort( __CFA_SIGPARMS__ );
    9893
    99 struct {
    100         __typeof__( exit  ) exit  __attribute__(( noreturn ));
    101         __typeof__( abort ) abort __attribute__(( noreturn ));
    102 } __cabi_libc;
    103 
    10494extern "C" {
    10595        void __cfaabi_interpose_startup(void)  __attribute__(( constructor( STARTUP_PRIORITY_CORE ) ));
     
    10797                const char *version = NULL;
    10898
    109                 INTERPOSE_LIBC( abort, version );
    110                 INTERPOSE_LIBC( exit , version );
     99                INIT_REALRTN( abort, version );
     100                INIT_REALRTN( exit, version );
    111101
    112102                __cfaabi_sigaction( SIGSEGV, sigHandler_segv , SA_SIGINFO ); // Failure handler
     
    122112//=============================================================================================
    123113
    124 // Forward declare abort after the __typeof__ call to avoid ambiguities
    125 void abort ( const char fmt[], ... ) __attribute__ ((__nothrow__, __leaf__, __noreturn__));
    126 
    127114extern "C" {
    128115        void abort( void ) __attribute__ ((__nothrow__, __leaf__, __noreturn__)) {
     
    130117        }
    131118
    132         void abortf( const char fmt[], ... ) __attribute__ ((__nothrow__, __leaf__, __noreturn__)) {
    133                 va_list argp;
    134                 va_start( argp, fmt );
    135                 abort( fmt, argp );
    136                 va_end( argp );
    137         }
    138 
    139119        void exit( int __status ) __attribute__ ((__nothrow__, __leaf__, __noreturn__)) {
    140                 __cabi_libc.exit(__status);
    141         }
     120                libc_exit(__status);
     121        }
     122}
     123
     124void abort( const char fmt[], ... ) __attribute__ ((__nothrow__, __leaf__, __noreturn__)) {
     125        va_list argp;
     126        va_start( argp, fmt );
     127        abortf( fmt, argp );
     128        va_end( argp );
    142129}
    143130
     
    150137static int abort_lastframe;
    151138
    152 void abort( const char fmt[], ... ) __attribute__ ((__nothrow__, __leaf__, __noreturn__)) {
    153         void * kernel_data = kernel_abort();                    // must be done here to lock down kernel
    154         int len;
    155 
    156         abort_lastframe = kernel_abort_lastframe();
    157         len = snprintf( abort_text, abort_text_size, "Cforall Runtime error (UNIX pid:%ld) ", (long int)getpid() ); // use UNIX pid (versus getPid)
    158         __cfaabi_dbg_bits_write( abort_text, len );
    159 
    160         if ( fmt ) {
    161                 va_list args;
    162                 va_start( args, fmt );
    163 
    164                 len = vsnprintf( abort_text, abort_text_size, fmt, args );
    165                 va_end( args );
     139extern "C" {
     140        void abortf( const char fmt[], ... ) __attribute__ ((__nothrow__, __leaf__, __noreturn__)) {
     141                void * kernel_data = kernel_abort();                    // must be done here to lock down kernel
     142                int len;
     143
     144                abort_lastframe = kernel_abort_lastframe();
     145                len = snprintf( abort_text, abort_text_size, "Cforall Runtime error (UNIX pid:%ld) ", (long int)getpid() ); // use UNIX pid (versus getPid)
    166146                __cfaabi_dbg_bits_write( abort_text, len );
    167147
    168                 if ( fmt[strlen( fmt ) - 1] != '\n' ) {         // add optional newline if missing at the end of the format text
    169                         __cfaabi_dbg_bits_write( "\n", 1 );
    170                 }
    171         }
    172 
    173         kernel_abort_msg( kernel_data, abort_text, abort_text_size );
    174         __cabi_libc.abort();
     148                if ( fmt ) {
     149                        va_list args;
     150                        va_start( args, fmt );
     151
     152                        len = vsnprintf( abort_text, abort_text_size, fmt, args );
     153                        va_end( args );
     154                        __cfaabi_dbg_bits_write( abort_text, len );
     155
     156                        if ( fmt[strlen( fmt ) - 1] != '\n' ) {         // add optional newline if missing at the end of the format text
     157                                __cfaabi_dbg_bits_write( "\n", 1 );
     158                        }
     159                }
     160
     161                kernel_abort_msg( kernel_data, abort_text, abort_text_size );
     162                libc_abort();
     163        }
    175164}
    176165
Note: See TracChangeset for help on using the changeset viewer.