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

Commit

Permalink
use EH tables from SectionGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinNowak committed Mar 6, 2013
1 parent 8b45908 commit da073b0
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 51 deletions.
47 changes: 16 additions & 31 deletions src/rt/deh2.d
Expand Up @@ -31,23 +31,6 @@ debug(PRINTF) import core.stdc.stdio : printf;

extern (C)
{
version (OSX)
{
// Set by rt.memory_osx.onAddImage()
__gshared ubyte[] _deh_eh_array;
}
else
{
extern __gshared
{
/* Symbols created by the compiler and inserted into the object file
* that 'bracket' the __deh_eh segment
*/
void* _deh_beg;
void* _deh_end;
}
}

Throwable.TraceInfo _d_traceContext(void* ptr = null);

int _d_isbaseof(ClassInfo oc, ClassInfo c);
Expand Down Expand Up @@ -128,21 +111,23 @@ void terminate()
* Return DHandlerTable if there is one, NULL if not.
*/

FuncTable *__eh_finddata(void *address)
immutable(FuncTable)* __eh_finddata(void *address)
{
debug(PRINTF) printf("FuncTable.sizeof = %p\n", FuncTable.sizeof);
debug(PRINTF) printf("__eh_finddata(address = %p)\n", address);

version (OSX)
{
auto pstart = cast(FuncTable *)_deh_eh_array.ptr;
auto pend = cast(FuncTable *)(_deh_eh_array.ptr + _deh_eh_array.length);
}
else
import rt.sections;
foreach (ref sg; SectionGroup)
{
auto pstart = cast(FuncTable *)&_deh_beg;
auto pend = cast(FuncTable *)&_deh_end;
auto pstart = sg.ehTables.ptr;
auto pend = pstart + sg.ehTables.length;
if (auto ft = __eh_finddata(address, pstart, pend))
return ft;
}
return null;
}

immutable(FuncTable)* __eh_finddata(void *address, immutable(FuncTable)* pstart, immutable(FuncTable)* pend)
{
debug(PRINTF) printf("FuncTable.sizeof = %p\n", FuncTable.sizeof);
debug(PRINTF) printf("__eh_finddata(address = %p)\n", address);
debug(PRINTF) printf("_deh_beg = %p, _deh_end = %p\n", pstart, pend);

for (auto ft = pstart; 1; ft++)
Expand All @@ -159,15 +144,15 @@ FuncTable *__eh_finddata(void *address)
*/
if (ft.fptr == null)
{
ft = cast(FuncTable *)(cast(void**)ft + 1);
ft = cast(immutable(FuncTable)*)(cast(void**)ft + 1);
goto Lagain;
}
}

debug(PRINTF) printf(" ft = %p, fptr = %p, handlertable = %p, fsize = x%03x\n",
ft, ft.fptr, ft.handlertable, ft.fsize);

void *fptr = ft.fptr;
immutable(void)* fptr = ft.fptr;
version (Win64)
{
/* If linked with /DEBUG, the linker rewrites it so the function pointer points
Expand Down
10 changes: 0 additions & 10 deletions src/rt/memory_osx.d
Expand Up @@ -18,7 +18,6 @@ version(OSX):
import src.core.sys.osx.mach.dyld;
import src.core.sys.osx.mach.getsect;

extern (C) extern __gshared ubyte[] _deh_eh_array;
extern (C) extern __gshared ubyte[][2] _tls_data_array;

extern (C) void gc_addRange( void* p, size_t sz );
Expand Down Expand Up @@ -86,15 +85,6 @@ extern (C) void onAddImage(in mach_header* h, intptr_t slide)
if (auto sect = getSection(h, slide, e.seg.ptr, e.sect.ptr))
gc_addRange(sect.ptr, sect.length);
}

if (auto sect = getSection(h, slide, "__DATA", "__deh_eh"))
{
//printf(" deh_eh\n");
/* BUG: this will fail if there are multiple images with __deh_eh
* sections. Not set up to handle that.
*/
_deh_eh_array = sect.ptr[0 .. sect.length];
}
}


Expand Down
3 changes: 2 additions & 1 deletion src/rt/sections.d
Expand Up @@ -23,13 +23,14 @@ else version (Win64)
else
static assert(0, "unimplemented");

import rt.minfo;
import rt.deh2, rt.minfo;

template isSectionGroup(T)
{
enum isSectionGroup =
is(typeof(T.init.modules) == ModuleInfo*[]) &&
is(typeof(T.init.moduleGroup) == ModuleGroup) &&
(!is(typeof(T.init.ehTables)) || is(typeof(T.init.ehTables) == immutable(FuncTable)[])) &&
is(typeof({ foreach (ref T; T) {}})) &&
is(typeof({ foreach_reverse (ref T; T) {}}));
}
Expand Down
18 changes: 17 additions & 1 deletion src/rt/sections_freebsd.d
Expand Up @@ -15,7 +15,7 @@ version (FreeBSD):
// debug = PRINTF;
debug(PRINTF) import core.stdc.stdio;
import core.stdc.stdlib : malloc, free;
import rt.minfo;
import rt.deh2, rt.minfo;

struct SectionGroup
{
Expand All @@ -39,6 +39,13 @@ struct SectionGroup
return _moduleGroup;
}

@property immutable(FuncTable)[] ehTables() const
{
auto pbeg = cast(immutable(FuncTable)*)&_deh_beg;
auto pend = cast(immutable(FuncTable)*)&_deh_end;
return pbeg[0 .. pend - pbeg];
}

