| 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 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 FILE* OS::FOpen(const char* path, const char* mode) { | 668 FILE* OS::FOpen(const char* path, const char* mode) { |
| 669 FILE* result; | 669 FILE* result; |
| 670 if (fopen_s(&result, path, mode) == 0) { | 670 if (fopen_s(&result, path, mode) == 0) { |
| 671 return result; | 671 return result; |
| 672 } else { | 672 } else { |
| 673 return NULL; | 673 return NULL; |
| 674 } | 674 } |
| 675 } | 675 } |
| 676 | 676 |
| 677 | 677 |
| 678 bool OS::Remove(const char* path) { |
| 679 return (DeleteFileA(path) != 0); |
| 680 } |
| 681 |
| 682 |
| 678 // Open log file in binary mode to avoid /n -> /r/n conversion. | 683 // Open log file in binary mode to avoid /n -> /r/n conversion. |
| 679 const char* const OS::LogFileOpenMode = "wb"; | 684 const char* const OS::LogFileOpenMode = "wb"; |
| 680 | 685 |
| 681 | 686 |
| 682 // Print (debug) message to console. | 687 // Print (debug) message to console. |
| 683 void OS::Print(const char* format, ...) { | 688 void OS::Print(const char* format, ...) { |
| 684 va_list args; | 689 va_list args; |
| 685 va_start(args, format); | 690 va_start(args, format); |
| 686 VPrint(format, args); | 691 VPrint(format, args); |
| 687 va_end(args); | 692 va_end(args); |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 #ifdef _MSC_VER | 917 #ifdef _MSC_VER |
| 913 __debugbreak(); | 918 __debugbreak(); |
| 914 #else | 919 #else |
| 915 ::DebugBreak(); | 920 ::DebugBreak(); |
| 916 #endif | 921 #endif |
| 917 } | 922 } |
| 918 | 923 |
| 919 | 924 |
| 920 class Win32MemoryMappedFile : public OS::MemoryMappedFile { | 925 class Win32MemoryMappedFile : public OS::MemoryMappedFile { |
| 921 public: | 926 public: |
| 922 Win32MemoryMappedFile(HANDLE file, HANDLE file_mapping, void* memory) | 927 Win32MemoryMappedFile(HANDLE file, |
| 923 : file_(file), file_mapping_(file_mapping), memory_(memory) { } | 928 HANDLE file_mapping, |
| 929 void* memory, |
| 930 int size) |
| 931 : file_(file), |
| 932 file_mapping_(file_mapping), |
| 933 memory_(memory), |
| 934 size_(size) { } |
| 924 virtual ~Win32MemoryMappedFile(); | 935 virtual ~Win32MemoryMappedFile(); |
| 925 virtual void* memory() { return memory_; } | 936 virtual void* memory() { return memory_; } |
| 937 virtual int size() { return size_; } |
| 926 private: | 938 private: |
| 927 HANDLE file_; | 939 HANDLE file_; |
| 928 HANDLE file_mapping_; | 940 HANDLE file_mapping_; |
| 929 void* memory_; | 941 void* memory_; |
| 942 int size_; |
| 930 }; | 943 }; |
| 931 | 944 |
| 932 | 945 |
| 946 OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) { |
| 947 // Open a physical file |
| 948 HANDLE file = CreateFileA(name, GENERIC_READ | GENERIC_WRITE, |
| 949 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); |
| 950 if (file == NULL) return NULL; |
| 951 |
| 952 int size = static_cast<int>(GetFileSize(file, NULL)); |
| 953 |
| 954 // Create a file mapping for the physical file |
| 955 HANDLE file_mapping = CreateFileMapping(file, NULL, |
| 956 PAGE_READWRITE, 0, static_cast<DWORD>(size), NULL); |
| 957 if (file_mapping == NULL) return NULL; |
| 958 |
| 959 // Map a view of the file into memory |
| 960 void* memory = MapViewOfFile(file_mapping, FILE_MAP_ALL_ACCESS, 0, 0, size); |
| 961 return new Win32MemoryMappedFile(file, file_mapping, memory, size); |
| 962 } |
| 963 |
| 964 |
| 933 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size, | 965 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size, |
| 934 void* initial) { | 966 void* initial) { |
| 935 // Open a physical file | 967 // Open a physical file |
| 936 HANDLE file = CreateFileA(name, GENERIC_READ | GENERIC_WRITE, | 968 HANDLE file = CreateFileA(name, GENERIC_READ | GENERIC_WRITE, |
| 937 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, 0, NULL); | 969 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, 0, NULL); |
| 938 if (file == NULL) return NULL; | 970 if (file == NULL) return NULL; |
| 939 // Create a file mapping for the physical file | 971 // Create a file mapping for the physical file |
| 940 HANDLE file_mapping = CreateFileMapping(file, NULL, | 972 HANDLE file_mapping = CreateFileMapping(file, NULL, |
| 941 PAGE_READWRITE, 0, static_cast<DWORD>(size), NULL); | 973 PAGE_READWRITE, 0, static_cast<DWORD>(size), NULL); |
| 942 if (file_mapping == NULL) return NULL; | 974 if (file_mapping == NULL) return NULL; |
| 943 // Map a view of the file into memory | 975 // Map a view of the file into memory |
| 944 void* memory = MapViewOfFile(file_mapping, FILE_MAP_ALL_ACCESS, 0, 0, size); | 976 void* memory = MapViewOfFile(file_mapping, FILE_MAP_ALL_ACCESS, 0, 0, size); |
| 945 if (memory) memmove(memory, initial, size); | 977 if (memory) memmove(memory, initial, size); |
| 946 return new Win32MemoryMappedFile(file, file_mapping, memory); | 978 return new Win32MemoryMappedFile(file, file_mapping, memory, size); |
| 947 } | 979 } |
| 948 | 980 |
| 949 | 981 |
| 950 Win32MemoryMappedFile::~Win32MemoryMappedFile() { | 982 Win32MemoryMappedFile::~Win32MemoryMappedFile() { |
| 951 if (memory_ != NULL) | 983 if (memory_ != NULL) |
| 952 UnmapViewOfFile(memory_); | 984 UnmapViewOfFile(memory_); |
| 953 CloseHandle(file_mapping_); | 985 CloseHandle(file_mapping_); |
| 954 CloseHandle(file_); | 986 CloseHandle(file_); |
| 955 } | 987 } |
| 956 | 988 |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1480 | 1512 |
| 1481 Thread::Thread(Isolate* isolate, const char* name) | 1513 Thread::Thread(Isolate* isolate, const char* name) |
| 1482 : ThreadHandle(ThreadHandle::INVALID), | 1514 : ThreadHandle(ThreadHandle::INVALID), |
| 1483 isolate_(isolate) { | 1515 isolate_(isolate) { |
| 1484 data_ = new PlatformData(kNoThread); | 1516 data_ = new PlatformData(kNoThread); |
| 1485 set_name(name); | 1517 set_name(name); |
| 1486 } | 1518 } |
| 1487 | 1519 |
| 1488 | 1520 |
| 1489 void Thread::set_name(const char* name) { | 1521 void Thread::set_name(const char* name) { |
| 1490 strncpy_s(name_, name, sizeof(name_)); | 1522 OS::StrNCpy(Vector<char>(name_, sizeof(name_)), name, strlen(name)); |
| 1491 name_[sizeof(name_) - 1] = '\0'; | 1523 name_[sizeof(name_) - 1] = '\0'; |
| 1492 } | 1524 } |
| 1493 | 1525 |
| 1494 | 1526 |
| 1495 // Close our own handle for the thread. | 1527 // Close our own handle for the thread. |
| 1496 Thread::~Thread() { | 1528 Thread::~Thread() { |
| 1497 if (data_->thread_ != kNoThread) CloseHandle(data_->thread_); | 1529 if (data_->thread_ != kNoThread) CloseHandle(data_->thread_); |
| 1498 delete data_; | 1530 delete data_; |
| 1499 } | 1531 } |
| 1500 | 1532 |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1986 | 2018 |
| 1987 void Sampler::Stop() { | 2019 void Sampler::Stop() { |
| 1988 ASSERT(IsActive()); | 2020 ASSERT(IsActive()); |
| 1989 SamplerThread::RemoveActiveSampler(this); | 2021 SamplerThread::RemoveActiveSampler(this); |
| 1990 SetActive(false); | 2022 SetActive(false); |
| 1991 } | 2023 } |
| 1992 | 2024 |
| 1993 #endif // ENABLE_LOGGING_AND_PROFILING | 2025 #endif // ENABLE_LOGGING_AND_PROFILING |
| 1994 | 2026 |
| 1995 } } // namespace v8::internal | 2027 } } // namespace v8::internal |
| OLD | NEW |