summaryrefslogtreecommitdiffstats
path: root/runtime/mem_map.cc
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/mem_map.cc')
-rw-r--r--runtime/mem_map.cc28
1 files changed, 15 insertions, 13 deletions
diff --git a/runtime/mem_map.cc b/runtime/mem_map.cc
index 6451d5c..00316f7 100644
--- a/runtime/mem_map.cc
+++ b/runtime/mem_map.cc
@@ -67,7 +67,8 @@ static void CheckMapRequest(byte* addr, size_t byte_count) {
static void CheckMapRequest(byte*, size_t) { }
#endif
-MemMap* MemMap::MapAnonymous(const char* name, byte* addr, size_t byte_count, int prot) {
+MemMap* MemMap::MapAnonymous(const char* name, byte* addr, size_t byte_count, int prot,
+ std::string* error_msg) {
if (byte_count == 0) {
return new MemMap(name, NULL, 0, NULL, 0, prot);
}
@@ -82,8 +83,8 @@ MemMap* MemMap::MapAnonymous(const char* name, byte* addr, size_t byte_count, in
ScopedFd fd(ashmem_create_region(debug_friendly_name.c_str(), page_aligned_byte_count));
int flags = MAP_PRIVATE;
if (fd.get() == -1) {
- PLOG(ERROR) << "ashmem_create_region failed (" << name << ")";
- return NULL;
+ *error_msg = StringPrintf("ashmem_create_region failed for '%s': %s", name, strerror(errno));
+ return nullptr;
}
#else
ScopedFd fd(-1);
@@ -94,16 +95,17 @@ MemMap* MemMap::MapAnonymous(const char* name, byte* addr, size_t byte_count, in
if (actual == MAP_FAILED) {
std::string maps;
ReadFileToString("/proc/self/maps", &maps);
- PLOG(ERROR) << "mmap(" << reinterpret_cast<void*>(addr) << ", " << page_aligned_byte_count
- << ", " << prot << ", " << flags << ", " << fd.get() << ", 0) failed for " << name
- << "\n" << maps;
- return NULL;
+ *error_msg = StringPrintf("anonymous mmap(%p, %zd, %x, %x, %d, 0) failed\n%s",
+ addr, page_aligned_byte_count, prot, flags, fd.get(),
+ maps.c_str());
+ return nullptr;
}
return new MemMap(name, actual, byte_count, actual, page_aligned_byte_count, prot);
}
-MemMap* MemMap::MapFileAtAddress(byte* addr, size_t byte_count,
- int prot, int flags, int fd, off_t start, bool reuse) {
+MemMap* MemMap::MapFileAtAddress(byte* addr, size_t byte_count, int prot, int flags, int fd,
+ off_t start, bool reuse, const char* filename,
+ std::string* error_msg) {
CHECK_NE(0, prot);
CHECK_NE(0, flags & (MAP_SHARED | MAP_PRIVATE));
if (byte_count == 0) {
@@ -133,10 +135,10 @@ MemMap* MemMap::MapFileAtAddress(byte* addr, size_t byte_count,
if (actual == MAP_FAILED) {
std::string maps;
ReadFileToString("/proc/self/maps", &maps);
- PLOG(ERROR) << "mmap(" << reinterpret_cast<void*>(page_aligned_addr)
- << ", " << page_aligned_byte_count
- << ", " << prot << ", " << flags << ", " << fd << ", " << page_aligned_offset
- << ") failed\n" << maps;
+ *error_msg = StringPrintf("mmap(%p, %zd, %x, %x, %d, %lld) of file '%s' failed\n%s",
+ page_aligned_addr, page_aligned_byte_count, prot, flags, fd,
+ static_cast<int64_t>(page_aligned_offset),
+ filename, maps.c_str());
return NULL;
}
return new MemMap("file", actual + page_offset, byte_count, actual, page_aligned_byte_count,