OLD | NEW |
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 Win32. | 5 // Platform-specific code for Win32. |
6 | 6 |
7 // Secure API functions are not available using MinGW with msvcrt.dll | 7 // Secure API functions are not available using MinGW with msvcrt.dll |
8 // on Windows XP. Make sure MINGW_HAS_SECURE_API is not defined to | 8 // on Windows XP. Make sure MINGW_HAS_SECURE_API is not defined to |
9 // disable definition of secure API functions in standard headers that | 9 // disable definition of secure API functions in standard headers that |
10 // would conflict with our own implementation. | 10 // would conflict with our own implementation. |
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 sizeof(address)); | 744 sizeof(address)); |
745 address <<= kPageSizeBits; | 745 address <<= kPageSizeBits; |
746 address += kAllocationRandomAddressMin; | 746 address += kAllocationRandomAddressMin; |
747 address &= kAllocationRandomAddressMax; | 747 address &= kAllocationRandomAddressMax; |
748 return reinterpret_cast<void *>(address); | 748 return reinterpret_cast<void *>(address); |
749 } | 749 } |
750 | 750 |
751 | 751 |
752 static void* RandomizedVirtualAlloc(size_t size, int action, int protection) { | 752 static void* RandomizedVirtualAlloc(size_t size, int action, int protection) { |
753 LPVOID base = NULL; | 753 LPVOID base = NULL; |
| 754 static BOOL use_aslr = -1; |
| 755 #ifdef V8_HOST_ARCH_32_BIT |
| 756 // Don't bother randomizing on 32-bit hosts, because they lack the room and |
| 757 // don't have viable ASLR anyway. |
| 758 if (use_aslr == -1 && !IsWow64Process(GetCurrentProcess(), &use_aslr)) |
| 759 use_aslr = FALSE; |
| 760 #else |
| 761 use_aslr = TRUE; |
| 762 #endif |
754 | 763 |
755 if (protection == PAGE_EXECUTE_READWRITE || protection == PAGE_NOACCESS) { | 764 if (use_aslr && |
756 // For exectutable pages try and randomize the allocation address | 765 (protection == PAGE_EXECUTE_READWRITE || protection == PAGE_NOACCESS)) { |
| 766 // For executable pages try and randomize the allocation address |
757 for (size_t attempts = 0; base == NULL && attempts < 3; ++attempts) { | 767 for (size_t attempts = 0; base == NULL && attempts < 3; ++attempts) { |
758 base = VirtualAlloc(OS::GetRandomMmapAddr(), size, action, protection); | 768 base = VirtualAlloc(OS::GetRandomMmapAddr(), size, action, protection); |
759 } | 769 } |
760 } | 770 } |
761 | 771 |
762 // After three attempts give up and let the OS find an address to use. | 772 // After three attempts give up and let the OS find an address to use. |
763 if (base == NULL) base = VirtualAlloc(NULL, size, action, protection); | 773 if (base == NULL) base = VirtualAlloc(NULL, size, action, protection); |
764 | 774 |
765 return base; | 775 return base; |
766 } | 776 } |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1379 | 1389 |
1380 | 1390 |
1381 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { | 1391 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { |
1382 BOOL result = TlsSetValue(static_cast<DWORD>(key), value); | 1392 BOOL result = TlsSetValue(static_cast<DWORD>(key), value); |
1383 USE(result); | 1393 USE(result); |
1384 DCHECK(result); | 1394 DCHECK(result); |
1385 } | 1395 } |
1386 | 1396 |
1387 } // namespace base | 1397 } // namespace base |
1388 } // namespace v8 | 1398 } // namespace v8 |
OLD | NEW |