Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Kotas <jkotas@microsoft.com>2017-12-30 19:54:29 +0300
committerGitHub <noreply@github.com>2017-12-30 19:54:29 +0300
commit2c0a57703a96af79b3c7ac4184c737bbb9a6fc09 (patch)
tree2aa9bb62b4f7ef35665e529518459adc5bb81224
parent0fae9d362f17b25f3201f23f8e3e2922ddc73b12 (diff)
Cleanup ifdefs (#5156)
* Cleanup ifdefs around RhAllocateThunksMapping * Cleanup FEATURE_DYNAMIC_CODE ifdefs around ICodeManager ICodeManager is not specific to dynamic code anymore
-rw-r--r--src/Native/Runtime/RuntimeInstance.cpp62
-rw-r--r--src/Native/Runtime/RuntimeInstance.h5
-rw-r--r--src/Native/Runtime/ThunksMapping.cpp73
-rw-r--r--src/Native/Runtime/portable.cpp5
-rw-r--r--src/Native/Runtime/unix/PalRedhawkUnix.cpp4
-rw-r--r--src/Native/Runtime/windows/PalRedhawkMinWin.cpp31
6 files changed, 70 insertions, 110 deletions
diff --git a/src/Native/Runtime/RuntimeInstance.cpp b/src/Native/Runtime/RuntimeInstance.cpp
index 9bda02075..277e75c13 100644
--- a/src/Native/Runtime/RuntimeInstance.cpp
+++ b/src/Native/Runtime/RuntimeInstance.cpp
@@ -167,16 +167,14 @@ ICodeManager * RuntimeInstance::FindCodeManagerByAddress(PTR_VOID pvAddress)
return pModule;
}
- // TODO: JIT support in DAC
+ // TODO: ICodeManager support in DAC
#ifndef DACCESS_COMPILE
-#ifdef FEATURE_DYNAMIC_CODE
for (CodeManagerEntry * pEntry = m_CodeManagerList.GetHead(); pEntry != NULL; pEntry = pEntry->m_pNext)
{
if (dac_cast<TADDR>(pvAddress) - dac_cast<TADDR>(pEntry->m_pvStartRange) < pEntry->m_cbRange)
return pEntry->m_pCodeManager;
}
#endif
-#endif
return NULL;
}
@@ -395,7 +393,6 @@ void RuntimeInstance::UnregisterModule(Module *pModule)
pModule->Destroy();
}
-#ifdef FEATURE_DYNAMIC_CODE
bool RuntimeInstance::RegisterCodeManager(ICodeManager * pCodeManager, PTR_VOID pvStartRange, UInt32 cbRange)
{
CodeManagerEntry * pEntry = new (nothrow) CodeManagerEntry();
@@ -447,7 +444,6 @@ extern "C" void __stdcall UnregisterCodeManager(ICodeManager * pCodeManager)
{
return GetRuntimeInstance()->UnregisterCodeManager(pCodeManager);
}
-#endif
bool RuntimeInstance::RegisterUnboxingStubs(PTR_VOID pvStartRange, UInt32 cbRange)
{
@@ -918,60 +914,4 @@ COOP_PINVOKE_HELPER(PTR_UInt8, RhGetThreadLocalStorageForDynamicType, (UInt32 uO
return pCurrentThread->AllocateThreadLocalStorageForDynamicType(uOffset, tlsStorageSize, numTlsCells);
}
-#ifndef FEATURE_RX_THUNKS
-
-COOP_PINVOKE_HELPER(void*, RhpGetThunksBase, ());
-COOP_PINVOKE_HELPER(int, RhpGetNumThunkBlocksPerMapping, ());
-COOP_PINVOKE_HELPER(int, RhpGetNumThunksPerBlock, ());
-COOP_PINVOKE_HELPER(int, RhpGetThunkSize, ());
-COOP_PINVOKE_HELPER(int, RhpGetThunkBlockSize, ());
-
-EXTERN_C REDHAWK_API void* __cdecl RhAllocateThunksMapping()
-{
- static void* pThunksTemplateAddress = NULL;
-
- void *pThunkMap = NULL;
-
- int thunkBlocksPerMapping = RhpGetNumThunkBlocksPerMapping();
- int thunkBlockSize = RhpGetThunkBlockSize();
- int templateSize = thunkBlocksPerMapping * thunkBlockSize;
-
- 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();
- pThunkMap = pThunksTemplateAddress;
- }
- else
- {
- // 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);
-
- if (!PalAllocateThunksFromTemplate((HANDLE)pModuleBase, templateRva, templateSize, &pThunkMap))
- return NULL;
- }
-
- if (!PalMarkThunksAsValidCallTargets(
- pThunkMap,
- RhpGetThunkSize(),
- RhpGetNumThunksPerBlock(),
- thunkBlockSize,
- thunkBlocksPerMapping))
- {
- if (pThunkMap != pThunksTemplateAddress)
- PalFreeThunksFromTemplate(pThunkMap);
-
- return NULL;
- }
-
- return pThunkMap;
-}
-
-#endif // FEATURE_RX_THUNKS
-
#endif
diff --git a/src/Native/Runtime/RuntimeInstance.h b/src/Native/Runtime/RuntimeInstance.h
index 1368ba41f..639a3f9a1 100644
--- a/src/Native/Runtime/RuntimeInstance.h
+++ b/src/Native/Runtime/RuntimeInstance.h
@@ -38,7 +38,6 @@ public:
private:
OsModuleList m_OsModuleList;
-#ifdef FEATURE_DYNAMIC_CODE
struct CodeManagerEntry;
typedef DPTR(CodeManagerEntry) PTR_CodeManagerEntry;
@@ -52,7 +51,6 @@ private:
typedef SList<CodeManagerEntry> CodeManagerList;
CodeManagerList m_CodeManagerList;
-#endif
public:
struct TypeManagerEntry
@@ -178,10 +176,9 @@ public:
void EnableConservativeStackReporting();
bool IsConservativeStackReportingEnabled() { return m_conservativeStackReportingEnabled; }
-#ifdef FEATURE_DYNAMIC_CODE
bool RegisterCodeManager(ICodeManager * pCodeManager, PTR_VOID pvStartRange, UInt32 cbRange);
void UnregisterCodeManager(ICodeManager * pCodeManager);
-#endif
+
ICodeManager * FindCodeManagerByAddress(PTR_VOID ControlPC);
bool RegisterTypeManager(TypeManager * pTypeManager);
diff --git a/src/Native/Runtime/ThunksMapping.cpp b/src/Native/Runtime/ThunksMapping.cpp
index 771ccf55f..387b6a706 100644
--- a/src/Native/Runtime/ThunksMapping.cpp
+++ b/src/Native/Runtime/ThunksMapping.cpp
@@ -15,22 +15,14 @@
#ifdef FEATURE_RX_THUNKS
-#if defined(USE_PORTABLE_HELPERS)
-static_assert(false, "Cannot use the portable helpers with FEATURE_RX_THUNKS");
-#endif
-
#ifdef _TARGET_AMD64_
#define THUNK_SIZE 20
#elif _TARGET_X86_
#define THUNK_SIZE 12
#elif _TARGET_ARM_
#define THUNK_SIZE 20
-#elif _TARGET_ARM64_
-//ARM64TODO
-#define THUNK_SIZE 0x8000 // This will cause RhpGetNumThunksPerBlock to return 0 for now
-#elif _TARGET_WASM_
-//WASMTODO
-#define THUNK_SIZE 0x8000 // This will cause RhpGetNumThunksPerBlock to return 0 for now
+#else
+#define THUNK_SIZE (2 * OS_PAGE_SIZE) // This will cause RhpGetNumThunksPerBlock to return 0
#endif
static_assert((THUNK_SIZE % 4) == 0, "Thunk stubs size not aligned correctly. This will cause runtime failures.");
@@ -201,11 +193,6 @@ EXTERN_C REDHAWK_API void* __cdecl RhAllocateThunksMapping()
*((UInt16*)pCurrentThunkAddress) = 0xbf00;
pCurrentThunkAddress += 2;
-#elif _TARGET_ARM64_
- UNREFERENCED_PARAMETER(pCurrentDataAddress);
- UNREFERENCED_PARAMETER(pCurrentThunkAddress);
- /* TODO */ ASSERT_UNCONDITIONALLY("NYI");
-
#else
UNREFERENCED_PARAMETER(pCurrentDataAddress);
UNREFERENCED_PARAMETER(pCurrentThunkAddress);
@@ -223,4 +210,58 @@ EXTERN_C REDHAWK_API void* __cdecl RhAllocateThunksMapping()
return pThunksSection;
}
-#endif // FEATURE_RX_THUNKS
+#else // FEATURE_RX_THUNKS
+
+COOP_PINVOKE_HELPER(void*, RhpGetThunksBase, ());
+COOP_PINVOKE_HELPER(int, RhpGetNumThunkBlocksPerMapping, ());
+COOP_PINVOKE_HELPER(int, RhpGetNumThunksPerBlock, ());
+COOP_PINVOKE_HELPER(int, RhpGetThunkSize, ());
+COOP_PINVOKE_HELPER(int, RhpGetThunkBlockSize, ());
+
+EXTERN_C REDHAWK_API void* __cdecl RhAllocateThunksMapping()
+{
+ static void* pThunksTemplateAddress = NULL;
+
+ void *pThunkMap = NULL;
+
+ int thunkBlocksPerMapping = RhpGetNumThunkBlocksPerMapping();
+ int thunkBlockSize = RhpGetThunkBlockSize();
+ int templateSize = thunkBlocksPerMapping * thunkBlockSize;
+
+ 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();
+ pThunkMap = pThunksTemplateAddress;
+ }
+ else
+ {
+ // 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);
+
+ if (!PalAllocateThunksFromTemplate((HANDLE)pModuleBase, templateRva, templateSize, &pThunkMap))
+ return NULL;
+ }
+
+ if (!PalMarkThunksAsValidCallTargets(
+ pThunkMap,
+ RhpGetThunkSize(),
+ RhpGetNumThunksPerBlock(),
+ thunkBlockSize,
+ thunkBlocksPerMapping))
+ {
+ if (pThunkMap != pThunksTemplateAddress)
+ PalFreeThunksFromTemplate(pThunkMap);
+
+ return NULL;
+ }
+
+ return pThunkMap;
+}
+
+#endif // FEATURE_RX_THUNKS
diff --git a/src/Native/Runtime/portable.cpp b/src/Native/Runtime/portable.cpp
index 336253ae3..fb7231b2d 100644
--- a/src/Native/Runtime/portable.cpp
+++ b/src/Native/Runtime/portable.cpp
@@ -380,6 +380,11 @@ COOP_PINVOKE_HELPER(void, RhpMemoryBarrier, ())
#endif
#if defined(USE_PORTABLE_HELPERS)
+EXTERN_C REDHAWK_API void* __cdecl RhAllocateThunksMapping()
+{
+ return NULL;
+}
+
COOP_PINVOKE_HELPER(void *, RhpGetThunksBase, ())
{
return NULL;
diff --git a/src/Native/Runtime/unix/PalRedhawkUnix.cpp b/src/Native/Runtime/unix/PalRedhawkUnix.cpp
index 942dad75f..6d151657e 100644
--- a/src/Native/Runtime/unix/PalRedhawkUnix.cpp
+++ b/src/Native/Runtime/unix/PalRedhawkUnix.cpp
@@ -544,6 +544,7 @@ REDHAWK_PALEXPORT unsigned int REDHAWK_PALAPI PalGetCurrentProcessorNumber()
#endif //HAVE_SCHED_GETCPU
}
+#if !defined(USE_PORTABLE_HELPERS) && !defined(FEATURE_RX_THUNKS)
REDHAWK_PALEXPORT UInt32_BOOL REDHAWK_PALAPI PalAllocateThunksFromTemplate(HANDLE hTemplateModule, uint32_t templateRva, size_t templateSize, void** newThunksOut)
{
PORTABILITY_ASSERT("UNIXTODO: Implement this function");
@@ -553,9 +554,10 @@ REDHAWK_PALEXPORT UInt32_BOOL REDHAWK_PALAPI PalFreeThunksFromTemplate(void *pBa
{
PORTABILITY_ASSERT("UNIXTODO: Implement this function");
}
+#endif // !USE_PORTABLE_HELPERS && !FEATURE_RX_THUNKS
REDHAWK_PALEXPORT UInt32_BOOL REDHAWK_PALAPI PalMarkThunksAsValidCallTargets(
- void *virtualAddress,
+ void *virtualAddress,
int thunkSize,
int thunksPerBlock,
int thunkBlockSize,
diff --git a/src/Native/Runtime/windows/PalRedhawkMinWin.cpp b/src/Native/Runtime/windows/PalRedhawkMinWin.cpp
index 209b5c0b9..366afce8f 100644
--- a/src/Native/Runtime/windows/PalRedhawkMinWin.cpp
+++ b/src/Native/Runtime/windows/PalRedhawkMinWin.cpp
@@ -162,33 +162,7 @@ extern "C" UInt64 PalGetCurrentThreadIdForLogging()
return GetCurrentThreadId();
}
-#define SUPPRESS_WARNING_4127 \
- __pragma(warning(push)) \
- __pragma(warning(disable:4127)) /* conditional expression is constant*/
-
-#define POP_WARNING_STATE \
- __pragma(warning(pop))
-
-#define WHILE_0 \
- SUPPRESS_WARNING_4127 \
- while(0) \
- POP_WARNING_STATE \
-
-#define RETURN_RESULT(success) \
- do \
- { \
- if (success) \
- return S_OK; \
- else \
- { \
- DWORD lasterror = GetLastError(); \
- if (lasterror == 0) \
- return E_FAIL; \
- return HRESULT_FROM_WIN32(lasterror); \
- } \
- } \
- WHILE_0;
-
+#if !defined(USE_PORTABLE_HELPERS) && !defined(FEATURE_RX_THUNKS)
REDHAWK_PALEXPORT UInt32_BOOL REDHAWK_PALAPI PalAllocateThunksFromTemplate(_In_ HANDLE hTemplateModule, UInt32 templateRva, size_t templateSize, _Outptr_result_bytebuffer_(templateSize) void** newThunksOut)
{
#ifdef XBOX_ONE
@@ -228,9 +202,10 @@ REDHAWK_PALEXPORT UInt32_BOOL REDHAWK_PALAPI PalFreeThunksFromTemplate(_In_ void
return UnmapViewOfFile(pBaseAddress);
#endif
}
+#endif // !USE_PORTABLE_HELPERS && !FEATURE_RX_THUNKS
REDHAWK_PALEXPORT UInt32_BOOL REDHAWK_PALAPI PalMarkThunksAsValidCallTargets(
- void *virtualAddress,
+ void *virtualAddress,
int thunkSize,
int thunksPerBlock,
int thunkBlockSize,