2010-02-28 16:54:25 +01:00
|
|
|
/* exception.h
|
|
|
|
|
2013-01-02 19:34:06 +01:00
|
|
|
Copyright 2010, 2011, 2012, 2013 Red Hat, Inc.
|
2010-02-28 16:54:25 +01:00
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2012-02-12 23:43:33 +01:00
|
|
|
#pragma once
|
2010-02-28 16:54:25 +01:00
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
#ifdef __x86_64__
|
|
|
|
#define _exception_list _EXCEPTION_REGISTRATION_RECORD
|
|
|
|
#endif
|
|
|
|
|
2010-02-28 16:54:25 +01:00
|
|
|
#include <exceptions.h>
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
#ifndef __x86_64__
|
2010-02-28 16:54:25 +01:00
|
|
|
extern exception_list *_except_list asm ("%fs:0");
|
2013-04-23 11:44:36 +02:00
|
|
|
#endif
|
2010-02-28 16:54:25 +01:00
|
|
|
|
|
|
|
class exception
|
|
|
|
{
|
2013-04-23 11:44:36 +02:00
|
|
|
#ifdef __x86_64__
|
|
|
|
static bool handler_installed;
|
|
|
|
static int handle (LPEXCEPTION_POINTERS);
|
|
|
|
#else
|
2010-02-28 16:54:25 +01:00
|
|
|
exception_list el;
|
|
|
|
exception_list *save;
|
|
|
|
static int handle (EXCEPTION_RECORD *, exception_list *, CONTEXT *, void *);
|
2013-04-23 11:44:36 +02:00
|
|
|
#endif
|
2010-02-28 16:54:25 +01:00
|
|
|
public:
|
|
|
|
exception () __attribute__ ((always_inline))
|
|
|
|
{
|
2013-04-23 11:44:36 +02:00
|
|
|
#ifdef __x86_64__
|
|
|
|
if (!handler_installed)
|
|
|
|
{
|
|
|
|
handler_installed = true;
|
|
|
|
/* The unhandled exception filter goes first. It won't work if the
|
|
|
|
executable is debugged, but then the vectored continue handler
|
|
|
|
kicks in. For some reason the vectored continue handler doesn't
|
|
|
|
get called if no unhandled exception filter is installed. */
|
|
|
|
SetUnhandledExceptionFilter (handle);
|
|
|
|
AddVectoredContinueHandler (1, handle);
|
|
|
|
}
|
|
|
|
#else
|
2010-02-28 16:54:25 +01:00
|
|
|
save = _except_list;
|
|
|
|
el.handler = handle;
|
|
|
|
el.prev = _except_list;
|
|
|
|
_except_list = ⪙
|
2013-04-23 11:44:36 +02:00
|
|
|
#endif
|
2010-02-28 16:54:25 +01:00
|
|
|
};
|
2013-04-23 11:44:36 +02:00
|
|
|
#ifndef __x86_64__
|
2010-02-28 16:54:25 +01:00
|
|
|
~exception () __attribute__ ((always_inline)) { _except_list = save; }
|
2013-04-23 11:44:36 +02:00
|
|
|
#endif
|
2010-02-28 16:54:25 +01:00
|
|
|
};
|
|
|
|
|
2013-01-02 19:34:06 +01:00
|
|
|
class cygwin_exception
|
2012-02-12 23:43:33 +01:00
|
|
|
{
|
2013-04-23 11:44:36 +02:00
|
|
|
PUINT_PTR framep;
|
2013-01-02 19:34:06 +01:00
|
|
|
PCONTEXT ctx;
|
|
|
|
EXCEPTION_RECORD *e;
|
|
|
|
void dump_exception ();
|
|
|
|
public:
|
2013-04-23 11:44:36 +02:00
|
|
|
cygwin_exception (PUINT_PTR in_framep, PCONTEXT in_ctx = NULL, EXCEPTION_RECORD *in_e = NULL):
|
|
|
|
framep (in_framep), ctx (in_ctx), e (in_e) {}
|
2013-01-02 19:34:06 +01:00
|
|
|
void dumpstack ();
|
|
|
|
PCONTEXT context () const {return ctx;}
|
|
|
|
};
|