diff options
author | Kevin Rocard | 2017-10-05 20:47:02 -0500 |
---|---|---|
committer | Mikhail Naganov | 2017-10-10 11:22:02 -0500 |
commit | 46cba442d25e16cce4d5f009f4700a88d53636b1 (patch) | |
tree | 45f08cbf9d894d735f4d69970bbc2153635f932f | |
parent | 3021f1fafbfb1a4b464effa543aee381f42d8080 (diff) | |
download | platform-hardware-interfaces-46cba442d25e16cce4d5f009f4700a88d53636b1.tar.gz platform-hardware-interfaces-46cba442d25e16cce4d5f009f4700a88d53636b1.tar.xz platform-hardware-interfaces-46cba442d25e16cce4d5f009f4700a88d53636b1.zip |
Legacy wrapper: Use arbitrary limit on buffer size
The legacy HAL wrapper prepareForWrite and prepareForRead used
to return INVALID_ARGUMENTS if the computed buffer size just
under SIZE_MAX.
This meant that the limitation depended on the architecture (32 vs 64
bit size_t). This caused VTS test failure on 64 bits.
Instead of dynamically calculating an arbitrary max size,
choose a fixed one. This max buffer size has been chosen at 1GiB.
It should be enough for the foreseeable future and not too close
from the 4GiB max on 32 bit.
Test: vts-tradefed run commandAndExit vts --module VtsHalAudioV2_0Target
Bug: 67030516
Change-Id: I4cc3efda9bb66e6dae8b4e6785f52d9e51440aee
Signed-off-by: Kevin Rocard <krocard@google.com>
-rw-r--r-- | audio/2.0/default/Stream.h | 7 | ||||
-rw-r--r-- | audio/2.0/default/StreamIn.cpp | 12 | ||||
-rw-r--r-- | audio/2.0/default/StreamOut.cpp | 11 |
3 files changed, 14 insertions, 16 deletions
diff --git a/audio/2.0/default/Stream.h b/audio/2.0/default/Stream.h index 82f05a77..e29af531 100644 --- a/audio/2.0/default/Stream.h +++ b/audio/2.0/default/Stream.h | |||
@@ -49,6 +49,13 @@ using ::android::sp; | |||
49 | struct Stream : public IStream, public ParametersUtil { | 49 | struct Stream : public IStream, public ParametersUtil { |
50 | explicit Stream(audio_stream_t* stream); | 50 | explicit Stream(audio_stream_t* stream); |
51 | 51 | ||
52 | /** 1GiB is the maximum buffer size the HAL client is allowed to request. | ||
53 | * This value has been chosen to be under SIZE_MAX and still big enough | ||
54 | * for all audio use case. | ||
55 | * Keep private for 2.0, put in .hal in 2.1 | ||
56 | */ | ||
57 | static constexpr uint32_t MAX_BUFFER_SIZE = 2 << 30 /* == 1GiB */; | ||
58 | |||
52 | // Methods from ::android::hardware::audio::V2_0::IStream follow. | 59 | // Methods from ::android::hardware::audio::V2_0::IStream follow. |
53 | Return<uint64_t> getFrameSize() override; | 60 | Return<uint64_t> getFrameSize() override; |
54 | Return<uint64_t> getFrameCount() override; | 61 | Return<uint64_t> getFrameCount() override; |
diff --git a/audio/2.0/default/StreamIn.cpp b/audio/2.0/default/StreamIn.cpp index b81cbb92..9c933a92 100644 --- a/audio/2.0/default/StreamIn.cpp +++ b/audio/2.0/default/StreamIn.cpp | |||
@@ -347,14 +347,10 @@ Return<void> StreamIn::prepareForReading(uint32_t frameSize, | |||
347 | sendError(Result::INVALID_ARGUMENTS); | 347 | sendError(Result::INVALID_ARGUMENTS); |
348 | return Void(); | 348 | return Void(); |
349 | } | 349 | } |
350 | // A message queue asserts if it can not handle the requested buffer, | 350 | |
351 | // thus the client has to guess the maximum size it can handle | 351 | if (frameSize > Stream::MAX_BUFFER_SIZE / framesCount) { |
352 | // Choose an arbitrary margin for the overhead of a message queue | 352 | ALOGE("Buffer too big: %u*%u bytes > MAX_BUFFER_SIZE (%u)", frameSize, framesCount, |
353 | size_t metadataOverhead = 100000; | 353 | Stream::MAX_BUFFER_SIZE); |
354 | if (frameSize > | ||
355 | (std::numeric_limits<size_t>::max() - metadataOverhead) / framesCount) { | ||
356 | ALOGE("Buffer too big: %u*%u bytes can not fit in a message queue", | ||
357 | frameSize, framesCount); | ||
358 | sendError(Result::INVALID_ARGUMENTS); | 354 | sendError(Result::INVALID_ARGUMENTS); |
359 | return Void(); | 355 | return Void(); |
360 | } | 356 | } |
diff --git a/audio/2.0/default/StreamOut.cpp b/audio/2.0/default/StreamOut.cpp index 290d0b10..22dcd0c9 100644 --- a/audio/2.0/default/StreamOut.cpp +++ b/audio/2.0/default/StreamOut.cpp | |||
@@ -323,14 +323,9 @@ Return<void> StreamOut::prepareForWriting(uint32_t frameSize, | |||
323 | sendError(Result::INVALID_ARGUMENTS); | 323 | sendError(Result::INVALID_ARGUMENTS); |
324 | return Void(); | 324 | return Void(); |
325 | } | 325 | } |
326 | // A message queue asserts if it can not handle the requested buffer, | 326 | if (frameSize > Stream::MAX_BUFFER_SIZE / framesCount) { |
327 | // thus the client has to guess the maximum size it can handle | 327 | ALOGE("Buffer too big: %u*%u bytes > MAX_BUFFER_SIZE (%u)", frameSize, framesCount, |
328 | size_t metadataOverhead = | 328 | Stream::MAX_BUFFER_SIZE); |
329 | 100000; // Arbitrary margin for the overhead of a message queue | ||
330 | if (frameSize > | ||
331 | (std::numeric_limits<size_t>::max() - metadataOverhead) / framesCount) { | ||
332 | ALOGE("Buffer too big: %u*%u bytes can not fit in a message queue", | ||
333 | frameSize, framesCount); | ||
334 | sendError(Result::INVALID_ARGUMENTS); | 329 | sendError(Result::INVALID_ARGUMENTS); |
335 | return Void(); | 330 | return Void(); |
336 | } | 331 | } |