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

Side by Side Diff: base/process_win.cc

Issue 7624052: Cleanup code used to diagnose and fix bug 81449. (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 | base/task.h » ('j') | 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
16 // Don't call CloseHandle on a pseudo-handle. 17 // Don't call CloseHandle on a pseudo-handle.
17 if (process_ != ::GetCurrentProcess()) { 18 if (process_ != ::GetCurrentProcess())
18 // TODO(apatrick): Call NtCloseHandle directly, without going through the 19 ::CloseHandle(process_);
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 20
31 process_ = NULL; 21 process_ = NULL;
32 } 22 }
33 23
34 void Process::Terminate(int result_code) { 24 void Process::Terminate(int result_code) {
35 if (!process_) 25 if (!process_)
36 return; 26 return;
37 27
38 // TODO(apatrick): Call NtTerminateProcess directly, without going through the 28 // Call NtTerminateProcess directly, without going through the import table,
39 // import table to determine if TerminateProcess is being hooked. 29 // which might have been hooked with a buggy replacement by third party
40 // http://crbug.com/81449. 30 // software. http://crbug.com/81449.
41 HMODULE module = GetModuleHandle(L"ntdll.dll"); 31 HMODULE module = GetModuleHandle(L"ntdll.dll");
42 typedef UINT (WINAPI *TerminateProcessPtr)(HANDLE handle, UINT code); 32 typedef UINT (WINAPI *TerminateProcessPtr)(HANDLE handle, UINT code);
43 TerminateProcessPtr terminate_process = reinterpret_cast<TerminateProcessPtr>( 33 TerminateProcessPtr terminate_process = reinterpret_cast<TerminateProcessPtr>(
44 GetProcAddress(module, "NtTerminateProcess")); 34 GetProcAddress(module, "NtTerminateProcess"));
45 terminate_process(process_, result_code); 35 terminate_process(process_, result_code);
46
47 // It used to look like this:
48 // ::TerminateProcess(process_, result_code);
49 } 36 }
50 37
51 bool Process::IsProcessBackgrounded() const { 38 bool Process::IsProcessBackgrounded() const {
52 if (!process_) 39 if (!process_)
53 return false; // Failure case. 40 return false; // Failure case.
54 DWORD priority = GetPriority(); 41 DWORD priority = GetPriority();
55 if (priority == 0) 42 if (priority == 0)
56 return false; // Failure case. 43 return false; // Failure case.
57 return ((priority == BELOW_NORMAL_PRIORITY_CLASS) || 44 return ((priority == BELOW_NORMAL_PRIORITY_CLASS) ||
58 (priority == IDLE_PRIORITY_CLASS)); 45 (priority == IDLE_PRIORITY_CLASS));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 Process Process::Current() { 78 Process Process::Current() {
92 return Process(::GetCurrentProcess()); 79 return Process(::GetCurrentProcess());
93 } 80 }
94 81
95 int Process::GetPriority() const { 82 int Process::GetPriority() const {
96 DCHECK(process_); 83 DCHECK(process_);
97 return ::GetPriorityClass(process_); 84 return ::GetPriorityClass(process_);
98 } 85 }
99 86
100 } // namespace base 87 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/task.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698