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

Commit

Permalink
Win64 EH
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Oct 9, 2012
1 parent 46e85ef commit 12f6dce
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
15 changes: 14 additions & 1 deletion src/core/runtime.d
Expand Up @@ -358,8 +358,10 @@ extern (C) bool runModuleUnitTests()
/**
*
*/
import core.stdc.stdio;
Throwable.TraceInfo defaultTraceHandler( void* ptr = null )
{
//printf("runtime.defaultTraceHandler()\n");
static if( __traits( compiles, backtrace ) )
{
import core.demangle;
Expand Down Expand Up @@ -563,7 +565,18 @@ Throwable.TraceInfo defaultTraceHandler( void* ptr = null )
}
else static if( __traits( compiles, new StackTrace ) )
{
return new StackTrace;
version (Win64)
{
/* Disabled for the moment, because DbgHelp's stack walking code
* does not work with dmd's stack frame.
*/
return null;
}
else
{
auto s = new StackTrace;
return s;
}
}
else
{
Expand Down
27 changes: 20 additions & 7 deletions src/rt/deh2.d
Expand Up @@ -167,10 +167,23 @@ FuncTable *__eh_finddata(void *address)
debug printf(" ft = %p, fptr = %p, handlertable = %p, fsize = x%03x\n",
ft, ft.fptr, ft.handlertable, ft.fsize);

if (ft.fptr <= address &&
address < cast(void *)(cast(char *)ft.fptr + ft.fsize))
void *fptr = ft.fptr;
version (Win64)
{
/* If linked with /DEBUG, the linker rewrites it so the function pointer points
* to a JMP to the actual code. The address will be in the actual code, so we
* need to follow the JMP.
*/
if ((cast(ubyte*)fptr)[0] == 0xE9)
{ // JMP target = RIP of next instruction + signed 32 bit displacement
fptr = fptr + 5 + *cast(int*)(fptr + 1);
}
}

if (fptr <= address &&
address < cast(void *)(cast(char *)fptr + ft.fsize))
{
debug printf("\tfound handler table\n");
debug printf("\tfound handler table\n");
return ft;
}
}
Expand Down Expand Up @@ -292,8 +305,8 @@ extern (C) void _d_throwc(Object *h)
for (int i = 0; i < dim; i++)
{
auto phi = &handler_table.handler_info.ptr[i];
printf("\t[%d]: offset = x%04x, endoffset = x%04x, prev_index = %d, cioffset = x%04x, finally_code = %x\n",
i, phi.offset, phi.endoffset, phi.prev_index, phi.cioffset, phi.finally_code);
printf("\t[%d]: offset = x%04x, endoffset = x%04x, prev_index = %d, cioffset = x%04x, finally_offset = %x\n",
i, phi.offset, phi.endoffset, phi.prev_index, phi.cioffset, phi.finally_offset);
}
}

Expand All @@ -312,7 +325,7 @@ extern (C) void _d_throwc(Object *h)
if (dim)
{
auto phi = &handler_table.handler_info.ptr[index+1];
debug printf("next finally_code %p\n", phi.finally_code);
debug printf("next finally_offset %p\n", phi.finally_offset);
auto prev = cast(InFlight*) &__inflight;
auto curr = prev.next;

Expand Down Expand Up @@ -408,7 +421,7 @@ extern (C) void _d_throwc(Object *h)
// Call finally block
// Note that it is unnecessary to adjust the ESP, as the finally block
// accesses all items on the stack as relative to EBP.
debug printf("calling finally_code %p\n", phi.finally_code);
debug printf("calling finally_offset %p\n", phi.finally_offset);

auto blockaddr = cast(void*)(funcoffset + phi.finally_offset);
InFlight inflight;
Expand Down

0 comments on commit 12f6dce

Please sign in to comment.