summaryrefslogtreecommitdiff
path: root/libhidlmemory
diff options
context:
space:
mode:
authorSteven Moreland <smoreland@google.com>2017-05-17 09:26:24 -0700
committerSteven Moreland <smoreland@google.com>2017-05-17 19:19:34 +0000
commit10de9efc734af6365ddf36013e3ddc5fcb42b5ef (patch)
tree17cad6c87190e9d75283b9904bbf3434b0babc47 /libhidlmemory
parente5091993a7c95b97cce2c218c6a1e922f094d6e3 (diff)
downloadlibhidl-10de9efc734af6365ddf36013e3ddc5fcb42b5ef.tar.gz
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
Diffstat (limited to 'libhidlmemory')
-rw-r--r--libhidlmemory/include/hidlmemory/mapping.h6
-rw-r--r--libhidlmemory/mapping.cpp9
2 files changed, 11 insertions, 4 deletions
diff --git a/libhidlmemory/include/hidlmemory/mapping.h b/libhidlmemory/include/hidlmemory/mapping.h
index 8ed0d54..5e1dab3 100644
--- a/libhidlmemory/include/hidlmemory/mapping.h
+++ b/libhidlmemory/include/hidlmemory/mapping.h
@@ -19,7 +19,11 @@
namespace android {
namespace hardware {
+/**
+ * Returns the IMemory instance corresponding to a hidl_memory object.
+ * If the shared memory cannot be fetched, this returns nullptr.
+ */
sp<android::hidl::memory::V1_0::IMemory> mapMemory(const hidl_memory &memory);
} // namespace hardware
-} // namespace android \ No newline at end of file
+} // namespace android
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<IMemory> mapMemory(const hidl_memory &memory) {
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;