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 DAC hardware exception handling on Unix #79824

Closed

Conversation

janvorli
Copy link
Member

Currently libmscordac doesn't install sigsegv handler and also isn't compiled with support for handling hardware exceptions in its native code. So when debugger ends up calling e.g.
MethodTable::ValidateWithPossibleAV and the passed in MethodTable is invalid, e.g. located in an unmapped region of memory, the sigsegv causes the debugger to abort. It was found when using the ClrMD in BnechmarkDotNet disassembler code which is trying to find if some constants in the code represent MethodTable or MethodDesc.

This change fixes it by setting the PAL_INITIALIZE_REGISTER_SIGNALS flag for PAL_InitializeDLL called from the mscordac's DllMain and adding the FEATURE_ENABLE_HARDWARE_EXCEPTIONS for the mscordac build.`

Currently libmscordac doesn't install sigsegv handler and also isn't
compiled with support for handling hardware exceptions in its native
code. So when debugger ends up calling e.g.
`MethodTable::ValidateWithPossibleAV` and the passed in `MethodTable` is
invalid, e.g. located in an unmapped region of memory, the sigsegv
causes the debugger to abort. It was found when using the ClrMD in
BnechmarkDotNet disassembler code which is trying to find if some
constants in the code represent `MethodTable` or `MethodDesc`.

This change fixes it by setting the `PAL_INITIALIZE_REGISTER_SIGNALS`
flag for `PAL_InitializeDLL` called from the mscordac's `DllMain`
and adding the `FEATURE_ENABLE_HARDWARE_EXCEPTIONS` for the mscordac
build.`
@ghost
Copy link

ghost commented Dec 19, 2022

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

Issue Details

Currently libmscordac doesn't install sigsegv handler and also isn't compiled with support for handling hardware exceptions in its native code. So when debugger ends up calling e.g.
MethodTable::ValidateWithPossibleAV and the passed in MethodTable is invalid, e.g. located in an unmapped region of memory, the sigsegv causes the debugger to abort. It was found when using the ClrMD in BnechmarkDotNet disassembler code which is trying to find if some constants in the code represent MethodTable or MethodDesc.

This change fixes it by setting the PAL_INITIALIZE_REGISTER_SIGNALS flag for PAL_InitializeDLL called from the mscordac's DllMain and adding the FEATURE_ENABLE_HARDWARE_EXCEPTIONS for the mscordac build.`

Author: janvorli
Assignees: janvorli
Labels:

area-Diagnostics-coreclr

Milestone: -

@janvorli
Copy link
Member Author

Interestingly, it was "broken" this way even in 3.1, 5.0 and 6.0.

@mikem8361
Copy link
Member

We purposely don't enable native exceptions in the DAC on Linux/MacOS because catching them and dispatching via a "software" exception through the C++ runtime doesn't always work. The C++ runtime doesn't expect exceptions at any arbitrary place in the code. The only way I've come up with to fix the ValidateWithPossibleAV functions is to make them fully DAC'ized so the invalid memory it accesses is done with read memory and a software exception is thrown/caught. I think I fixed some the places in 7.0 like in DacValidateMD, I know there are still more. This all works on Windows because SEH is used and the C++ can handle it.

/cc: @jkotas

@janvorli
Copy link
Member Author

Ah, now I remember, IIRC the issue was when the failure stems from functions where there is no try / catch in the method where the fault can occur (inlining can make it a bit better).
@mikem8361 thank you for the suggestion of full DAC-ization of the problematic methods.

I will close this PR and fix the issue by DAC-izing the methods that the BenchmarkDotNet disassembler uses.

@janvorli janvorli closed this Dec 19, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jan 18, 2023
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.

2 participants