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 |
18 namespace sandbox { | 20 namespace sandbox { |
19 | 21 |
20 class PolicyBase; | 22 class PolicyBase; |
(...skipping 17 matching lines...) Expand all Loading... | |
38 | 40 |
39 virtual TargetPolicy* CreatePolicy(); | 41 virtual TargetPolicy* CreatePolicy(); |
40 | 42 |
41 virtual ResultCode SpawnTarget(const wchar_t* exe_path, | 43 virtual ResultCode SpawnTarget(const wchar_t* exe_path, |
42 const wchar_t* command_line, | 44 const wchar_t* command_line, |
43 TargetPolicy* policy, | 45 TargetPolicy* policy, |
44 PROCESS_INFORMATION* target); | 46 PROCESS_INFORMATION* target); |
45 | 47 |
46 virtual ResultCode WaitForAllTargets(); | 48 virtual ResultCode WaitForAllTargets(); |
47 | 49 |
50 virtual ResultCode AddTargetPeer(HANDLE peer_process); | |
51 | |
48 // Checks if the supplied process ID matches one of the broker's active | 52 // Checks if the supplied process ID matches one of the broker's active |
49 // target processes | 53 // target processes |
50 // Returns: | 54 // Returns: |
51 // true if there is an active target process for this ID, otherwise false. | 55 // true if there is an active target process for this ID, otherwise false. |
52 bool IsActiveTarget(DWORD process_id); | 56 bool IsActiveTarget(DWORD process_id); |
53 | 57 |
54 private: | 58 private: |
55 // Helper structure that allows the Broker to associate a job notification | 59 // Helper structure that allows the Broker to associate a job notification |
56 // with a job object and with a policy. | 60 // with a job object and with a policy. |
57 struct JobTracker { | 61 struct JobTracker { |
58 HANDLE job; | 62 HANDLE job; |
59 PolicyBase* policy; | 63 PolicyBase* policy; |
60 JobTracker(HANDLE cjob, PolicyBase* cpolicy) | 64 JobTracker(HANDLE cjob, PolicyBase* cpolicy) |
61 : job(cjob), policy(cpolicy) { | 65 : job(cjob), policy(cpolicy) { |
62 } | 66 } |
63 }; | 67 }; |
64 | 68 |
69 // Helper structure that allows the broker to track peer processes | |
70 typedef struct PeerTracker { | |
cpu_(ooo_6.6-7.5)
2012/04/10 22:00:14
please add a fwd decl here are move PeerTracker de
| |
71 HANDLE wait_object_; | |
72 base::win::ScopedHandle process_; | |
73 PeerTracker() : wait_object_(NULL) { | |
74 } | |
75 }; | |
76 | |
65 // Releases the Job and notifies the associated Policy object to its | 77 // Releases the Job and notifies the associated Policy object to its |
66 // resources as well. | 78 // resources as well. |
67 static void FreeResources(JobTracker* tracker); | 79 static void FreeResources(JobTracker* tracker); |
68 | 80 |
69 // The routine that the worker thread executes. It is in charge of | 81 // The routine that the worker thread executes. It is in charge of |
70 // notifications and cleanup-related tasks. | 82 // notifications and cleanup-related tasks. |
71 static DWORD WINAPI TargetEventsThread(PVOID param); | 83 static DWORD WINAPI TargetEventsThread(PVOID param); |
72 | 84 |
85 // Removes a target peer from the process list if it expires. | |
86 static VOID CALLBACK RemovePeerData(PVOID parameter, BOOLEAN); | |
87 | |
73 // The completion port used by the job objects to communicate events to | 88 // The completion port used by the job objects to communicate events to |
74 // the worker thread. | 89 // the worker thread. |
75 HANDLE job_port_; | 90 HANDLE job_port_; |
76 | 91 |
77 // Handle to a manual-reset event that is signaled when the total target | 92 // Handle to a manual-reset event that is signaled when the total target |
78 // process count reaches zero. | 93 // process count reaches zero. |
79 HANDLE no_targets_; | 94 HANDLE no_targets_; |
80 | 95 |
81 // Handle to the worker thread that reacts to job notifications. | 96 // Handle to the worker thread that reacts to job notifications. |
82 HANDLE job_thread_; | 97 HANDLE job_thread_; |
83 | 98 |
84 // Lock used to protect the list of targets from being modified by 2 | 99 // Lock used to protect the list of targets from being modified by 2 |
85 // threads at the same time. | 100 // threads at the same time. |
86 CRITICAL_SECTION lock_; | 101 CRITICAL_SECTION lock_; |
87 | 102 |
88 // provides a pool of threads that are used to wait on the IPC calls. | 103 // provides a pool of threads that are used to wait on the IPC calls. |
89 ThreadProvider* thread_pool_; | 104 ThreadProvider* thread_pool_; |
90 | 105 |
91 // List of the trackers for closing and cleanup purposes. | 106 // List of the trackers for closing and cleanup purposes. |
92 typedef std::list<JobTracker*> JobTrackerList; | 107 typedef std::list<JobTracker*> JobTrackerList; |
93 JobTrackerList tracker_list_; | 108 JobTrackerList tracker_list_; |
94 | 109 |
110 // Maps peer process IDs to the saved handle and wait event. | |
111 // Prevents peer callbacks from accessing the broker after destruction. | |
112 typedef std::map<DWORD, PeerTracker*> PeerTrackerMap; | |
113 PeerTrackerMap peer_map_; | |
114 | |
95 // Provides a fast lookup to identify sandboxed processes. | 115 // Provides a fast lookup to identify sandboxed processes. |
96 std::set<DWORD> child_process_ids_; | 116 std::set<DWORD> child_process_ids_; |
97 | 117 |
98 DISALLOW_COPY_AND_ASSIGN(BrokerServicesBase); | 118 DISALLOW_COPY_AND_ASSIGN(BrokerServicesBase); |
99 }; | 119 }; |
100 | 120 |
101 } // namespace sandbox | 121 } // namespace sandbox |
102 | 122 |
103 | 123 |
104 #endif // SANDBOX_SRC_BROKER_SERVICES_H__ | 124 #endif // SANDBOX_SRC_BROKER_SERVICES_H__ |
OLD | NEW |