Smarter memory protection with Buffer class
Introduces a dedicated Buffer
abstraction for managing blocks of memory. Buffer comes with protection mechanisms that can be enabled by setting the KAI_TEST_BUFFER_POLICY
environment variable.
Example usage:
KAI_TEST_BUFFER_POLICY=PROTECT_OVERFLOW ./kleidiai_test
Available memory protection mechanisms:
KAI_TEST_BUFFER_POLICY=PROTECT_UNDERFLOW
KAI_TEST_BUFFER_POLICY=PROTECT_OVERFLOW
If KAI_TEST_BUFFER_POLICY
is not set or is not one of the above values, then no memory protection mechanisms are enabled and Buffer performs naive malloc() allocation of memory.
When KAI_TEST_BUFFER_POLICY
is set to one of the above values, the following protections are enabled:
-
PROTECT_UNDERFLOW
: Memory equal to the size of the user buffer rounded to the nearest whole page plus adjacent guard pages is allocated, and the user buffer is aligned to the end of the head guard page thus detecting whenever a buffer underflow occurs. -
PROTECT_OVERFLOW
: Same as above, but now the edge of the user buffer is aligned to the start of the tail guard page thus detecting whenever a buffer overflow occurs.
Buffer is only intended to opaquely allocate and manage memory. The underlying memory resource can be requested using the familiar Buffer::data()
method and interacted with using kai::test::read_array<T>()
and kai::test::write_array<T>()
utilities.
Signed-off-by: Jakub Sujak jakub.sujak@arm.com