diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-31 20:37:59 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-31 20:37:59 +0000 |
commit | fecbc6cac20962ff51d60d2a7726ce3be8f345e4 (patch) | |
tree | 17b433feb1ca9027e0915751ef7935d44a27b86d /base | |
parent | 3492fc6d1534eec4418232349cdcd5d36c61a881 (diff) | |
download | chromium_src-fecbc6cac20962ff51d60d2a7726ce3be8f345e4.zip chromium_src-fecbc6cac20962ff51d60d2a7726ce3be8f345e4.tar.gz chromium_src-fecbc6cac20962ff51d60d2a7726ce3be8f345e4.tar.bz2 |
Simplify chrome_exe_main_*.cc, moving as much of the code out as possible. This is in preparation for moving the code in ChromeMain (and associated platform files) to a common place that can be used by both chrome and other embedders of content (i.e. content_shell). Included is a change to make the sandbox code not need an AtExitManager. This is necessary because content_shell would be just one exe, and we'd need to initialize the sandbox before calling ChromeMain, which is what would creat AtExitManager.I removed the code that printed the tcmalloc stacks in the OOM handler (i.e. r33993) under Windows. The issue is I wanted to move the OOM handling code to base to match the other platforms (in a long string of changes to make the startup code more sane, so I can share it with a browser built over content). When I tried moving the tcmalloc code to base, then I ran into a bunch of linker errors because a bunch of targets that depend on base don't depend on allocator. When I tried to add that to base, I ran into strange gyp errors (see patchset 2). I asked Jim/Eric and they said they don't use this data from dumps, and that most of the OOM minimdumps are in v8 heap anyways. When James get back, if he still uses this I can figure out how to put this back.BUG=90445
Review URL: http://codereview.chromium.org/7810005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99032 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/process_util.h | 6 | ||||
-rw-r--r-- | base/process_util_win.cc | 13 | ||||
-rw-r--r-- | base/win/windows_version.cc | 13 | ||||
-rw-r--r-- | base/win/windows_version.h | 8 |
4 files changed, 31 insertions, 9 deletions
diff --git a/base/process_util.h b/base/process_util.h index 2109401..66c63dd 100644 --- a/base/process_util.h +++ b/base/process_util.h @@ -697,15 +697,13 @@ BASE_EXPORT bool EnableLowFragmentationHeap(); // overflow. Has no effect if the OS doesn't provide the necessary facility. BASE_EXPORT void EnableTerminationOnHeapCorruption(); -#if !defined(OS_WIN) -// Turns on process termination if memory runs out. This is handled on Windows -// inside RegisterInvalidParamHandler(). +// Turns on process termination if memory runs out. BASE_EXPORT void EnableTerminationOnOutOfMemory(); + #if defined(OS_MACOSX) // Exposed for testing. BASE_EXPORT malloc_zone_t* GetPurgeableZone(); #endif // defined(OS_MACOSX) -#endif // !defined(OS_WIN) // Enables stack dump to console output on exception and signals. // When enabled, the process will quit immediately. This is meant to be used in diff --git a/base/process_util_win.cc b/base/process_util_win.cc index 8a2eafe..315a68f 100644 --- a/base/process_util_win.cc +++ b/base/process_util_win.cc @@ -94,6 +94,15 @@ void AttachToConsole() { std::ios::sync_with_stdio(); } +void OnNoMemory() { + // Kill the process. This is important for security, since WebKit doesn't + // NULL-check many memory allocations. If a malloc fails, returns NULL, and + // the buffer is then used, it provides a handy mapping of memory starting at + // address 0 for an attacker to utilize. + __debugbreak(); + _exit(1); +} + } // namespace ProcessId GetCurrentProcId() { @@ -822,6 +831,10 @@ void EnableTerminationOnHeapCorruption() { HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0); } +void EnableTerminationOnOutOfMemory() { + std::set_new_handler(&OnNoMemory); +} + bool EnableInProcessStackDumping() { // Add stack dumping support on exception on windows. Similar to OS_POSIX // signal() handling in process_util_posix.cc. diff --git a/base/win/windows_version.cc b/base/win/windows_version.cc index 8dc2d93..5779074 100644 --- a/base/win/windows_version.cc +++ b/base/win/windows_version.cc @@ -13,7 +13,18 @@ namespace win { // static OSInfo* OSInfo::GetInstance() { - return Singleton<OSInfo>::get(); + // Note: we don't use the Singleton class because it depends on AtExitManager, + // and it's convenient for other modules to use this classs without it. This + // pattern is copied from gurl.cc. + static OSInfo* info; + if (!info) { + OSInfo* new_info = new OSInfo(); + if (InterlockedCompareExchangePointer( + reinterpret_cast<PVOID*>(&info), new_info, NULL)) { + delete new_info; + } + } + return info; } OSInfo::OSInfo() diff --git a/base/win/windows_version.h b/base/win/windows_version.h index 296e0da..920438b 100644 --- a/base/win/windows_version.h +++ b/base/win/windows_version.h @@ -7,7 +7,7 @@ #pragma once #include "base/base_export.h" -#include "base/memory/singleton.h" +#include "base/basictypes.h" typedef void* HANDLE; @@ -27,8 +27,9 @@ enum Version { VERSION_WIN7, }; -// A Singleton that can be used to query various pieces of information about the -// OS and process state. +// A singleton that can be used to query various pieces of information about the +// OS and process state. Note that this doesn't use the base Singleton class, so +// it can be used without an AtExitManager. class BASE_EXPORT OSInfo { public: struct VersionNumber { @@ -92,7 +93,6 @@ class BASE_EXPORT OSInfo { size_t allocation_granularity_; WOW64Status wow64_status_; - friend struct DefaultSingletonTraits<OSInfo>; DISALLOW_COPY_AND_ASSIGN(OSInfo); }; |