Allow clients of mapMemory to recover.
Before, memory could only be nullptr if a mapper instance returned
nullptr. However, sometimes this method would abort. This is
problematic, for instance, when unknown code sends an instance
of hidl_memory to another process. You are forced to manually
write the contents of this mapMemory method with the proper
error handling or to risk your process being aborted. Since this
method already returns nullptr sometimes, and the default usecase
is to pass things into this method which are from another process,
allowing users of this method to handle errors manually will
close a whole class of errors.
Test: (sanity) hidl_test, internal device boots
Fixes: 38377981
Change-Id: Ida6e73b224da34175746e86a08f545ef6db92293
diff --git a/libhidlmemory/mapping.cpp b/libhidlmemory/mapping.cpp
index 3761f99..f4bb21e 100644
--- a/libhidlmemory/mapping.cpp
+++ b/libhidlmemory/mapping.cpp
@@ -33,17 +33,20 @@
sp<IMapper> mapper = IMapper::getService(memory.name(), true /* getStub */);
if (mapper == nullptr) {
- LOG(FATAL) << "Could not fetch mapper for " << memory.name() << " shared memory";
+ LOG(ERROR) << "Could not fetch mapper for " << memory.name() << " shared memory";
+ return nullptr;
}
if (mapper->isRemote()) {
- LOG(FATAL) << "IMapper must be a passthrough service.";
+ LOG(ERROR) << "IMapper must be a passthrough service.";
+ return nullptr;
}
Return<sp<IMemory>> ret = mapper->mapMemory(memory);
if (!ret.isOk()) {
- LOG(FATAL) << "hidl_memory map returned transport error.";
+ LOG(ERROR) << "hidl_memory map returned transport error.";
+ return nullptr;
}
return ret;