Revert "Merged all Chromoting Host code into remoting_core.dll (Windows)."
[chromium-blink-merge.git] / sandbox / win / src / target_process.h
blobbe4cd2a0e1c797aee6dced8a060547c82161332d
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.
5 #ifndef SANDBOX_WIN_SRC_TARGET_PROCESS_H_
6 #define SANDBOX_WIN_SRC_TARGET_PROCESS_H_
8 #include <windows.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"
14 #include "sandbox/win/src/crosscall_server.h"
15 #include "sandbox/win/src/sandbox_types.h"
17 namespace base {
18 namespace win {
20 class StartupInformation;
22 }; // namespace win
23 }; // namespace base
25 namespace sandbox {
27 class AttributeList;
28 class SharedMemIPCServer;
29 class ThreadProvider;
31 // TargetProcess models a target instance (child process). Objects of this
32 // class are owned by the Policy used to create them.
33 class TargetProcess {
34 public:
35 // The constructor takes ownership of |initial_token| and |lockdown_token|.
36 TargetProcess(HANDLE initial_token, HANDLE lockdown_token, HANDLE job,
37 ThreadProvider* thread_pool);
38 ~TargetProcess();
40 // TODO(cpu): Currently there does not seem to be a reason to implement
41 // reference counting for this class since is internal, but kept the
42 // the same interface so the interception framework does not need to be
43 // touched at this point.
44 void AddRef() {}
45 void Release() {}
47 // Creates the new target process. The process is created suspended.
48 DWORD Create(const wchar_t* exe_path,
49 const wchar_t* command_line,
50 const base::win::StartupInformation& startup_info,
51 base::win::ScopedProcessInformation* target_info);
53 // Destroys the target process.
54 void Terminate();
56 // Creates the IPC objects such as the BrokerDispatcher and the
57 // IPC server. The IPC server uses the services of the thread_pool.
58 DWORD Init(Dispatcher* ipc_dispatcher, void* policy,
59 uint32 shared_IPC_size, uint32 shared_policy_size);
61 // Returns the handle to the target process.
62 HANDLE Process() const {
63 return sandbox_process_info_.process_handle();
66 // Returns the handle to the job object that the target process belongs to.
67 HANDLE Job() const {
68 return job_;
71 // Returns the address of the target main exe. This is used by the
72 // interceptions framework.
73 HMODULE MainModule() const {
74 return reinterpret_cast<HMODULE>(base_address_);
77 // Returns the name of the executable.
78 const wchar_t* Name() const {
79 return exe_name_.get();
82 // Returns the process id.
83 DWORD ProcessId() const {
84 return sandbox_process_info_.process_id();
87 // Returns the handle to the main thread.
88 HANDLE MainThread() const {
89 return sandbox_process_info_.thread_handle();
92 // Transfers a 32-bit variable between the broker and the target.
93 ResultCode TransferVariable(const char* name, void* address, size_t size);
95 private:
96 // Details of the target process.
97 base::win::ScopedProcessInformation sandbox_process_info_;
98 // The token associated with the process. It provides the core of the
99 // sbox security.
100 base::win::ScopedHandle lockdown_token_;
101 // The token given to the initial thread so that the target process can
102 // start. It has more powers than the lockdown_token.
103 base::win::ScopedHandle initial_token_;
104 // Kernel handle to the shared memory used by the IPC server.
105 base::win::ScopedHandle shared_section_;
106 // Job object containing the target process.
107 HANDLE job_;
108 // Reference to the IPC subsystem.
109 scoped_ptr<SharedMemIPCServer> ipc_server_;
110 // Provides the threads used by the IPC. This class does not own this pointer.
111 ThreadProvider* thread_pool_;
112 // Base address of the main executable
113 void* base_address_;
114 // Full name of the target executable.
115 scoped_ptr_malloc<wchar_t> exe_name_;
117 // Function used for testing.
118 friend TargetProcess* MakeTestTargetProcess(HANDLE process,
119 HMODULE base_address);
121 DISALLOW_IMPLICIT_CONSTRUCTORS(TargetProcess);
124 // Creates a mock TargetProcess used for testing interceptions.
125 // TODO(cpu): It seems that this method is not going to be used anymore.
126 TargetProcess* MakeTestTargetProcess(HANDLE process, HMODULE base_address);
129 } // namespace sandbox
131 #endif // SANDBOX_WIN_SRC_TARGET_PROCESS_H_