Skip to content
Permalink
Browse files
HHVM Debugger: Add memory barriers to extension
Summary: Current access to m_enabled and s_debugger is not thread-safe since threads can actually still be running after the extension registry calls moduleShutdown on the extension.

Reviewed By: velocityboy

Differential Revision: D13972853

fbshipit-source-id: 2c65095d41c1d35a3dd6c064289d6df3adb09e58
  • Loading branch information
ebluestein authored and hhvm-bot committed Feb 6, 2019
1 parent 55342a0 commit 204d6cf3b4367f743249ebedf80b72373d809d35
Showing with 8 additions and 1 deletion.
  1. +8 −1 hphp/runtime/ext/vsdebug/ext_vsdebug.cpp
@@ -22,10 +22,13 @@ namespace HPHP {
namespace VSDEBUG {

VSDebugExtension::~VSDebugExtension() {
std::atomic_thread_fence(std::memory_order_acquire);
if (s_debugger != nullptr) {
delete s_debugger;
s_debugger = nullptr;
}

std::atomic_thread_fence(std::memory_order_release);
}

void VSDebugExtension::moduleLoad(const IniSetting::Map& ini, const Hdf hdf) {
@@ -146,12 +149,14 @@ void VSDebugExtension::moduleInit() {
}

void VSDebugExtension::moduleShutdown() {
std::atomic_thread_fence(std::memory_order_acquire);
if (s_debugger != nullptr) {
delete s_debugger;
s_debugger = nullptr;
}

VSDebugLogger::FinalizeLogging();
std::atomic_thread_fence(std::memory_order_release);
}

void VSDebugExtension::requestInit() {
@@ -188,7 +193,9 @@ void VSDebugExtension::requestInit() {
}

void VSDebugExtension::requestShutdown() {
if (!m_enabled) {
// Barrier for m_enabled and s_debugger
std::atomic_thread_fence(std::memory_order_acquire);
if (!m_enabled || s_debugger == nullptr) {
return;
}

0 comments on commit 204d6cf

Please sign in to comment.