Add support for mmaped file descriptor - create new API to create ANeuralNetworks_Memory from a mmaped fd. - add the corresponding Memory constructor to NeuralNetworksWrapper.h - Add unit test TestFd for the new API. Bug: 63905942 Test: mm Test: TestFd pass with CPU path. Test: TestFd pass on sample HIDL driver, with ag/2588539 Change-Id: I1fcb0f0bd01e58bd592e18eff11c27034ee4a4c3
diff --git a/runtime/RequestBuilder.cpp b/runtime/RequestBuilder.cpp index ab027a1..1c7e4aa 100644 --- a/runtime/RequestBuilder.cpp +++ b/runtime/RequestBuilder.cpp
@@ -106,6 +106,9 @@ << count; return ANEURALNETWORKS_BAD_DATA; } + if (!memory->validateSize(offset, length)) { + return ANEURALNETWORKS_BAD_DATA; + } uint32_t poolIndex = mMemories.add(memory); return mInputs[index].setFromMemory(mModel->getInputOperand(index), type, poolIndex, offset, length); @@ -129,6 +132,9 @@ << count; return ANEURALNETWORKS_BAD_DATA; } + if (!memory->validateSize(offset, length)) { + return ANEURALNETWORKS_BAD_DATA; + } uint32_t poolIndex = mMemories.add(memory); return mOutputs[index].setFromMemory(mModel->getOutputOperand(index), type, poolIndex, offset, length);