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

Side by Side Diff: src/base/platform/platform-cygwin.cc

Issue 367953002: Fix platform-cygwin.cc to really not use an Isolate (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Platform-specific code for Cygwin goes here. For the POSIX-compatible 5 // Platform-specific code for Cygwin goes here. For the POSIX-compatible
6 // parts, the implementation is in platform-posix.cc. 6 // parts, the implementation is in platform-posix.cc.
7 7
8 #include <errno.h> 8 #include <errno.h>
9 #include <pthread.h> 9 #include <pthread.h>
10 #include <semaphore.h> 10 #include <semaphore.h>
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 // Nothing to do on Cygwin. 172 // Nothing to do on Cygwin.
173 } 173 }
174 174
175 175
176 // The VirtualMemory implementation is taken from platform-win32.cc. 176 // The VirtualMemory implementation is taken from platform-win32.cc.
177 // The mmap-based virtual memory implementation as it is used on most posix 177 // The mmap-based virtual memory implementation as it is used on most posix
178 // platforms does not work well because Cygwin does not support MAP_FIXED. 178 // platforms does not work well because Cygwin does not support MAP_FIXED.
179 // This causes VirtualMemory::Commit to not always commit the memory region 179 // This causes VirtualMemory::Commit to not always commit the memory region
180 // specified. 180 // specified.
181 181
182 static void* GetRandomAddr() {
183 Isolate* isolate = Isolate::UncheckedCurrent();
184 // Note that the current isolate isn't set up in a call path via
185 // CpuFeatures::Probe. We don't care about randomization in this case because
186 // the code page is immediately freed.
187 if (isolate != NULL) {
188 // The address range used to randomize RWX allocations in OS::Allocate
189 // Try not to map pages into the default range that windows loads DLLs
190 // Use a multiple of 64k to prevent committing unused memory.
191 // Note: This does not guarantee RWX regions will be within the
192 // range kAllocationRandomAddressMin to kAllocationRandomAddressMax
193 #ifdef V8_HOST_ARCH_64_BIT
194 static const intptr_t kAllocationRandomAddressMin = 0x0000000080000000;
195 static const intptr_t kAllocationRandomAddressMax = 0x000003FFFFFF0000;
196 #else
197 static const intptr_t kAllocationRandomAddressMin = 0x04000000;
198 static const intptr_t kAllocationRandomAddressMax = 0x3FFF0000;
199 #endif
200 uintptr_t address =
201 (isolate->random_number_generator()->NextInt() << kPageSizeBits) |
202 kAllocationRandomAddressMin;
203 address &= kAllocationRandomAddressMax;
204 return reinterpret_cast<void *>(address);
205 }
206 return NULL;
207 }
208
209
210 static void* RandomizedVirtualAlloc(size_t size, int action, int protection) { 182 static void* RandomizedVirtualAlloc(size_t size, int action, int protection) {
211 LPVOID base = NULL; 183 LPVOID base = NULL;
212 184
213 if (protection == PAGE_EXECUTE_READWRITE || protection == PAGE_NOACCESS) { 185 if (protection == PAGE_EXECUTE_READWRITE || protection == PAGE_NOACCESS) {
214 // For exectutable pages try and randomize the allocation address 186 // For exectutable pages try and randomize the allocation address
215 for (size_t attempts = 0; base == NULL && attempts < 3; ++attempts) { 187 for (size_t attempts = 0; base == NULL && attempts < 3; ++attempts) {
216 base = VirtualAlloc(GetRandomAddr(), size, action, protection); 188 base = VirtualAlloc(OS::GetRandomMmapAddr(), size, action, protection);
217 } 189 }
218 } 190 }
219 191
220 // After three attempts give up and let the OS find an address to use. 192 // After three attempts give up and let the OS find an address to use.
221 if (base == NULL) base = VirtualAlloc(NULL, size, action, protection); 193 if (base == NULL) base = VirtualAlloc(NULL, size, action, protection);
222 194
223 return base; 195 return base;
224 } 196 }
225 197
226 198
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 return VirtualFree(base, 0, MEM_RELEASE) != 0; 294 return VirtualFree(base, 0, MEM_RELEASE) != 0;
323 } 295 }
324 296
325 297
326 bool VirtualMemory::HasLazyCommits() { 298 bool VirtualMemory::HasLazyCommits() {
327 // TODO(alph): implement for the platform. 299 // TODO(alph): implement for the platform.
328 return false; 300 return false;
329 } 301 }
330 302
331 } } // namespace v8::base 303 } } // namespace v8::base
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