Reviewers: Søren Gjesse, jschuh1,
http://codereview.chromium.org/2832095/diff/6001/7001
File src/platform-win32.cc (right):
http://codereview.chromium.org/2832095/diff/6001/7001#newcode846
src/platform-win32.cc:846: // TODO([email protected]): Port to x64 and
Linux
On 2010/07/30 08:08:14, Søren Gjesse wrote:
Please create an issue on code.google.com/p/v8 and change this TODO to
TODO(issue number).
Done.
http://codereview.chromium.org/2832095/diff/6001/7001#newcode846
src/platform-win32.cc:846: // TODO([email protected]): Port to x64 and
Linux
On 2010/07/30 08:08:14, Søren Gjesse wrote:
Please add a comment that for executable pages we try to randomize the
allocation address.
Done.
http://codereview.chromium.org/2832095/diff/6001/7001#newcode846
src/platform-win32.cc:846: // TODO([email protected]): Port to x64 and
Linux
On 2010/07/30 08:08:14, Søren Gjesse wrote:
To support x64 will it not just be a matter of having the constant
0x4FFF0000 in
a intptr_t constant with a different constant on x64 controlled by
V8_HOST_ARCH_64_BIT, see globals.h. If not please use a #ifdef
V8_HOST_ARCH_64_BIT to use the original code for x64.
Yup, your right. I wasn't sure if platform-win32.cc was used for the
x64 build. I defined kAllocationRandomAddressMin/Max in platform.h (is
this the right place for it? I didn't think that globals.h was since its
OS/Architecture dependent)
http://codereview.chromium.org/2832095/diff/6001/7001#newcode847
src/platform-win32.cc:847: if (prot == PAGE_EXECUTE_READWRITE &&
On 2010/07/30 08:08:14, Søren Gjesse wrote:
I suggest you keep this condition on one line.
Done.
http://codereview.chromium.org/2832095/diff/6001/7001#newcode854
src/platform-win32.cc:854: if (mbase == NULL &&
On 2010/07/30 08:08:14, Søren Gjesse wrote:
Condition on one line.
Done.
Description:
VirtualAlloc on Windows 7 does not currently provide sufficient
randomization to
protect JIT code from being aligned in large regions at a predictable
location.
This patch manually randomizes the allocation address for
PAGE_EXECUTE_READWRITE
regions between kAllocationRandomAddressMin and kAllocationRandomAddressMax.
BUG=none
TEST=allocate lots of javascript code and check for contiguous allocations
Please review this at http://codereview.chromium.org/2832095/show
SVN Base: http://v8.googlecode.com/svn/trunk/
Affected files:
M src/platform-win32.cc
M src/platform.h
Index: src/platform-win32.cc
===================================================================
--- src/platform-win32.cc (revision 5136)
+++ src/platform-win32.cc (working copy)
@@ -840,10 +840,23 @@
bool is_executable) {
// VirtualAlloc rounds allocated size to page size automatically.
size_t msize = RoundUp(requested, static_cast<int>(GetPageSize()));
-
+ intptr_t address = NULL;
// Windows XP SP2 allows Data Excution Prevention (DEP).
int prot = is_executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE;
- LPVOID mbase = VirtualAlloc(NULL, msize, MEM_COMMIT | MEM_RESERVE, prot);
+ // TODO(805): Port to Linux
+ // For exectutable pages try and randomize the allocation address
+ if (prot == PAGE_EXECUTE_READWRITE && msize >= Page::kPageSize) {
+ address = (V8::Random() << kPageSizeBits) |
kAllocationRandomAddressMin;
+ address &= kAllocationRandomAddressMax;
+ }
+
+ LPVOID mbase = VirtualAlloc(reinterpret_cast<void *>(address),
+ msize,
+ MEM_COMMIT | MEM_RESERVE,
+ prot);
+ if (mbase == NULL && address != NULL)
+ mbase = VirtualAlloc(NULL, msize, MEM_COMMIT | MEM_RESERVE, prot);
+
if (mbase == NULL) {
LOG(StringEvent("OS::Allocate", "VirtualAlloc failed"));
return NULL;
Index: src/platform.h
===================================================================
--- src/platform.h (revision 5136)
+++ src/platform.h (working copy)
@@ -282,6 +282,18 @@
private:
static const int msPerSecond = 1000;
+ // The address range used to randomize RWX allocations in OS::Allocate
+ // Try not to map pages into the default range that windows loads DLLs
+ // Note: This does not guarantee RWX regions will be within the
+ // range kAllocationRandomAddressMin to kAllocationRandomAddressMax
+#ifdef V8_HOST_ARCH_64_BIT
+ static const intptr_t kAllocationRandomAddressMin = 0x0000000080000000;
+ static const intptr_t kAllocationRandomAddressMax = 0x000004FFFFFFFFFF;
+#else
+ static const intptr_t kAllocationRandomAddressMin = 0x04000000;
+ static const intptr_t kAllocationRandomAddressMax = 0x4FFFFFFF;
+#endif
+
DISALLOW_IMPLICIT_CONSTRUCTORS(OS);
};
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev