Commit 1986ad6c authored by cpu@chromium.org's avatar cpu@chromium.org

fix excesive number of mutexes created by sandbox

The |cient_control->server_alive| mutex was being created for each
target (child) process and leaked (that part is necessary). Instead
a single mutex can be reused for all targets.

R=rvargas
BUG=331241

Review URL: https://codereview.chromium.org/167593003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@252782 0039d316-1c4b-4281-b951-d872f2087c98
parent d6f8de19
......@@ -12,6 +12,11 @@
#include "sandbox/win/src/crosscall_params.h"
#include "sandbox/win/src/crosscall_server.h"
namespace {
// This handle must not be closed.
volatile HANDLE g_alive_mutex = NULL;
}
namespace sandbox {
SharedMemIPCServer::SharedMemIPCServer(HANDLE target_process,
......@@ -25,6 +30,19 @@ SharedMemIPCServer::SharedMemIPCServer(HANDLE target_process,
target_process_id_(target_process_id),
target_job_object_(target_job),
call_dispatcher_(dispatcher) {
// We create a initially owned mutex. If the server dies unexpectedly,
// the thread that owns it will fail to release the lock and windows will
// report to the target (when it tries to acquire it) that the wait was
// abandoned. Note: We purposely leak the local handle because we want it to
// be closed by Windows itself so it is properly marked as abandoned if the
// server dies.
if (!g_alive_mutex) {
HANDLE mutex = ::CreateMutexW(NULL, TRUE, NULL);
if (::InterlockedCompareExchangePointer(&g_alive_mutex, mutex, NULL)) {
// We lost the race to create the mutex.
::CloseHandle(mutex);
}
}
}
SharedMemIPCServer::~SharedMemIPCServer() {
......@@ -108,15 +126,7 @@ bool SharedMemIPCServer::Init(void* shared_mem, uint32 shared_size,
thread_provider_->RegisterWait(this, service_context->ping_event,
ThreadPingEventReady, service_context);
}
// We create a mutex that the server locks. If the server dies unexpectedly,
// the thread that owns it will fail to release the lock and windows will
// report to the target (when it tries to acquire it) that the wait was
// abandoned. Note: We purposely leak the local handle because we want it to
// be closed by Windows itself so it is properly marked as abandoned if the
// server dies.
if (!::DuplicateHandle(::GetCurrentProcess(),
::CreateMutexW(NULL, TRUE, NULL),
if (!::DuplicateHandle(::GetCurrentProcess(), g_alive_mutex,
target_process_, &client_control_->server_alive,
SYNCHRONIZE | EVENT_MODIFY_STATE, FALSE, 0)) {
return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment