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

Unified Diff: sandbox/src/broker_services.cc

Issue 9960045: Add sandbox support for associating peer processes (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sandbox/src/broker_services.h ('k') | sandbox/src/handle_policy_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sandbox/src/broker_services.cc
===================================================================
--- sandbox/src/broker_services.cc (revision 131782)
+++ sandbox/src/broker_services.cc (working copy)
@@ -45,8 +45,26 @@
THREAD_CTRL_LAST
};
-}
+// Helper structure that allows the Broker to associate a job notification
+// with a job object and with a policy.
+struct JobTracker {
+ HANDLE job;
+ sandbox::PolicyBase* policy;
+ JobTracker(HANDLE cjob, sandbox::PolicyBase* cpolicy)
+ : job(cjob), policy(cpolicy) {
+ }
+};
+// Helper structure that allows the broker to track peer processes
+struct PeerTracker {
+ HANDLE wait_object_;
+ base::win::ScopedHandle process_;
+ PeerTracker() : wait_object_(NULL) {
+ }
+};
+
+} // namespace
+
namespace sandbox {
BrokerServicesBase::BrokerServicesBase()
@@ -85,6 +103,16 @@
// If there is no port Init() was never called successfully.
if (!job_port_)
return;
+
+ { // Cancel the wait events for all the peers.
+ AutoLock lock(&lock_);
+ for (PeerTrackerMap::iterator it = peer_map_.begin();
+ it != peer_map_.end(); ++it) {
+ ::UnregisterWaitEx(it->second->wait_object_, NULL);
+ delete it->second;
+ }
+ }
cpu_(ooo_6.6-7.5) 2012/04/12 02:17:52 sounds like you want peer_map.clear() after 113 so
jschuh 2012/04/12 03:04:23 Oops. Looks like I accidentally dropped the "erase
+
// Closing the port causes, that no more Job notifications are delivered to
// the worker thread and also causes the thread to exit. This is what we
// want to do since we are going to close all outstanding Jobs and notifying
@@ -312,7 +340,50 @@
bool BrokerServicesBase::IsActiveTarget(DWORD process_id) {
AutoLock lock(&lock_);
- return child_process_ids_.find(process_id) != child_process_ids_.end();
+ return child_process_ids_.find(process_id) != child_process_ids_.end() ||
+ peer_map_.find(process_id) != peer_map_.end();
}
+VOID CALLBACK BrokerServicesBase::RemovePeerData(PVOID parameter, BOOLEAN) {
+ DWORD process_id = reinterpret_cast<DWORD>(parameter);
+ BrokerServicesBase* broker = BrokerServicesBase::GetInstance();
+
+ AutoLock lock(&broker->lock_);
+ PeerTrackerMap::iterator it = broker->peer_map_.find(process_id);
+ // Failure means we're shutting down, and the destructor will clean up.
+ if (::UnregisterWaitEx(it->second->wait_object_, NULL)) {
+ broker->peer_map_.erase(it);
+ delete it->second;
+ }
+}
+
+ResultCode BrokerServicesBase::AddTargetPeer(HANDLE peer_process) {
+ DWORD process_id = ::GetProcessId(peer_process);
+ if (!process_id)
+ return SBOX_ERROR_GENERIC;
+
+ scoped_ptr<PeerTracker> peer(new PeerTracker);
+ if (!::DuplicateHandle(::GetCurrentProcess(), peer_process,
+ ::GetCurrentProcess(), peer->process_.Receive(),
+ SYNCHRONIZE, FALSE, 0)) {
+ return SBOX_ERROR_GENERIC;
+ }
+
+ AutoLock lock(&lock_);
+ if (!peer_map_.insert(std::make_pair(process_id, peer.get())).second)
+ return SBOX_ERROR_BAD_PARAMS;
+
+ if (!::RegisterWaitForSingleObject(&peer->wait_object_,
+ peer->process_, RemovePeerData,
+ reinterpret_cast<void*>(process_id),
+ INFINITE, WT_EXECUTEONLYONCE)) {
+ peer_map_.erase(process_id);
+ return SBOX_ERROR_GENERIC;
+ }
+
+ // Leak the pointer since it will be cleaned up by the callback.
+ peer.release();
+ return SBOX_ALL_OK;
+}
+
} // namespace sandbox
« no previous file with comments | « sandbox/src/broker_services.h ('k') | sandbox/src/handle_policy_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698