* Throughout, use __try/__except/__endtry blocks, rather than myfault
handler. * cygtls.cc (_cygtls::remove): Accommodate the fact that pathbufs has been moved from _local_storage to _cygtls. * cygtls.h (class tls_pathbuf): Add comment to hint to gendef usage of counters. Change type of counters to uint32_t for clarity. Remove _cygtls as friend class. (struct _local_storage): Move pathbufs from here... (struct _cygtls): ...to here, allowing to access it from _sigbe. (class san): Only define on 32 bit. Remove errno, _c_cnt and _w_cnt members. (san::setup): Drop parameter. Don't initialize removed members. (san::leave): Don't set removed members. (class myfault): Only define on 32 bit. (myfault::faulted): Only keep implementation not taking any parameter. Drop argument in call to sebastian.setup. (__try/__leave/__except/__endtry): Implement to support real SEH. For now stick to SJLJ on 32 bit. * dcrt0.cc (dll_crt0_0): Drop 64 bit call to exception::install_myfault_handler. * exception.h (exception_handler): Define with EXCEPTION_DISPOSITION as return type. (PDISPATCHER_CONTEXT): Define as void * on 32 bit. Define as pointer to _DISPATCHER_CONTEXT on 64 bit. (class exception): Define separately for 32 and 64 bit. (exception::myfault): Add handler for myfault SEH handling on 64 bit. (exception::exception): Fix mangled method name to account for change in type of last parameter. (exception::install_myfault_handler): Remove. * exceptions.cc (exception::myfault_handle): Remove. (exception::myfault): New SEH handler for 64 bit. * gendef (_sigbe): Set tls_pathbuf counters to 0 explicitely when returning to the caller. * ntdll.h: Move a comment to a better place. (struct _SCOPE_TABLE): Define on 64 bit. * thread.cc (verifyable_object_isvalid): Remove gcc 4.7 workaround. * tls_pbuf.cc (tls_pbuf): Fix to accommodate new place of pathbufs. (tls_pathbuf::destroy): Change type of loop variables to uint32_t. * tls_pbuf.h (class tmp_pathbuf): Change type of buffer counters to uint32_t. Accommodate new place of pathbufs. * tlsoffsets.h: Regenerate. * tlsoffsets64.h: Regenerate.
This commit is contained in:
@ -94,8 +94,10 @@ to install your own exception filter. This one is documented.
|
||||
a teensy bit of detail of the innards of exception handling (i.e. what we
|
||||
have to do). */
|
||||
|
||||
typedef int (exception_handler) (EXCEPTION_RECORD *, struct _exception_list *,
|
||||
CONTEXT *, void *);
|
||||
typedef EXCEPTION_DISPOSITION (exception_handler) (EXCEPTION_RECORD *,
|
||||
struct _exception_list *,
|
||||
CONTEXT *,
|
||||
void *);
|
||||
|
||||
typedef struct _exception_list
|
||||
{
|
||||
@ -104,70 +106,53 @@ typedef struct _exception_list
|
||||
} exception_list;
|
||||
|
||||
extern exception_list *_except_list asm ("%fs:0");
|
||||
#else
|
||||
typedef void exception_list;
|
||||
#endif /* !__x86_64 */
|
||||
typedef void *PDISPATCHER_CONTEXT;
|
||||
|
||||
class exception
|
||||
{
|
||||
#ifdef __x86_64__
|
||||
static LONG myfault_handle (LPEXCEPTION_POINTERS ep);
|
||||
#else
|
||||
exception_list el;
|
||||
exception_list *save;
|
||||
#endif /* __x86_64__ */
|
||||
static int handle (EXCEPTION_RECORD *, exception_list *, CONTEXT *, void *);
|
||||
static EXCEPTION_DISPOSITION handle (EXCEPTION_RECORD *, exception_list *,
|
||||
CONTEXT *, PDISPATCHER_CONTEXT);
|
||||
public:
|
||||
exception () __attribute__ ((always_inline))
|
||||
{
|
||||
/* Install SEH handler. */
|
||||
save = _except_list;
|
||||
el.handler = handle;
|
||||
el.prev = _except_list;
|
||||
_except_list = ⪙
|
||||
};
|
||||
~exception () __attribute__ ((always_inline)) { _except_list = save; }
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
#define exception_list void
|
||||
typedef struct _DISPATCHER_CONTEXT *PDISPATCHER_CONTEXT;
|
||||
|
||||
class exception
|
||||
{
|
||||
#ifdef __x86_64__
|
||||
static EXCEPTION_DISPOSITION myfault (EXCEPTION_RECORD *, exception_list *,
|
||||
CONTEXT *, PDISPATCHER_CONTEXT);
|
||||
#endif
|
||||
static EXCEPTION_DISPOSITION handle (EXCEPTION_RECORD *, exception_list *,
|
||||
CONTEXT *, PDISPATCHER_CONTEXT);
|
||||
public:
|
||||
exception () __attribute__ ((always_inline))
|
||||
{
|
||||
/* Install SEH handler. */
|
||||
asm volatile ("\n\
|
||||
1: \n\
|
||||
.seh_handler \
|
||||
_ZN9exception6handleEP17_EXCEPTION_RECORDPvP8_CONTEXTS2_, \
|
||||
_ZN9exception6handleEP17_EXCEPTION_RECORDPvP8_CONTEXTP19_DISPATCHER_CONTEXT, \
|
||||
@except \n\
|
||||
.seh_handlerdata \n\
|
||||
.long 1 \n\
|
||||
.rva 1b, 2f, 2f, 2f \n\
|
||||
.seh_code \n");
|
||||
#else
|
||||
save = _except_list;
|
||||
el.handler = handle;
|
||||
el.prev = _except_list;
|
||||
_except_list = ⪙
|
||||
#endif /* __x86_64__ */
|
||||
};
|
||||
#ifdef __x86_64__
|
||||
static void install_myfault_handler () __attribute__ ((always_inline))
|
||||
{
|
||||
/* Install myfault exception handler as VEH. Here's what happens:
|
||||
Some Windows DLLs (advapi32, for instance) are using SEH to catch
|
||||
exceptions inside its own functions. If we install a VEH handler
|
||||
to catch all exceptions, our Cygwin VEH handler would illegitimatly
|
||||
handle exceptions inside of Windows DLLs which are usually handled
|
||||
by its own SEH handler. So, for standard exceptions we use an SEH
|
||||
handler as installed in the constructor above so as not to override
|
||||
the SEH handlers in Windows DLLs.
|
||||
But we have a special case, myfault handling. The myfault handling
|
||||
catches exceptions inside of the Cygwin DLL, some of them entirely
|
||||
expected as in verifyable_object_isvalid. The ultimately right thing
|
||||
to do would be to install SEH handlers for each of these cases.
|
||||
But there are two problems with that:
|
||||
|
||||
1. It would be a massive and, partially unreliable change in the
|
||||
calling functions due to the incomplete SEH support in GCC.
|
||||
|
||||
2. It doesn't always work. Certain DLLs appear to call Cygwin
|
||||
functions during DLL initialization while the SEH handler is
|
||||
not installed in the active call frame. For these cases we
|
||||
need a more generic approach.
|
||||
|
||||
So, what we do here is to install a myfault VEH handler. This
|
||||
function is called from dll_crt0_0, so the myfault handler is
|
||||
available very early. */
|
||||
AddVectoredExceptionHandler (1, myfault_handle);
|
||||
}
|
||||
~exception () __attribute__ ((always_inline))
|
||||
{
|
||||
asm volatile ("\n\
|
||||
@ -175,11 +160,10 @@ public:
|
||||
2: \n\
|
||||
nop \n");
|
||||
}
|
||||
#else
|
||||
~exception () __attribute__ ((always_inline)) { _except_list = save; }
|
||||
#endif /* !__x86_64__ */
|
||||
};
|
||||
|
||||
#endif /* !__x86_64 */
|
||||
|
||||
class cygwin_exception
|
||||
{
|
||||
PUINT_PTR framep;
|
||||
|
Reference in New Issue
Block a user