Skip to content
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

Fix stack pointer in core dumps #76221

Closed
wants to merge 2 commits into from

Conversation

arbrauns
Copy link
Contributor

The register set in the coredump contains the register values from just before the trap (these are pushed by hardware as the exception stack frame/ESF). Thus, the SP register also needs to point to the stack location from before the ESF was pushed; this is simply the location of the ESF plus the size of the ESF.

ithinuel
ithinuel previously approved these changes Jul 31, 2024
@arbrauns arbrauns marked this pull request as draft August 1, 2024 11:38
@arbrauns
Copy link
Contributor Author

arbrauns commented Aug 1, 2024

Marking as draft because it needs more logic - the size of the Exception Stack Frame depends on whether or not floating-point instructions were used by the faulting thread: https://developer.arm.com/documentation/107706/0100/Floating-point-and-MVE-support/Floating-point-context-handling-mechanisms?lang=en

Bit 4 of EXC_CAUSE (stored in lr on exception entry) tells us whether it's a Basic or Extended stack frame. This is easy enough to check in z_arm_fault(), which already gets exc_cause as an arument, but z_do_kernel_oops() is shared between Cortex-M and Cortex-A/R, the latter of which don't even have a concept of exception stack frames. How can I sneak this in there without too many hacks?

This was introduced in ff1a5e7, which
already put the ESF in r0 and the exception reason in r1.

Signed-off-by: Armin Brauns <[email protected]>
@arbrauns arbrauns force-pushed the coredump-fix-sp branch 2 times, most recently from 927f590 to b33d0ad Compare August 2, 2024 14:22
The register set in the coredump contains the register values from just
before the trap (these are pushed by hardware as the exception stack
frame/ESF). Thus, the SP register also needs to point to the stack location
from *before* the ESF was pushed; this is obtained by incrementing the
address of the ESF by the size of the ESF.

The ESF can be of two types[0]: a Basic stack frame or an Extended stack
frame (including FPU registers). Bit 4 in EXC_RETURN (stored in lr on
exception entry) determines which type is used.

Cortex-A/Cortex-R, don't have hardware exception stacking at all, but also
no support for coredumps, so the value passed to exc_return is irrelevant.

[0]: https://developer.arm.com/documentation/107706/0100/Floating-point-and-MVE-support/Floating-point-context-handling-mechanisms

Signed-off-by: Armin Brauns <[email protected]>
@arbrauns
Copy link
Contributor Author

arbrauns commented Aug 5, 2024

I don't understand the C++ errors (invalid application of 'sizeof' to incomplete type 'z_arm_get_hw_esf_size(uint32_t)::__basic_sf').

@mrkhldn
Copy link
Contributor

mrkhldn commented Aug 6, 2024

I believe I'm trying to address the same issue here - #73189

@arbrauns
Copy link
Contributor Author

arbrauns commented Aug 7, 2024

Hah, indeed, left a review there.

@MaureenHelm
Copy link
Member

@ithinuel please take a look

@kartben
Copy link
Collaborator

kartben commented Nov 25, 2024

@arbrauns this needs rebasing. Thanks!

@arbrauns
Copy link
Contributor Author

Fixed by #79622.

@arbrauns arbrauns closed this Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Architectures area: ARM ARM (32-bit) Architecture
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants