| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
| 6 #if defined(TARGET_OS_WINDOWS) | 6 #if defined(TARGET_OS_WINDOWS) |
| 7 | 7 |
| 8 #include "bin/file.h" | 8 #include "bin/file.h" |
| 9 | 9 |
| 10 #include <fcntl.h> // NOLINT | 10 #include <fcntl.h> // NOLINT |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 intptr_t File::GetFD() { | 68 intptr_t File::GetFD() { |
| 69 return handle_->fd(); | 69 return handle_->fd(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 | 72 |
| 73 bool File::IsClosed() { | 73 bool File::IsClosed() { |
| 74 return handle_->fd() == kClosedFd; | 74 return handle_->fd() == kClosedFd; |
| 75 } | 75 } |
| 76 | 76 |
| 77 | 77 |
| 78 void* File::Map(File::MapType type, int64_t position, int64_t length) { | 78 MappedMemory* File::Map(File::MapType type, int64_t position, int64_t length) { |
| 79 DWORD prot_alloc; | 79 DWORD prot_alloc; |
| 80 DWORD prot_final; | 80 DWORD prot_final; |
| 81 switch (type) { | 81 switch (type) { |
| 82 case File::kReadOnly: | 82 case File::kReadOnly: |
| 83 prot_alloc = PAGE_READWRITE; | 83 prot_alloc = PAGE_READWRITE; |
| 84 prot_final = PAGE_READONLY; | 84 prot_final = PAGE_READONLY; |
| 85 break; | 85 break; |
| 86 case File::kReadExecute: | 86 case File::kReadExecute: |
| 87 prot_alloc = PAGE_EXECUTE_READWRITE; | 87 prot_alloc = PAGE_EXECUTE_READWRITE; |
| 88 prot_final = PAGE_EXECUTE_READ; | 88 prot_final = PAGE_EXECUTE_READ; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 104 return NULL; | 104 return NULL; |
| 105 } | 105 } |
| 106 | 106 |
| 107 DWORD old_prot; | 107 DWORD old_prot; |
| 108 bool result = VirtualProtect(addr, length, prot_final, &old_prot); | 108 bool result = VirtualProtect(addr, length, prot_final, &old_prot); |
| 109 if (!result) { | 109 if (!result) { |
| 110 Log::PrintErr("VirtualProtect failed %d\n", GetLastError()); | 110 Log::PrintErr("VirtualProtect failed %d\n", GetLastError()); |
| 111 VirtualFree(addr, 0, MEM_RELEASE); | 111 VirtualFree(addr, 0, MEM_RELEASE); |
| 112 return NULL; | 112 return NULL; |
| 113 } | 113 } |
| 114 return addr; | 114 return new MappedMemory(addr, length); |
| 115 } | 115 } |
| 116 | 116 |
| 117 | 117 |
| 118 void MappedMemory::Unmap() { |
| 119 bool result = VirtualFree(address_, size_, MEM_RELEASE); |
| 120 ASSERT(result); |
| 121 address_ = 0; |
| 122 size_ = 0; |
| 123 } |
| 124 |
| 125 |
| 118 int64_t File::Read(void* buffer, int64_t num_bytes) { | 126 int64_t File::Read(void* buffer, int64_t num_bytes) { |
| 119 ASSERT(handle_->fd() >= 0); | 127 ASSERT(handle_->fd() >= 0); |
| 120 return read(handle_->fd(), buffer, num_bytes); | 128 return read(handle_->fd(), buffer, num_bytes); |
| 121 } | 129 } |
| 122 | 130 |
| 123 | 131 |
| 124 int64_t File::Write(const void* buffer, int64_t num_bytes) { | 132 int64_t File::Write(const void* buffer, int64_t num_bytes) { |
| 125 ASSERT(handle_->fd() >= 0); | 133 ASSERT(handle_->fd() >= 0); |
| 126 return write(handle_->fd(), buffer, num_bytes); | 134 return write(handle_->fd(), buffer, num_bytes); |
| 127 } | 135 } |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 return kIdentical; | 728 return kIdentical; |
| 721 } else { | 729 } else { |
| 722 return kDifferent; | 730 return kDifferent; |
| 723 } | 731 } |
| 724 } | 732 } |
| 725 | 733 |
| 726 } // namespace bin | 734 } // namespace bin |
| 727 } // namespace dart | 735 } // namespace dart |
| 728 | 736 |
| 729 #endif // defined(TARGET_OS_WINDOWS) | 737 #endif // defined(TARGET_OS_WINDOWS) |
| OLD | NEW |