Skip to content

Commit 8eb15df

Browse files
committed
Merge pull request #463 from dawgfoto/getSectionOSX
simplify rt.sections_osx.getSection
2 parents ba8be06 + e631f09 commit 8eb15df

File tree

1 file changed

+12
-24
lines changed

1 file changed

+12
-24
lines changed

src/rt/sections_osx.d

+12-24
Original file line numberDiff line numberDiff line change
@@ -236,36 +236,24 @@ static immutable SegRef[] dataSegs = [{SEG_DATA, SECT_DATA},
236236
ubyte[] getSection(in mach_header* header, intptr_t slide,
237237
in char* segmentName, in char* sectionName)
238238
{
239-
if (header.magic == MH_MAGIC)
239+
version (X86)
240240
{
241+
assert(header.magic == MH_MAGIC);
241242
auto sect = getsectbynamefromheader(header,
242243
segmentName,
243244
sectionName);
244-
245-
if (sect !is null && sect.size > 0)
246-
{
247-
auto addr = cast(size_t) sect.addr;
248-
auto size = cast(size_t) sect.size;
249-
return (cast(ubyte*) addr)[slide .. slide + size];
250-
}
251-
return null;
252-
253245
}
254-
else if (header.magic == MH_MAGIC_64)
246+
else version (X86_64)
255247
{
256-
auto header64 = cast(mach_header_64*) header;
257-
auto sect = getsectbynamefromheader_64(header64,
258-
segmentName,
259-
sectionName);
260-
261-
if (sect !is null && sect.size > 0)
262-
{
263-
auto addr = cast(size_t) sect.addr;
264-
auto size = cast(size_t) sect.size;
265-
return (cast(ubyte*) addr)[slide .. slide + size];
266-
}
267-
return null;
248+
assert(header.magic == MH_MAGIC_64);
249+
auto sect = getsectbynamefromheader_64(cast(mach_header_64*)header,
250+
segmentName,
251+
sectionName);
268252
}
269253
else
270-
return null;
254+
static assert(0, "unimplemented");
255+
256+
if (sect !is null && sect.size > 0)
257+
return (cast(ubyte*)sect.addr + slide)[0 .. cast(size_t)sect.size];
258+
return null;
271259
}

0 commit comments

Comments
 (0)