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

The storage in UnwindContext.stack was changed to a Vec #683

Closed
philipc opened this issue Nov 18, 2023 · 3 comments · Fixed by #687
Closed

The storage in UnwindContext.stack was changed to a Vec #683

philipc opened this issue Nov 18, 2023 · 3 comments · Fixed by #687

Comments

@philipc
Copy link
Collaborator

philipc commented Nov 18, 2023

#595 changed the storage of UnwindContext.stack from an array to a Vec. @nbdd0121 Was this an intentional change? I'm inclined to change it back. I think defaulting to a fixed size allocation is preferable.

@nbdd0121
Copy link
Contributor

IIRC In majority of cases of unwinding this stack is not needed. The previous 4-element storage consumes quite a bit of stack. If you are allowed to allocate then it's better off to just use a Vec so that it doesn't allocate in fast path.

@philipc
Copy link
Collaborator Author

philipc commented Nov 18, 2023

In majority of cases of unwinding this stack is not needed.

It always needs at least one element for the rules, so it needs to allocate in every case:

self.stack.try_push(UnwindTableRow::default()).unwrap();

The previous 4-element storage consumes quite a bit of stack.

That's why the documentation and example suggested putting the UnwindContext on the heap. And if you put the UnwindContext on the heap and reuse it, then allocating it is a once only cost.

The advantage using only 4 elements is that it puts an upper bound on memory usage, and it is sufficient for all CFI in practice.

@nbdd0121
Copy link
Contributor

Ah, the current row. How about store the current row along side with the stack then?

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 a pull request may close this issue.

2 participants