diff options
author | Fadi Hanna <fadim@microsoft.com> | 2016-11-15 22:27:43 +0300 |
---|---|---|
committer | Fadi Hanna <fadim@microsoft.com> | 2016-11-15 22:27:43 +0300 |
commit | 4e29f019e860dfcf8ddfee9b47376f76e51af2ae (patch) | |
tree | 72df3fbd434fe317f65f4f33c23b6c048a226d65 /src/Native/Runtime/RuntimeInstance.cpp | |
parent | 691756f86e4def5c8ca13acd3e0c17011d436857 (diff) |
Thunk pool implementation for CoreRT. In CoreRT, the thunk mappings are allocated dynamically in memory using VirtualAlloc. The thunk stubs pages are marked with RX permissions and the thunks data pages are marked with RW permissions.
Refactored some code in ThunkPool.cs to remove from it any knowledge about the thunk sections layout. Thunks layout and allocation become a black box to ThunkPool.cs. All the section layout information is moved to the native component, and section navigation is done by calls to some APIs.
The dynamically allocated thunks pages are enabled by a FEATURE_RX_THUNKS, and only in CoreRT's Full build for now. The portable build doesn't yet support thunks.
[tfs-changeset: 1638131]
Diffstat (limited to 'src/Native/Runtime/RuntimeInstance.cpp')
-rw-r--r-- | src/Native/Runtime/RuntimeInstance.cpp | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/Native/Runtime/RuntimeInstance.cpp b/src/Native/Runtime/RuntimeInstance.cpp index 2ebcd33da..917deac59 100644 --- a/src/Native/Runtime/RuntimeInstance.cpp +++ b/src/Native/Runtime/RuntimeInstance.cpp @@ -808,13 +808,37 @@ COOP_PINVOKE_HELPER(void *, RhGetGcStaticFieldData, (EEType * pEEType)) return NULL; } -COOP_PINVOKE_HELPER(void *, RhAllocateThunksFromTemplate, (PTR_UInt8 moduleBase, UInt32 templateRva, UInt32 templateSize)) +#ifndef FEATURE_RX_THUNKS + +COOP_PINVOKE_HELPER(void*, RhpGetThunksBase, ()); +COOP_PINVOKE_HELPER(int, RhpGetNumThunkBlocksPerMapping, ()); +EXTERN_C REDHAWK_API void* __cdecl RhAllocateThunksMapping() { + static void* pThunksTemplateAddress = NULL; + + if (pThunksTemplateAddress == NULL) + { + // First, we use the thunks directly from the thunks template sections in the module until all + // thunks in that template are used up. + pThunksTemplateAddress = RhpGetThunksBase(); + return pThunksTemplateAddress; + } + + // We've already used the thunks template in the module for some previous thunks, and we + // cannot reuse it here. Now we need to create a new mapping of the thunks section in order to have + // more thunks + + UInt8* pModuleBase = (UInt8*)PalGetModuleHandleFromPointer(pThunksTemplateAddress); + int templateRva = (int)((UInt8*)RhpGetThunksBase() - pModuleBase); + int templateSize = RhpGetNumThunkBlocksPerMapping() * OS_PAGE_SIZE * 2; + void* pThunkMap = NULL; - if (PalAllocateThunksFromTemplate((HANDLE)moduleBase, templateRva, templateSize, &pThunkMap) == FALSE) + if (PalAllocateThunksFromTemplate((HANDLE)pModuleBase, templateRva, templateSize, &pThunkMap) == FALSE) return NULL; return pThunkMap; } +#endif // FEATURE_RX_THUNKS + #endif |