From 344bdeb797b31bb99158010f255a7219fe77e2ec Mon Sep 17 00:00:00 2001 From: =?utf8?q?Martin=20Storsj=C3=B6?= Date: Wed, 16 Oct 2019 11:41:59 +0300 Subject: [PATCH] [LLDB] Avoid using InitializeContext for zero-initializing a CONTEXT. NFC. InitializeContext is useful for allocating a (potentially variable size) CONTEXT struct in an unaligned byte buffer. In this case, we already have a fixed size CONTEXT we want to initialize, and we only used this as a very roundabout way of zero initializing it. Instead just memset the CONTEXT we have, and set the ContextFlags field manually. This matches how it is done in NativeRegisterContextWindows_*.cpp. This also makes LLDB run successfully in Wine (for a trivial tested case at least), as Wine hasn't implemented the InitializeContext function. Differential Revision: https://reviews.llvm.org/D70742 --- .../Plugins/Process/Windows/Common/RegisterContextWindows.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/lldb/source/Plugins/Process/Windows/Common/RegisterContextWindows.cpp b/lldb/source/Plugins/Process/Windows/Common/RegisterContextWindows.cpp index 28e7a59..c3cb455 100644 --- a/lldb/source/Plugins/Process/Windows/Common/RegisterContextWindows.cpp +++ b/lldb/source/Plugins/Process/Windows/Common/RegisterContextWindows.cpp @@ -154,15 +154,8 @@ bool RegisterContextWindows::CacheAllRegisterValues() { return true; TargetThreadWindows &wthread = static_cast(m_thread); - uint8_t buffer[2048]; - memset(buffer, 0, sizeof(buffer)); - PCONTEXT tmpContext = NULL; - DWORD contextLength = (DWORD)sizeof(buffer); - if (!::InitializeContext(buffer, kWinContextFlags, &tmpContext, - &contextLength)) { - return false; - } - memcpy(&m_context, tmpContext, sizeof(m_context)); + memset(&m_context, 0, sizeof(m_context)); + m_context.ContextFlags = kWinContextFlags; if (::SuspendThread( wthread.GetHostThread().GetNativeThread().GetSystemHandle()) == (DWORD)-1) { -- 2.7.4