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

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

Issue 1231673005: Sandbox: Update the constructor of TargetProcess to receive ScopedHandles. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « sandbox/win/src/target_process.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "sandbox/win/src/target_process.h" 5 #include "sandbox/win/src/target_process.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/win/pe_image.h" 9 #include "base/win/pe_image.h"
10 #include "base/win/startup_information.h" 10 #include "base/win/startup_information.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 } 58 }
59 PIMAGE_NT_HEADERS nt_header = pe.GetNTHeaders(); 59 PIMAGE_NT_HEADERS nt_header = pe.GetNTHeaders();
60 char* base = reinterpret_cast<char*>(entry_point) - 60 char* base = reinterpret_cast<char*>(entry_point) -
61 nt_header->OptionalHeader.AddressOfEntryPoint; 61 nt_header->OptionalHeader.AddressOfEntryPoint;
62 62
63 ::FreeLibrary(exe); 63 ::FreeLibrary(exe);
64 return base; 64 return base;
65 } 65 }
66 66
67 67
68 TargetProcess::TargetProcess(HANDLE initial_token, HANDLE lockdown_token, 68 TargetProcess::TargetProcess(base::win::ScopedHandle initial_token,
69 base::win::ScopedHandle lockdown_token,
69 HANDLE job, ThreadProvider* thread_pool) 70 HANDLE job, ThreadProvider* thread_pool)
70 // This object owns everything initialized here except thread_pool and 71 // This object owns everything initialized here except thread_pool and
71 // the job_ handle. The Job handle is closed by BrokerServices and results 72 // the job_ handle. The Job handle is closed by BrokerServices and results
72 // eventually in a call to our dtor. 73 // eventually in a call to our dtor.
73 : lockdown_token_(lockdown_token), 74 : lockdown_token_(lockdown_token.Pass()),
74 initial_token_(initial_token), 75 initial_token_(initial_token.Pass()),
75 job_(job), 76 job_(job),
76 thread_pool_(thread_pool), 77 thread_pool_(thread_pool),
77 base_address_(NULL) { 78 base_address_(NULL) {
78 } 79 }
79 80
80 TargetProcess::~TargetProcess() { 81 TargetProcess::~TargetProcess() {
81 DWORD exit_code = 0; 82 DWORD exit_code = 0;
82 // Give a chance to the process to die. In most cases the JOB_KILL_ON_CLOSE 83 // Give a chance to the process to die. In most cases the JOB_KILL_ON_CLOSE
83 // will take effect only when the context changes. As far as the testing went, 84 // will take effect only when the context changes. As far as the testing went,
84 // this wait was enough to switch context and kill the processes in the job. 85 // this wait was enough to switch context and kill the processes in the job.
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 } 368 }
368 369
369 void TargetProcess::Terminate() { 370 void TargetProcess::Terminate() {
370 if (!sandbox_process_info_.IsValid()) 371 if (!sandbox_process_info_.IsValid())
371 return; 372 return;
372 373
373 ::TerminateProcess(sandbox_process_info_.process_handle(), 0); 374 ::TerminateProcess(sandbox_process_info_.process_handle(), 0);
374 } 375 }
375 376
376 TargetProcess* MakeTestTargetProcess(HANDLE process, HMODULE base_address) { 377 TargetProcess* MakeTestTargetProcess(HANDLE process, HMODULE base_address) {
377 TargetProcess* target = new TargetProcess(NULL, NULL, NULL, NULL); 378 TargetProcess* target = new TargetProcess(base::win::ScopedHandle(),
379 base::win::ScopedHandle(),
380 NULL, NULL);
378 PROCESS_INFORMATION process_info = {}; 381 PROCESS_INFORMATION process_info = {};
379 process_info.hProcess = process; 382 process_info.hProcess = process;
380 target->sandbox_process_info_.Set(process_info); 383 target->sandbox_process_info_.Set(process_info);
381 target->base_address_ = base_address; 384 target->base_address_ = base_address;
382 return target; 385 return target;
383 } 386 }
384 387
385 } // namespace sandbox 388 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/win/src/target_process.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698