summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
Diffstat (limited to 'base')
-rw-r--r--base/process_util.h6
-rw-r--r--base/process_util_win.cc13
-rw-r--r--base/win/windows_version.cc13
-rw-r--r--base/win/windows_version.h8
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);
};