Conversation
src/arch/aarch64.rs
Outdated
| seh!(".seh_save_fplr_x 32"), | ||
| "str x19, [sp, #16]", | ||
| seh!(".seh_save_reg x19, 16"), | ||
| seh!("mov x29, sp"), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Good point. Our usage only resumes once; so I missed this in testing. I'll dig into it a bit more for a fix.
There was a problem hiding this comment.
@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.
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_returnTested using the Patina QEMU project using the WinDbg support provided as part of that project.