OLD | NEW |
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 #ifndef SANDBOX_SRC_BROKER_SERVICES_H__ | 5 #ifndef SANDBOX_SRC_BROKER_SERVICES_H__ |
6 #define SANDBOX_SRC_BROKER_SERVICES_H__ | 6 #define SANDBOX_SRC_BROKER_SERVICES_H__ |
7 | 7 |
8 #include <list> | 8 #include <list> |
| 9 #include <map> |
9 #include <set> | 10 #include <set> |
10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/win/scoped_handle.h" |
11 #include "sandbox/src/crosscall_server.h" | 13 #include "sandbox/src/crosscall_server.h" |
12 #include "sandbox/src/job.h" | 14 #include "sandbox/src/job.h" |
13 #include "sandbox/src/sandbox.h" | 15 #include "sandbox/src/sandbox.h" |
14 #include "sandbox/src/sharedmem_ipc_server.h" | 16 #include "sandbox/src/sharedmem_ipc_server.h" |
15 #include "sandbox/src/win2k_threadpool.h" | 17 #include "sandbox/src/win2k_threadpool.h" |
16 #include "sandbox/src/win_utils.h" | 18 #include "sandbox/src/win_utils.h" |
17 | 19 |
| 20 namespace { |
| 21 |
| 22 struct JobTracker; |
| 23 struct PeerTracker; |
| 24 |
| 25 } // namespace |
| 26 |
18 namespace sandbox { | 27 namespace sandbox { |
19 | 28 |
20 class PolicyBase; | 29 class PolicyBase; |
21 | 30 |
22 // BrokerServicesBase --------------------------------------------------------- | 31 // BrokerServicesBase --------------------------------------------------------- |
23 // Broker implementation version 0 | 32 // Broker implementation version 0 |
24 // | 33 // |
25 // This is an implementation of the interface BrokerServices and | 34 // This is an implementation of the interface BrokerServices and |
26 // of the associated TargetProcess interface. In this implementation | 35 // of the associated TargetProcess interface. In this implementation |
27 // TargetProcess is a friend of BrokerServices where the later manages a | 36 // TargetProcess is a friend of BrokerServices where the later manages a |
(...skipping 10 matching lines...) Expand all Loading... |
38 | 47 |
39 virtual TargetPolicy* CreatePolicy(); | 48 virtual TargetPolicy* CreatePolicy(); |
40 | 49 |
41 virtual ResultCode SpawnTarget(const wchar_t* exe_path, | 50 virtual ResultCode SpawnTarget(const wchar_t* exe_path, |
42 const wchar_t* command_line, | 51 const wchar_t* command_line, |
43 TargetPolicy* policy, | 52 TargetPolicy* policy, |
44 PROCESS_INFORMATION* target); | 53 PROCESS_INFORMATION* target); |
45 | 54 |
46 virtual ResultCode WaitForAllTargets(); | 55 virtual ResultCode WaitForAllTargets(); |
47 | 56 |
| 57 virtual ResultCode AddTargetPeer(HANDLE peer_process); |
| 58 |
48 // Checks if the supplied process ID matches one of the broker's active | 59 // Checks if the supplied process ID matches one of the broker's active |
49 // target processes | 60 // target processes |
50 // Returns: | 61 // Returns: |
51 // true if there is an active target process for this ID, otherwise false. | 62 // true if there is an active target process for this ID, otherwise false. |
52 bool IsActiveTarget(DWORD process_id); | 63 bool IsActiveTarget(DWORD process_id); |
53 | 64 |
54 private: | 65 private: |
55 // Helper structure that allows the Broker to associate a job notification | |
56 // with a job object and with a policy. | |
57 struct JobTracker { | |
58 HANDLE job; | |
59 PolicyBase* policy; | |
60 JobTracker(HANDLE cjob, PolicyBase* cpolicy) | |
61 : job(cjob), policy(cpolicy) { | |
62 } | |
63 }; | |
64 | |
65 // Releases the Job and notifies the associated Policy object to its | 66 // Releases the Job and notifies the associated Policy object to its |
66 // resources as well. | 67 // resources as well. |
67 static void FreeResources(JobTracker* tracker); | 68 static void FreeResources(JobTracker* tracker); |
68 | 69 |
69 // The routine that the worker thread executes. It is in charge of | 70 // The routine that the worker thread executes. It is in charge of |
70 // notifications and cleanup-related tasks. | 71 // notifications and cleanup-related tasks. |
71 static DWORD WINAPI TargetEventsThread(PVOID param); | 72 static DWORD WINAPI TargetEventsThread(PVOID param); |
72 | 73 |
| 74 // Removes a target peer from the process list if it expires. |
| 75 static VOID CALLBACK RemovePeer(PVOID parameter, BOOLEAN); |
| 76 |
73 // The completion port used by the job objects to communicate events to | 77 // The completion port used by the job objects to communicate events to |
74 // the worker thread. | 78 // the worker thread. |
75 HANDLE job_port_; | 79 HANDLE job_port_; |
76 | 80 |
77 // Handle to a manual-reset event that is signaled when the total target | 81 // Handle to a manual-reset event that is signaled when the total target |
78 // process count reaches zero. | 82 // process count reaches zero. |
79 HANDLE no_targets_; | 83 HANDLE no_targets_; |
80 | 84 |
81 // Handle to the worker thread that reacts to job notifications. | 85 // Handle to the worker thread that reacts to job notifications. |
82 HANDLE job_thread_; | 86 HANDLE job_thread_; |
83 | 87 |
84 // Lock used to protect the list of targets from being modified by 2 | 88 // Lock used to protect the list of targets from being modified by 2 |
85 // threads at the same time. | 89 // threads at the same time. |
86 CRITICAL_SECTION lock_; | 90 CRITICAL_SECTION lock_; |
87 | 91 |
88 // provides a pool of threads that are used to wait on the IPC calls. | 92 // provides a pool of threads that are used to wait on the IPC calls. |
89 ThreadProvider* thread_pool_; | 93 ThreadProvider* thread_pool_; |
90 | 94 |
91 // List of the trackers for closing and cleanup purposes. | 95 // List of the trackers for closing and cleanup purposes. |
92 typedef std::list<JobTracker*> JobTrackerList; | 96 typedef std::list<JobTracker*> JobTrackerList; |
93 JobTrackerList tracker_list_; | 97 JobTrackerList tracker_list_; |
94 | 98 |
| 99 // Maps peer process IDs to the saved handle and wait event. |
| 100 // Prevents peer callbacks from accessing the broker after destruction. |
| 101 typedef std::map<DWORD, PeerTracker*> PeerTrackerMap; |
| 102 PeerTrackerMap peer_map_; |
| 103 |
95 // Provides a fast lookup to identify sandboxed processes. | 104 // Provides a fast lookup to identify sandboxed processes. |
96 std::set<DWORD> child_process_ids_; | 105 std::set<DWORD> child_process_ids_; |
97 | 106 |
98 DISALLOW_COPY_AND_ASSIGN(BrokerServicesBase); | 107 DISALLOW_COPY_AND_ASSIGN(BrokerServicesBase); |
99 }; | 108 }; |
100 | 109 |
101 } // namespace sandbox | 110 } // namespace sandbox |
102 | 111 |
103 | 112 |
104 #endif // SANDBOX_SRC_BROKER_SERVICES_H__ | 113 #endif // SANDBOX_SRC_BROKER_SERVICES_H__ |
OLD | NEW |