Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Dwarf EH: add _d_eh_swapContextDwarf
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Dec 30, 2015
1 parent 4ed3b72 commit 7e99ae1
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
48 changes: 46 additions & 2 deletions src/core/thread.d
Expand Up @@ -118,6 +118,50 @@ private
* is switched in for the first time.
*/
extern(C) void* _d_eh_swapContext(void* newContext) nothrow;

version (DigitalMars)
{
version (Windows)
alias _d_eh_swapContext swapContext;
else
{
extern(C) void* _d_eh_swapContextDwarf(void* newContext) nothrow;

void* swapContext(void* newContext) nothrow
{
/* Detect at runtime which scheme is being used.
* Eventually, determine it statically.
*/
static int which = 0;
final switch (which)
{
case 0:
{
assert(newContext == null);
auto p = _d_eh_swapContext(newContext);
auto pdwarf = _d_eh_swapContextDwarf(newContext);
if (p)
{
which = 1;
return p;
}
else if (pdwarf)
{
which = 2;
return pdwarf;
}
return null;
}
case 1:
return _d_eh_swapContext(newContext);
case 2:
return _d_eh_swapContextDwarf(newContext);
}
}
}
}
else
alias _d_eh_swapContext swapContext;
}


Expand Down Expand Up @@ -1461,7 +1505,7 @@ private:
}
body
{
m_curr.ehContext = _d_eh_swapContext(c.ehContext);
m_curr.ehContext = swapContext(c.ehContext);
c.within = m_curr;
m_curr = c;
}
Expand All @@ -1476,7 +1520,7 @@ private:
{
Context* c = m_curr;
m_curr = c.within;
c.ehContext = _d_eh_swapContext(m_curr.ehContext);
c.ehContext = swapContext(m_curr.ehContext);
c.within = null;
}

Expand Down
15 changes: 15 additions & 0 deletions src/rt/dwarfeh.d
Expand Up @@ -150,6 +150,21 @@ extern(C) Throwable __dmd_begin_catch(_Unwind_Exception* exceptionObject)
return o;
}

/****************************************
* Called when fibers switch contexts.
* Params:
* newContext = stack to switch to
* Returns:
* previous value of stack
*/
extern(C) void* _d_eh_swapContextDwarf(void* newContext) nothrow
{
auto old = ExceptionHeader.stack;
ExceptionHeader.stack = cast(ExceptionHeader*)newContext;
return old;
}


/*********************
* Called by D code to throw an exception via
* ---
Expand Down

0 comments on commit 7e99ae1

Please sign in to comment.