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

Commit 90e6976

Browse files
committed
rt.sections_elf_shared: Refactor findDSOInfoForAddr()
1 parent 3e9e202 commit 90e6976

File tree

1 file changed

+31
-39
lines changed

1 file changed

+31
-39
lines changed

src/rt/sections_elf_shared.d

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -774,59 +774,51 @@ void scanSegments(in ref dl_phdr_info info, DSO* pdso) nothrow @nogc
774774

775775
/**************************
776776
* Input:
777-
* result where the output is to be written; dl_phdr_info is a Linux struct
777+
* result where the output is to be written; dl_phdr_info is an OS struct
778778
* Returns:
779779
* true if found, and *result is filled in
780780
* References:
781781
* http://linux.die.net/man/3/dl_iterate_phdr
782782
*/
783-
version (linux) bool findDSOInfoForAddr(in void* addr, dl_phdr_info* result=null) nothrow @nogc
783+
bool findDSOInfoForAddr(in void* addr, dl_phdr_info* result=null) nothrow @nogc
784784
{
785-
static struct DG { const(void)* addr; dl_phdr_info* result; }
785+
version (linux) enum IterateManually = true;
786+
else version (NetBSD) enum IterateManually = true;
787+
else enum IterateManually = false;
786788

787-
extern(C) int callback(dl_phdr_info* info, size_t sz, void* arg) nothrow @nogc
789+
static if (IterateManually)
788790
{
789-
auto p = cast(DG*)arg;
790-
if (findSegmentForAddr(*info, p.addr))
791+
static struct DG { const(void)* addr; dl_phdr_info* result; }
792+
793+
extern(C) int callback(dl_phdr_info* info, size_t sz, void* arg) nothrow @nogc
791794
{
792-
if (p.result !is null) *p.result = *info;
793-
return 1; // break;
795+
auto p = cast(DG*)arg;
796+
if (findSegmentForAddr(*info, p.addr))
797+
{
798+
if (p.result !is null) *p.result = *info;
799+
return 1; // break;
800+
}
801+
return 0; // continue iteration
794802
}
795-
return 0; // continue iteration
796-
}
797-
798-
auto dg = DG(addr, result);
799803

800-
/* Linux function that walks through the list of an application's shared objects and
801-
* calls 'callback' once for each object, until either all shared objects
802-
* have been processed or 'callback' returns a nonzero value.
803-
*/
804-
return dl_iterate_phdr(&callback, &dg) != 0;
805-
}
806-
else version (FreeBSD) bool findDSOInfoForAddr(in void* addr, dl_phdr_info* result=null) nothrow @nogc
807-
{
808-
return !!_rtld_addr_phdr(addr, result);
809-
}
810-
else version (NetBSD) bool findDSOInfoForAddr(in void* addr, dl_phdr_info* result=null) nothrow @nogc
811-
{
812-
static struct DG { const(void)* addr; dl_phdr_info* result; }
804+
auto dg = DG(addr, result);
813805

814-
extern(C) int callback(dl_phdr_info* info, size_t sz, void* arg) nothrow @nogc
806+
/* OS function that walks through the list of an application's shared objects and
807+
* calls 'callback' once for each object, until either all shared objects
808+
* have been processed or 'callback' returns a nonzero value.
809+
*/
810+
return dl_iterate_phdr(&callback, &dg) != 0;
811+
}
812+
else version (FreeBSD)
815813
{
816-
auto p = cast(DG*)arg;
817-
if (findSegmentForAddr(*info, p.addr))
818-
{
819-
if (p.result !is null) *p.result = *info;
820-
return 1; // break;
821-
}
822-
return 0; // continue iteration
814+
return !!_rtld_addr_phdr(addr, result);
823815
}
824-
auto dg = DG(addr, result);
825-
return dl_iterate_phdr(&callback, &dg) != 0;
826-
}
827-
else version (DragonFlyBSD) bool findDSOInfoForAddr(in void* addr, dl_phdr_info* result=null) nothrow @nogc
828-
{
829-
return !!_rtld_addr_phdr(addr, result);
816+
else version (DragonFlyBSD)
817+
{
818+
return !!_rtld_addr_phdr(addr, result);
819+
}
820+
else
821+
static assert(0, "unimplemented");
830822
}
831823

832824
/*********************************

0 commit comments

Comments
 (0)