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

Side by Side Diff: Source/wtf/PageAllocator.cpp

Issue 408483004: Avoid fragmenting address space on small windows systems. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Check via IsWow64Process(). Created 6 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #elif OS(WIN) 51 #elif OS(WIN)
52 52
53 #include <windows.h> 53 #include <windows.h>
54 54
55 #else 55 #else
56 #error Unknown OS 56 #error Unknown OS
57 #endif // OS(POSIX) 57 #endif // OS(POSIX)
58 58
59 namespace WTF { 59 namespace WTF {
60 60
61 #if OS(WIN)
62
63 static bool shouldUseAddressHint()
64 {
65 #if !CPU(X86_64)
66 // When running 32-bit processes under 32-bit Windows, the userspace is
67 // limited to 2 GB, and we risk fragmenting it badly if we allow further
68 // randomization via our address hint. On the other hand, if the process
69 // is running under WOW64, then it has 3 GB available, and we want use the
jschuh 2014/07/21 16:43:45 nit: Actually, it usually has 4GB available. I thi
70 // additional randomness.
71 static BOOL bIsWow64 = -1;
72 if (bIsWow64 == -1) {
73 IsWow64Process(GetCurrentProcess(), &bIsWow64);
74 }
75 return !!bIsWow64;
76 #else // !CPU(X86_64)
77 return true;
78 #endif // !CPU(X86_64)
79 }
80
81 #endif // OS(WIN)
82
61 // This simple internal function wraps the OS-specific page allocation call so 83 // This simple internal function wraps the OS-specific page allocation call so
62 // that it behaves consistently: the address is a hint and if it cannot be used, 84 // that it behaves consistently: the address is a hint and if it cannot be used,
63 // the allocation will be placed elsewhere. 85 // the allocation will be placed elsewhere.
64 static void* systemAllocPages(void* addr, size_t len) 86 static void* systemAllocPages(void* addr, size_t len)
65 { 87 {
66 ASSERT(!(len & kPageAllocationGranularityOffsetMask)); 88 ASSERT(!(len & kPageAllocationGranularityOffsetMask));
67 ASSERT(!(reinterpret_cast<uintptr_t>(addr) & kPageAllocationGranularityOffse tMask)); 89 ASSERT(!(reinterpret_cast<uintptr_t>(addr) & kPageAllocationGranularityOffse tMask));
68 void* ret; 90 void* ret = 0;
69 #if OS(WIN) 91 #if OS(WIN)
70 ret = VirtualAlloc(addr, len, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); 92 if (shouldUseAddressHint())
93 ret = VirtualAlloc(addr, len, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
71 if (!ret) 94 if (!ret)
72 ret = VirtualAlloc(0, len, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); 95 ret = VirtualAlloc(0, len, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
73 #else 96 #else
74 ret = mmap(addr, len, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, - 1, 0); 97 ret = mmap(addr, len, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, - 1, 0);
75 if (ret == MAP_FAILED) 98 if (ret == MAP_FAILED)
76 ret = 0; 99 ret = 0;
77 #endif 100 #endif
78 return ret; 101 return ret;
79 } 102 }
80 103
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 ASSERT(!(len & kSystemPageOffsetMask)); 239 ASSERT(!(len & kSystemPageOffsetMask));
217 #if OS(POSIX) 240 #if OS(POSIX)
218 (void) addr; 241 (void) addr;
219 #else 242 #else
220 setSystemPagesAccessible(addr, len); 243 setSystemPagesAccessible(addr, len);
221 #endif 244 #endif
222 } 245 }
223 246
224 } // namespace WTF 247 } // namespace WTF
225 248
OLDNEW
« 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