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* _tm, const time_t* time) { |
| 171 tm * posix_local_time_struct = localtime(time); |
| 172 if (posix_local_time_struct == NULL) return 1; |
| 173 *_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 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 } | 842 } |
799 | 843 |
800 | 844 |
801 void OS::Sleep(int milliseconds) { | 845 void OS::Sleep(int milliseconds) { |
802 ::Sleep(milliseconds); | 846 ::Sleep(milliseconds); |
803 } | 847 } |
804 | 848 |
805 | 849 |
806 void OS::Abort() { | 850 void OS::Abort() { |
807 if (!IsDebuggerPresent()) { | 851 if (!IsDebuggerPresent()) { |
| 852 #ifdef _MSC_VER |
808 // Make the MSVCRT do a silent abort. | 853 // Make the MSVCRT do a silent abort. |
809 _set_abort_behavior(0, _WRITE_ABORT_MSG); | 854 _set_abort_behavior(0, _WRITE_ABORT_MSG); |
810 _set_abort_behavior(0, _CALL_REPORTFAULT); | 855 _set_abort_behavior(0, _CALL_REPORTFAULT); |
| 856 #endif // _MSC_VER |
811 abort(); | 857 abort(); |
812 } else { | 858 } else { |
813 DebugBreak(); | 859 DebugBreak(); |
814 } | 860 } |
815 } | 861 } |
816 | 862 |
817 | 863 |
818 void OS::DebugBreak() { | 864 void OS::DebugBreak() { |
| 865 #ifdef _MSC_VER |
819 __debugbreak(); | 866 __debugbreak(); |
| 867 #else |
| 868 ::DebugBreak(); |
| 869 #endif |
820 } | 870 } |
821 | 871 |
822 | 872 |
823 class Win32MemoryMappedFile : public OS::MemoryMappedFile { | 873 class Win32MemoryMappedFile : public OS::MemoryMappedFile { |
824 public: | 874 public: |
825 Win32MemoryMappedFile(HANDLE file, HANDLE file_mapping, void* memory) | 875 Win32MemoryMappedFile(HANDLE file, HANDLE file_mapping, void* memory) |
826 : file_(file), file_mapping_(file_mapping), memory_(memory) { } | 876 : file_(file), file_mapping_(file_mapping), memory_(memory) { } |
827 virtual ~Win32MemoryMappedFile(); | 877 virtual ~Win32MemoryMappedFile(); |
828 virtual void* memory() { return memory_; } | 878 virtual void* memory() { return memory_; } |
829 private: | 879 private: |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 // definitions are copied from DbgHelp.h and TlHelp32.h. The IN and VOID macros | 942 // definitions are copied from DbgHelp.h and TlHelp32.h. The IN and VOID macros |
893 // from the Windows include files are redefined here to have the function | 943 // from the Windows include files are redefined here to have the function |
894 // definitions to be as close to the ones in the original .h files as possible. | 944 // definitions to be as close to the ones in the original .h files as possible. |
895 #ifndef IN | 945 #ifndef IN |
896 #define IN | 946 #define IN |
897 #endif | 947 #endif |
898 #ifndef VOID | 948 #ifndef VOID |
899 #define VOID void | 949 #define VOID void |
900 #endif | 950 #endif |
901 | 951 |
| 952 // DbgHelp isn't supported on MinGW yet |
| 953 #ifndef __MINGW32__ |
902 // DbgHelp.h functions. | 954 // DbgHelp.h functions. |
903 typedef BOOL (__stdcall *DLL_FUNC_TYPE(SymInitialize))(IN HANDLE hProcess, | 955 typedef BOOL (__stdcall *DLL_FUNC_TYPE(SymInitialize))(IN HANDLE hProcess, |
904 IN PSTR UserSearchPath, | 956 IN PSTR UserSearchPath, |
905 IN BOOL fInvadeProcess); | 957 IN BOOL fInvadeProcess); |
906 typedef DWORD (__stdcall *DLL_FUNC_TYPE(SymGetOptions))(VOID); | 958 typedef DWORD (__stdcall *DLL_FUNC_TYPE(SymGetOptions))(VOID); |
907 typedef DWORD (__stdcall *DLL_FUNC_TYPE(SymSetOptions))(IN DWORD SymOptions); | 959 typedef DWORD (__stdcall *DLL_FUNC_TYPE(SymSetOptions))(IN DWORD SymOptions); |
908 typedef BOOL (__stdcall *DLL_FUNC_TYPE(SymGetSearchPath))( | 960 typedef BOOL (__stdcall *DLL_FUNC_TYPE(SymGetSearchPath))( |
909 IN HANDLE hProcess, | 961 IN HANDLE hProcess, |
910 OUT PSTR SearchPath, | 962 OUT PSTR SearchPath, |
911 IN DWORD SearchPathLength); | 963 IN DWORD SearchPathLength); |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1214 frames_count++; | 1266 frames_count++; |
1215 } | 1267 } |
1216 | 1268 |
1217 // Return the number of frames filled in. | 1269 // Return the number of frames filled in. |
1218 return frames_count; | 1270 return frames_count; |
1219 } | 1271 } |
1220 | 1272 |
1221 // Restore warnings to previous settings. | 1273 // Restore warnings to previous settings. |
1222 #pragma warning(pop) | 1274 #pragma warning(pop) |
1223 | 1275 |
| 1276 #else // __MINGW32__ |
| 1277 void OS::LogSharedLibraryAddresses() { } |
| 1278 int OS::StackWalk(OS::StackFrame* frames, int frames_size) { return 0; } |
| 1279 #endif // __MINGW32__ |
| 1280 |
1224 | 1281 |
1225 double OS::nan_value() { | 1282 double OS::nan_value() { |
| 1283 #ifdef _MSC_VER |
1226 static const __int64 nanval = 0xfff8000000000000; | 1284 static const __int64 nanval = 0xfff8000000000000; |
1227 return *reinterpret_cast<const double*>(&nanval); | 1285 return *reinterpret_cast<const double*>(&nanval); |
| 1286 #else // _MSC_VER |
| 1287 return NAN; |
| 1288 #endif // _MSC_VER |
1228 } | 1289 } |
1229 | 1290 |
1230 | 1291 |
1231 int OS::ActivationFrameAlignment() { | 1292 int OS::ActivationFrameAlignment() { |
1232 // No constraint on Windows. | 1293 // No constraint on Windows. |
1233 return 0; | 1294 return 0; |
1234 } | 1295 } |
1235 | 1296 |
1236 | 1297 |
1237 bool VirtualMemory::IsReserved() { | 1298 bool VirtualMemory::IsReserved() { |
(...skipping 20 matching lines...) Expand all Loading... |
1258 return false; | 1319 return false; |
1259 } | 1320 } |
1260 | 1321 |
1261 UpdateAllocatedSpaceLimits(address, size); | 1322 UpdateAllocatedSpaceLimits(address, size); |
1262 return true; | 1323 return true; |
1263 } | 1324 } |
1264 | 1325 |
1265 | 1326 |
1266 bool VirtualMemory::Uncommit(void* address, size_t size) { | 1327 bool VirtualMemory::Uncommit(void* address, size_t size) { |
1267 ASSERT(IsReserved()); | 1328 ASSERT(IsReserved()); |
1268 return VirtualFree(address, size, MEM_DECOMMIT) != NULL; | 1329 return VirtualFree(address, size, MEM_DECOMMIT) != FALSE; |
1269 } | 1330 } |
1270 | 1331 |
1271 | 1332 |
1272 // ---------------------------------------------------------------------------- | 1333 // ---------------------------------------------------------------------------- |
1273 // Win32 thread support. | 1334 // Win32 thread support. |
1274 | 1335 |
1275 // Definition of invalid thread handle and id. | 1336 // Definition of invalid thread handle and id. |
1276 static const HANDLE kNoThread = INVALID_HANDLE_VALUE; | 1337 static const HANDLE kNoThread = INVALID_HANDLE_VALUE; |
1277 static const DWORD kNoThreadId = 0; | 1338 static const DWORD kNoThreadId = 0; |
1278 | 1339 |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1593 | 1654 |
1594 // Release the thread handles | 1655 // Release the thread handles |
1595 CloseHandle(data_->sampler_thread_); | 1656 CloseHandle(data_->sampler_thread_); |
1596 CloseHandle(data_->profiled_thread_); | 1657 CloseHandle(data_->profiled_thread_); |
1597 } | 1658 } |
1598 | 1659 |
1599 | 1660 |
1600 #endif // ENABLE_LOGGING_AND_PROFILING | 1661 #endif // ENABLE_LOGGING_AND_PROFILING |
1601 | 1662 |
1602 } } // namespace v8::internal | 1663 } } // namespace v8::internal |
OLD | NEW |