| 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 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 } | 726 } |
| 727 | 727 |
| 728 | 728 |
| 729 void* OS::GetRandomMmapAddr() { | 729 void* OS::GetRandomMmapAddr() { |
| 730 // The address range used to randomize RWX allocations in OS::Allocate | 730 // The address range used to randomize RWX allocations in OS::Allocate |
| 731 // Try not to map pages into the default range that windows loads DLLs | 731 // Try not to map pages into the default range that windows loads DLLs |
| 732 // Use a multiple of 64k to prevent committing unused memory. | 732 // Use a multiple of 64k to prevent committing unused memory. |
| 733 // Note: This does not guarantee RWX regions will be within the | 733 // Note: This does not guarantee RWX regions will be within the |
| 734 // range kAllocationRandomAddressMin to kAllocationRandomAddressMax | 734 // range kAllocationRandomAddressMin to kAllocationRandomAddressMax |
| 735 #ifdef V8_HOST_ARCH_64_BIT | 735 #ifdef V8_HOST_ARCH_64_BIT |
| 736 static const intptr_t kAllocationRandomAddressMin = 0x0000000080000000; | 736 static const uintptr_t kAllocationRandomAddressMin = 0x0000000080000000; |
| 737 static const intptr_t kAllocationRandomAddressMax = 0x000003FFFFFF0000; | 737 static const uintptr_t kAllocationRandomAddressMax = 0x000003FFFFFF0000; |
| 738 #else | 738 #else |
| 739 static const intptr_t kAllocationRandomAddressMin = 0x04000000; | 739 static const uintptr_t kAllocationRandomAddressMin = 0x04000000; |
| 740 static const intptr_t kAllocationRandomAddressMax = 0x3FFF0000; | 740 static const uintptr_t kAllocationRandomAddressMax = 0x3FFF0000; |
| 741 #endif | 741 #endif |
| 742 uintptr_t address = | 742 uintptr_t address; |
| 743 (platform_random_number_generator.Pointer()->NextInt() << kPageSizeBits) | | 743 platform_random_number_generator.Pointer()->NextBytes(&address, |
| 744 kAllocationRandomAddressMin; | 744 sizeof(address)); |
| 745 address <<= kPageSizeBits; |
| 746 address += kAllocationRandomAddressMin; |
| 745 address &= kAllocationRandomAddressMax; | 747 address &= kAllocationRandomAddressMax; |
| 746 return reinterpret_cast<void *>(address); | 748 return reinterpret_cast<void *>(address); |
| 747 } | 749 } |
| 748 | 750 |
| 749 | 751 |
| 750 static void* RandomizedVirtualAlloc(size_t size, int action, int protection) { | 752 static void* RandomizedVirtualAlloc(size_t size, int action, int protection) { |
| 751 LPVOID base = NULL; | 753 LPVOID base = NULL; |
| 752 | 754 |
| 753 if (protection == PAGE_EXECUTE_READWRITE || protection == PAGE_NOACCESS) { | 755 if (protection == PAGE_EXECUTE_READWRITE || protection == PAGE_NOACCESS) { |
| 754 // For exectutable pages try and randomize the allocation address | 756 // For exectutable pages try and randomize the allocation address |
| (...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1381 DCHECK(result); | 1383 DCHECK(result); |
| 1382 } | 1384 } |
| 1383 | 1385 |
| 1384 | 1386 |
| 1385 | 1387 |
| 1386 void Thread::YieldCPU() { | 1388 void Thread::YieldCPU() { |
| 1387 Sleep(0); | 1389 Sleep(0); |
| 1388 } | 1390 } |
| 1389 | 1391 |
| 1390 } } // namespace v8::base | 1392 } } // namespace v8::base |
| OLD | NEW |