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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 intptr_t File::GetFD() { | 73 intptr_t File::GetFD() { |
74 return handle_->fd(); | 74 return handle_->fd(); |
75 } | 75 } |
76 | 76 |
77 | 77 |
78 bool File::IsClosed() { | 78 bool File::IsClosed() { |
79 return handle_->fd() == kClosedFd; | 79 return handle_->fd() == kClosedFd; |
80 } | 80 } |
81 | 81 |
82 | 82 |
83 void* File::MapExecutable(intptr_t* len) { | 83 void* File::Map(MapType type, int64_t position, int64_t length) { |
84 ASSERT(handle_->fd() >= 0); | 84 ASSERT(handle_->fd() >= 0); |
85 intptr_t length = Length(); | 85 int prot = PROT_NONE; |
86 void* addr = mmap(0, length, | 86 switch (type) { |
87 PROT_READ | PROT_EXEC, MAP_PRIVATE, | 87 case kReadOnly: |
88 handle_->fd(), 0); | 88 prot = PROT_READ; |
| 89 break; |
| 90 case kReadExecute: |
| 91 prot = PROT_READ | PROT_EXEC; |
| 92 break; |
| 93 } |
| 94 void* addr = mmap(NULL, length, prot, MAP_PRIVATE, |
| 95 handle_->fd(), position); |
89 if (addr == MAP_FAILED) { | 96 if (addr == MAP_FAILED) { |
90 *len = -1; | 97 return NULL; |
91 } else { | |
92 *len = length; | |
93 } | 98 } |
94 return addr; | 99 return addr; |
95 } | 100 } |
96 | 101 |
97 | 102 |
98 int64_t File::Read(void* buffer, int64_t num_bytes) { | 103 int64_t File::Read(void* buffer, int64_t num_bytes) { |
99 ASSERT(handle_->fd() >= 0); | 104 ASSERT(handle_->fd() >= 0); |
100 return TEMP_FAILURE_RETRY(read(handle_->fd(), buffer, num_bytes)); | 105 return TEMP_FAILURE_RETRY(read(handle_->fd(), buffer, num_bytes)); |
101 } | 106 } |
102 | 107 |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 return ((file_1_info.st_ino == file_2_info.st_ino) && | 488 return ((file_1_info.st_ino == file_2_info.st_ino) && |
484 (file_1_info.st_dev == file_2_info.st_dev)) ? | 489 (file_1_info.st_dev == file_2_info.st_dev)) ? |
485 File::kIdentical : | 490 File::kIdentical : |
486 File::kDifferent; | 491 File::kDifferent; |
487 } | 492 } |
488 | 493 |
489 } // namespace bin | 494 } // namespace bin |
490 } // namespace dart | 495 } // namespace dart |
491 | 496 |
492 #endif // defined(TARGET_OS_MACOS) | 497 #endif // defined(TARGET_OS_MACOS) |
OLD | NEW |