| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 intptr_t File::GetFD() { | 67 intptr_t File::GetFD() { |
| 68 return handle_->fd(); | 68 return handle_->fd(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 | 71 |
| 72 bool File::IsClosed() { | 72 bool File::IsClosed() { |
| 73 return handle_->fd() == kClosedFd; | 73 return handle_->fd() == kClosedFd; |
| 74 } | 74 } |
| 75 | 75 |
| 76 | 76 |
| 77 void* File::Map(MapType type, int64_t position, int64_t length) { | 77 void* File::Map(File::MapType type, int64_t position, int64_t length) { |
| 78 UNIMPLEMENTED(); | 78 DWORD prot_alloc; |
| 79 return NULL; | 79 DWORD prot_final; |
| 80 switch (type) { |
| 81 case File::kReadOnly: |
| 82 prot_alloc = PAGE_READWRITE; |
| 83 prot_final = PAGE_READONLY; |
| 84 break; |
| 85 case File::kReadExecute: |
| 86 prot_alloc = PAGE_EXECUTE_READWRITE; |
| 87 prot_final = PAGE_EXECUTE_READ; |
| 88 break; |
| 89 default: |
| 90 return NULL; |
| 91 } |
| 92 |
| 93 void* addr = VirtualAlloc(NULL, length, MEM_COMMIT | MEM_RESERVE, prot_alloc); |
| 94 if (addr == NULL) { |
| 95 Log::PrintErr("VirtualAlloc failed %d\n", GetLastError()); |
| 96 return NULL; |
| 97 } |
| 98 |
| 99 SetPosition(position); |
| 100 if (!ReadFully(addr, length)) { |
| 101 Log::PrintErr("ReadFully failed %d\n", GetLastError()); |
| 102 VirtualFree(addr, 0, MEM_RELEASE); |
| 103 return NULL; |
| 104 } |
| 105 |
| 106 DWORD old_prot; |
| 107 bool result = VirtualProtect(addr, length, prot_final, &old_prot); |
| 108 if (!result) { |
| 109 Log::PrintErr("VirtualProtect failed %d\n", GetLastError()); |
| 110 VirtualFree(addr, 0, MEM_RELEASE); |
| 111 return NULL; |
| 112 } |
| 113 return addr; |
| 80 } | 114 } |
| 81 | 115 |
| 82 | 116 |
| 83 int64_t File::Read(void* buffer, int64_t num_bytes) { | 117 int64_t File::Read(void* buffer, int64_t num_bytes) { |
| 84 ASSERT(handle_->fd() >= 0); | 118 ASSERT(handle_->fd() >= 0); |
| 85 return read(handle_->fd(), buffer, num_bytes); | 119 return read(handle_->fd(), buffer, num_bytes); |
| 86 } | 120 } |
| 87 | 121 |
| 88 | 122 |
| 89 int64_t File::Write(const void* buffer, int64_t num_bytes) { | 123 int64_t File::Write(const void* buffer, int64_t num_bytes) { |
| (...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 return kIdentical; | 734 return kIdentical; |
| 701 } else { | 735 } else { |
| 702 return kDifferent; | 736 return kDifferent; |
| 703 } | 737 } |
| 704 } | 738 } |
| 705 | 739 |
| 706 } // namespace bin | 740 } // namespace bin |
| 707 } // namespace dart | 741 } // namespace dart |
| 708 | 742 |
| 709 #endif // defined(TARGET_OS_WINDOWS) | 743 #endif // defined(TARGET_OS_WINDOWS) |
| OLD | NEW |