| Index: src/platform-win32.cc
|
| ===================================================================
|
| --- src/platform-win32.cc (revision 6353)
|
| +++ src/platform-win32.cc (working copy)
|
| @@ -670,6 +670,11 @@
|
| }
|
|
|
|
|
| +bool OS::Remove(const char* path) {
|
| + return (DeleteFile(path) != 0);
|
| +}
|
| +
|
| +
|
| // Open log file in binary mode to avoid /n -> /r/n conversion.
|
| const char* OS::LogFileOpenMode = "wb";
|
|
|
| @@ -911,17 +916,44 @@
|
|
|
| class Win32MemoryMappedFile : public OS::MemoryMappedFile {
|
| public:
|
| - Win32MemoryMappedFile(HANDLE file, HANDLE file_mapping, void* memory)
|
| - : file_(file), file_mapping_(file_mapping), memory_(memory) { }
|
| + Win32MemoryMappedFile(HANDLE file,
|
| + HANDLE file_mapping,
|
| + void* memory,
|
| + int size)
|
| + : file_(file),
|
| + file_mapping_(file_mapping),
|
| + memory_(memory),
|
| + size_(size) { }
|
| virtual ~Win32MemoryMappedFile();
|
| virtual void* memory() { return memory_; }
|
| + virtual void* size() { return size_; }
|
| private:
|
| HANDLE file_;
|
| HANDLE file_mapping_;
|
| void* memory_;
|
| + int size_;
|
| };
|
|
|
|
|
| +OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
|
| + // Open a physical file
|
| + HANDLE file = CreateFileA(name, GENERIC_READ | GENERIC_WRITE,
|
| + FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
|
| + if (file == NULL) return NULL;
|
| +
|
| + int size = static_cast<int>(GetFileSize(file, NULL));
|
| +
|
| + // Create a file mapping for the physical file
|
| + HANDLE file_mapping = CreateFileMapping(file, NULL,
|
| + PAGE_READWRITE, 0, static_cast<DWORD>(size), NULL);
|
| + if (file_mapping == NULL) return NULL;
|
| +
|
| + // Map a view of the file into memory
|
| + void* memory = MapViewOfFile(file_mapping, FILE_MAP_ALL_ACCESS, 0, 0, size);
|
| + return new Win32MemoryMappedFile(file, file_mapping, memory, size);
|
| +}
|
| +
|
| +
|
| OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
|
| void* initial) {
|
| // Open a physical file
|
| @@ -935,7 +967,7 @@
|
| // Map a view of the file into memory
|
| void* memory = MapViewOfFile(file_mapping, FILE_MAP_ALL_ACCESS, 0, 0, size);
|
| if (memory) memmove(memory, initial, size);
|
| - return new Win32MemoryMappedFile(file, file_mapping, memory);
|
| + return new Win32MemoryMappedFile(file, file_mapping, memory, size);
|
| }
|
|
|
|
|
|
|