Skip to content

Add SEH for aarch64 UEFI target#75

Open
joschock wants to merge 2 commits intoAmanieu:masterfrom
joschock:uefi_seh_aarch64
Open

Add SEH for aarch64 UEFI target#75
joschock wants to merge 2 commits intoAmanieu:masterfrom
joschock:uefi_seh_aarch64

Conversation

@joschock
Copy link
Copy Markdown
Contributor

Adds SEH support for AARCH64 UEFI targets.

Tested that this produces full backtraces on UEFI targets in windbg where backtraces used to stop at stack_init_trampoline_return

Tested using the Patina QEMU project using the WinDbg support provided as part of that project.

seh!(".seh_save_fplr_x 32"),
"str x19, [sp, #16]",
seh!(".seh_save_reg x19, 16"),
seh!("mov x29, sp"),
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Unfortunately this is incorrect: you are saving the parent SP at the time the coroutine is first entered into x29, but this value will be invalid for later resumes of the coroutine. Instead you need to do what the CFI code is doing (and what the x86_64 SEH code is doing) which is to load the value from the parent link field on the stack since that is dynamically updated to the parent stack pointer value on each stack switch.

I haven't looked at the exact AArch64 SEH opcodes but it would probably involve x29 pointing at the parent link and be something like:

  • move x29 to SP
  • load x29 from [SP]
  • mov x29 to SP
  • load x19, x29, lr from [SP]

You also shouldn't worry about making the SEH precise for every instruction. That's just not possible with the current structure of stack_init_trampoline.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. Our usage only resumes once; so I missed this in testing. I'll dig into it a bit more for a fix.

Copy link
Copy Markdown
Contributor Author

@joschock joschock Apr 13, 2026

Choose a reason for hiding this comment

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

@Amanieu thank you for the feedback; I've updated the implementation accordingly. I'm still very new to SEH (in general) on AARCH64 (in particular) and I used AI to help me learn the area and build the code. I'm under no illusion that I'm an expert here - so if you have a suggestions on better approaches, I am all ears.

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