| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #ifdef MINGW_HAS_SECURE_API | 36 #ifdef MINGW_HAS_SECURE_API |
| 37 #undef MINGW_HAS_SECURE_API | 37 #undef MINGW_HAS_SECURE_API |
| 38 #endif // MINGW_HAS_SECURE_API | 38 #endif // MINGW_HAS_SECURE_API |
| 39 #endif // __MINGW32__ | 39 #endif // __MINGW32__ |
| 40 | 40 |
| 41 #include "win32-headers.h" | 41 #include "win32-headers.h" |
| 42 | 42 |
| 43 #include "v8.h" | 43 #include "v8.h" |
| 44 | 44 |
| 45 #include "codegen.h" | 45 #include "codegen.h" |
| 46 #include "isolate-inl.h" |
| 46 #include "platform.h" | 47 #include "platform.h" |
| 47 #include "simulator.h" | 48 #include "simulator.h" |
| 48 #include "vm-state-inl.h" | 49 #include "vm-state-inl.h" |
| 49 | 50 |
| 50 #ifdef _MSC_VER | 51 #ifdef _MSC_VER |
| 51 | 52 |
| 52 // Case-insensitive bounded string comparisons. Use stricmp() on Win32. Usually | 53 // Case-insensitive bounded string comparisons. Use stricmp() on Win32. Usually |
| 53 // defined in strings.h. | 54 // defined in strings.h. |
| 54 int strncasecmp(const char* s1, const char* s2, int n) { | 55 int strncasecmp(const char* s1, const char* s2, int n) { |
| 55 return _strnicmp(s1, s2, n); | 56 return _strnicmp(s1, s2, n); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 --count; | 118 --count; |
| 118 } | 119 } |
| 119 } | 120 } |
| 120 CHECK_GT(dest_size, 0); | 121 CHECK_GT(dest_size, 0); |
| 121 *dest = 0; | 122 *dest = 0; |
| 122 return 0; | 123 return 0; |
| 123 } | 124 } |
| 124 | 125 |
| 125 #endif // __MINGW32__ | 126 #endif // __MINGW32__ |
| 126 | 127 |
| 127 // Generate a pseudo-random number in the range 0-2^31-1. Usually | |
| 128 // defined in stdlib.h. Missing in both Microsoft Visual Studio C++ and MinGW. | |
| 129 int random() { | |
| 130 return rand(); | |
| 131 } | |
| 132 | |
| 133 | |
| 134 namespace v8 { | 128 namespace v8 { |
| 135 namespace internal { | 129 namespace internal { |
| 136 | 130 |
| 137 intptr_t OS::MaxVirtualMemory() { | 131 intptr_t OS::MaxVirtualMemory() { |
| 138 return 0; | 132 return 0; |
| 139 } | 133 } |
| 140 | 134 |
| 141 | 135 |
| 142 double ceiling(double x) { | 136 double ceiling(double x) { |
| 143 return ceil(x); | 137 return ceil(x); |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 // Use a multiple of 64k to prevent committing unused memory. | 781 // Use a multiple of 64k to prevent committing unused memory. |
| 788 // Note: This does not guarantee RWX regions will be within the | 782 // Note: This does not guarantee RWX regions will be within the |
| 789 // range kAllocationRandomAddressMin to kAllocationRandomAddressMax | 783 // range kAllocationRandomAddressMin to kAllocationRandomAddressMax |
| 790 #ifdef V8_HOST_ARCH_64_BIT | 784 #ifdef V8_HOST_ARCH_64_BIT |
| 791 static const intptr_t kAllocationRandomAddressMin = 0x0000000080000000; | 785 static const intptr_t kAllocationRandomAddressMin = 0x0000000080000000; |
| 792 static const intptr_t kAllocationRandomAddressMax = 0x000003FFFFFF0000; | 786 static const intptr_t kAllocationRandomAddressMax = 0x000003FFFFFF0000; |
| 793 #else | 787 #else |
| 794 static const intptr_t kAllocationRandomAddressMin = 0x04000000; | 788 static const intptr_t kAllocationRandomAddressMin = 0x04000000; |
| 795 static const intptr_t kAllocationRandomAddressMax = 0x3FFF0000; | 789 static const intptr_t kAllocationRandomAddressMax = 0x3FFF0000; |
| 796 #endif | 790 #endif |
| 797 uintptr_t address = (V8::RandomPrivate(isolate) << kPageSizeBits) | 791 uintptr_t address = |
| 798 | kAllocationRandomAddressMin; | 792 (isolate->random_number_generator()->NextInt() << kPageSizeBits) | |
| 793 kAllocationRandomAddressMin; |
| 799 address &= kAllocationRandomAddressMax; | 794 address &= kAllocationRandomAddressMax; |
| 800 return reinterpret_cast<void *>(address); | 795 return reinterpret_cast<void *>(address); |
| 801 } | 796 } |
| 802 return NULL; | 797 return NULL; |
| 803 } | 798 } |
| 804 | 799 |
| 805 | 800 |
| 806 static void* RandomizedVirtualAlloc(size_t size, int action, int protection) { | 801 static void* RandomizedVirtualAlloc(size_t size, int action, int protection) { |
| 807 LPVOID base = NULL; | 802 LPVOID base = NULL; |
| 808 | 803 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 827 size_t msize = RoundUp(requested, static_cast<int>(GetPageSize())); | 822 size_t msize = RoundUp(requested, static_cast<int>(GetPageSize())); |
| 828 | 823 |
| 829 // Windows XP SP2 allows Data Excution Prevention (DEP). | 824 // Windows XP SP2 allows Data Excution Prevention (DEP). |
| 830 int prot = is_executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE; | 825 int prot = is_executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE; |
| 831 | 826 |
| 832 LPVOID mbase = RandomizedVirtualAlloc(msize, | 827 LPVOID mbase = RandomizedVirtualAlloc(msize, |
| 833 MEM_COMMIT | MEM_RESERVE, | 828 MEM_COMMIT | MEM_RESERVE, |
| 834 prot); | 829 prot); |
| 835 | 830 |
| 836 if (mbase == NULL) { | 831 if (mbase == NULL) { |
| 837 LOG(ISOLATE, StringEvent("OS::Allocate", "VirtualAlloc failed")); | 832 LOG(Isolate::Current(), StringEvent("OS::Allocate", "VirtualAlloc failed")); |
| 838 return NULL; | 833 return NULL; |
| 839 } | 834 } |
| 840 | 835 |
| 841 ASSERT(IsAligned(reinterpret_cast<size_t>(mbase), OS::AllocateAlignment())); | 836 ASSERT(IsAligned(reinterpret_cast<size_t>(mbase), OS::AllocateAlignment())); |
| 842 | 837 |
| 843 *allocated = msize; | 838 *allocated = msize; |
| 844 return mbase; | 839 return mbase; |
| 845 } | 840 } |
| 846 | 841 |
| 847 | 842 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 858 | 853 |
| 859 | 854 |
| 860 void OS::ProtectCode(void* address, const size_t size) { | 855 void OS::ProtectCode(void* address, const size_t size) { |
| 861 DWORD old_protect; | 856 DWORD old_protect; |
| 862 VirtualProtect(address, size, PAGE_EXECUTE_READ, &old_protect); | 857 VirtualProtect(address, size, PAGE_EXECUTE_READ, &old_protect); |
| 863 } | 858 } |
| 864 | 859 |
| 865 | 860 |
| 866 void OS::Guard(void* address, const size_t size) { | 861 void OS::Guard(void* address, const size_t size) { |
| 867 DWORD oldprotect; | 862 DWORD oldprotect; |
| 868 VirtualProtect(address, size, PAGE_READONLY | PAGE_GUARD, &oldprotect); | 863 VirtualProtect(address, size, PAGE_NOACCESS, &oldprotect); |
| 869 } | 864 } |
| 870 | 865 |
| 871 | 866 |
| 872 void OS::Sleep(int milliseconds) { | 867 void OS::Sleep(int milliseconds) { |
| 873 ::Sleep(milliseconds); | 868 ::Sleep(milliseconds); |
| 874 } | 869 } |
| 875 | 870 |
| 876 | 871 |
| 877 void OS::Abort() { | 872 void OS::Abort() { |
| 878 if (IsDebuggerPresent() || FLAG_break_on_abort) { | 873 if (IsDebuggerPresent() || FLAG_break_on_abort) { |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 // application is closed. | 1122 // application is closed. |
| 1128 } | 1123 } |
| 1129 | 1124 |
| 1130 #undef DBGHELP_FUNCTION_LIST | 1125 #undef DBGHELP_FUNCTION_LIST |
| 1131 #undef TLHELP32_FUNCTION_LIST | 1126 #undef TLHELP32_FUNCTION_LIST |
| 1132 #undef DLL_FUNC_VAR | 1127 #undef DLL_FUNC_VAR |
| 1133 #undef DLL_FUNC_TYPE | 1128 #undef DLL_FUNC_TYPE |
| 1134 | 1129 |
| 1135 | 1130 |
| 1136 // Load the symbols for generating stack traces. | 1131 // Load the symbols for generating stack traces. |
| 1137 static bool LoadSymbols(HANDLE process_handle) { | 1132 static bool LoadSymbols(Isolate* isolate, HANDLE process_handle) { |
| 1138 static bool symbols_loaded = false; | 1133 static bool symbols_loaded = false; |
| 1139 | 1134 |
| 1140 if (symbols_loaded) return true; | 1135 if (symbols_loaded) return true; |
| 1141 | 1136 |
| 1142 BOOL ok; | 1137 BOOL ok; |
| 1143 | 1138 |
| 1144 // Initialize the symbol engine. | 1139 // Initialize the symbol engine. |
| 1145 ok = _SymInitialize(process_handle, // hProcess | 1140 ok = _SymInitialize(process_handle, // hProcess |
| 1146 NULL, // UserSearchPath | 1141 NULL, // UserSearchPath |
| 1147 false); // fInvadeProcess | 1142 false); // fInvadeProcess |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1176 0, // hFile | 1171 0, // hFile |
| 1177 reinterpret_cast<PSTR>(module_entry.szExePath), // ImageName | 1172 reinterpret_cast<PSTR>(module_entry.szExePath), // ImageName |
| 1178 reinterpret_cast<PSTR>(module_entry.szModule), // ModuleName | 1173 reinterpret_cast<PSTR>(module_entry.szModule), // ModuleName |
| 1179 reinterpret_cast<DWORD64>(module_entry.modBaseAddr), // BaseOfDll | 1174 reinterpret_cast<DWORD64>(module_entry.modBaseAddr), // BaseOfDll |
| 1180 module_entry.modBaseSize); // SizeOfDll | 1175 module_entry.modBaseSize); // SizeOfDll |
| 1181 if (base == 0) { | 1176 if (base == 0) { |
| 1182 int err = GetLastError(); | 1177 int err = GetLastError(); |
| 1183 if (err != ERROR_MOD_NOT_FOUND && | 1178 if (err != ERROR_MOD_NOT_FOUND && |
| 1184 err != ERROR_INVALID_HANDLE) return false; | 1179 err != ERROR_INVALID_HANDLE) return false; |
| 1185 } | 1180 } |
| 1186 LOG(i::Isolate::Current(), | 1181 LOG(isolate, |
| 1187 SharedLibraryEvent( | 1182 SharedLibraryEvent( |
| 1188 module_entry.szExePath, | 1183 module_entry.szExePath, |
| 1189 reinterpret_cast<unsigned int>(module_entry.modBaseAddr), | 1184 reinterpret_cast<unsigned int>(module_entry.modBaseAddr), |
| 1190 reinterpret_cast<unsigned int>(module_entry.modBaseAddr + | 1185 reinterpret_cast<unsigned int>(module_entry.modBaseAddr + |
| 1191 module_entry.modBaseSize))); | 1186 module_entry.modBaseSize))); |
| 1192 cont = _Module32NextW(snapshot, &module_entry); | 1187 cont = _Module32NextW(snapshot, &module_entry); |
| 1193 } | 1188 } |
| 1194 CloseHandle(snapshot); | 1189 CloseHandle(snapshot); |
| 1195 | 1190 |
| 1196 symbols_loaded = true; | 1191 symbols_loaded = true; |
| 1197 return true; | 1192 return true; |
| 1198 } | 1193 } |
| 1199 | 1194 |
| 1200 | 1195 |
| 1201 void OS::LogSharedLibraryAddresses() { | 1196 void OS::LogSharedLibraryAddresses(Isolate* isolate) { |
| 1202 // SharedLibraryEvents are logged when loading symbol information. | 1197 // SharedLibraryEvents are logged when loading symbol information. |
| 1203 // Only the shared libraries loaded at the time of the call to | 1198 // Only the shared libraries loaded at the time of the call to |
| 1204 // LogSharedLibraryAddresses are logged. DLLs loaded after | 1199 // LogSharedLibraryAddresses are logged. DLLs loaded after |
| 1205 // initialization are not accounted for. | 1200 // initialization are not accounted for. |
| 1206 if (!LoadDbgHelpAndTlHelp32()) return; | 1201 if (!LoadDbgHelpAndTlHelp32()) return; |
| 1207 HANDLE process_handle = GetCurrentProcess(); | 1202 HANDLE process_handle = GetCurrentProcess(); |
| 1208 LoadSymbols(process_handle); | 1203 LoadSymbols(isolate, process_handle); |
| 1209 } | 1204 } |
| 1210 | 1205 |
| 1211 | 1206 |
| 1212 void OS::SignalCodeMovingGC() { | 1207 void OS::SignalCodeMovingGC() { |
| 1213 } | 1208 } |
| 1214 | 1209 |
| 1215 | 1210 |
| 1216 // Walk the stack using the facilities in dbghelp.dll and tlhelp32.dll | 1211 // Walk the stack using the facilities in dbghelp.dll and tlhelp32.dll |
| 1217 | 1212 |
| 1218 // Switch off warning 4748 (/GS can not protect parameters and local variables | 1213 // Switch off warning 4748 (/GS can not protect parameters and local variables |
| 1219 // from local buffer overrun because optimizations are disabled in function) as | 1214 // from local buffer overrun because optimizations are disabled in function) as |
| 1220 // it is triggered by the use of inline assembler. | 1215 // it is triggered by the use of inline assembler. |
| 1221 #pragma warning(push) | 1216 #pragma warning(push) |
| 1222 #pragma warning(disable : 4748) | 1217 #pragma warning(disable : 4748) |
| 1223 int OS::StackWalk(Vector<OS::StackFrame> frames) { | 1218 int OS::StackWalk(Vector<OS::StackFrame> frames) { |
| 1224 BOOL ok; | 1219 BOOL ok; |
| 1225 | 1220 |
| 1226 // Load the required functions from DLL's. | 1221 // Load the required functions from DLL's. |
| 1227 if (!LoadDbgHelpAndTlHelp32()) return kStackWalkError; | 1222 if (!LoadDbgHelpAndTlHelp32()) return kStackWalkError; |
| 1228 | 1223 |
| 1229 // Get the process and thread handles. | 1224 // Get the process and thread handles. |
| 1230 HANDLE process_handle = GetCurrentProcess(); | 1225 HANDLE process_handle = GetCurrentProcess(); |
| 1231 HANDLE thread_handle = GetCurrentThread(); | 1226 HANDLE thread_handle = GetCurrentThread(); |
| 1232 | 1227 |
| 1233 // Read the symbols. | 1228 // Read the symbols. |
| 1234 if (!LoadSymbols(process_handle)) return kStackWalkError; | 1229 if (!LoadSymbols(Isolate::Current(), process_handle)) return kStackWalkError; |
| 1235 | 1230 |
| 1236 // Capture current context. | 1231 // Capture current context. |
| 1237 CONTEXT context; | 1232 CONTEXT context; |
| 1238 RtlCaptureContext(&context); | 1233 RtlCaptureContext(&context); |
| 1239 | 1234 |
| 1240 // Initialize the stack walking | 1235 // Initialize the stack walking |
| 1241 STACKFRAME64 stack_frame; | 1236 STACKFRAME64 stack_frame; |
| 1242 memset(&stack_frame, 0, sizeof(stack_frame)); | 1237 memset(&stack_frame, 0, sizeof(stack_frame)); |
| 1243 #ifdef _WIN64 | 1238 #ifdef _WIN64 |
| 1244 stack_frame.AddrPC.Offset = context.Rip; | 1239 stack_frame.AddrPC.Offset = context.Rip; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1330 | 1325 |
| 1331 // Return the number of frames filled in. | 1326 // Return the number of frames filled in. |
| 1332 return frames_count; | 1327 return frames_count; |
| 1333 } | 1328 } |
| 1334 | 1329 |
| 1335 | 1330 |
| 1336 // Restore warnings to previous settings. | 1331 // Restore warnings to previous settings. |
| 1337 #pragma warning(pop) | 1332 #pragma warning(pop) |
| 1338 | 1333 |
| 1339 #else // __MINGW32__ | 1334 #else // __MINGW32__ |
| 1340 void OS::LogSharedLibraryAddresses() { } | 1335 void OS::LogSharedLibraryAddresses(Isolate* isolate) { } |
| 1341 void OS::SignalCodeMovingGC() { } | 1336 void OS::SignalCodeMovingGC() { } |
| 1342 int OS::StackWalk(Vector<OS::StackFrame> frames) { return 0; } | 1337 int OS::StackWalk(Vector<OS::StackFrame> frames) { return 0; } |
| 1343 #endif // __MINGW32__ | 1338 #endif // __MINGW32__ |
| 1344 | 1339 |
| 1345 | 1340 |
| 1346 uint64_t OS::CpuFeaturesImpliedByPlatform() { | 1341 uint64_t OS::CpuFeaturesImpliedByPlatform() { |
| 1347 return 0; // Windows runs on anything. | 1342 return 0; // Windows runs on anything. |
| 1348 } | 1343 } |
| 1349 | 1344 |
| 1350 | 1345 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1434 bool VirtualMemory::Uncommit(void* address, size_t size) { | 1429 bool VirtualMemory::Uncommit(void* address, size_t size) { |
| 1435 ASSERT(IsReserved()); | 1430 ASSERT(IsReserved()); |
| 1436 return UncommitRegion(address, size); | 1431 return UncommitRegion(address, size); |
| 1437 } | 1432 } |
| 1438 | 1433 |
| 1439 | 1434 |
| 1440 bool VirtualMemory::Guard(void* address) { | 1435 bool VirtualMemory::Guard(void* address) { |
| 1441 if (NULL == VirtualAlloc(address, | 1436 if (NULL == VirtualAlloc(address, |
| 1442 OS::CommitPageSize(), | 1437 OS::CommitPageSize(), |
| 1443 MEM_COMMIT, | 1438 MEM_COMMIT, |
| 1444 PAGE_READONLY | PAGE_GUARD)) { | 1439 PAGE_NOACCESS)) { |
| 1445 return false; | 1440 return false; |
| 1446 } | 1441 } |
| 1447 return true; | 1442 return true; |
| 1448 } | 1443 } |
| 1449 | 1444 |
| 1450 | 1445 |
| 1451 void* VirtualMemory::ReserveRegion(size_t size) { | 1446 void* VirtualMemory::ReserveRegion(size_t size) { |
| 1452 return RandomizedVirtualAlloc(size, MEM_RESERVE, PAGE_NOACCESS); | 1447 return RandomizedVirtualAlloc(size, MEM_RESERVE, PAGE_NOACCESS); |
| 1453 } | 1448 } |
| 1454 | 1449 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1573 USE(result); | 1568 USE(result); |
| 1574 ASSERT(result); | 1569 ASSERT(result); |
| 1575 } | 1570 } |
| 1576 | 1571 |
| 1577 | 1572 |
| 1578 | 1573 |
| 1579 void Thread::YieldCPU() { | 1574 void Thread::YieldCPU() { |
| 1580 Sleep(0); | 1575 Sleep(0); |
| 1581 } | 1576 } |
| 1582 | 1577 |
| 1583 | |
| 1584 void OS::SetUp() { | |
| 1585 // Seed the random number generator. | |
| 1586 // Convert the current time to a 64-bit integer first, before converting it | |
| 1587 // to an unsigned. Going directly can cause an overflow and the seed to be | |
| 1588 // set to all ones. The seed will be identical for different instances that | |
| 1589 // call this setup code within the same millisecond. | |
| 1590 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis()); | |
| 1591 srand(static_cast<unsigned int>(seed)); | |
| 1592 } | |
| 1593 | |
| 1594 } } // namespace v8::internal | 1578 } } // namespace v8::internal |
| OLD | NEW |