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_ANDROID) | 6 #if defined(TARGET_OS_ANDROID) |
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 intptr_t File::GetFD() { | 71 intptr_t File::GetFD() { |
72 return handle_->fd(); | 72 return handle_->fd(); |
73 } | 73 } |
74 | 74 |
75 | 75 |
76 bool File::IsClosed() { | 76 bool File::IsClosed() { |
77 return handle_->fd() == kClosedFd; | 77 return handle_->fd() == kClosedFd; |
78 } | 78 } |
79 | 79 |
80 | 80 |
81 void* File::MapExecutable(intptr_t* len) { | 81 void* File::Map(MapType type, int64_t position, int64_t length) { |
82 ASSERT(handle_->fd() >= 0); | 82 ASSERT(handle_->fd() >= 0); |
83 | 83 int prot = PROT_NONE; |
84 intptr_t length = Length(); | 84 switch (type) { |
85 void* addr = mmap(0, length, | 85 case kReadOnly: |
86 PROT_READ | PROT_EXEC, MAP_PRIVATE, | 86 prot = PROT_READ; |
87 handle_->fd(), 0); | 87 break; |
| 88 case kReadExecute: |
| 89 prot = PROT_READ | PROT_EXEC; |
| 90 break; |
| 91 default: |
| 92 return NULL; |
| 93 } |
| 94 void* addr = mmap(NULL, length, prot, MAP_PRIVATE, |
| 95 handle_->fd(), position); |
88 if (addr == MAP_FAILED) { | 96 if (addr == MAP_FAILED) { |
89 *len = -1; | 97 return NULL; |
90 } else { | |
91 *len = length; | |
92 } | 98 } |
93 return addr; | 99 return addr; |
94 } | 100 } |
95 | 101 |
96 | 102 |
97 int64_t File::Read(void* buffer, int64_t num_bytes) { | 103 int64_t File::Read(void* buffer, int64_t num_bytes) { |
98 ASSERT(handle_->fd() >= 0); | 104 ASSERT(handle_->fd() >= 0); |
99 return TEMP_FAILURE_RETRY(read(handle_->fd(), buffer, num_bytes)); | 105 return TEMP_FAILURE_RETRY(read(handle_->fd(), buffer, num_bytes)); |
100 } | 106 } |
101 | 107 |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 return ((file_1_info.st_ino == file_2_info.st_ino) && | 514 return ((file_1_info.st_ino == file_2_info.st_ino) && |
509 (file_1_info.st_dev == file_2_info.st_dev)) ? | 515 (file_1_info.st_dev == file_2_info.st_dev)) ? |
510 File::kIdentical : | 516 File::kIdentical : |
511 File::kDifferent; | 517 File::kDifferent; |
512 } | 518 } |
513 | 519 |
514 } // namespace bin | 520 } // namespace bin |
515 } // namespace dart | 521 } // namespace dart |
516 | 522 |
517 #endif // defined(TARGET_OS_ANDROID) | 523 #endif // defined(TARGET_OS_ANDROID) |
OLD | NEW |