private:
ModuleGroup _moduleGroup;
}
Expand Down Expand Up @@ -88,3 +95,12 @@ body
}
return result;
}

extern(C)
{
/* Symbols created by the compiler and inserted into the object file
* that 'bracket' the __deh_eh segment
*/
extern __gshared void* _deh_beg;
extern __gshared void* _deh_end;
}
12 changes: 6 additions & 6 deletions src/rt/sections_linux.d
Expand Up @@ -54,9 +54,9 @@ struct DSO
return _moduleGroup;
}

@property inout(FuncTable)[] ehtables() inout
@property immutable(FuncTable)[] ehTables() const
{
return _ehtables[];
return _ehTables[];
}

@property inout(void[])[] gcRanges() inout
Expand All @@ -77,8 +77,8 @@ private:
assert(_tlsMod || !_tlsSize);
}

FuncTable[] _ehtables;
ModuleGroup _moduleGroup;
immutable(FuncTable)[] _ehTables;
ModuleGroup _moduleGroup;
Array!(void[]) _gcRanges;
size_t _tlsMod;
size_t _tlsSize;
Expand Down Expand Up @@ -120,7 +120,7 @@ struct CompilerDSOData
size_t _version;
void** _slot; // can be used to store runtime data
object.ModuleInfo** _minfo_beg, _minfo_end;
rt.deh2.FuncTable* _deh_beg, _deh_end;
immutable(rt.deh2.FuncTable)* _deh_beg, _deh_end;
}

T[] toRange(T)(T* beg, T* end) { return beg[0 .. end - beg]; }
Expand All @@ -139,7 +139,7 @@ extern(C) void _d_dso_registry(CompilerDSOData* data)
*data._slot = pdso; // store backlink in library record

pdso._moduleGroup = ModuleGroup(toRange(data._minfo_beg, data._minfo_end));
pdso._ehtables = toRange(data._deh_beg, data._deh_end);
pdso._ehTables = toRange(data._deh_beg, data._deh_end);

dl_phdr_info info = void;
findDSOInfoForAddr(data._slot, &info) || assert(0);
Expand Down
20 changes: 19 additions & 1 deletion src/rt/sections_osx.d
Expand Up @@ -17,7 +17,7 @@ version(OSX):
// debug = PRINTF;
debug(PRINTF) import core.stdc.stdio;
import core.stdc.stdlib : malloc, free;
import rt.minfo;
import rt.deh2, rt.minfo;
import rt.memory_osx;
import src.core.sys.osx.mach.dyld;
import src.core.sys.osx.mach.getsect;
Expand All @@ -44,7 +44,13 @@ struct SectionGroup
return _moduleGroup;
}

@property immutable(FuncTable)[] ehTables() const
{
return _ehTables[];
}

private:
immutable(FuncTable)[] _ehTables;
ModuleGroup _moduleGroup;
}

Expand Down Expand Up @@ -74,4 +80,16 @@ extern (C) void sections_osx_onAddImage(in mach_header* h, intptr_t slide)

_sections._moduleGroup = ModuleGroup(p[0 .. len]);
}

if (auto sect = getSection(h, slide, "__DATA", "__deh_eh"))
{
// no support for multiple images yet
_sections._ehTables.ptr is null || assert(0);

debug(PRINTF) printf(" deh_eh\n");
auto p = cast(immutable(FuncTable)*)sect.ptr;
immutable len = sect.length / (*p).sizeof;

_sections._ehTables = p[0 .. len];
}
}
16 changes: 16 additions & 0 deletions src/rt/sections_solaris.d
Expand Up @@ -39,6 +39,13 @@ struct SectionGroup
return _moduleGroup;
}

@property immutable(FuncTable)[] ehTables() const
{
auto pbeg = cast(immutable(FuncTable)*)&_deh_beg;
auto pend = cast(immutable(FuncTable)*)&_deh_end;
return pbeg[0 .. pend - pbeg];
}

private:
ModuleGroup _moduleGroup;
}
Expand Down Expand Up @@ -88,3 +95,12 @@ body
}
return result;
}

extern(C)
{
/* Symbols created by the compiler and inserted into the object file
* that 'bracket' the __deh_eh segment
*/
extern __gshared void* _deh_beg;
extern __gshared void* _deh_end;
}
18 changes: 17 additions & 1 deletion src/rt/sections_win64.d
Expand Up @@ -17,7 +17,7 @@ version(Win64):
// debug = PRINTF;
debug(PRINTF) import core.stdc.stdio;
import core.stdc.stdlib : malloc, free;
import rt.minfo;
import rt.deh2, rt.minfo;

struct SectionGroup
{
Expand All @@ -41,6 +41,13 @@ struct SectionGroup
return _moduleGroup;
}

@property immutable(FuncTable)[] ehTables() const
{
auto pbeg = cast(immutable(FuncTable)*)&_deh_beg;
auto pend = cast(immutable(FuncTable)*)&_deh_end;
return pbeg[0 .. pend - pbeg];
}

private:
ModuleGroup _moduleGroup;
}
Expand Down Expand Up @@ -95,3 +102,12 @@ body

return result;
}

extern(C)
{
/* Symbols created by the compiler and inserted into the object file
* that 'bracket' the __deh_eh segment
*/
extern __gshared void* _deh_beg;
extern __gshared void* _deh_end;
}

0 comments on commit da073b0

Please sign in to comment.