Skip to content

Commit a921e71

Browse files
davidwrightontommcdon
authored andcommitted
Reapply "Create a single copy of stub templates (#115749)
* Reapply "Create a single copy of stub templates (#114462)" (#115665) This reverts commit f7fc178. * Disable feature on Apple platforms for now Co-authored-by: Tom McDonald <[email protected]>
1 parent 1433333 commit a921e71

16 files changed

+905
-50
lines changed

src/coreclr/clrdefinitions.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ if (FEATURE_STUBPRECODE_DYNAMIC_HELPERS)
218218
add_definitions(-DFEATURE_STUBPRECODE_DYNAMIC_HELPERS)
219219
endif()
220220

221+
if (CLR_CMAKE_TARGET_APPLE)
222+
# Re-enable when dbgshim containing https://github.com/dotnet/diagnostics/pull/5487 is generally available
223+
# add_definitions(-DFEATURE_MAP_THUNKS_FROM_IMAGE)
224+
endif()
225+
221226
# Use this function to enable building with a specific target OS and architecture set of defines
222227
# This is known to work for the set of defines used by the JIT and gcinfo, it is not likely correct for
223228
# other components of the runtime

src/coreclr/inc/executableallocator.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ class ExecutableAllocator
182182
// Return true if double mapping is enabled.
183183
static bool IsDoubleMappingEnabled();
184184

185+
// Release memory allocated via DoubleMapping for either templates or normal double mapped data
186+
void ReleaseWorker(void* pRX, bool releaseTemplate);
187+
185188
// Initialize the allocator instance
186189
bool Initialize();
187190

@@ -262,6 +265,18 @@ class ExecutableAllocator
262265

263266
// Unmap the RW mapping at the specified address
264267
void UnmapRW(void* pRW);
268+
269+
// Allocate thunks from a template. pTemplate is the return value from CreateTemplate
270+
void* AllocateThunksFromTemplate(void *pTemplate, size_t templateSize);
271+
272+
// Free a set of thunks allocated from templates. pThunks must have been returned from AllocateThunksFromTemplate
273+
void FreeThunksFromTemplate(void *pThunks, size_t templateSize);
274+
275+
// Create a template
276+
// If templateInImage is not null, it will attempt to use it as the template, otherwise it will create an temporary in memory file to serve as the template
277+
// Some OS/Architectures may/may not be able to work with this, so this api is permitted to return NULL, and callers should have an alternate approach using
278+
// the codePageGenerator directly.
279+
void* CreateTemplate(void* templateInImage, size_t templateSize, void (*codePageGenerator)(uint8_t* pageBase, uint8_t* pageBaseRX, size_t size));
265280
};
266281

267282
#define ExecutableWriterHolder ExecutableWriterHolderNoLog

src/coreclr/inc/loaderheap.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -455,10 +455,19 @@ class UnlockedLoaderHeap : public UnlockedLoaderHeapBase
455455
static void WeGotAFaultNowWhat(UnlockedLoaderHeap *pHeap);
456456
};
457457

458+
struct InterleavedLoaderHeapConfig
459+
{
460+
uint32_t StubSize;
461+
void* Template;
462+
void (*CodePageGenerator)(uint8_t* pageBase, uint8_t* pageBaseRX, size_t size);
463+
};
464+
465+
void InitializeLoaderHeapConfig(InterleavedLoaderHeapConfig *pConfig, size_t stubSize, void* templateInImage, void (*codePageGenerator)(uint8_t* pageBase, uint8_t* pageBaseRX, size_t size));
466+
458467
//===============================================================================
459468
// This is the base class for InterleavedLoaderHeap It's used as a simple
460469
// allocator for stubs in a scheme where each stub is a small fixed size, and is paired
461-
// with memory which is GetOSStubPageSize() bytes away. In addition there is an
470+
// with memory which is GetStubCodePageSize() bytes away. In addition there is an
462471
// ability to free is via a "backout" mechanism that is not considered to have good performance.
463472
//
464473
//===============================================================================
@@ -492,16 +501,13 @@ class UnlockedInterleavedLoaderHeap : public UnlockedLoaderHeapBase
492501

493502
InterleavedStubFreeListNode *m_pFreeListHead;
494503

495-
public:
496-
public:
497-
void (*m_codePageGenerator)(BYTE* pageBase, BYTE* pageBaseRX, SIZE_T size);
504+
const InterleavedLoaderHeapConfig *m_pConfig;
498505

499506
#ifndef DACCESS_COMPILE
500507
protected:
501508
UnlockedInterleavedLoaderHeap(
502509
RangeList *pRangeList,
503-
void (*codePageGenerator)(BYTE* pageBase, BYTE* pageBaseRX, SIZE_T size),
504-
DWORD dwGranularity);
510+
const InterleavedLoaderHeapConfig *pConfig);
505511

506512
virtual ~UnlockedInterleavedLoaderHeap();
507513
#endif
@@ -1039,13 +1045,11 @@ class InterleavedLoaderHeap : public UnlockedInterleavedLoaderHeap
10391045
public:
10401046
InterleavedLoaderHeap(RangeList *pRangeList,
10411047
BOOL fUnlocked,
1042-
void (*codePageGenerator)(BYTE* pageBase, BYTE* pageBaseRX, SIZE_T size),
1043-
DWORD dwGranularity
1048+
const InterleavedLoaderHeapConfig *pConfig
10441049
)
10451050
: UnlockedInterleavedLoaderHeap(
10461051
pRangeList,
1047-
codePageGenerator,
1048-
dwGranularity),
1052+
pConfig),
10491053
m_CriticalSection(fUnlocked ? NULL : CreateLoaderHeapLock())
10501054
{
10511055
WRAPPER_NO_CONTRACT;

0 commit comments

Comments
 (0)