OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 // Require Windows 2000 or higher (this is required for the IsDebuggerPresent | 51 // Require Windows 2000 or higher (this is required for the IsDebuggerPresent |
52 // function to be present). | 52 // function to be present). |
53 #ifndef _WIN32_WINNT | 53 #ifndef _WIN32_WINNT |
54 #define _WIN32_WINNT 0x500 | 54 #define _WIN32_WINNT 0x500 |
55 #endif | 55 #endif |
56 | 56 |
57 #include <windows.h> | 57 #include <windows.h> |
58 | 58 |
59 #include <time.h> // For LocalOffset() implementation. | 59 #include <time.h> // For LocalOffset() implementation. |
60 #include <mmsystem.h> // For timeGetTime(). | 60 #include <mmsystem.h> // For timeGetTime(). |
| 61 #ifndef __MINGW32__ |
61 #include <dbghelp.h> // For SymLoadModule64 and al. | 62 #include <dbghelp.h> // For SymLoadModule64 and al. |
| 63 #endif // __MINGW32__ |
| 64 #include <limits.h> // For INT_MAX and al. |
62 #include <tlhelp32.h> // For Module32First and al. | 65 #include <tlhelp32.h> // For Module32First and al. |
63 | 66 |
64 // These additional WIN32 includes have to be right here as the #undef's below | 67 // These additional WIN32 includes have to be right here as the #undef's below |
65 // makes it impossible to have them elsewhere. | 68 // makes it impossible to have them elsewhere. |
66 #include <winsock2.h> | 69 #include <winsock2.h> |
67 #include <process.h> // for _beginthreadex() | 70 #include <process.h> // for _beginthreadex() |
68 #include <stdlib.h> | 71 #include <stdlib.h> |
69 | 72 |
70 #pragma comment(lib, "winmm.lib") // force linkage with winmm. | |
71 | |
72 #undef VOID | 73 #undef VOID |
73 #undef DELETE | 74 #undef DELETE |
74 #undef IN | 75 #undef IN |
75 #undef THIS | 76 #undef THIS |
76 #undef CONST | 77 #undef CONST |
77 #undef NAN | 78 #undef NAN |
78 #undef GetObject | 79 #undef GetObject |
79 #undef CreateMutex | 80 #undef CreateMutex |
80 #undef CreateSemaphore | 81 #undef CreateSemaphore |
81 | 82 |
82 #include "v8.h" | 83 #include "v8.h" |
83 | 84 |
84 #include "platform.h" | 85 #include "platform.h" |
85 | 86 |
86 // Extra POSIX/ANSI routines for Win32. Please refer to The Open Group Base | 87 // Extra POSIX/ANSI routines for Win32 when when using Visual Studio C++. Please |
87 // Specification for specification of the correct semantics for these | 88 // refer to The Open Group Base Specification for specification of the correct |
88 // functions. | 89 // semantics for these functions. |
89 // (http://www.opengroup.org/onlinepubs/000095399/) | 90 // (http://www.opengroup.org/onlinepubs/000095399/) |
| 91 #ifdef _MSC_VER |
90 | 92 |
91 // Test for finite value - usually defined in math.h | |
92 namespace v8 { | 93 namespace v8 { |
93 namespace internal { | 94 namespace internal { |
94 | 95 |
| 96 // Test for finite value - usually defined in math.h |
95 int isfinite(double x) { | 97 int isfinite(double x) { |
96 return _finite(x); | 98 return _finite(x); |
97 } | 99 } |
98 | 100 |
99 } // namespace v8 | 101 } // namespace v8 |
100 } // namespace internal | 102 } // namespace internal |
101 | 103 |
102 // Test for a NaN (not a number) value - usually defined in math.h | 104 // Test for a NaN (not a number) value - usually defined in math.h |
103 int isnan(double x) { | 105 int isnan(double x) { |
104 return _isnan(x); | 106 return _isnan(x); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 int signbit(double x) { | 147 int signbit(double x) { |
146 // We need to take care of the special case of both positive | 148 // We need to take care of the special case of both positive |
147 // and negative versions of zero. | 149 // and negative versions of zero. |
148 if (x == 0) | 150 if (x == 0) |
149 return _fpclass(x) & _FPCLASS_NZ; | 151 return _fpclass(x) & _FPCLASS_NZ; |
150 else | 152 else |
151 return x < 0; | 153 return x < 0; |
152 } | 154 } |
153 | 155 |
154 | 156 |
155 // Generate a pseudo-random number in the range 0-2^31-1. Usually | |
156 // defined in stdlib.h | |
157 int random() { | |
158 return rand(); | |
159 } | |
160 | |
161 | |
162 // Case-insensitive bounded string comparisons. Use stricmp() on Win32. Usually | 157 // Case-insensitive bounded string comparisons. Use stricmp() on Win32. Usually |
163 // defined in strings.h. | 158 // defined in strings.h. |
164 int strncasecmp(const char* s1, const char* s2, int n) { | 159 int strncasecmp(const char* s1, const char* s2, int n) { |
165 return _strnicmp(s1, s2, n); | 160 return _strnicmp(s1, s2, n); |
166 } | 161 } |
167 | 162 |
| 163 #endif // _MSC_VER |
| 164 |
| 165 |
| 166 // Extra functions for MinGW. Most of these are the _s functions which are in |
| 167 // the Microsoft Visual Studio C++ CRT. |
| 168 #ifdef __MINGW32__ |
| 169 |
| 170 int localtime_s(tm* out_tm, const time_t* time) { |
| 171 tm* posix_local_time_struct = localtime(time); |
| 172 if (posix_local_time_struct == NULL) return 1; |
| 173 *out_tm = *posix_local_time_struct; |
| 174 return 0; |
| 175 } |
| 176 |
| 177 |
| 178 // Not sure this the correct interpretation of _mkgmtime |
| 179 time_t _mkgmtime(tm* timeptr) { |
| 180 return mktime(timeptr); |
| 181 } |
| 182 |
| 183 |
| 184 int fopen_s(FILE** pFile, const char* filename, const char* mode) { |
| 185 *pFile = fopen(filename, mode); |
| 186 return *pFile != NULL ? 0 : 1; |
| 187 } |
| 188 |
| 189 |
| 190 int _vsnprintf_s(char* buffer, size_t sizeOfBuffer, size_t count, |
| 191 const char* format, va_list argptr) { |
| 192 return _vsnprintf(buffer, sizeOfBuffer, format, argptr); |
| 193 } |
| 194 #define _TRUNCATE 0 |
| 195 |
| 196 |
| 197 int strncpy_s(char* strDest, size_t numberOfElements, |
| 198 const char* strSource, size_t count) { |
| 199 strncpy(strDest, strSource, count); |
| 200 return 0; |
| 201 } |
| 202 |
| 203 #endif // __MINGW32__ |
| 204 |
| 205 // Generate a pseudo-random number in the range 0-2^31-1. Usually |
| 206 // defined in stdlib.h. Missing in both Microsoft Visual Studio C++ and MinGW. |
| 207 int random() { |
| 208 return rand(); |
| 209 } |
| 210 |
| 211 |
168 namespace v8 { namespace internal { | 212 namespace v8 { namespace internal { |
169 | 213 |
170 double ceiling(double x) { | 214 double ceiling(double x) { |
171 return ceil(x); | 215 return ceil(x); |
172 } | 216 } |
173 | 217 |
174 // ---------------------------------------------------------------------------- | 218 // ---------------------------------------------------------------------------- |
175 // The Time class represents time on win32. A timestamp is represented as | 219 // The Time class represents time on win32. A timestamp is represented as |
176 // a 64-bit integer in 100 nano-seconds since January 1, 1601 (UTC). JavaScript | 220 // a 64-bit integer in 100 nano-seconds since January 1, 1601 (UTC). JavaScript |
177 // timestamps are represented as a doubles in milliseconds since 00:00:00 UTC, | 221 // timestamps are represented as a doubles in milliseconds since 00:00:00 UTC, |
(...skipping 21 matching lines...) Expand all Loading... |
199 | 243 |
200 // Returns the daylight savings time offset for the time in milliseconds. | 244 // Returns the daylight savings time offset for the time in milliseconds. |
201 int64_t DaylightSavingsOffset(); | 245 int64_t DaylightSavingsOffset(); |
202 | 246 |
203 // Returns a string identifying the current timezone for the | 247 // Returns a string identifying the current timezone for the |
204 // timestamp taking into account daylight saving. | 248 // timestamp taking into account daylight saving. |
205 char* LocalTimezone(); | 249 char* LocalTimezone(); |
206 | 250 |
207 private: | 251 private: |
208 // Constants for time conversion. | 252 // Constants for time conversion. |
209 static const int64_t kTimeEpoc = 116444736000000000; | 253 static const int64_t kTimeEpoc = 116444736000000000LL; |
210 static const int64_t kTimeScaler = 10000; | 254 static const int64_t kTimeScaler = 10000; |
211 static const int64_t kMsPerMinute = 60000; | 255 static const int64_t kMsPerMinute = 60000; |
212 | 256 |
213 // Constants for timezone information. | 257 // Constants for timezone information. |
214 static const int kTzNameSize = 128; | 258 static const int kTzNameSize = 128; |
215 static const bool kShortTzNames = false; | 259 static const bool kShortTzNames = false; |
216 | 260 |
217 // Timezone information. We need to have static buffers for the | 261 // Timezone information. We need to have static buffers for the |
218 // timezone names because we return pointers to these in | 262 // timezone names because we return pointers to these in |
219 // LocalTimezone(). | 263 // LocalTimezone(). |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 } | 844 } |
801 | 845 |
802 | 846 |
803 void OS::Sleep(int milliseconds) { | 847 void OS::Sleep(int milliseconds) { |
804 ::Sleep(milliseconds); | 848 ::Sleep(milliseconds); |
805 } | 849 } |
806 | 850 |
807 | 851 |
808 void OS::Abort() { | 852 void OS::Abort() { |
809 if (!IsDebuggerPresent()) { | 853 if (!IsDebuggerPresent()) { |
| 854 #ifdef _MSC_VER |
810 // Make the MSVCRT do a silent abort. | 855 // Make the MSVCRT do a silent abort. |
811 _set_abort_behavior(0, _WRITE_ABORT_MSG); | 856 _set_abort_behavior(0, _WRITE_ABORT_MSG); |
812 _set_abort_behavior(0, _CALL_REPORTFAULT); | 857 _set_abort_behavior(0, _CALL_REPORTFAULT); |
| 858 #endif // _MSC_VER |
813 abort(); | 859 abort(); |
814 } else { | 860 } else { |
815 DebugBreak(); | 861 DebugBreak(); |
816 } | 862 } |
817 } | 863 } |
818 | 864 |
819 | 865 |
820 void OS::DebugBreak() { | 866 void OS::DebugBreak() { |
| 867 #ifdef _MSC_VER |
821 __debugbreak(); | 868 __debugbreak(); |
| 869 #else |
| 870 ::DebugBreak(); |
| 871 #endif |
822 } | 872 } |
823 | 873 |
824 | 874 |
825 class Win32MemoryMappedFile : public OS::MemoryMappedFile { | 875 class Win32MemoryMappedFile : public OS::MemoryMappedFile { |
826 public: | 876 public: |
827 Win32MemoryMappedFile(HANDLE file, HANDLE file_mapping, void* memory) | 877 Win32MemoryMappedFile(HANDLE file, HANDLE file_mapping, void* memory) |
828 : file_(file), file_mapping_(file_mapping), memory_(memory) { } | 878 : file_(file), file_mapping_(file_mapping), memory_(memory) { } |
829 virtual ~Win32MemoryMappedFile(); | 879 virtual ~Win32MemoryMappedFile(); |
830 virtual void* memory() { return memory_; } | 880 virtual void* memory() { return memory_; } |
831 private: | 881 private: |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 // definitions are copied from DbgHelp.h and TlHelp32.h. The IN and VOID macros | 944 // definitions are copied from DbgHelp.h and TlHelp32.h. The IN and VOID macros |
895 // from the Windows include files are redefined here to have the function | 945 // from the Windows include files are redefined here to have the function |
896 // definitions to be as close to the ones in the original .h files as possible. | 946 // definitions to be as close to the ones in the original .h files as possible. |
897 #ifndef IN | 947 #ifndef IN |
898 #define IN | 948 #define IN |
899 #endif | 949 #endif |
900 #ifndef VOID | 950 #ifndef VOID |
901 #define VOID void | 951 #define VOID void |
902 #endif | 952 #endif |
903 | 953 |
| 954 // DbgHelp isn't supported on MinGW yet |
| 955 #ifndef __MINGW32__ |
904 // DbgHelp.h functions. | 956 // DbgHelp.h functions. |
905 typedef BOOL (__stdcall *DLL_FUNC_TYPE(SymInitialize))(IN HANDLE hProcess, | 957 typedef BOOL (__stdcall *DLL_FUNC_TYPE(SymInitialize))(IN HANDLE hProcess, |
906 IN PSTR UserSearchPath, | 958 IN PSTR UserSearchPath, |
907 IN BOOL fInvadeProcess); | 959 IN BOOL fInvadeProcess); |
908 typedef DWORD (__stdcall *DLL_FUNC_TYPE(SymGetOptions))(VOID); | 960 typedef DWORD (__stdcall *DLL_FUNC_TYPE(SymGetOptions))(VOID); |
909 typedef DWORD (__stdcall *DLL_FUNC_TYPE(SymSetOptions))(IN DWORD SymOptions); | 961 typedef DWORD (__stdcall *DLL_FUNC_TYPE(SymSetOptions))(IN DWORD SymOptions); |
910 typedef BOOL (__stdcall *DLL_FUNC_TYPE(SymGetSearchPath))( | 962 typedef BOOL (__stdcall *DLL_FUNC_TYPE(SymGetSearchPath))( |
911 IN HANDLE hProcess, | 963 IN HANDLE hProcess, |
912 OUT PSTR SearchPath, | 964 OUT PSTR SearchPath, |
913 IN DWORD SearchPathLength); | 965 IN DWORD SearchPathLength); |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1216 frames_count++; | 1268 frames_count++; |
1217 } | 1269 } |
1218 | 1270 |
1219 // Return the number of frames filled in. | 1271 // Return the number of frames filled in. |
1220 return frames_count; | 1272 return frames_count; |
1221 } | 1273 } |
1222 | 1274 |
1223 // Restore warnings to previous settings. | 1275 // Restore warnings to previous settings. |
1224 #pragma warning(pop) | 1276 #pragma warning(pop) |
1225 | 1277 |
| 1278 #else // __MINGW32__ |
| 1279 void OS::LogSharedLibraryAddresses() { } |
| 1280 int OS::StackWalk(OS::StackFrame* frames, int frames_size) { return 0; } |
| 1281 #endif // __MINGW32__ |
| 1282 |
1226 | 1283 |
1227 double OS::nan_value() { | 1284 double OS::nan_value() { |
| 1285 #ifdef _MSC_VER |
1228 static const __int64 nanval = 0xfff8000000000000; | 1286 static const __int64 nanval = 0xfff8000000000000; |
1229 return *reinterpret_cast<const double*>(&nanval); | 1287 return *reinterpret_cast<const double*>(&nanval); |
| 1288 #else // _MSC_VER |
| 1289 return NAN; |
| 1290 #endif // _MSC_VER |
1230 } | 1291 } |
1231 | 1292 |
1232 | 1293 |
1233 int OS::ActivationFrameAlignment() { | 1294 int OS::ActivationFrameAlignment() { |
1234 // No constraint on Windows. | 1295 // No constraint on Windows. |
1235 return 0; | 1296 return 0; |
1236 } | 1297 } |
1237 | 1298 |
1238 | 1299 |
1239 bool VirtualMemory::IsReserved() { | 1300 bool VirtualMemory::IsReserved() { |
(...skipping 20 matching lines...) Expand all Loading... |
1260 return false; | 1321 return false; |
1261 } | 1322 } |
1262 | 1323 |
1263 UpdateAllocatedSpaceLimits(address, size); | 1324 UpdateAllocatedSpaceLimits(address, size); |
1264 return true; | 1325 return true; |
1265 } | 1326 } |
1266 | 1327 |
1267 | 1328 |
1268 bool VirtualMemory::Uncommit(void* address, size_t size) { | 1329 bool VirtualMemory::Uncommit(void* address, size_t size) { |
1269 ASSERT(IsReserved()); | 1330 ASSERT(IsReserved()); |
1270 return VirtualFree(address, size, MEM_DECOMMIT) != NULL; | 1331 return VirtualFree(address, size, MEM_DECOMMIT) != FALSE; |
1271 } | 1332 } |
1272 | 1333 |
1273 | 1334 |
1274 // ---------------------------------------------------------------------------- | 1335 // ---------------------------------------------------------------------------- |
1275 // Win32 thread support. | 1336 // Win32 thread support. |
1276 | 1337 |
1277 // Definition of invalid thread handle and id. | 1338 // Definition of invalid thread handle and id. |
1278 static const HANDLE kNoThread = INVALID_HANDLE_VALUE; | 1339 static const HANDLE kNoThread = INVALID_HANDLE_VALUE; |
1279 static const DWORD kNoThreadId = 0; | 1340 static const DWORD kNoThreadId = 0; |
1280 | 1341 |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1595 | 1656 |
1596 // Release the thread handles | 1657 // Release the thread handles |
1597 CloseHandle(data_->sampler_thread_); | 1658 CloseHandle(data_->sampler_thread_); |
1598 CloseHandle(data_->profiled_thread_); | 1659 CloseHandle(data_->profiled_thread_); |
1599 } | 1660 } |
1600 | 1661 |
1601 | 1662 |
1602 #endif // ENABLE_LOGGING_AND_PROFILING | 1663 #endif // ENABLE_LOGGING_AND_PROFILING |
1603 | 1664 |
1604 } } // namespace v8::internal | 1665 } } // namespace v8::internal |
OLD | NEW |