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 Windows Arm64 unwinding #102258

Merged
merged 2 commits into from
May 16, 2024
Merged

Conversation

janvorli
Copy link
Member

There was an issue with unwinding native code functions in case of calls to no-return function placed at an end of a function code block. The return address was not in range of the function code, so RtlLookupFunctionEntry was not finding anything, we were thinking that it was a leaf function due to that and tried to unwind using LR only, which was wrong and resulted in staying on the same instruction. Thus the unwinding ended up in an infinite loop for those cases. The fix, that matches what RtlUnwind does, is to adjust the instruction pointer at call sites back. This is arm64 specific.

Close #101921

There was an issue with unwinding native code functions in case of calls
to no-return function placed at an end of a function code block. The
return address was not in range of the function code, so
RtlLookupFunctionEntry was not finding anything, we were thinking that
it was a leaf function due to that and tried to unwind using LR only,
which was wrong and resulted in staying on the same instruction. Thus
the unwinding ended up in an infinite loop for those cases.
The fix, that matches what RtlUnwind does, is to adjust the instruction
pointer at call sites back. This is arm64 specific.

Close dotnet#101921
@janvorli janvorli added this to the 9.0.0 milestone May 15, 2024
@janvorli janvorli requested a review from jkotas May 15, 2024 14:06
@janvorli janvorli self-assigned this May 15, 2024
Copy link
Contributor

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

@@ -553,6 +553,13 @@ PCODE Thread::VirtualUnwindCallFrame(T_CONTEXT* pContext,
UINT_PTR uImageBase;
PT_RUNTIME_FUNCTION pFunctionEntry;

#if !defined(TARGET_UNIX) && defined(CONTEXT_UNWOUND_TO_CALL)
Copy link
Member

Choose a reason for hiding this comment

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

When is CONTEXT_UNWOUND_TO_CALL not defined on Windows here?

I see CONTEXT_UNWOUND_TO_CALL defined for both x64 and arm64 in Windows SDK.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, that's strange. In pal.h we don't define it for x64 and Windows also doesn't set it for non-arm.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've added a commit to change that ifdef to TARGET_ARM64

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

Thanks

@janvorli janvorli merged commit ccce949 into dotnet:main May 16, 2024
89 checks passed
@janvorli janvorli deleted the fix-windows-arm64-unwinding branch May 16, 2024 11:36
Ruihan-Yin pushed a commit to Ruihan-Yin/runtime that referenced this pull request May 30, 2024
* Fix Windows Arm64 unwinding

There was an issue with unwinding native code functions in case of calls
to no-return function placed at an end of a function code block. The
return address was not in range of the function code, so
RtlLookupFunctionEntry was not finding anything, we were thinking that
it was a leaf function due to that and tried to unwind using LR only,
which was wrong and resulted in staying on the same instruction. Thus
the unwinding ended up in an infinite loop for those cases.
The fix, that matches what RtlUnwind does, is to adjust the instruction
pointer at call sites back. This is arm64 specific.

Close dotnet#101921

* Modify the ifdef from CONTEXT_UNWOUND_TO_CALL to TARGET_ARM64
@github-actions github-actions bot locked and limited conversation to collaborators Jun 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Infinite loop in Frame::UpdateFloatingPointRegisters on ARM64
3 participants