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

Side by Side Diff: base/process_win.cc

Issue 7640008: Call NtTerminateProcess directly in Process::Terminate (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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
« no previous file with comments | « no previous file | 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) 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 #include "base/process.h" 5 #include "base/process.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/process_util.h" 8 #include "base/process_util.h"
9 #include "base/win/windows_version.h" 9 #include "base/win/windows_version.h"
10 10
11 namespace base { 11 namespace base {
12 12
13 void Process::Close() { 13 void Process::Close() {
14 if (!process_) 14 if (!process_)
15 return; 15 return;
16 // Don't call CloseHandle on a pseudo-handle. 16 // Don't call CloseHandle on a pseudo-handle.
17 if (process_ != ::GetCurrentProcess()) 17 if (process_ != ::GetCurrentProcess()) {
18 ::CloseHandle(process_); 18 // TODO(apatrick): Call NtCloseHandle directly, without going through the
19 // import table to determine if CloseHandle is being hooked.
20 // http://crbug.com/81449.
21 HMODULE module = GetModuleHandle(L"ntdll.dll");
22 typedef UINT (WINAPI *CloseHandlePtr)(HANDLE handle);
23 CloseHandlePtr close_handle = reinterpret_cast<CloseHandlePtr>(
24 GetProcAddress(module, "NtClose"));
25 close_handle(process_);
26
27 // It used to look like this:
28 // ::CloseHandle(process_);
29 }
30
19 process_ = NULL; 31 process_ = NULL;
20 } 32 }
21 33
22 void Process::Terminate(int result_code) { 34 void Process::Terminate(int result_code) {
23 if (!process_) 35 if (!process_)
24 return; 36 return;
25 ::TerminateProcess(process_, result_code); 37
38 // TODO(apatrick): Call NtTerminateProcess directly, without going through the
39 // import table to determine if TerminateProcess is being hooked.
40 // http://crbug.com/81449.
41 HMODULE module = GetModuleHandle(L"ntdll.dll");
42 typedef UINT (WINAPI *TerminateProcessPtr)(HANDLE handle, UINT code);
43 TerminateProcessPtr terminate_process = reinterpret_cast<TerminateProcessPtr>(
44 GetProcAddress(module, "NtTerminateProcess"));
45 terminate_process(process_, result_code);
46
47 // It used to look like this:
48 // ::TerminateProcess(process_, result_code);
26 } 49 }
27 50
28 bool Process::IsProcessBackgrounded() const { 51 bool Process::IsProcessBackgrounded() const {
29 if (!process_) 52 if (!process_)
30 return false; // Failure case. 53 return false; // Failure case.
31 DWORD priority = GetPriority(); 54 DWORD priority = GetPriority();
32 if (priority == 0) 55 if (priority == 0)
33 return false; // Failure case. 56 return false; // Failure case.
34 return ((priority == BELOW_NORMAL_PRIORITY_CLASS) || 57 return ((priority == BELOW_NORMAL_PRIORITY_CLASS) ||
35 (priority == IDLE_PRIORITY_CLASS)); 58 (priority == IDLE_PRIORITY_CLASS));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 Process Process::Current() { 91 Process Process::Current() {
69 return Process(::GetCurrentProcess()); 92 return Process(::GetCurrentProcess());
70 } 93 }
71 94
72 int Process::GetPriority() const { 95 int Process::GetPriority() const {
73 DCHECK(process_); 96 DCHECK(process_);
74 return ::GetPriorityClass(process_); 97 return ::GetPriorityClass(process_);
75 } 98 }
76 99
77 } // namespace base 100 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698