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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 intptr_t File::GetFD() { | 72 intptr_t File::GetFD() { |
73 return handle_->fd(); | 73 return handle_->fd(); |
74 } | 74 } |
75 | 75 |
76 | 76 |
77 bool File::IsClosed() { | 77 bool File::IsClosed() { |
78 return handle_->fd() == kClosedFd; | 78 return handle_->fd() == kClosedFd; |
79 } | 79 } |
80 | 80 |
81 | 81 |
82 void* File::Map(MapType type, int64_t position, int64_t length) { | 82 MappedMemory* File::Map(MapType type, int64_t position, int64_t length) { |
83 ASSERT(handle_->fd() >= 0); | 83 ASSERT(handle_->fd() >= 0); |
84 int prot = PROT_NONE; | 84 int prot = PROT_NONE; |
85 switch (type) { | 85 switch (type) { |
86 case kReadOnly: | 86 case kReadOnly: |
87 prot = PROT_READ; | 87 prot = PROT_READ; |
88 break; | 88 break; |
89 case kReadExecute: | 89 case kReadExecute: |
90 prot = PROT_READ | PROT_EXEC; | 90 prot = PROT_READ | PROT_EXEC; |
91 break; | 91 break; |
92 default: | 92 default: |
93 return NULL; | 93 return NULL; |
94 } | 94 } |
95 void* addr = mmap(NULL, length, prot, MAP_PRIVATE, handle_->fd(), position); | 95 void* addr = mmap(NULL, length, prot, MAP_PRIVATE, handle_->fd(), position); |
96 if (addr == MAP_FAILED) { | 96 if (addr == MAP_FAILED) { |
97 return NULL; | 97 return NULL; |
98 } | 98 } |
99 return addr; | 99 return new MappedMemory(addr, length); |
100 } | 100 } |
101 | 101 |
102 | 102 |
| 103 void MappedMemory::Unmap() { |
| 104 int result = munmap(address_, size_); |
| 105 ASSERT(result == 0); |
| 106 address_ = 0; |
| 107 size_ = 0; |
| 108 } |
| 109 |
| 110 |
103 int64_t File::Read(void* buffer, int64_t num_bytes) { | 111 int64_t File::Read(void* buffer, int64_t num_bytes) { |
104 ASSERT(handle_->fd() >= 0); | 112 ASSERT(handle_->fd() >= 0); |
105 return TEMP_FAILURE_RETRY(read(handle_->fd(), buffer, num_bytes)); | 113 return TEMP_FAILURE_RETRY(read(handle_->fd(), buffer, num_bytes)); |
106 } | 114 } |
107 | 115 |
108 | 116 |
109 int64_t File::Write(const void* buffer, int64_t num_bytes) { | 117 int64_t File::Write(const void* buffer, int64_t num_bytes) { |
110 ASSERT(handle_->fd() >= 0); | 118 ASSERT(handle_->fd() >= 0); |
111 return TEMP_FAILURE_RETRY(write(handle_->fd(), buffer, num_bytes)); | 119 return TEMP_FAILURE_RETRY(write(handle_->fd(), buffer, num_bytes)); |
112 } | 120 } |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 return ((file_1_info.st_ino == file_2_info.st_ino) && | 576 return ((file_1_info.st_ino == file_2_info.st_ino) && |
569 (file_1_info.st_dev == file_2_info.st_dev)) | 577 (file_1_info.st_dev == file_2_info.st_dev)) |
570 ? File::kIdentical | 578 ? File::kIdentical |
571 : File::kDifferent; | 579 : File::kDifferent; |
572 } | 580 } |
573 | 581 |
574 } // namespace bin | 582 } // namespace bin |
575 } // namespace dart | 583 } // namespace dart |
576 | 584 |
577 #endif // defined(TARGET_OS_ANDROID) | 585 #endif // defined(TARGET_OS_ANDROID) |
OLD | NEW |