Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: sandbox/win/src/sharedmem_ipc_server.cc

Issue 1231673002: Sandbox: remove raw handles from SharedMemIPCServer::ServerControl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sandbox/win/src/sharedmem_ipc_server.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/callback.h" 5 #include "base/callback.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/stl_util.h"
8 #include "sandbox/win/src/sharedmem_ipc_server.h" 9 #include "sandbox/win/src/sharedmem_ipc_server.h"
9 #include "sandbox/win/src/sharedmem_ipc_client.h" 10 #include "sandbox/win/src/sharedmem_ipc_client.h"
10 #include "sandbox/win/src/sandbox.h" 11 #include "sandbox/win/src/sandbox.h"
11 #include "sandbox/win/src/sandbox_types.h" 12 #include "sandbox/win/src/sandbox_types.h"
12 #include "sandbox/win/src/crosscall_params.h" 13 #include "sandbox/win/src/crosscall_params.h"
13 #include "sandbox/win/src/crosscall_server.h" 14 #include "sandbox/win/src/crosscall_server.h"
14 15
15 namespace { 16 namespace {
16 // This handle must not be closed. 17 // This handle must not be closed.
17 volatile HANDLE g_alive_mutex = NULL; 18 volatile HANDLE g_alive_mutex = NULL;
(...skipping 26 matching lines...) Expand all
44 } 45 }
45 } 46 }
46 } 47 }
47 48
48 SharedMemIPCServer::~SharedMemIPCServer() { 49 SharedMemIPCServer::~SharedMemIPCServer() {
49 // Free the wait handles associated with the thread pool. 50 // Free the wait handles associated with the thread pool.
50 if (!thread_provider_->UnRegisterWaits(this)) { 51 if (!thread_provider_->UnRegisterWaits(this)) {
51 // Better to leak than to crash. 52 // Better to leak than to crash.
52 return; 53 return;
53 } 54 }
54 // Free the IPC signal events. 55 STLDeleteElements(&server_contexts_);
55 ServerContexts::iterator it;
56 for (it = server_contexts_.begin(); it != server_contexts_.end(); ++it) {
57 ServerControl* context = (*it);
58 ::CloseHandle(context->ping_event);
59 ::CloseHandle(context->pong_event);
60 delete context;
61 }
62 56
63 if (client_control_) 57 if (client_control_)
64 ::UnmapViewOfFile(client_control_); 58 ::UnmapViewOfFile(client_control_);
65 } 59 }
66 60
67 bool SharedMemIPCServer::Init(void* shared_mem, uint32 shared_size, 61 bool SharedMemIPCServer::Init(void* shared_mem, uint32 shared_size,
68 uint32 channel_size) { 62 uint32 channel_size) {
69 // The shared memory needs to be at least as big as a channel. 63 // The shared memory needs to be at least as big as a channel.
70 if (shared_size < channel_size) { 64 if (shared_size < channel_size) {
71 return false; 65 return false;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 service_context->channel = client_context; 113 service_context->channel = client_context;
120 service_context->channel_buffer = service_context->shared_base + 114 service_context->channel_buffer = service_context->shared_base +
121 client_context->channel_base; 115 client_context->channel_base;
122 service_context->dispatcher = call_dispatcher_; 116 service_context->dispatcher = call_dispatcher_;
123 service_context->target_info.process = target_process_; 117 service_context->target_info.process = target_process_;
124 service_context->target_info.process_id = target_process_id_; 118 service_context->target_info.process_id = target_process_id_;
125 service_context->target_info.job_object = target_job_object_; 119 service_context->target_info.job_object = target_job_object_;
126 // Advance to the next channel. 120 // Advance to the next channel.
127 base_start += channel_size; 121 base_start += channel_size;
128 // Register the ping event with the threadpool. 122 // Register the ping event with the threadpool.
129 thread_provider_->RegisterWait(this, service_context->ping_event, 123 thread_provider_->RegisterWait(this, service_context->ping_event.Get(),
130 ThreadPingEventReady, service_context); 124 ThreadPingEventReady, service_context);
131 } 125 }
132 if (!::DuplicateHandle(::GetCurrentProcess(), g_alive_mutex, 126 if (!::DuplicateHandle(::GetCurrentProcess(), g_alive_mutex,
133 target_process_, &client_control_->server_alive, 127 target_process_, &client_control_->server_alive,
134 SYNCHRONIZE | EVENT_MODIFY_STATE, FALSE, 0)) { 128 SYNCHRONIZE | EVENT_MODIFY_STATE, FALSE, 0)) {
135 return false; 129 return false;
136 } 130 }
137 // This last setting indicates to the client all is setup. 131 // This last setting indicates to the client all is setup.
138 client_control_->channels_count = channel_count; 132 client_control_->channels_count = channel_count;
139 return true; 133 return true;
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 CrossCallReturn call_result = {0}; 384 CrossCallReturn call_result = {0};
391 void* buffer = service_context->channel_buffer; 385 void* buffer = service_context->channel_buffer;
392 386
393 InvokeCallback(service_context, buffer, &call_result); 387 InvokeCallback(service_context, buffer, &call_result);
394 388
395 // Copy the answer back into the channel and signal the pong event. This 389 // Copy the answer back into the channel and signal the pong event. This
396 // should wake up the client so he can finish the the ipc cycle. 390 // should wake up the client so he can finish the the ipc cycle.
397 CrossCallParams* call_params = reinterpret_cast<CrossCallParams*>(buffer); 391 CrossCallParams* call_params = reinterpret_cast<CrossCallParams*>(buffer);
398 memcpy(call_params->GetCallReturn(), &call_result, sizeof(call_result)); 392 memcpy(call_params->GetCallReturn(), &call_result, sizeof(call_result));
399 ::InterlockedExchange(&service_context->channel->state, kAckChannel); 393 ::InterlockedExchange(&service_context->channel->state, kAckChannel);
400 ::SetEvent(service_context->pong_event); 394 ::SetEvent(service_context->pong_event.Get());
401 } 395 }
cpu_(ooo_6.6-7.5) 2015/07/09 16:51:53 maybe check() the return of set event?
rvargas (doing something else) 2015/07/09 18:14:44 I'd prefer to keep this CL strictly as a refactor
402 396
403 bool SharedMemIPCServer::MakeEvents(HANDLE* server_ping, HANDLE* server_pong, 397 bool SharedMemIPCServer::MakeEvents(base::win::ScopedHandle* server_ping,
398 base::win::ScopedHandle* server_pong,
404 HANDLE* client_ping, HANDLE* client_pong) { 399 HANDLE* client_ping, HANDLE* client_pong) {
405 // Note that the IPC client has no right to delete the events. That would 400 // Note that the IPC client has no right to delete the events. That would
406 // cause problems. The server *owns* the events. 401 // cause problems. The server *owns* the events.
407 const DWORD kDesiredAccess = SYNCHRONIZE | EVENT_MODIFY_STATE; 402 const DWORD kDesiredAccess = SYNCHRONIZE | EVENT_MODIFY_STATE;
408 403
409 // The events are auto reset, and start not signaled. 404 // The events are auto reset, and start not signaled.
410 *server_ping = ::CreateEventW(NULL, FALSE, FALSE, NULL); 405 server_ping->Set(::CreateEventW(NULL, FALSE, FALSE, NULL));
411 if (!::DuplicateHandle(::GetCurrentProcess(), *server_ping, target_process_, 406 if (!::DuplicateHandle(::GetCurrentProcess(), server_ping->Get(),
412 client_ping, kDesiredAccess, FALSE, 0)) { 407 target_process_, client_ping, kDesiredAccess, FALSE,
408 0)) {
413 return false; 409 return false;
414 } 410 }
415 *server_pong = ::CreateEventW(NULL, FALSE, FALSE, NULL); 411
416 if (!::DuplicateHandle(::GetCurrentProcess(), *server_pong, target_process_, 412 server_pong->Set(::CreateEventW(NULL, FALSE, FALSE, NULL));
417 client_pong, kDesiredAccess, FALSE, 0)) { 413 if (!::DuplicateHandle(::GetCurrentProcess(), server_pong->Get(),
414 target_process_, client_pong, kDesiredAccess, FALSE,
415 0)) {
418 return false; 416 return false;
419 } 417 }
420 return true; 418 return true;
421 } 419 }
422 420
423 } // namespace sandbox 421 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/win/src/sharedmem_ipc_server.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698