Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(376)

Side by Side Diff: src/base/platform/platform-win32.cc

Issue 358363002: Move platform abstraction to base library (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: updates Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #ifdef _MSC_VER
19 #include <limits>
20 #endif
21
18 #include "src/base/win32-headers.h" 22 #include "src/base/win32-headers.h"
19 23
20 #include "src/base/lazy-instance.h" 24 #include "src/base/lazy-instance.h"
21 #include "src/platform.h" 25 #include "src/base/macros.h"
22 #include "src/platform/time.h" 26 #include "src/base/platform/platform.h"
23 #include "src/utils.h" 27 #include "src/base/platform/time.h"
24 #include "src/utils/random-number-generator.h" 28 #include "src/base/utils/random-number-generator.h"
25 29
26 #ifdef _MSC_VER 30 #ifdef _MSC_VER
27 31
28 // Case-insensitive bounded string comparisons. Use stricmp() on Win32. Usually 32 // Case-insensitive bounded string comparisons. Use stricmp() on Win32. Usually
29 // defined in strings.h. 33 // defined in strings.h.
30 int strncasecmp(const char* s1, const char* s2, int n) { 34 int strncasecmp(const char* s1, const char* s2, int n) {
31 return _strnicmp(s1, s2, n); 35 return _strnicmp(s1, s2, n);
32 } 36 }
33 37
34 #endif // _MSC_VER 38 #endif // _MSC_VER
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 } 98 }
95 } 99 }
96 CHECK_GT(dest_size, 0); 100 CHECK_GT(dest_size, 0);
97 *dest = 0; 101 *dest = 0;
98 return 0; 102 return 0;
99 } 103 }
100 104
101 #endif // __MINGW32__ 105 #endif // __MINGW32__
102 106
103 namespace v8 { 107 namespace v8 {
104 namespace internal { 108 namespace base {
105 109
106 namespace { 110 namespace {
107 111
108 bool g_hard_abort = false; 112 bool g_hard_abort = false;
109 113
110 } // namespace 114 } // namespace
111 115
112 intptr_t OS::MaxVirtualMemory() { 116 intptr_t OS::MaxVirtualMemory() {
113 return 0; 117 return 0;
114 } 118 }
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 static size_t allocate_alignment = 0; 712 static size_t allocate_alignment = 0;
709 if (allocate_alignment == 0) { 713 if (allocate_alignment == 0) {
710 SYSTEM_INFO info; 714 SYSTEM_INFO info;
711 GetSystemInfo(&info); 715 GetSystemInfo(&info);
712 allocate_alignment = info.dwAllocationGranularity; 716 allocate_alignment = info.dwAllocationGranularity;
713 } 717 }
714 return allocate_alignment; 718 return allocate_alignment;
715 } 719 }
716 720
717 721
718 static base::LazyInstance<RandomNumberGenerator>::type 722 static LazyInstance<RandomNumberGenerator>::type
719 platform_random_number_generator = LAZY_INSTANCE_INITIALIZER; 723 platform_random_number_generator = LAZY_INSTANCE_INITIALIZER;
720 724
721 725
722 void OS::Initialize(int64_t random_seed, bool hard_abort, 726 void OS::Initialize(int64_t random_seed, bool hard_abort,
723 const char* const gc_fake_mmap) { 727 const char* const gc_fake_mmap) {
724 if (random_seed) { 728 if (random_seed) {
725 platform_random_number_generator.Pointer()->SetSeed(random_seed); 729 platform_random_number_generator.Pointer()->SetSeed(random_seed);
726 } 730 }
727 g_hard_abort = hard_abort; 731 g_hard_abort = hard_abort;
728 } 732 }
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 // Open a physical file 887 // Open a physical file
884 HANDLE file = CreateFileA(name, GENERIC_READ | GENERIC_WRITE, 888 HANDLE file = CreateFileA(name, GENERIC_READ | GENERIC_WRITE,
885 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, 0, NULL); 889 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, 0, NULL);
886 if (file == NULL) return NULL; 890 if (file == NULL) return NULL;
887 // Create a file mapping for the physical file 891 // Create a file mapping for the physical file
888 HANDLE file_mapping = CreateFileMapping(file, NULL, 892 HANDLE file_mapping = CreateFileMapping(file, NULL,
889 PAGE_READWRITE, 0, static_cast<DWORD>(size), NULL); 893 PAGE_READWRITE, 0, static_cast<DWORD>(size), NULL);
890 if (file_mapping == NULL) return NULL; 894 if (file_mapping == NULL) return NULL;
891 // Map a view of the file into memory 895 // Map a view of the file into memory
892 void* memory = MapViewOfFile(file_mapping, FILE_MAP_ALL_ACCESS, 0, 0, size); 896 void* memory = MapViewOfFile(file_mapping, FILE_MAP_ALL_ACCESS, 0, 0, size);
893 if (memory) MemMove(memory, initial, size); 897 if (memory) memmove(memory, initial, size);
894 return new Win32MemoryMappedFile(file, file_mapping, memory, size); 898 return new Win32MemoryMappedFile(file, file_mapping, memory, size);
895 } 899 }
896 900
897 901
898 Win32MemoryMappedFile::~Win32MemoryMappedFile() { 902 Win32MemoryMappedFile::~Win32MemoryMappedFile() {
899 if (memory_ != NULL) 903 if (memory_ != NULL)
900 UnmapViewOfFile(memory_); 904 UnmapViewOfFile(memory_);
901 CloseHandle(file_mapping_); 905 CloseHandle(file_mapping_);
902 CloseHandle(file_); 906 CloseHandle(file_);
903 } 907 }
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 1093
1090 DWORD options = _SymGetOptions(); 1094 DWORD options = _SymGetOptions();
1091 options |= SYMOPT_LOAD_LINES; 1095 options |= SYMOPT_LOAD_LINES;
1092 options |= SYMOPT_FAIL_CRITICAL_ERRORS; 1096 options |= SYMOPT_FAIL_CRITICAL_ERRORS;
1093 options = _SymSetOptions(options); 1097 options = _SymSetOptions(options);
1094 1098
1095 char buf[OS::kStackWalkMaxNameLen] = {0}; 1099 char buf[OS::kStackWalkMaxNameLen] = {0};
1096 ok = _SymGetSearchPath(process_handle, buf, OS::kStackWalkMaxNameLen); 1100 ok = _SymGetSearchPath(process_handle, buf, OS::kStackWalkMaxNameLen);
1097 if (!ok) { 1101 if (!ok) {
1098 int err = GetLastError(); 1102 int err = GetLastError();
1099 PrintF("%d\n", err); 1103 OS::Print("%d\n", err);
1100 return result; 1104 return result;
1101 } 1105 }
1102 1106
1103 HANDLE snapshot = _CreateToolhelp32Snapshot( 1107 HANDLE snapshot = _CreateToolhelp32Snapshot(
1104 TH32CS_SNAPMODULE, // dwFlags 1108 TH32CS_SNAPMODULE, // dwFlags
1105 GetCurrentProcessId()); // th32ProcessId 1109 GetCurrentProcessId()); // th32ProcessId
1106 if (snapshot == INVALID_HANDLE_VALUE) return result; 1110 if (snapshot == INVALID_HANDLE_VALUE) return result;
1107 MODULEENTRY32W module_entry; 1111 MODULEENTRY32W module_entry;
1108 module_entry.dwSize = sizeof(module_entry); // Set the size of the structure. 1112 module_entry.dwSize = sizeof(module_entry); // Set the size of the structure.
1109 BOOL cont = _Module32FirstW(snapshot, &module_entry); 1113 BOOL cont = _Module32FirstW(snapshot, &module_entry);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 1187
1184 int OS::NumberOfProcessorsOnline() { 1188 int OS::NumberOfProcessorsOnline() {
1185 SYSTEM_INFO info; 1189 SYSTEM_INFO info;
1186 GetSystemInfo(&info); 1190 GetSystemInfo(&info);
1187 return info.dwNumberOfProcessors; 1191 return info.dwNumberOfProcessors;
1188 } 1192 }
1189 1193
1190 1194
1191 double OS::nan_value() { 1195 double OS::nan_value() {
1192 #ifdef _MSC_VER 1196 #ifdef _MSC_VER
1193 // Positive Quiet NaN with no payload (aka. Indeterminate) has all bits 1197 return std::numeric_limits<double>::quiet_NaN();
1194 // in mask set, so value equals mask.
1195 static const __int64 nanval = kQuietNaNMask;
1196 return *reinterpret_cast<const double*>(&nanval);
1197 #else // _MSC_VER 1198 #else // _MSC_VER
1198 return NAN; 1199 return NAN;
1199 #endif // _MSC_VER 1200 #endif // _MSC_VER
1200 } 1201 }
1201 1202
1202 1203
1203 int OS::ActivationFrameAlignment() { 1204 int OS::ActivationFrameAlignment() {
1204 #ifdef _WIN64 1205 #ifdef _WIN64
1205 return 16; // Windows 64-bit ABI requires the stack to be 16-byte aligned. 1206 return 16; // Windows 64-bit ABI requires the stack to be 16-byte aligned.
1206 #elif defined(__MINGW32__) 1207 #elif defined(__MINGW32__)
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1413 USE(result); 1414 USE(result);
1414 ASSERT(result); 1415 ASSERT(result);
1415 } 1416 }
1416 1417
1417 1418
1418 1419
1419 void Thread::YieldCPU() { 1420 void Thread::YieldCPU() {
1420 Sleep(0); 1421 Sleep(0);
1421 } 1422 }
1422 1423
1423 } } // namespace v8::internal 1424 } } // namespace v8::base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698