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

Unified Diff: Source/wtf/AddressSpaceRandomization.cpp

Issue 1185303003: Improve seeding of AddressSpaceRandomization randomness. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/AddressSpaceRandomization.cpp
diff --git a/Source/wtf/AddressSpaceRandomization.cpp b/Source/wtf/AddressSpaceRandomization.cpp
index daaa1fd73c495f40c3ede4b8da28311edded6ed3..2a363a33e306649fdf2dfc68a43e537f20a8d937 100644
--- a/Source/wtf/AddressSpaceRandomization.cpp
+++ b/Source/wtf/AddressSpaceRandomization.cpp
@@ -6,9 +6,15 @@
#include "wtf/AddressSpaceRandomization.h"
#include "wtf/PageAllocator.h"
-#include "wtf/ProcessID.h"
#include "wtf/SpinLock.h"
+#if OS(WIN)
+#include <windows.h>
+#else
+#include <sys/time.h>
+#include <unistd.h>
+#endif
+
namespace WTF {
namespace {
@@ -45,7 +51,21 @@ uint32_t ranval(ranctx* x)
x->initialized = true;
char c;
uint32_t seed = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(&c));
- seed ^= static_cast<uint32_t>(getCurrentProcessID());
+ uint32_t pid;
+ uint32_t usec;
+#if OS(WIN)
+ pid = GetCurrentProcessId();
+ SYSTEMTIME st;
+ GetSystemTime(&st);
+ usec = static_cast<uint32_t>(st.wMilliseconds * 1000);
+#else
+ pid = static_cast<uint32_t>(getpid());
+ struct timeval tv;
+ gettimeofday(&tv, 0);
+ usec = static_cast<uint32_t>(tv.tv_usec);
+#endif
+ seed ^= pid;
+ seed ^= usec;
x->a = 0xf1ea5eed;
x->b = x->c = x->d = seed;
for (int i = 0; i < 20; ++i) {
@@ -76,6 +96,7 @@ void* getRandomPageBase()
#if OS(WIN)
// 64-bit Windows has a bizarrely small 8TB user address space.
// Allocates in the 1-5TB region.
+ // TODO(cevans): I think Win 8.1 has 47-bits like Linux.
random &= 0x3ffffffffffUL;
random += 0x10000000000UL;
#else
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698