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

Side by Side Diff: sandbox/src/target_process.h

Issue 9959018: Use ScopedProcessInformation and other RAII types in sandbox. (Closed) Base URL: svn://svn.chromium.org/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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_TARGET_PROCESS_H__ 5 #ifndef SANDBOX_SRC_TARGET_PROCESS_H__
6 #define SANDBOX_SRC_TARGET_PROCESS_H__ 6 #define SANDBOX_SRC_TARGET_PROCESS_H__
7 7
8 #include <windows.h> 8 #include <windows.h>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/win/scoped_handle.h"
13 #include "base/win/scoped_process_information.h"
11 #include "sandbox/src/crosscall_server.h" 14 #include "sandbox/src/crosscall_server.h"
12 #include "sandbox/src/sandbox_types.h" 15 #include "sandbox/src/sandbox_types.h"
13 16
14 namespace sandbox { 17 namespace sandbox {
15 18
16 class SharedMemIPCServer; 19 class SharedMemIPCServer;
17 class ThreadProvider; 20 class ThreadProvider;
18 21
19 // TargetProcess models a target instance (child process). Objects of this 22 // TargetProcess models a target instance (child process). Objects of this
20 // class are owned by the Policy used to create them. 23 // class are owned by the Policy used to create them.
21 class TargetProcess { 24 class TargetProcess {
22 public: 25 public:
23 // The constructor takes ownership of |initial_token| and |lockdown_token|. 26 // The constructor takes ownership of |initial_token| and |lockdown_token|.
24 TargetProcess(HANDLE initial_token, HANDLE lockdown_token, HANDLE job, 27 TargetProcess(HANDLE initial_token, HANDLE lockdown_token, HANDLE job,
25 ThreadProvider* thread_pool); 28 ThreadProvider* thread_pool);
26 ~TargetProcess(); 29 ~TargetProcess();
27 30
28 // TODO(cpu): Currently there does not seem to be a reason to implement 31 // TODO(cpu): Currently there does not seem to be a reason to implement
29 // reference counting for this class since is internal, but kept the 32 // reference counting for this class since is internal, but kept the
30 // the same interface so the interception framework does not need to be 33 // the same interface so the interception framework does not need to be
31 // touched at this point. 34 // touched at this point.
32 void AddRef() {} 35 void AddRef() {}
33 void Release() {} 36 void Release() {}
34 37
35 // Creates the new target process. The process is created suspended. 38 // Creates the new target process. The process is created suspended.
36 DWORD Create(const wchar_t* exe_path, const wchar_t* command_line, 39 DWORD Create(const wchar_t* exe_path,
37 const wchar_t* desktop, PROCESS_INFORMATION* target_info); 40 const wchar_t* command_line,
41 const wchar_t* desktop,
42 base::win::ScopedProcessInformation* target_info);
38 43
39 // Destroys the target process. 44 // Destroys the target process.
40 void Terminate(); 45 void Terminate();
41 46
42 // Creates the IPC objects such as the BrokerDispatcher and the 47 // Creates the IPC objects such as the BrokerDispatcher and the
43 // IPC server. The IPC server uses the services of the thread_pool. 48 // IPC server. The IPC server uses the services of the thread_pool.
44 DWORD Init(Dispatcher* ipc_dispatcher, void* policy, 49 DWORD Init(Dispatcher* ipc_dispatcher, void* policy,
45 size_t shared_IPC_size, size_t shared_policy_size); 50 size_t shared_IPC_size, size_t shared_policy_size);
46 51
47 // Returns the handle to the target process. 52 // Returns the handle to the target process.
48 HANDLE Process() const { 53 HANDLE Process() const {
49 return sandbox_process_; 54 return sandbox_process_info_.process_handle();
50 } 55 }
51 56
52 // Returns the handle to the job object that the target process belongs to. 57 // Returns the handle to the job object that the target process belongs to.
53 HANDLE Job() const { 58 HANDLE Job() const {
54 return job_; 59 return job_;
55 } 60 }
56 61
57 // Returns the address of the target main exe. This is used by the 62 // Returns the address of the target main exe. This is used by the
58 // interceptions framework. 63 // interceptions framework.
59 HMODULE MainModule() const { 64 HMODULE MainModule() const {
60 return reinterpret_cast<HMODULE>(base_address_); 65 return reinterpret_cast<HMODULE>(base_address_);
61 } 66 }
62 67
63 // Returns the name of the executable. 68 // Returns the name of the executable.
64 const wchar_t* Name() const { 69 const wchar_t* Name() const {
65 return exe_name_; 70 return exe_name_.get();
66 } 71 }
67 72
68 // Returns the process id. 73 // Returns the process id.
69 DWORD ProcessId() const { 74 DWORD ProcessId() const {
70 return sandbox_process_id_; 75 return sandbox_process_info_.process_id();
71 } 76 }
72 77
73 // Returns the handle to the main thread. 78 // Returns the handle to the main thread.
74 HANDLE MainThread() const { 79 HANDLE MainThread() const {
75 return sandbox_thread_; 80 return sandbox_process_info_.thread_handle();
76 } 81 }
77 82
78 // Transfers a 32-bit variable between the broker and the target. 83 // Transfers a 32-bit variable between the broker and the target.
79 ResultCode TransferVariable(char* name, void* address, size_t size); 84 ResultCode TransferVariable(char* name, void* address, size_t size);
80 85
81 private: 86 private:
82 // The handle to the target process. 87 // Details of the target process.
83 HANDLE sandbox_process_; 88 base::win::ScopedProcessInformation sandbox_process_info_;
84 // The handle to the main thread.
85 HANDLE sandbox_thread_;
86 // The process id of the target process.
87 DWORD sandbox_process_id_;
88 // The token associated with the process. It provides the core of the 89 // The token associated with the process. It provides the core of the
89 // sbox security. 90 // sbox security.
90 HANDLE lockdown_token_; 91 base::win::ScopedHandle lockdown_token_;
91 // The token given to the initial thread so that the target process can 92 // The token given to the initial thread so that the target process can
92 // start. It has more powers than the lockdown_token. 93 // start. It has more powers than the lockdown_token.
93 HANDLE initial_token_; 94 base::win::ScopedHandle initial_token_;
94 // Kernel handle to the shared memory used by the IPC server. 95 // Kernel handle to the shared memory used by the IPC server.
95 HANDLE shared_section_; 96 base::win::ScopedHandle shared_section_;
96 // Job object containing the target process. 97 // Job object containing the target process.
97 HANDLE job_; 98 HANDLE job_;
98 // Reference to the IPC subsystem. 99 // Reference to the IPC subsystem.
99 SharedMemIPCServer* ipc_server_; 100 scoped_ptr<SharedMemIPCServer> ipc_server_;
100 // Provides the threads used by the IPC. This class does not own this pointer. 101 // Provides the threads used by the IPC. This class does not own this pointer.
101 ThreadProvider* thread_pool_; 102 ThreadProvider* thread_pool_;
102 // Base address of the main executable 103 // Base address of the main executable
103 void* base_address_; 104 void* base_address_;
104 // Full name of the target executable. 105 // Full name of the target executable.
105 wchar_t* exe_name_; 106 scoped_ptr_malloc<wchar_t> exe_name_;
106 107
107 // Function used for testing. 108 // Function used for testing.
108 friend TargetProcess* MakeTestTargetProcess(HANDLE process, 109 friend TargetProcess* MakeTestTargetProcess(HANDLE process,
109 HMODULE base_address); 110 HMODULE base_address);
110 111
111 DISALLOW_IMPLICIT_CONSTRUCTORS(TargetProcess); 112 DISALLOW_IMPLICIT_CONSTRUCTORS(TargetProcess);
112 }; 113 };
113 114
114 // Creates a mock TargetProcess used for testing interceptions. 115 // Creates a mock TargetProcess used for testing interceptions.
115 // TODO(cpu): It seems that this method is not going to be used anymore. 116 // TODO(cpu): It seems that this method is not going to be used anymore.
116 TargetProcess* MakeTestTargetProcess(HANDLE process, HMODULE base_address); 117 TargetProcess* MakeTestTargetProcess(HANDLE process, HMODULE base_address);
117 118
118 119
119 } // namespace sandbox 120 } // namespace sandbox
120 121
121 #endif // SANDBOX_SRC_TARGET_PROCESS_H__ 122 #endif // SANDBOX_SRC_TARGET_PROCESS_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698