| 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. |
| 11 #ifdef __MINGW32__ | 11 #ifdef __MINGW32__ |
| 12 #include <_mingw.h> | 12 #include <_mingw.h> |
| 13 #ifdef MINGW_HAS_SECURE_API | 13 #ifdef MINGW_HAS_SECURE_API |
| 14 #undef MINGW_HAS_SECURE_API | 14 #undef MINGW_HAS_SECURE_API |
| 15 #endif // MINGW_HAS_SECURE_API | 15 #endif // MINGW_HAS_SECURE_API |
| 16 #endif // __MINGW32__ | 16 #endif // __MINGW32__ |
| 17 | 17 |
| 18 #include "src/base/win32-headers.h" | 18 #include "src/base/win32-headers.h" |
| 19 | 19 |
| 20 #include "src/v8.h" | |
| 21 | |
| 22 #include "src/base/lazy-instance.h" | 20 #include "src/base/lazy-instance.h" |
| 23 #include "src/platform.h" | 21 #include "src/platform.h" |
| 22 #include "src/platform/time.h" |
| 23 #include "src/utils.h" |
| 24 #include "src/utils/random-number-generator.h" | 24 #include "src/utils/random-number-generator.h" |
| 25 | 25 |
| 26 #ifdef _MSC_VER | 26 #ifdef _MSC_VER |
| 27 | 27 |
| 28 // Case-insensitive bounded string comparisons. Use stricmp() on Win32. Usually | 28 // Case-insensitive bounded string comparisons. Use stricmp() on Win32. Usually |
| 29 // defined in strings.h. | 29 // defined in strings.h. |
| 30 int strncasecmp(const char* s1, const char* s2, int n) { | 30 int strncasecmp(const char* s1, const char* s2, int n) { |
| 31 return _strnicmp(s1, s2, n); | 31 return _strnicmp(s1, s2, n); |
| 32 } | 32 } |
| 33 | 33 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 CHECK_GT(dest_size, 0); | 96 CHECK_GT(dest_size, 0); |
| 97 *dest = 0; | 97 *dest = 0; |
| 98 return 0; | 98 return 0; |
| 99 } | 99 } |
| 100 | 100 |
| 101 #endif // __MINGW32__ | 101 #endif // __MINGW32__ |
| 102 | 102 |
| 103 namespace v8 { | 103 namespace v8 { |
| 104 namespace internal { | 104 namespace internal { |
| 105 | 105 |
| 106 namespace { |
| 107 |
| 108 bool g_hard_abort = false; |
| 109 |
| 110 } // namespace |
| 111 |
| 106 intptr_t OS::MaxVirtualMemory() { | 112 intptr_t OS::MaxVirtualMemory() { |
| 107 return 0; | 113 return 0; |
| 108 } | 114 } |
| 109 | 115 |
| 110 | 116 |
| 111 class TimezoneCache { | 117 class TimezoneCache { |
| 112 public: | 118 public: |
| 113 TimezoneCache() : initialized_(false) { } | 119 TimezoneCache() : initialized_(false) { } |
| 114 | 120 |
| 115 void Clear() { | 121 void Clear() { |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 allocate_alignment = info.dwAllocationGranularity; | 712 allocate_alignment = info.dwAllocationGranularity; |
| 707 } | 713 } |
| 708 return allocate_alignment; | 714 return allocate_alignment; |
| 709 } | 715 } |
| 710 | 716 |
| 711 | 717 |
| 712 static base::LazyInstance<RandomNumberGenerator>::type | 718 static base::LazyInstance<RandomNumberGenerator>::type |
| 713 platform_random_number_generator = LAZY_INSTANCE_INITIALIZER; | 719 platform_random_number_generator = LAZY_INSTANCE_INITIALIZER; |
| 714 | 720 |
| 715 | 721 |
| 716 void OS::SetRandomSeed(int64_t seed) { | 722 void OS::Initialize(int64_t random_seed, bool hard_abort, |
| 717 platform_random_number_generator.Pointer()->SetSeed(seed); | 723 const char* const gc_fake_mmap) { |
| 724 if (random_seed) { |
| 725 platform_random_number_generator.Pointer()->SetSeed(random_seed); |
| 726 } |
| 727 g_hard_abort = hard_abort; |
| 718 } | 728 } |
| 719 | 729 |
| 720 | 730 |
| 721 void* OS::GetRandomMmapAddr() { | 731 void* OS::GetRandomMmapAddr() { |
| 722 // The address range used to randomize RWX allocations in OS::Allocate | 732 // The address range used to randomize RWX allocations in OS::Allocate |
| 723 // Try not to map pages into the default range that windows loads DLLs | 733 // Try not to map pages into the default range that windows loads DLLs |
| 724 // Use a multiple of 64k to prevent committing unused memory. | 734 // Use a multiple of 64k to prevent committing unused memory. |
| 725 // Note: This does not guarantee RWX regions will be within the | 735 // Note: This does not guarantee RWX regions will be within the |
| 726 // range kAllocationRandomAddressMin to kAllocationRandomAddressMax | 736 // range kAllocationRandomAddressMin to kAllocationRandomAddressMax |
| 727 #ifdef V8_HOST_ARCH_64_BIT | 737 #ifdef V8_HOST_ARCH_64_BIT |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 VirtualProtect(address, size, PAGE_NOACCESS, &oldprotect); | 811 VirtualProtect(address, size, PAGE_NOACCESS, &oldprotect); |
| 802 } | 812 } |
| 803 | 813 |
| 804 | 814 |
| 805 void OS::Sleep(int milliseconds) { | 815 void OS::Sleep(int milliseconds) { |
| 806 ::Sleep(milliseconds); | 816 ::Sleep(milliseconds); |
| 807 } | 817 } |
| 808 | 818 |
| 809 | 819 |
| 810 void OS::Abort() { | 820 void OS::Abort() { |
| 811 if (FLAG_hard_abort) { | 821 if (g_hard_abort) { |
| 812 V8_IMMEDIATE_CRASH(); | 822 V8_IMMEDIATE_CRASH(); |
| 813 } | 823 } |
| 814 // Make the MSVCRT do a silent abort. | 824 // Make the MSVCRT do a silent abort. |
| 815 raise(SIGABRT); | 825 raise(SIGABRT); |
| 816 } | 826 } |
| 817 | 827 |
| 818 | 828 |
| 819 void OS::DebugBreak() { | 829 void OS::DebugBreak() { |
| 820 #ifdef _MSC_VER | 830 #ifdef _MSC_VER |
| 821 // To avoid Visual Studio runtime support the following code can be used | 831 // To avoid Visual Studio runtime support the following code can be used |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 : address_(ReserveRegion(size)), size_(size) { } | 1220 : address_(ReserveRegion(size)), size_(size) { } |
| 1211 | 1221 |
| 1212 | 1222 |
| 1213 VirtualMemory::VirtualMemory(size_t size, size_t alignment) | 1223 VirtualMemory::VirtualMemory(size_t size, size_t alignment) |
| 1214 : address_(NULL), size_(0) { | 1224 : address_(NULL), size_(0) { |
| 1215 ASSERT(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment()))); | 1225 ASSERT(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment()))); |
| 1216 size_t request_size = RoundUp(size + alignment, | 1226 size_t request_size = RoundUp(size + alignment, |
| 1217 static_cast<intptr_t>(OS::AllocateAlignment())); | 1227 static_cast<intptr_t>(OS::AllocateAlignment())); |
| 1218 void* address = ReserveRegion(request_size); | 1228 void* address = ReserveRegion(request_size); |
| 1219 if (address == NULL) return; | 1229 if (address == NULL) return; |
| 1220 Address base = RoundUp(static_cast<Address>(address), alignment); | 1230 uint8_t* base = RoundUp(static_cast<uint8_t*>(address), alignment); |
| 1221 // Try reducing the size by freeing and then reallocating a specific area. | 1231 // Try reducing the size by freeing and then reallocating a specific area. |
| 1222 bool result = ReleaseRegion(address, request_size); | 1232 bool result = ReleaseRegion(address, request_size); |
| 1223 USE(result); | 1233 USE(result); |
| 1224 ASSERT(result); | 1234 ASSERT(result); |
| 1225 address = VirtualAlloc(base, size, MEM_RESERVE, PAGE_NOACCESS); | 1235 address = VirtualAlloc(base, size, MEM_RESERVE, PAGE_NOACCESS); |
| 1226 if (address != NULL) { | 1236 if (address != NULL) { |
| 1227 request_size = size; | 1237 request_size = size; |
| 1228 ASSERT(base == static_cast<Address>(address)); | 1238 ASSERT(base == static_cast<uint8_t*>(address)); |
| 1229 } else { | 1239 } else { |
| 1230 // Resizing failed, just go with a bigger area. | 1240 // Resizing failed, just go with a bigger area. |
| 1231 address = ReserveRegion(request_size); | 1241 address = ReserveRegion(request_size); |
| 1232 if (address == NULL) return; | 1242 if (address == NULL) return; |
| 1233 } | 1243 } |
| 1234 address_ = address; | 1244 address_ = address; |
| 1235 size_ = request_size; | 1245 size_ = request_size; |
| 1236 } | 1246 } |
| 1237 | 1247 |
| 1238 | 1248 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1404 ASSERT(result); | 1414 ASSERT(result); |
| 1405 } | 1415 } |
| 1406 | 1416 |
| 1407 | 1417 |
| 1408 | 1418 |
| 1409 void Thread::YieldCPU() { | 1419 void Thread::YieldCPU() { |
| 1410 Sleep(0); | 1420 Sleep(0); |
| 1411 } | 1421 } |
| 1412 | 1422 |
| 1413 } } // namespace v8::internal | 1423 } } // namespace v8::internal |
| OLD | NEW |