Index: runtime/bin/file_macos.cc |
diff --git a/runtime/bin/file_macos.cc b/runtime/bin/file_macos.cc |
index 03c27c3ba114d108487a0939cee8dc2aece45b86..941d419352b64e904631ada3b4041d1942d37e05 100644 |
--- a/runtime/bin/file_macos.cc |
+++ b/runtime/bin/file_macos.cc |
@@ -12,6 +12,7 @@ |
#include <fcntl.h> // NOLINT |
#include <libgen.h> // NOLINT |
#include <limits.h> // NOLINT |
+#include <sys/mman.h> // NOLINT |
#include <sys/stat.h> // NOLINT |
#include <unistd.h> // NOLINT |
@@ -78,6 +79,21 @@ bool File::IsClosed() { |
} |
+void* File::MapExecutable(intptr_t* len) { |
+ ASSERT(handle_->fd() >= 0); |
+ intptr_t length = Length(); |
+ void* addr = mmap(0, length, |
+ PROT_READ | PROT_EXEC, MAP_PRIVATE, |
+ handle_->fd(), 0); |
+ if (addr == MAP_FAILED) { |
+ *len = -1; |
+ } else { |
+ *len = length; |
+ } |
+ return addr; |
+} |
+ |
+ |
int64_t File::Read(void* buffer, int64_t num_bytes) { |
ASSERT(handle_->fd() >= 0); |
return TEMP_FAILURE_RETRY(read(handle_->fd(), buffer, num_bytes)); |