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

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

Issue 113190: Add support for alternate window station. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 #include "sandbox/src/target_process.h" 5 #include "sandbox/src/target_process.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "sandbox/src/crosscall_server.h" 9 #include "sandbox/src/crosscall_server.h"
10 #include "sandbox/src/crosscall_client.h" 10 #include "sandbox/src/crosscall_client.h"
11 #include "sandbox/src/pe_image.h" 11 #include "sandbox/src/pe_image.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 : lockdown_token_(lockdown_token), 76 : lockdown_token_(lockdown_token),
77 initial_token_(initial_token), 77 initial_token_(initial_token),
78 job_(job), 78 job_(job),
79 shared_section_(NULL), 79 shared_section_(NULL),
80 ipc_server_(NULL), 80 ipc_server_(NULL),
81 thread_pool_(thread_pool), 81 thread_pool_(thread_pool),
82 base_address_(NULL), 82 base_address_(NULL),
83 exe_name_(NULL), 83 exe_name_(NULL),
84 sandbox_process_(NULL), 84 sandbox_process_(NULL),
85 sandbox_thread_(NULL), 85 sandbox_thread_(NULL),
86 desktop_handle_(NULL),
87 sandbox_process_id_(0) { 86 sandbox_process_id_(0) {
88 } 87 }
89 88
90 TargetProcess::~TargetProcess() { 89 TargetProcess::~TargetProcess() {
91 DWORD exit_code = 0; 90 DWORD exit_code = 0;
92 // Give a chance to the process to die. In most cases the JOB_KILL_ON_CLOSE 91 // Give a chance to the process to die. In most cases the JOB_KILL_ON_CLOSE
93 // will take effect only when the context changes. As far as the testing went, 92 // will take effect only when the context changes. As far as the testing went,
94 // this wait was enough to switch context and kill the processes in the job. 93 // this wait was enough to switch context and kill the processes in the job.
95 // If this process is already dead, the function will return without waiting. 94 // If this process is already dead, the function will return without waiting.
96 // TODO(nsylvain): If the process is still alive at the end, we should kill 95 // TODO(nsylvain): If the process is still alive at the end, we should kill
97 // it. http://b/893891 96 // it. http://b/893891
98 // For now, this wait is there only to do a best effort to prevent some leaks 97 // For now, this wait is there only to do a best effort to prevent some leaks
99 // from showing up in purify. 98 // from showing up in purify.
100 ::WaitForSingleObject(sandbox_process_, 50); 99 ::WaitForSingleObject(sandbox_process_, 50);
101 if (!::GetExitCodeProcess(sandbox_process_, &exit_code) || 100 if (!::GetExitCodeProcess(sandbox_process_, &exit_code) ||
102 (STILL_ACTIVE == exit_code)) { 101 (STILL_ACTIVE == exit_code)) {
103 // It is an error to destroy this object while the target process is still 102 // It is an error to destroy this object while the target process is still
104 // alive because we need to destroy the IPC subsystem and cannot risk to 103 // alive because we need to destroy the IPC subsystem and cannot risk to
105 // have an IPC reach us after this point. 104 // have an IPC reach us after this point.
106 return; 105 return;
107 } 106 }
108 107
109 delete ipc_server_; 108 delete ipc_server_;
110 109
111 ::CloseHandle(lockdown_token_); 110 ::CloseHandle(lockdown_token_);
112 ::CloseHandle(initial_token_); 111 ::CloseHandle(initial_token_);
113 ::CloseHandle(sandbox_process_); 112 ::CloseHandle(sandbox_process_);
114 if (shared_section_) 113 if (shared_section_)
115 ::CloseHandle(shared_section_); 114 ::CloseHandle(shared_section_);
116 if (desktop_handle_)
117 ::CloseDesktop(desktop_handle_);
118 free(exe_name_); 115 free(exe_name_);
119 } 116 }
120 117
121 // Creates the target (child) process suspended and assigns it to the job 118 // Creates the target (child) process suspended and assigns it to the job
122 // object. 119 // object.
123 DWORD TargetProcess::Create(const wchar_t* exe_path, 120 DWORD TargetProcess::Create(const wchar_t* exe_path,
124 const wchar_t* command_line, 121 const wchar_t* command_line,
125 const wchar_t* desktop, 122 const wchar_t* desktop,
126 PROCESS_INFORMATION* target_info) { 123 PROCESS_INFORMATION* target_info) {
127 exe_name_ = _wcsdup(exe_path); 124 exe_name_ = _wcsdup(exe_path);
128 125
129 // the command line needs to be writable by CreateProcess(). 126 // the command line needs to be writable by CreateProcess().
130 scoped_ptr_malloc<wchar_t> cmd_line(_wcsdup(command_line)); 127 scoped_ptr_malloc<wchar_t> cmd_line(_wcsdup(command_line));
131 scoped_ptr_malloc<wchar_t> desktop_name(desktop ? _wcsdup(desktop) : NULL); 128 scoped_ptr_malloc<wchar_t> desktop_name(desktop ? _wcsdup(desktop) : NULL);
132 129
130 // Start the target process suspended.
133 const DWORD flags = CREATE_SUSPENDED | CREATE_BREAKAWAY_FROM_JOB | 131 const DWORD flags = CREATE_SUSPENDED | CREATE_BREAKAWAY_FROM_JOB |
134 CREATE_UNICODE_ENVIRONMENT | DETACHED_PROCESS; 132 CREATE_UNICODE_ENVIRONMENT | DETACHED_PROCESS;
135 133
136 // Start the target process suspended
137 STARTUPINFO startup_info = {sizeof(STARTUPINFO)}; 134 STARTUPINFO startup_info = {sizeof(STARTUPINFO)};
138 if (desktop) { 135 if (desktop) {
139 // Ensure that the desktop exists
140 desktop_handle_ = ::CreateDesktop(desktop_name.get(), NULL, NULL, 0,
141 DESKTOP_CREATEWINDOW, NULL);
142 startup_info.lpDesktop = desktop_name.get(); 136 startup_info.lpDesktop = desktop_name.get();
143 } 137 }
144 138
145 PROCESS_INFORMATION process_info = {0}; 139 PROCESS_INFORMATION process_info = {0};
146 140
147 if (!::CreateProcessAsUserW(lockdown_token_, 141 if (!::CreateProcessAsUserW(lockdown_token_,
148 exe_path, 142 exe_path,
149 cmd_line.get(), 143 cmd_line.get(),
150 NULL, // No security attribute. 144 NULL, // No security attribute.
151 NULL, // No thread attribute. 145 NULL, // No thread attribute.
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 317
324 318
325 TargetProcess* MakeTestTargetProcess(HANDLE process, HMODULE base_address) { 319 TargetProcess* MakeTestTargetProcess(HANDLE process, HMODULE base_address) {
326 TargetProcess* target = new TargetProcess(NULL, NULL, NULL, NULL); 320 TargetProcess* target = new TargetProcess(NULL, NULL, NULL, NULL);
327 target->sandbox_process_ = process; 321 target->sandbox_process_ = process;
328 target->base_address_ = base_address; 322 target->base_address_ = base_address;
329 return target; 323 return target;
330 } 324 }
331 325
332 } // namespace sandbox 326 } // namespace sandbox
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698