Skip to content

Commit

Permalink
Merge pull request #5285 from WalterBright/eh
Browse files Browse the repository at this point in the history
update to use new config.ehmethod
  • Loading branch information
yebblies committed Nov 28, 2015
2 parents fc42ae8 + fe20403 commit ce51092
Showing 1 changed file with 18 additions and 29 deletions.
47 changes: 18 additions & 29 deletions src/eh.c
@@ -1,6 +1,6 @@
/*
* Copyright (c) 1994-1998 by Symantec
* Copyright (c) 2000-2013 by Digital Mars
* Copyright (c) 2000-2015 by Digital Mars
* All Rights Reserved
* http://www.digitalmars.com
* Written by Walter Bright
Expand Down Expand Up @@ -29,17 +29,6 @@
static char __file__[] = __FILE__; /* for tassert.h */
#include "tassert.h"

/* If we do our own EH tables and stack walking scheme
* (Otherwise use NT Structured Exception Handling)
*/
#if (TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS)
#define OUREH 1
#elif TARGET_WINDOS
#define OUREH I64
#else
#error fix
#endif

extern void error(const char *filename, unsigned linnum, unsigned charnum, const char *format, ...);

/****************************
Expand All @@ -49,7 +38,7 @@ extern void error(const char *filename, unsigned linnum, unsigned charnum, const
symbol *except_gentables()
{
//printf("except_gentables()\n");
if (OUREH)
if (config.ehmethod == EH_DM)
{
// BUG: alloca() changes the stack size, which is not reflected
// in the fixed eh tables.
Expand Down Expand Up @@ -81,7 +70,7 @@ symbol *except_gentables()
*
* struct Guard
* {
* if (OUREH)
* if (EH_DM)
* {
* unsigned offset; // offset of start of guarded section (Linux)
* unsigned endoffset; // ending offset of guarded section (Linux)
Expand Down Expand Up @@ -115,18 +104,17 @@ void except_fillInEHTable(symbol *s)
* in the compiler.
*/
unsigned GUARD_SIZE;
if (OUREH)
if (config.ehmethod == EH_DM)
GUARD_SIZE = (I64 ? 3*8 : 5*4);
else
else if (config.ehmethod == EH_WIN32)
GUARD_SIZE = 3*4;
else
assert(0);

int sz = 0;

// Address of start of function
if (OUREH)
{
}
else
if (config.ehmethod == EH_WIN32)
{
symbol_debug(funcsym_p);
pdt = dtxoff(pdt,funcsym_p,0,TYnptr);
Expand Down Expand Up @@ -162,9 +150,10 @@ void except_fillInEHTable(symbol *s)
}
//printf("guarddim = %d, ndctors = %d\n", guarddim, ndctors);

if (OUREH)
{ pdt = dtsize_t(pdt,guarddim + ndctors);
sz += NPTRSIZE;
if (config.ehmethod == EH_DM)
{
pdt = dtsize_t(pdt,guarddim + ndctors);
sz += NPTRSIZE;
}

unsigned catchoffset = sz + (guarddim + ndctors) * GUARD_SIZE;
Expand All @@ -186,7 +175,7 @@ void except_fillInEHTable(symbol *s)

int nsucc = b->numSucc();

if (OUREH)
if (config.ehmethod == EH_DM)
{
//printf("DHandlerInfo: offset = %x", (int)(b->Boffset - startblock->Boffset));
pdt = dtdword(pdt,b->Boffset - startblock->Boffset); // offset to start of block
Expand Down Expand Up @@ -225,7 +214,7 @@ void except_fillInEHTable(symbol *s)
// To successor of BC_finally block
bhandler = bhandler->nthSucc(0);
// finally handler address
if (OUREH)
if (config.ehmethod == EH_DM)
{
assert(bhandler->Boffset > startblock->Boffset);
pdt = dtsize_t(pdt,bhandler->Boffset - startblock->Boffset); // finally handler offset
Expand Down Expand Up @@ -264,7 +253,7 @@ void except_fillInEHTable(symbol *s)
code *c2 = code_next(c);
if (config.flags2 & CFG2seh)
nteh_patchindex(c2, scopeindex);
if (OUREH)
if (config.ehmethod == EH_DM)
pdt = dtdword(pdt,boffset - startblock->Boffset); // guard offset
// Find corresponding ddtor instruction
int n = 0;
Expand Down Expand Up @@ -299,7 +288,7 @@ void except_fillInEHTable(symbol *s)
// issue 9438
//cf = code_next(cf);
//foffset += calccodsize(cf);
if (OUREH)
if (config.ehmethod == EH_DM)
pdt = dtdword(pdt,eoffset - startblock->Boffset); // guard offset
break;
}
Expand All @@ -314,7 +303,7 @@ void except_fillInEHTable(symbol *s)
//printf("boffset = %x, eoffset = %x, foffset = %x\n", boffset, eoffset, foffset);
pdt = dtdword(pdt,stack[stacki - 1]); // parent index
pdt = dtdword(pdt,0); // no catch offset
if (OUREH)
if (config.ehmethod == EH_DM)
{
assert(foffset > startblock->Boffset);
pdt = dtsize_t(pdt,foffset - startblock->Boffset); // finally handler offset
Expand Down Expand Up @@ -366,7 +355,7 @@ void except_fillInEHTable(symbol *s)
pdt = dtsize_t(pdt,cod3_bpoffset(b->jcatchvar)); // EBP offset

// catch handler address
if (OUREH)
if (config.ehmethod == EH_DM)
{
assert(bcatch->Boffset > startblock->Boffset);
pdt = dtsize_t(pdt,bcatch->Boffset - startblock->Boffset); // catch handler offset
Expand Down

0 comments on commit ce51092

Please sign in to comment.