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_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
7 | 7 |
8 #include "bin/file.h" | 8 #include "bin/file.h" |
9 | 9 |
10 #include <errno.h> // NOLINT | 10 #include <errno.h> // NOLINT |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 intptr_t File::GetFD() { | 70 intptr_t File::GetFD() { |
71 return handle_->fd(); | 71 return handle_->fd(); |
72 } | 72 } |
73 | 73 |
74 | 74 |
75 bool File::IsClosed() { | 75 bool File::IsClosed() { |
76 return handle_->fd() == kClosedFd; | 76 return handle_->fd() == kClosedFd; |
77 } | 77 } |
78 | 78 |
79 | 79 |
80 void* File::MapExecutable(intptr_t* len) { | 80 void* File::Map(MapType type, int64_t position, int64_t length) { |
81 ASSERT(handle_->fd() >= 0); | 81 ASSERT(handle_->fd() >= 0); |
82 intptr_t length = Length(); | 82 int prot = PROT_NONE; |
83 void* addr = mmap(0, length, | 83 switch (type) { |
84 PROT_READ | PROT_EXEC, MAP_PRIVATE, | 84 case kReadOnly: |
85 handle_->fd(), 0); | 85 prot = PROT_READ; |
| 86 break; |
| 87 case kReadExecute: |
| 88 prot = PROT_READ | PROT_EXEC; |
| 89 break; |
| 90 default: |
| 91 return NULL; |
| 92 } |
| 93 void* addr = mmap(NULL, length, prot, MAP_PRIVATE, |
| 94 handle_->fd(), position); |
86 if (addr == MAP_FAILED) { | 95 if (addr == MAP_FAILED) { |
87 *len = -1; | 96 return NULL; |
88 } else { | |
89 *len = length; | |
90 } | 97 } |
91 return addr; | 98 return addr; |
92 } | 99 } |
93 | 100 |
94 | 101 |
95 int64_t File::Read(void* buffer, int64_t num_bytes) { | 102 int64_t File::Read(void* buffer, int64_t num_bytes) { |
96 ASSERT(handle_->fd() >= 0); | 103 ASSERT(handle_->fd() >= 0); |
97 return TEMP_FAILURE_RETRY(read(handle_->fd(), buffer, num_bytes)); | 104 return TEMP_FAILURE_RETRY(read(handle_->fd(), buffer, num_bytes)); |
98 } | 105 } |
99 | 106 |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 return ((file_1_info.st_ino == file_2_info.st_ino) && | 526 return ((file_1_info.st_ino == file_2_info.st_ino) && |
520 (file_1_info.st_dev == file_2_info.st_dev)) ? | 527 (file_1_info.st_dev == file_2_info.st_dev)) ? |
521 File::kIdentical : | 528 File::kIdentical : |
522 File::kDifferent; | 529 File::kDifferent; |
523 } | 530 } |
524 | 531 |
525 } // namespace bin | 532 } // namespace bin |
526 } // namespace dart | 533 } // namespace dart |
527 | 534 |
528 #endif // defined(TARGET_OS_LINUX) | 535 #endif // defined(TARGET_OS_LINUX) |
OLD | NEW |