Skip to content

[REBASE & FF] patina_debugger: Fix use of crate without "alloc" and fix associated issues#1331

Merged
Javagedes merged 2 commits intoOpenDevicePartnership:mainfrom
cfernald:dbg_alloc
Feb 24, 2026
Merged

[REBASE & FF] patina_debugger: Fix use of crate without "alloc" and fix associated issues#1331
Javagedes merged 2 commits intoOpenDevicePartnership:mainfrom
cfernald:dbg_alloc

Conversation

@cfernald
Copy link
Contributor

Description

Currently the alloc feature attempts to prevent use of the alloc features but does not actually remove the use of the alloc crate. This means that it is quite easy to accidentally use the alloc crate and break this use case.

Additionally, it makes it too easy to accidentally add heap allocations where they shouldn't be, such as by using format! in a monitor command. This feature also helps increase awareness of when heap allocations are used which is important for the debugger which runs in limited environments.

The commit removes use of the alloc crate when the alloc feature is not enabled, and removes all code leveraging it.

Issue #1318

  • Impacts functionality?
  • Impacts security?
  • Breaking change?
  • Includes tests?
  • Includes documentation?

How This Was Tested

Tested on local build and Q35

Integration Instructions

N/A

@github-actions github-actions bot added the impact:non-functional Does not have a functional impact label Feb 20, 2026
@codecov
Copy link

codecov bot commented Feb 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@cfernald cfernald changed the title patina_debugger: Disable use of the alloc crate without alloc feature [REBASE & FF] patina_debugger: Disable use of the alloc crate without alloc feature Feb 22, 2026
@cfernald cfernald force-pushed the dbg_alloc branch 2 times, most recently from f00f72b to 9af70e8 Compare February 23, 2026 21:43
@cfernald cfernald requested a review from makubacki February 23, 2026 21:44
@cfernald cfernald changed the title [REBASE & FF] patina_debugger: Disable use of the alloc crate without alloc feature [REBASE & FF] patina_debugger: Fix use of crate without "alloc" and fix associated issues Feb 23, 2026
@cfernald cfernald force-pushed the dbg_alloc branch 2 times, most recently from 5d87fd1 to da05ff0 Compare February 24, 2026 18:23
Currently the alloc feature attempts to prevent use of the alloc features
but does not actually remove the use of the alloc crate. This means that
it is quite easy to accidentally use the alloc crate and break this use
case.

Additionally, it makes it too easy to accidentally add heap allocations
where they shouldn't be, such as by using `format!` in a monitor command.
This feature also helps increase awareness of when heap allocations are
used which is important for the debugger which runs in limited environments.

The commit removes use of the `alloc` crate when the `alloc` feature is
not enabled, and removes all code leveraging it.
In all cases, the GDB stub is transitioned though a constant reference and
pointer before being converted back to a mutable reference for use. This
can cause unexpected behavior with the compilers interpretting the type
as immutable.

When the `alloc` feature is disabled, the debugger uses a static buffer
for the GDB stub. This buffer current defines the buffer simple as a
const array of `u8`. However, the GDB stub converts this to a mutable reference
leading to undefined behavior, and active causes faults if the stub is placed
in a read-only section by the linker.

This commit stores the GDB buffer as a NonNull pointer in the mutable internal
struct, and prevents use of any const pointer to the memory. When the `alloc`
feature is disabled, the static buffer the static buffer is now wrapped
in an UnsafeCell to allow for interior mutability ensuring the compiler
knows the memory should be treated as mutable.
@Javagedes
Copy link
Contributor

@codecov re-run

@Javagedes Javagedes merged commit 364a8c9 into OpenDevicePartnership:main Feb 24, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

impact:non-functional Does not have a functional impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants