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