Skip to content

Commit

Permalink
Reimplement PalAllocateThunksFromTemplate to work inside shared libra…
Browse files Browse the repository at this point in the history
…ries
  • Loading branch information
filipnavara committed Feb 25, 2023
1 parent a1a6193 commit 49fb9f7
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,12 +503,15 @@ REDHAWK_PALEXPORT UInt32_BOOL REDHAWK_PALAPI PalAllocateThunksFromTemplate(HANDL
{
#ifdef TARGET_APPLE
int f;
char *exepath;
Dl_info info;

int st = dladdr((const void*)hTemplateModule, &info);
if (st == 0)
{
return UInt32_FALSE;
}

// NOTE: We ignore hTemplateModule, it is always the current module
exepath = minipal_getexepath();
f = open(exepath, O_RDONLY);
free(exepath);
f = open(info.dli_fname, O_RDONLY);
if (f < 0)
{
return UInt32_FALSE;
Expand All @@ -519,8 +522,9 @@ REDHAWK_PALEXPORT UInt32_BOOL REDHAWK_PALAPI PalAllocateThunksFromTemplate(HANDL
// executable and determine the size from them.
if (thunks_section == NULL)
{
thunks_section = getsectbyname("__THUNKS", "__thunks");
thunks_data_section = getsectbyname("__THUNKS_DATA", "__thunks");
const struct mach_header_64 *hdr = (const struct mach_header_64 *)hTemplateModule;
thunks_section = getsectbynamefromheader_64(hdr, "__THUNKS", "__thunks");
thunks_data_section = getsectbynamefromheader_64(hdr, "__THUNKS_DATA", "__thunks");
}

*newThunksOut = mmap(
Expand Down

0 comments on commit 49fb9f7

Please sign in to comment.