Skip to content
Commit 73d1e85d authored by Jakub Sujak's avatar Jakub Sujak
Browse files

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's avatarJakub Sujak <jakub.sujak@arm.com>

Reviewed-by: Viet-Hoa Do's avatarViet-Hoa Do <viet-hoa.do@arm.com>
Reviewed-by: Jakub Sujak's avatarJakub Sujak <jakub.sujak@arm.com>
Reviewed-by: Emil Ohlsson's avatarEmil Ohlsson <emil.ohlsson@arm.com>
Approved-by: Felix Johnny Thomasmathibalan's avatarFelix Johnny Thomasmathibalan <felixjohnny.thomasmathibalan@arm.com>
parent 49e0f869
Loading
Loading
Loading
Pipeline #26107 passed with stages
in 10 minutes and 53 seconds
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment