/* <syslib/exc_handling.h>
 *
 *	Exception handling for threads (V5.5,V6.2).
 */
#ifndef _EXC_HANDLING_H
#define _EXC_HANDLING_H
# ifdef __cpluscplus
extern "C" {
# endif

#if defined(_EXC_NO_EXCEPTIONS_) || defined(_CMA_SUPPRESS_EXTERNALS_)
#define __GNUC_OVERRIDE_EXC_EXCEPTIONS_ 0
#else
#define __GNUC_OVERRIDE_EXC_EXCEPTIONS_ 1
#define _EXC_NO_EXCEPTIONS_
#endif

/* GNU C support in V5.5-2's <exc_handling.h> contains a fatal typo */
#define exc_t_address exc_address_t

#define _EXC_IMPORT_ extern
#include "sys$library:exc_handling.h"

/* exc_fetch_fp is a function except for VMS + VAX C; override that here */
/*  [note: this was needed for V5.5, but no longer matters for V5.5-2]	 */
#ifndef exc_fetch_fp
/* note: must have the __GNUC__ version of this, not the one in sys$library */
#include <exc_handling_vms.h>
#endif

#undef exc_t_address

#if __GNUC_OVERRIDE_EXC_EXCEPTIONS_
#undef _EXC_NO_EXCEPTIONS_
#define _CMA_EXCNAME(XYZZY) \
	exc_e_##XYZZY	__asm("_$$PsectAttributes_GLOBALSYMBOL$$" "cma$e_" # XYZZY), \
	exc_##XYZZY##_e __asm("_$$PsectAttributes_GLOBALSYMBOL$$" "cma$e_" # XYZZY)
#define _CMA_CMANAME(XYZZY) \
	cma_e_##XYZZY	__asm("_$$PsectAttributes_GLOBALSYMBOL$$" "cma$e_" # XYZZY), \
	pthread_##XYZZY##_e __asm("_$$PsectAttributes_GLOBALSYMBOL$$" "cma$e_" # XYZZY)
#define pthread_alerted_e pthread_cancel_e

extern EXCEPTION
    _CMA_EXCNAME (uninitexc),
    _CMA_EXCNAME (illaddr),
    _CMA_EXCNAME (exquota),
    _CMA_EXCNAME (insfmem),
    _CMA_EXCNAME (nopriv),
    _CMA_EXCNAME (illinstr),
    _CMA_EXCNAME (resaddr),
    _CMA_EXCNAME (privinst),
    _CMA_EXCNAME (resoper),
    _CMA_EXCNAME (SIGTRAP),
    _CMA_EXCNAME (SIGIOT),
    _CMA_EXCNAME (SIGEMT),
    _CMA_EXCNAME (aritherr),
    _CMA_EXCNAME (SIGSYS),
    _CMA_EXCNAME (SIGPIPE),
    _CMA_EXCNAME (excpu),
    _CMA_EXCNAME (exfilsiz),
    _CMA_EXCNAME (intovf),
    _CMA_EXCNAME (intdiv),
    _CMA_EXCNAME (fltovf),
    _CMA_EXCNAME (fltdiv),
    _CMA_EXCNAME (fltund),
    _CMA_EXCNAME (decovf),
    _CMA_EXCNAME (subrng),
    _CMA_CMANAME (alerted),
    _CMA_CMANAME (assertion),
    _CMA_CMANAME (badparam),
    _CMA_CMANAME (bugcheck),
    _CMA_CMANAME (exit_thread),
    _CMA_CMANAME (existence),
    _CMA_CMANAME (in_use),
    _CMA_CMANAME (use_error),
    _CMA_CMANAME (wrongmutex),
    _CMA_CMANAME (stackovf),
    _CMA_CMANAME (nostackmem),
    _CMA_CMANAME (notcmastack),
    _CMA_CMANAME (unimp),
    _CMA_CMANAME (inialrpro),
    _CMA_CMANAME (defer_q_full),
    _CMA_CMANAME (signal_q_full),
    _CMA_CMANAME (alert_nesting);

#define exc_e_accvio	exc_e_illaddr
#define exc_e_SIGILL	exc_e_illinstr
#define exc_e_SIGFPE	exc_e_aritherr
#define exc_e_SIGBUS	exc_e_illaddr
#define exc_e_SIGSEGV	exc_e_illaddr
#define exc_e_SIGXCPU	exc_e_excpu
#define exc_e_SIGXFSZ	exc_e_exfilsiz
#define exc_accvio_e	exc_illaddr_e
#define exc_SIGILL_e	exc_illinstr_e
#define exc_SIGFPE_e	exc_aritherr_e
#define exc_SIGBUS_e	exc_illaddr_e
#define exc_SIGSEGV_e	exc_illaddr_e
#define exc_SIGXCPU_e	exc_excpu_e
#define exc_SIGXFSZ_e	exc_exfilsiz_e

#endif	/* __GNUC_OVERRIDE_EXC_EXCEPTIONS_ */
#undef	__GNUC_OVERRIDE_EXC_EXCEPTIONS_

# ifdef __cpluscplus
}
# endif
#endif	/*_EXC_HANDLING_H*/
