[Lldb-commits] [PATCH] Don't use CopyContext in RegisterContextWin
Adrian McCarthy
amccarth at google.com
Wed Feb 11 15:26:47 PST 2015
Hi zturner,
Bug 22410
http://reviews.llvm.org/D7572
Files:
include/lldb/Host/windows/windows.h
source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.cpp
source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.h
Index: include/lldb/Host/windows/windows.h
===================================================================
--- include/lldb/Host/windows/windows.h
+++ include/lldb/Host/windows/windows.h
@@ -19,8 +19,6 @@
#undef GetUserName
#undef LoadImage
#undef CreateProcess
-#undef LoadImage
-#undef GetUserName
#undef far
#undef near
#undef FAR
Index: source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.cpp
===================================================================
--- source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.cpp
+++ source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.cpp
@@ -7,6 +7,8 @@
//
//===----------------------------------------------------------------------===//
+#include <cstdint>
+
#include "lldb/lldb-private-types.h"
#include "lldb/Core/DataBufferHeap.h"
#include "lldb/Core/Error.h"
@@ -232,9 +234,10 @@
if (!InitializeContextDataBuffer(data_sp, &dest_context))
return false;
- // Write the OS's internal CONTEXT structure into the buffer.
- if (!CopyContext(dest_context, kWinContextFlags, m_context_ptr))
- return false;
+ // In the future, we should use CopyContext to safely get XState. Since
+ // we're not using XState at this time, we're doing a straight memcpy to
+ // avoid relying on AVX APIs that aren't available prior to Windows 7 SP1.
+ memcpy(data_sp->GetBytes(), m_context_ptr, sizeof(*m_context_ptr));
return true;
}
@@ -325,16 +328,18 @@
bool
RegisterContextWindows_x86::InitializeContextDataBuffer(DataBufferSP &buffer, CONTEXT **context_ptr)
{
- DWORD length = 0;
- if (!::InitializeContext(nullptr, kWinContextFlags, nullptr, &length) && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
- return false;
+ // In the future, we should use InitializeContext to ensure proper size and
+ // alignment. Since we're not using XState at this time, we're doing a
+ // straight allocation and manually aligning to a 16-byte boundary in order
+ // to avoid relying on AVX APIs that aren't available prior to Windows 7 SP1.
+ const std::size_t kAlignment = 16;
+ buffer.reset(new DataBufferHeap(sizeof(CONTEXT) + kAlignment, 0));
+ std::intptr_t address = reinterpret_cast<std::intptr_t>(buffer->GetBytes());
+ address += kAlignment - (address % kAlignment);
+ *context_ptr = reinterpret_cast<CONTEXT *>(address);
+
+ (*context_ptr)->ContextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER;
- buffer.reset(new DataBufferHeap(length, 0));
- if (!::InitializeContext(buffer->GetBytes(), kWinContextFlags, context_ptr, &length))
- {
- buffer.reset();
- return false;
- }
return true;
}
Index: source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.h
===================================================================
--- source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.h
+++ source/Plugins/Process/Windows/x86/RegisterContextWindows_x86.h
@@ -69,7 +69,7 @@
bool HardwareSingleStep(bool enable) override;
private:
- bool InitializeContextDataBuffer(lldb::DataBufferSP &buffer, CONTEXT **context_ptr);
+ static bool InitializeContextDataBuffer(lldb::DataBufferSP &buffer, CONTEXT **context_ptr);
bool CacheAllRegisterValues();
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7572.19788.patch
Type: text/x-patch
Size: 3275 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150211/4c9866ff/attachment.bin>
More information about the lldb-commits
mailing list