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