diff options
author | Adeel Mujahid <adeelbm@outlook.com> | 2017-09-24 06:33:05 +0300 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2017-09-24 06:33:05 +0300 |
commit | aa7549417fac672a7c8dae31ccd4d7ccc46b2dda (patch) | |
tree | 0960867179fb4b12bbbab7fd5d9a7305c87ebc62 /src/Native/Runtime/windows | |
parent | 5705c262df6b6da588e65eb4d7224700e10d9c87 (diff) |
Enable x86 build (#4598)
Diffstat (limited to 'src/Native/Runtime/windows')
4 files changed, 75 insertions, 25 deletions
diff --git a/src/Native/Runtime/windows/CoffNativeCodeManager.cpp b/src/Native/Runtime/windows/CoffNativeCodeManager.cpp index 3abd0b188..d0d8ff81c 100644 --- a/src/Native/Runtime/windows/CoffNativeCodeManager.cpp +++ b/src/Native/Runtime/windows/CoffNativeCodeManager.cpp @@ -29,13 +29,48 @@ #define UBF_FUNC_REVERSE_PINVOKE 0x08 #define UBF_FUNC_HAS_ASSOCIATED_DATA 0x10 -#if defined(_TARGET_AMD64_) +#ifdef _TARGET_X86_ +// +// x86 ABI does not define RUNTIME_FUNCTION. Define our own to allow unification between x86 and other platforms. +// +typedef struct _RUNTIME_FUNCTION { + DWORD BeginAddress; + DWORD EndAddress; + DWORD UnwindData; +} RUNTIME_FUNCTION, *PRUNTIME_FUNCTION; + +typedef struct _KNONVOLATILE_CONTEXT_POINTERS { + + // The ordering of these fields should be aligned with that + // of corresponding fields in CONTEXT + // + // (See REGDISPLAY in Runtime/regdisp.h for details) + PDWORD Edi; + PDWORD Esi; + PDWORD Ebx; + PDWORD Edx; + PDWORD Ecx; + PDWORD Eax; + + PDWORD Ebp; + +} KNONVOLATILE_CONTEXT_POINTERS, *PKNONVOLATILE_CONTEXT_POINTERS; + +typedef struct _UNWIND_INFO { + ULONG FunctionLength; +} UNWIND_INFO, *PUNWIND_INFO; + +#elif defined(_TARGET_AMD64_) + +#define UNW_FLAG_NHANDLER 0x0 +#define UNW_FLAG_EHANDLER 0x1 +#define UNW_FLAG_UHANDLER 0x2 +#define UNW_FLAG_CHAININFO 0x4 // // The following structures are defined in Windows x64 unwind info specification // http://www.bing.com/search?q=msdn+Exception+Handling+x64 // - typedef union _UNWIND_CODE { struct { uint8_t CodeOffset; @@ -46,11 +81,6 @@ typedef union _UNWIND_CODE { uint16_t FrameOffset; } UNWIND_CODE, *PUNWIND_CODE; -#define UNW_FLAG_NHANDLER 0x0 -#define UNW_FLAG_EHANDLER 0x1 -#define UNW_FLAG_UHANDLER 0x2 -#define UNW_FLAG_CHAININFO 0x4 - typedef struct _UNWIND_INFO { uint8_t Version : 3; uint8_t Flags : 5; @@ -61,11 +91,11 @@ typedef struct _UNWIND_INFO { UNWIND_CODE UnwindCode[1]; } UNWIND_INFO, *PUNWIND_INFO; +#endif // _TARGET_X86_ + typedef DPTR(struct _UNWIND_INFO) PTR_UNWIND_INFO; typedef DPTR(union _UNWIND_CODE) PTR_UNWIND_CODE; -#endif // _TARGET_AMD64_ - static PTR_VOID GetUnwindDataBlob(TADDR moduleBase, PTR_RUNTIME_FUNCTION pRuntimeFunction, /* out */ size_t * pSize) { #if defined(_TARGET_AMD64_) @@ -86,6 +116,14 @@ static PTR_VOID GetUnwindDataBlob(TADDR moduleBase, PTR_RUNTIME_FUNCTION pRuntim return pUnwindInfo; +#elif defined(_TARGET_X86_) + + PTR_UNWIND_INFO pUnwindInfo(dac_cast<PTR_UNWIND_INFO>(moduleBase + pRuntimeFunction->UnwindInfoAddress)); + + *pSize = sizeof(UNWIND_INFO); + + return pUnwindInfo; + #elif defined(_TARGET_ARM_) // if this function uses packed unwind data then at least one of the two least significant bits @@ -126,7 +164,9 @@ static PTR_VOID GetUnwindDataBlob(TADDR moduleBase, PTR_RUNTIME_FUNCTION pRuntim *pSize = size; return xdata; #else - #error unexpected target architecture + PORTABILITY_ASSERT("GetUnwindDataBlob"); + *pSize = 0; + return NULL; #endif } @@ -389,18 +429,29 @@ bool CoffNativeCodeManager::UnwindStackFrame(MethodInfo * pMethodInfo, memset(&contextPointers, 0xDD, sizeof(contextPointers)); #endif -#define FOR_EACH_NONVOLATILE_REGISTER(F) \ - F(Rax) F(Rcx) F(Rdx) F(Rbx) F(Rbp) F(Rsi) F(Rdi) F(R8) F(R9) F(R10) F(R11) F(R12) F(R13) F(R14) F(R15) +#ifdef _TARGET_X86_ + #define FOR_EACH_NONVOLATILE_REGISTER(F) \ + F(E, ax) F(E, cx) F(E, dx) F(E, bx) F(E, bp) F(E, si) F(E, di) + #define WORDPTR PDWORD +#else + #define FOR_EACH_NONVOLATILE_REGISTER(F) \ + F(R, ax) F(R, cx) F(R, dx) F(R, bx) F(R, bp) F(R, si) F(R, di) \ + F(R, 8) F(R, 9) F(R, 10) F(R, 11) F(R, 12) F(R, 13) F(R, 14) F(R, 15) + #define WORDPTR PDWORD64 +#endif -#define REGDISPLAY_TO_CONTEXT(reg) \ - contextPointers.reg = (PDWORD64) pRegisterSet->p##reg; \ - if (pRegisterSet->p##reg != NULL) context.reg = *(pRegisterSet->p##reg); +#define REGDISPLAY_TO_CONTEXT(prefix, reg) \ + contextPointers.prefix####reg = (WORDPTR) pRegisterSet->pR##reg; \ + if (pRegisterSet->pR##reg != NULL) context.prefix##reg = *(pRegisterSet->pR##reg); -#define CONTEXT_TO_REGDISPLAY(reg) \ - pRegisterSet->p##reg = (PTR_UIntNative) contextPointers.reg; +#define CONTEXT_TO_REGDISPLAY(prefix, reg) \ + pRegisterSet->pR##reg = (PTR_UIntNative) contextPointers.prefix####reg; FOR_EACH_NONVOLATILE_REGISTER(REGDISPLAY_TO_CONTEXT); +#ifdef _TARGET_X86_ + PORTABILITY_ASSERT("CoffNativeCodeManager::UnwindStackFrame"); +#else // _TARGET_X86_ memcpy(&context.Xmm6, pRegisterSet->Xmm, sizeof(pRegisterSet->Xmm)); context.Rsp = pRegisterSet->SP; @@ -424,6 +475,7 @@ bool CoffNativeCodeManager::UnwindStackFrame(MethodInfo * pMethodInfo, pRegisterSet->pIP = PTR_PCODE(pRegisterSet->SP - sizeof(TADDR)); memcpy(pRegisterSet->Xmm, &context.Xmm6, sizeof(pRegisterSet->Xmm)); +#endif // _TARGET_X86_ FOR_EACH_NONVOLATILE_REGISTER(CONTEXT_TO_REGDISPLAY); diff --git a/src/Native/Runtime/windows/CoffNativeCodeManager.h b/src/Native/Runtime/windows/CoffNativeCodeManager.h index b0d5390a4..31261614d 100644 --- a/src/Native/Runtime/windows/CoffNativeCodeManager.h +++ b/src/Native/Runtime/windows/CoffNativeCodeManager.h @@ -4,7 +4,7 @@ #pragma once -#if defined(_TARGET_AMD64_) +#if defined(_TARGET_AMD64_) || defined(_TARGET_X86_) struct T_RUNTIME_FUNCTION { uint32_t BeginAddress; uint32_t EndAddress; diff --git a/src/Native/Runtime/windows/PalRedhawkCommon.cpp b/src/Native/Runtime/windows/PalRedhawkCommon.cpp index 77375ee9f..7618b24c0 100644 --- a/src/Native/Runtime/windows/PalRedhawkCommon.cpp +++ b/src/Native/Runtime/windows/PalRedhawkCommon.cpp @@ -222,7 +222,7 @@ REDHAWK_PALEXPORT void REDHAWK_PALAPI PalGetPDBInfo(HANDLE hOsHandle, _Out_ GUID } } -REDHAWK_PALEXPORT Int32 PalGetProcessCpuCount() +REDHAWK_PALEXPORT Int32 REDHAWK_PALAPI PalGetProcessCpuCount() { static int CpuCount = 0; @@ -246,7 +246,7 @@ REDHAWK_PALEXPORT Int32 PalGetProcessCpuCount() //Reads the entire contents of the file into the specified buffer, buff //returns the number of bytes read if the file is successfully read //returns 0 if the file is not found, size is greater than maxBytesToRead or the file couldn't be opened or read -REDHAWK_PALEXPORT UInt32 PalReadFileContents(_In_z_ const TCHAR* fileName, _Out_writes_all_(maxBytesToRead) char* buff, _In_ UInt32 maxBytesToRead) +REDHAWK_PALEXPORT UInt32 REDHAWK_PALAPI PalReadFileContents(_In_z_ const TCHAR* fileName, _Out_writes_all_(maxBytesToRead) char* buff, _In_ UInt32 maxBytesToRead) { WIN32_FILE_ATTRIBUTE_DATA attrData; @@ -282,7 +282,7 @@ REDHAWK_PALEXPORT UInt32 PalReadFileContents(_In_z_ const TCHAR* fileName, _Out_ // Retrieves the entire range of memory dedicated to the calling thread's stack. This does // not get the current dynamic bounds of the stack, which can be significantly smaller than // the maximum bounds. -REDHAWK_PALEXPORT bool PalGetMaximumStackBounds(_Out_ void** ppStackLowOut, _Out_ void** ppStackHighOut) +REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalGetMaximumStackBounds(_Out_ void** ppStackLowOut, _Out_ void** ppStackHighOut) { // VirtualQuery on the address of a local variable to get the allocation // base of the stack. Then use the StackBase field in the TEB to give diff --git a/src/Native/Runtime/windows/PalRedhawkMinWin.cpp b/src/Native/Runtime/windows/PalRedhawkMinWin.cpp index 80351f820..99d5a0315 100644 --- a/src/Native/Runtime/windows/PalRedhawkMinWin.cpp +++ b/src/Native/Runtime/windows/PalRedhawkMinWin.cpp @@ -112,7 +112,7 @@ REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalHasCapability(PalCapability capability) // or if the thread was already registered with a different fiber. // Parameters: // thread - thread to attach -extern "C" void PalAttachThread(void* thread) +REDHAWK_PALEXPORT void REDHAWK_PALAPI PalAttachThread(void* thread) { void* threadFromCurrentFiber = FlsGetValue(g_flsIndex); @@ -134,7 +134,7 @@ extern "C" void PalAttachThread(void* thread) // thread - thread to detach // Return: // true if the thread was detached, false if there was no attached thread -extern "C" bool PalDetachThread(void* thread) +REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalDetachThread(void* thread) { ASSERT(g_flsIndex != FLS_OUT_OF_INDEXES); void* threadFromCurrentFiber = FlsGetValue(g_flsIndex); @@ -189,8 +189,6 @@ extern "C" UInt64 PalGetCurrentThreadIdForLogging() } \ WHILE_0; -extern "C" int __stdcall PalGetModuleFileName(_Out_ const TCHAR** pModuleNameOut, HANDLE moduleBase); - REDHAWK_PALEXPORT UInt32_BOOL REDHAWK_PALAPI PalAllocateThunksFromTemplate(_In_ HANDLE hTemplateModule, UInt32 templateRva, size_t templateSize, _Outptr_result_bytebuffer_(templateSize) void** newThunksOut) { #ifdef XBOX_ONE |