Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // TODO(port): the ifdefs in here are a first step towards trying to determine | 5 // TODO(port): the ifdefs in here are a first step towards trying to determine |
| 6 // the correct abstraction for all the OS functionality required at this | 6 // the correct abstraction for all the OS functionality required at this |
| 7 // stage of process initialization. It should not be taken as a final | 7 // stage of process initialization. It should not be taken as a final |
| 8 // abstraction. | 8 // abstraction. |
| 9 | 9 |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 void InvalidParameter(const wchar_t* expression, const wchar_t* function, | 102 void InvalidParameter(const wchar_t* expression, const wchar_t* function, |
| 103 const wchar_t* file, unsigned int line, | 103 const wchar_t* file, unsigned int line, |
| 104 uintptr_t reserved) { | 104 uintptr_t reserved) { |
| 105 __debugbreak(); | 105 __debugbreak(); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void PureCall() { | 108 void PureCall() { |
| 109 __debugbreak(); | 109 __debugbreak(); |
| 110 } | 110 } |
| 111 | 111 |
| 112 int OnNoMemory(size_t memory_size) { | 112 void OnNoMemory() { |
| 113 // Kill the process. This is important for security, since WebKit doesn't | 113 // Kill the process. This is important for security, since WebKit doesn't |
| 114 // NULL-check many memory allocations. If a malloc fails, returns NULL, and | 114 // NULL-check many memory allocations. If a malloc fails, returns NULL, and |
| 115 // the buffer is then used, it provides a handy mapping of memory starting at | 115 // the buffer is then used, it provides a handy mapping of memory starting at |
| 116 // address 0 for an attacker to utilize. | 116 // address 0 for an attacker to utilize. |
| 117 __debugbreak(); | 117 __debugbreak(); |
| 118 | |
| 119 // Return memory_size so it is not optimized out. Make sure the return value | |
| 120 // is at least 1 so malloc/new is retried, especially useful when under a | |
| 121 // debugger. | |
| 122 return memory_size ? static_cast<int>(memory_size) : 1; | |
| 123 } | 118 } |
| 124 | 119 |
| 125 // Handlers to silently dump the current process when there is an assert in | 120 // Handlers to silently dump the current process when there is an assert in |
| 126 // chrome. | 121 // chrome. |
| 127 void ChromeAssert(const std::string& str) { | 122 void ChromeAssert(const std::string& str) { |
| 128 // Get the breakpad pointer from chrome.exe | 123 // Get the breakpad pointer from chrome.exe |
| 129 typedef void (__stdcall *DumpProcessFunction)(); | 124 typedef void (__stdcall *DumpProcessFunction)(); |
| 130 DumpProcessFunction DumpProcess = reinterpret_cast<DumpProcessFunction>( | 125 DumpProcessFunction DumpProcess = reinterpret_cast<DumpProcessFunction>( |
| 131 ::GetProcAddress(::GetModuleHandle(L"chrome.exe"), "DumpProcess")); | 126 ::GetProcAddress(::GetModuleHandle(L"chrome.exe"), "DumpProcess")); |
| 132 if (DumpProcess) | 127 if (DumpProcess) |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 } | 181 } |
| 187 #endif // defined(OS_LINUX) | 182 #endif // defined(OS_LINUX) |
| 188 | 183 |
| 189 // Register the invalid param handler and pure call handler to be able to | 184 // Register the invalid param handler and pure call handler to be able to |
| 190 // notify breakpad when it happens. | 185 // notify breakpad when it happens. |
| 191 void RegisterInvalidParamHandler() { | 186 void RegisterInvalidParamHandler() { |
| 192 #if defined(OS_WIN) | 187 #if defined(OS_WIN) |
| 193 _set_invalid_parameter_handler(InvalidParameter); | 188 _set_invalid_parameter_handler(InvalidParameter); |
| 194 _set_purecall_handler(PureCall); | 189 _set_purecall_handler(PureCall); |
| 195 // Gather allocation failure. | 190 // Gather allocation failure. |
| 196 _set_new_handler(&OnNoMemory); | 191 std::set_new_handler(&OnNoMemory); |
| 197 // Make sure malloc() calls the new handler too. | |
| 198 _set_new_mode(1); | |
|
cpu_(ooo_6.6-7.5)
2009/04/28 22:38:16
why is _set_new_mode(1) gone?
| |
| 199 #endif | 192 #endif |
| 200 } | 193 } |
| 201 | 194 |
| 202 void SetupCRT(const CommandLine& parsed_command_line) { | 195 void SetupCRT(const CommandLine& parsed_command_line) { |
| 203 #if defined(OS_WIN) | 196 #if defined(OS_WIN) |
| 204 #ifdef _CRTDBG_MAP_ALLOC | 197 #ifdef _CRTDBG_MAP_ALLOC |
| 205 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); | 198 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); |
| 206 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); | 199 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); |
| 207 #else | 200 #else |
| 208 if (!parsed_command_line.HasSwitch(switches::kDisableBreakpad)) { | 201 if (!parsed_command_line.HasSwitch(switches::kDisableBreakpad)) { |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 _CrtDumpMemoryLeaks(); | 462 _CrtDumpMemoryLeaks(); |
| 470 #endif // _CRTDBG_MAP_ALLOC | 463 #endif // _CRTDBG_MAP_ALLOC |
| 471 | 464 |
| 472 _Module.Term(); | 465 _Module.Term(); |
| 473 #endif | 466 #endif |
| 474 | 467 |
| 475 logging::CleanupChromeLogging(); | 468 logging::CleanupChromeLogging(); |
| 476 | 469 |
| 477 return rv; | 470 return rv; |
| 478 } | 471 } |
| OLD | NEW |