-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Fix exception propagation over HW exception frame on macOS arm64 #63596
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
Merged
janvorli
merged 4 commits into
dotnet:main
from
janvorli:fix-macos-arm64-exception-propagation-over-hw-exception-frame
Jan 20, 2022
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
16652fa
Fix exception propagation over HW exception frame on macOS arm64
janvorli f15b34e
Fix GC stress C - wrong context being restored
janvorli cc2df9c
Fix exception context leak in GC stress C
janvorli 62f2e7e
Reenable DllImportGenerator.Unit.Tests
janvorli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Fix exception propagation over HW exception frame on macOS arm64
There is a problem unwinding over the PAL_DispatchExceptionWrapper to the actual hardware exception location. The unwinder is unable to get distinct LR and PC in that frame and sets both of them to the same value. This is caused by the fact that the PAL_DispatchExceptionWrapper is just an injected fake frame and there was no real call. Calls always return with LR and PC set to the same value. The fix unifies the hardware exception frame unwinding with Linux where we had problems unwinding over signal handler trampoline, so PAL_VirtualUnwind skips the trampoline and now also the PAL_DispatchExceptionWrapper frame by copying the context of the exception as the unwound context.
- Loading branch information
commit 16652fadd482f54ed55bd1a9c0da2f1c324a809b
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
|
|
||
| public class Program | ||
| { | ||
| private interface IFoo | ||
| { | ||
| bool IsValid { get; } | ||
| } | ||
|
|
||
| private class Foo : IFoo | ||
| { | ||
| public bool IsValid { get; set; } | ||
| } | ||
|
|
||
| public static int Main(string[] args) | ||
| { | ||
| bool warmup = new Foo().IsValid; | ||
| CatchIgnore(() => | ||
| CatchRethrow(() => | ||
| { | ||
| IFoo[] foos = {new Foo(), null}; | ||
| foreach (var foo in foos) | ||
| { | ||
| bool check = foo.IsValid; | ||
| } | ||
| })); | ||
|
|
||
| return 100; | ||
| } | ||
|
|
||
| public static void CatchRethrow(Action action) | ||
| { | ||
| try | ||
| { | ||
| action.Invoke(); | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| Console.Out.WriteLine("catch"); | ||
| Console.Out.Flush(); | ||
| throw new Exception("catch", e); // throw; doesn't work either | ||
janvorli marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| public static void CatchIgnore(Action action) | ||
| { | ||
| try | ||
| { | ||
| action.Invoke(); | ||
| } | ||
| catch (Exception) | ||
| { | ||
| Console.Out.WriteLine("ignore"); | ||
| Console.Out.Flush(); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <CLRTestPriority>1</CLRTestPriority> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Compile Include="test62058.cs" /> | ||
| </ItemGroup> | ||
| </Project> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@janvorli, should this:
runtime/src/coreclr/pal/src/exception/seh-unwind.cpp
Lines 186 to 187 in f3e4e76
(only pass one argument to
ASSIGN_FP_REG)While working on #64043, I had a misconfiguration (related to
UNWIND_CONTEXT_IS_UCONTEXT_Tdetection) and was getting errors during macro expansion, when this code compiled on linux arm64.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@am11 Seems to be the case considering the only use of
ASSIGN_FP_REGhas a single argument.runtime/src/coreclr/pal/src/exception/seh-unwind.cpp
Lines 134 to 157 in f3e4e76
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this code was ever compiling and is dead? cl.exe on Windows and clang on Linux both fail the
UNWIND_CONTEXT_IS_UCONTEXT_Ttest and set it to 0 onmain. To unveil the problem, i.e. misconfiguration which I had -- in order to set it to 1, delete the last/includefrom:runtime/src/coreclr/pal/src/configure.cmake
Line 1033 in f3e4e76
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@am11 you are right, it is a dead code. I've added it when fixing floating point registers unwind because we had that code path for ARM64. However, the libunwind currently doesn't use the ucontext_t as unwind context for ARM64, IIRC a comment in there says it is done that way in order to reduce size of the unwind context. So everything for ARM64 with
UNWIND_CONTEXT_IS_UCONTEXT_Tset is not being ever compiled.I think that we should just remove all of that and replace it with
#error