Skip to content

[REBASE & FF] Add Stack Overflow Hint in Exception Handlers#1554

Merged
os-d merged 3 commits into
OpenDevicePartnership:mainfrom
os-d:exception_updates
Jun 5, 2026
Merged

[REBASE & FF] Add Stack Overflow Hint in Exception Handlers#1554
os-d merged 3 commits into
OpenDevicePartnership:mainfrom
os-d:exception_updates

Conversation

@os-d

@os-d os-d commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Description

Stack overflows show up as page faults in the exception handler, which can be hard to distinguish from other kinds of page faults. This PR contains three commits to provide a hint that a stack overflow occurred.

x64: IDT: Use a Separate Stack for Page Fault Exceptions

Currently, only double faults use a separate stack. However, a stack overflow manifests as a page fault, so taking a stack overflow causes a double fault. This makes it harder to reason about what the fault was.

This commit instead using a separate stack for x64 page faults, aligning with the aarch64 side. This is in preparation for giving better information about stack overflows in the exception handlers.

exception handlers: Print Stack Overflow Hint

Currently, stack overflows show up as page faults in the exception handlers. This can make it hard to identify when a different page fault has occurred.

This commit introduces a heuristic to hint that a stack overflow likely occurred in the exception handler. It checks if the faulting address is on the same page as or one page lower than the stack pointer. In some cases, the stack pointer is incremented first, then data is written (in which case the faulting address is on the same page as the stack pointer) and in other cases the data is written before the stack pointer is decremented (so the faulting address is on the page below the stack pointer).

A pretty message is then printed to indicate a stack overflow occurred.

internal_cpu: Rename EfiExceptionStackTrace Trait

The EfiExceptionStackTrace trait is an internal trait that originally was just used so the common exception handler can use arch specific stack trace dumping.

However, this was expanded to also include dumping a page table walk, so the name is not accurate.

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

How This Was Tested

In Q35 and SBSA testing stack overflows which now look like:

image image

Integration Instructions

N/A.

@patina-automation

patina-automation Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

✅ QEMU Validation Passed

All QEMU validation jobs completed successfully.

Note: Q35 is only built on Windows hosts (QEMU boot is disabled due to a QEMU vfat issue).

Workflow run: https://github.com/OpenDevicePartnership/patina/actions/runs/27032539361

Boot Time to EFI Shell

Platform Elapsed
Q35 (Linux Host) 26.6s
SBSA (Linux Host) 34.3s

Dependencies

Repository Ref
patina b14f3ca
patina-dxe-core-qemu 178b781
patina-fw-patcher 1958fd4
patina-qemu firmware v3.0.0
patina-qemu build script b9cb783

This comment was automatically generated by the Patina QEMU PR Validation Post workflow.

@codecov

codecov Bot commented Jun 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Comment thread core/patina_internal_cpu/src/interrupts/x64/idt.rs
@os-d os-d force-pushed the exception_updates branch from 4c67189 to dae4a0e Compare June 3, 2026 20:01
Comment thread core/patina_internal_cpu/src/interrupts/x64/interrupt_manager.rs Outdated
os-d added 3 commits June 5, 2026 11:06
Currently, only double faults use a separate stack. However,
a stack overflow manifests as a page fault, so taking a stack
overflow causes a double fault. This makes it harder to reason
about what the fault was.

This commit instead using a separate stack for x64 page faults,
aligning with the aarch64 side. This is in preparation for giving
better information about stack overflows in the exception handlers.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
Currently, stack overflows show up as page faults in the
exception handlers. This can make it hard to identify when a
different page fault has occurred.

This commit introduces a heuristic to hint that a stack overflow
likely occurred in the exception handler. It checks if the faulting
address is on the same page as or one page lower than the stack pointer.
In some cases, the stack pointer is incremented first, then data is
written (in which case the faulting address is on the same page as the
stack pointer) and in other cases the data is written before the stack
pointer is decremented (so the faulting address is on the page below
the stack pointer).

A pretty message is then printed to indicate a stack overflow occurred.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
The EfiExceptionStackTrace trait is an internal trait that
originally was just used so the common exception handler
can use arch specific stack trace dumping.

However, this was expanded to also include dumping a page
table walk, so the name is not accurate.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
@os-d os-d force-pushed the exception_updates branch from dae4a0e to b14f3ca Compare June 5, 2026 18:06
@os-d os-d enabled auto-merge (rebase) June 5, 2026 18:06
@os-d os-d merged commit 446a64d into OpenDevicePartnership:main Jun 5, 2026
11 checks passed
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.

3 participants