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_MACOS) | 6 #if defined(TARGET_OS_MACOS) |
7 | 7 |
8 #include "bin/file.h" | 8 #include "bin/file.h" |
9 | 9 |
10 #include <copyfile.h> // NOLINT | 10 #include <copyfile.h> // NOLINT |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 intptr_t File::GetFD() { | 74 intptr_t File::GetFD() { |
75 return handle_->fd(); | 75 return handle_->fd(); |
76 } | 76 } |
77 | 77 |
78 | 78 |
79 bool File::IsClosed() { | 79 bool File::IsClosed() { |
80 return handle_->fd() == kClosedFd; | 80 return handle_->fd() == kClosedFd; |
81 } | 81 } |
82 | 82 |
83 | 83 |
84 void* File::Map(MapType type, int64_t position, int64_t length) { | 84 MappedMemory* File::Map(MapType type, int64_t position, int64_t length) { |
85 ASSERT(handle_->fd() >= 0); | 85 ASSERT(handle_->fd() >= 0); |
86 int prot = PROT_NONE; | 86 int prot = PROT_NONE; |
87 switch (type) { | 87 switch (type) { |
88 case kReadOnly: | 88 case kReadOnly: |
89 prot = PROT_READ; | 89 prot = PROT_READ; |
90 break; | 90 break; |
91 case kReadExecute: | 91 case kReadExecute: |
92 prot = PROT_READ | PROT_EXEC; | 92 prot = PROT_READ | PROT_EXEC; |
93 break; | 93 break; |
94 default: | 94 default: |
95 return NULL; | 95 return NULL; |
96 } | 96 } |
97 void* addr = mmap(NULL, length, prot, MAP_PRIVATE, handle_->fd(), position); | 97 void* addr = mmap(NULL, length, prot, MAP_PRIVATE, handle_->fd(), position); |
98 if (addr == MAP_FAILED) { | 98 if (addr == MAP_FAILED) { |
99 return NULL; | 99 return NULL; |
100 } | 100 } |
101 return addr; | 101 return new MappedMemory(addr, length); |
102 } | 102 } |
103 | 103 |
104 | 104 |
| 105 void MappedMemory::Unmap() { |
| 106 int result = munmap(address_, size_); |
| 107 ASSERT(result == 0); |
| 108 address_ = 0; |
| 109 size_ = 0; |
| 110 } |
| 111 |
| 112 |
105 int64_t File::Read(void* buffer, int64_t num_bytes) { | 113 int64_t File::Read(void* buffer, int64_t num_bytes) { |
106 ASSERT(handle_->fd() >= 0); | 114 ASSERT(handle_->fd() >= 0); |
107 return TEMP_FAILURE_RETRY(read(handle_->fd(), buffer, num_bytes)); | 115 return TEMP_FAILURE_RETRY(read(handle_->fd(), buffer, num_bytes)); |
108 } | 116 } |
109 | 117 |
110 | 118 |
111 int64_t File::Write(const void* buffer, int64_t num_bytes) { | 119 int64_t File::Write(const void* buffer, int64_t num_bytes) { |
112 ASSERT(handle_->fd() >= 0); | 120 ASSERT(handle_->fd() >= 0); |
113 return TEMP_FAILURE_RETRY(write(handle_->fd(), buffer, num_bytes)); | 121 return TEMP_FAILURE_RETRY(write(handle_->fd(), buffer, num_bytes)); |
114 } | 122 } |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 return ((file_1_info.st_ino == file_2_info.st_ino) && | 551 return ((file_1_info.st_ino == file_2_info.st_ino) && |
544 (file_1_info.st_dev == file_2_info.st_dev)) | 552 (file_1_info.st_dev == file_2_info.st_dev)) |
545 ? File::kIdentical | 553 ? File::kIdentical |
546 : File::kDifferent; | 554 : File::kDifferent; |
547 } | 555 } |
548 | 556 |
549 } // namespace bin | 557 } // namespace bin |
550 } // namespace dart | 558 } // namespace dart |
551 | 559 |
552 #endif // defined(TARGET_OS_MACOS) | 560 #endif // defined(TARGET_OS_MACOS) |
OLD | NEW |