Skip to content

Framework to measure stack usage - #318

Open
gilles-peskine-arm wants to merge 1 commit into
Mbed-TLS:mainfrom
gilles-peskine-arm:mbedtls_test_stack_usage-create
Open

Framework to measure stack usage#318
gilles-peskine-arm wants to merge 1 commit into
Mbed-TLS:mainfrom
gilles-peskine-arm:mbedtls_test_stack_usage-create

Conversation

@gilles-peskine-arm

Copy link
Copy Markdown
Contributor

Measure the stack usage of a code snippet. The new macro MBEDTLS_TEST_STACK_USAGE_CHECK() allows test code to assert that no more than N bytes of stack have been used.

PR checklist

Please add the numbers (or links) of the associated pull requests for consuming branches. You can omit branches where this pull request is not needed.

  • TF-PSA-Crypto development PR provided Fix missing zeroization in psa_key_agreement() TF-PSA-Crypto#886
  • TF-PSA-Crypto 1.1 PR not required because: new feature only used in crypto development
  • mbedtls development PR not required because: new feature only used in crypto development
  • mbedtls 4.1 PR not required because: new feature only used in crypto development
  • mbedtls 3.6 PR not required because: new feature only used in crypto development

Measure the stack usage of a code snippet. The new macro
`MBEDTLS_TEST_STACK_USAGE_CHECK()` allows test code to assert that no more
than N bytes of stack have been used.

The implementation uses `alloca()`. It is only enabled when the C compiler
has `__has_include`, which allows the build to succeed on targets that don't
have `alloca()`.

The implementation would be compatible with MSan, but it is disabled because
MSan causes stack usage to be more than doubled, which would make
measurements mostly useless.

The implementation is compatible with Valgrind.

If the stack usage implementation is disabled, provide dummy functions that
do nothing.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
@gilles-peskine-arm gilles-peskine-arm added needs-review Every commit must be reviewed by at least two team members. needs-reviewer This PR needs someone to pick it up for review size-s Estimated task size: small (~2d) priority-medium Medium priority - this can be reviewed as time permits labels Aug 31, 2026
@gilles-peskine-arm gilles-peskine-arm added needs-ci Needs to pass CI tests and removed needs-ci Needs to pass CI tests labels Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-review Every commit must be reviewed by at least two team members. needs-reviewer This PR needs someone to pick it up for review priority-medium Medium priority - this can be reviewed as time permits size-s Estimated task size: small (~2d)

Projects

Status: In Development

Development

Successfully merging this pull request may close these issues.

1 participant