OLD | NEW |
---|---|
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 "base/process_util.h" | 5 #include "base/process_util.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <io.h> | 8 #include <io.h> |
9 #include <windows.h> | 9 #include <windows.h> |
10 #include <userenv.h> | 10 #include <userenv.h> |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 // Prints the exception call stack. | 63 // Prints the exception call stack. |
64 // This is the unit tests exception filter. | 64 // This is the unit tests exception filter. |
65 long WINAPI StackDumpExceptionFilter(EXCEPTION_POINTERS* info) { | 65 long WINAPI StackDumpExceptionFilter(EXCEPTION_POINTERS* info) { |
66 debug::StackTrace(info).PrintBacktrace(); | 66 debug::StackTrace(info).PrintBacktrace(); |
67 if (g_previous_filter) | 67 if (g_previous_filter) |
68 return g_previous_filter(info); | 68 return g_previous_filter(info); |
69 return EXCEPTION_CONTINUE_SEARCH; | 69 return EXCEPTION_CONTINUE_SEARCH; |
70 } | 70 } |
71 | 71 |
72 // Connects back to a console if available. | 72 // Connects back to a console if available. |
73 void AttachToConsole() { | 73 void AttachToConsole() { |
brettw
2012/08/19 23:26:46
Maybe just rename this one and move out of the ano
jbates
2012/08/20 17:43:00
Done.
| |
74 static bool g_attached = false; | |
75 if (g_attached) | |
76 return; | |
77 g_attached = true; | |
78 | |
74 if (!AttachConsole(ATTACH_PARENT_PROCESS)) { | 79 if (!AttachConsole(ATTACH_PARENT_PROCESS)) { |
M-A Ruel
2012/08/20 12:42:29
This already takes care of not doing it 2 times in
jbates
2012/08/20 17:43:00
Done.
| |
75 unsigned int result = GetLastError(); | 80 unsigned int result = GetLastError(); |
76 // Was probably already attached. | 81 // Was probably already attached. |
77 if (result == ERROR_ACCESS_DENIED) | 82 if (result == ERROR_ACCESS_DENIED) |
78 return; | 83 return; |
79 | 84 |
80 if (result == ERROR_INVALID_HANDLE || result == ERROR_INVALID_HANDLE) { | 85 if (result == ERROR_INVALID_HANDLE || result == ERROR_INVALID_HANDLE) { |
81 // TODO(maruel): Walk up the process chain if deemed necessary. | 86 // TODO(maruel): Walk up the process chain if deemed necessary. |
82 } | 87 } |
83 // Continue even if the function call fails. | 88 // Continue even if the function call fails. |
84 AllocConsole(); | 89 AllocConsole(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 // TerminateProcess should do for us. Don't check for the result code since | 165 // TerminateProcess should do for us. Don't check for the result code since |
161 // it fails quite often. This should be investigated eventually. | 166 // it fails quite often. This should be investigated eventually. |
162 base::KillProcess(process_, kProcessKilledExitCode, false); | 167 base::KillProcess(process_, kProcessKilledExitCode, false); |
163 | 168 |
164 // Now, just cleanup as if the process exited normally. | 169 // Now, just cleanup as if the process exited normally. |
165 OnObjectSignaled(process_); | 170 OnObjectSignaled(process_); |
166 } | 171 } |
167 | 172 |
168 } // namespace | 173 } // namespace |
169 | 174 |
175 void RouteStdioToConsole() { | |
176 AttachToConsole(); | |
177 } | |
178 | |
170 ProcessId GetCurrentProcId() { | 179 ProcessId GetCurrentProcId() { |
171 return ::GetCurrentProcessId(); | 180 return ::GetCurrentProcessId(); |
172 } | 181 } |
173 | 182 |
174 ProcessHandle GetCurrentProcessHandle() { | 183 ProcessHandle GetCurrentProcessHandle() { |
175 return ::GetCurrentProcess(); | 184 return ::GetCurrentProcess(); |
176 } | 185 } |
177 | 186 |
178 HMODULE GetModuleFromAddress(void* address) { | 187 HMODULE GetModuleFromAddress(void* address) { |
179 HMODULE instance = NULL; | 188 HMODULE instance = NULL; |
(...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
995 | 1004 |
996 PERFORMANCE_INFORMATION info; | 1005 PERFORMANCE_INFORMATION info; |
997 if (!InternalGetPerformanceInfo(&info, sizeof(info))) { | 1006 if (!InternalGetPerformanceInfo(&info, sizeof(info))) { |
998 DLOG(ERROR) << "Failed to fetch internal performance info."; | 1007 DLOG(ERROR) << "Failed to fetch internal performance info."; |
999 return 0; | 1008 return 0; |
1000 } | 1009 } |
1001 return (info.CommitTotal * system_info.dwPageSize) / 1024; | 1010 return (info.CommitTotal * system_info.dwPageSize) / 1024; |
1002 } | 1011 } |
1003 | 1012 |
1004 } // namespace base | 1013 } // namespace base |
OLD | NEW |