Skip to content

Remove Allocations from Panic Handler #818

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

adamperlin
Copy link

This PR fixes #735. The approach used here is to create a FixedStringBuf type which wraps a byte slice and which implements fmt::Write by writing into this underlying slice. This static buffer can then be used to format the actual panic message.

using a new FixedStringBuf type backed by a static mut array.
Adds a test to verify that StackOverflow no longer occurs on OOM panic

Signed-off-by: adamperlin <[email protected]>
Add some docstrings

Signed-off-by: adamperlin <[email protected]>
Signed-off-by: adamperlin <[email protected]>
@adamperlin adamperlin force-pushed the adamperlin/panic-remove-allocations branch from c83158f to 93e8563 Compare August 22, 2025 21:18
@jprendes jprendes added the kind/bugfix For PRs that fix bugs label Aug 22, 2025
@danbugs danbugs requested a review from Copilot August 22, 2025 21:39
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses issue #735 by removing allocations from the panic handler in the hyperlight guest environment. The implementation introduces a FixedStringBuf type that wraps a pre-allocated byte slice and implements fmt::Write to enable string formatting without dynamic allocation.

Key changes:

  • Implements a new FixedStringBuf type for allocation-free string formatting
  • Replaces allocation-based panic message handling with a static buffer approach
  • Adds test coverage to verify panic handling works correctly under memory exhaustion scenarios

Reviewed Changes

Copilot reviewed 6 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/hyperlight_common/src/fixed_buf.rs New module implementing FixedStringBuf for allocation-free string formatting
src/hyperlight_common/src/lib.rs Adds the new fixed_buf module to the crate
src/hyperlight_guest_bin/src/lib.rs Replaces allocation-based panic handler with static buffer implementation
src/tests/rust_guests/simpleguest/src/main.rs Adds heap exhaustion test function to verify panic behavior under OOM conditions
src/hyperlight_host/tests/integration_test.rs Adds integration test to verify panic handler doesn't cause stack overflow
flake.nix Updates cargo hash for build system

…n panic handler to avoid any possible recursive panic

Signed-off-by: adamperlin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bugfix For PRs that fix bugs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't alloc memory in panic handler
4 participants