| 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 default: |
| 94 return NULL; |
| 95 } |
| 96 void* addr = mmap(NULL, length, prot, MAP_PRIVATE, |
| 97 handle_->fd(), position); |
| 89 if (addr == MAP_FAILED) { | 98 if (addr == MAP_FAILED) { |
| 90 *len = -1; | 99 return NULL; |
| 91 } else { | |
| 92 *len = length; | |
| 93 } | 100 } |
| 94 return addr; | 101 return addr; |
| 95 } | 102 } |
| 96 | 103 |
| 97 | 104 |
| 98 int64_t File::Read(void* buffer, int64_t num_bytes) { | 105 int64_t File::Read(void* buffer, int64_t num_bytes) { |
| 99 ASSERT(handle_->fd() >= 0); | 106 ASSERT(handle_->fd() >= 0); |
| 100 return TEMP_FAILURE_RETRY(read(handle_->fd(), buffer, num_bytes)); | 107 return TEMP_FAILURE_RETRY(read(handle_->fd(), buffer, num_bytes)); |
| 101 } | 108 } |
| 102 | 109 |
| (...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) && | 490 return ((file_1_info.st_ino == file_2_info.st_ino) && |
| 484 (file_1_info.st_dev == file_2_info.st_dev)) ? | 491 (file_1_info.st_dev == file_2_info.st_dev)) ? |
| 485 File::kIdentical : | 492 File::kIdentical : |
| 486 File::kDifferent; | 493 File::kDifferent; |
| 487 } | 494 } |
| 488 | 495 |
| 489 } // namespace bin | 496 } // namespace bin |
| 490 } // namespace dart | 497 } // namespace dart |
| 491 | 498 |
| 492 #endif // defined(TARGET_OS_MACOS) | 499 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |