Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce stack usage #1

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

Reduce stack usage #1

wants to merge 4 commits into from

Conversation

robin-nitrokey
Copy link
Member

@robin-nitrokey robin-nitrokey commented Oct 9, 2023

This PR contains several patches that reduce stack usage on the lpc55:

  • from 22 kB to 3 kB for ApduDispatch::handle_response
  • from 12 kB to 6 kB for ApduDispatch::check_for_request
  • from 15 kB to 8 kB for ApduBuffer::request

Instead of copying the remaining data out of the APDU buffer and back
into it, we can use a memmove to move it to the beginning and truncate
the buffer afterwards.  This reduces the stack usage on lpc55 from 21 kB
to 6 kB.
This halfs stack usage on the lpc55.
This patch replaces the Responder::take_request in
ApduDispatch::check_for_request with Responder::request, reducing stack
usage from 12 kB to 6 kB.
(message, Interface::Contact)
} else {
return RequestType::None;
};

// Parse the message as an APDU.
match Self::parse_apdu::<{ interchanges::SIZE }>(&message) {
match Self::parse_apdu::<{ interchanges::SIZE }>(message) {
Copy link

@sosthene-nitrokey sosthene-nitrokey Nov 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we update iso7816 we can use CommandView here and avoid copying the APDU data

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I checked that but there was some reason why it did not make a big difference. Maybe the data does not live long enough? I’ll have another look.

@robin-nitrokey robin-nitrokey marked this pull request as draft November 8, 2023 09:59
@robin-nitrokey
Copy link
Member Author

I think I made a mistake when changing the buffer sizes. At least I remember running into a panic the last time I tested this change. I have to test it again before merging it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants