-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Capture AccessViolationException #12077
Comments
I'd say it's generally a bad idea to execute any code when this happens. Windows Error Reporting (aka Watson) can provide memory dumps in these occasions. This can be used both for local diagnosis and for tracking the errors from customers through the Partner Portal (as long as the application is signed with valid code signing certificate). |
I don't want to use Window error reporting because:
In short it's a terrible solution for us. I'm well aware that it's not smart to continue running but ultimately I think that decision should be left to the developer, not the .net runtime. Just like it is with framework. And by default there needs to be something to tell the user a crash has occurred, not just closing the application. As a bare minimum the documentation needs to make it clear that this feature doesn't work in .net core, really the tag should just be removed if it's not going to be supported (it should be supported) |
@dotnet/dotnet-diag for suggestions |
I kinda started writing a long follow-up before I noticed this sentence... Can you elaborate on why 64Kb pages are a problem for you? How would 4Kb pages help you? Are you trying to create some guard page scheme? I will post my original follow-up anyway in case someone else stumbles upon it:
|
Agreed. If the documentation is wrong it should be fixed. Note that the documentation is hosted on GitHub, so issues/PRs can be submitted for it. |
To start the reason all this is needed is because we are writing a switch emulator called Ryujinx (https://github.com/Ryujinx/Ryujinx)
This basically is kernel code. At least it's emulating one. We want to be able to allocate pages but if the game accesses an unmapped page we want to capture it. As we are emulating switch games it's very rare the game is actually broken and probably the emulator. This also leads on to this question:
If we could use 4kb pages we could directly map the switch (ARM) address space to windows. Meaning we can cut out all page table translation as the hardware will do it for up. On linux this is available and it works giving us the fastest solution possible. On windows you can't do that unless you are a driver, for unknown reason as it internally uses 4kb pages -_- Regarding WER My point That was a long post so if I missed out something from your question I apologize, just let me know. |
Thinking about it. I should really ask. |
If you only care about running on Windows - you might be able to "handle" your EXCEPTION_ACCESS_VIOLATION by registering your own VectoredExceptionHandler. You need to make sure you:
Fingers crossed, it might just work. Adding a vectored exception handler after CoreCLR did and so it acts as the first one is a total hack. It is neither recommended nor supported, but it might solve your problem. Would love to hear from you if it works. |
That does sound like a total hack. I doubt it will be accepted on released code but I will mess around with it tomorrow anyway because it just seems interesting. I would still like a proper solution. |
@janvorli am I remembering right that you did a bunch of the earlier exception handling work for .Net Core? Do you recall if there was a conscious decision one way or another to support corrupting state exceptions? Looking in the code I see conflicting evidence, for example FEATURE_CORRUPTING_EXCEPTIONS appears enabled, but the test tree has no tests for it and in practice it doesn't appear to work. |
I've verified that if you set env var COMPlus_legacyCorruptedStateExceptionsPolicy=1, you can catch the exception in .NET Core. The HandleProcessCorruptedStateExceptionsAttribute should work too, based on what I can see in the runtime here: |
Could it be related to this: dotnet/coreclr#10957 ? |
@janvorli To the best of your understanding the fact that it doesn't work is simply a bug we should fix (and hopefully add tests for) rather than a feature we deliberately wanted to disable for some reason? |
dotnet/coreclr#10957 certainly looks related. @jkotas perhaps you could add a little background since you filed #7272? |
Reading through #7272 more thoroughly, a few bits of interest: https://github.com/dotnet/coreclr/issues/9045#issuecomment-292452208
https://github.com/dotnet/coreclr/issues/9045#issuecomment-290159433
https://github.com/dotnet/coreclr/issues/9045#issuecomment-289949603
|
Ok, it seems all the details /reasons are now clear. The legacyCorruptedStateExceptionsPolicy config switch is what @BaronKiko can use. |
So I should be using https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/legacycorruptedstateexceptionspolicy-element |
This sounds like a bug. The runtime should not exit silently on fatal crash. Yes, we should fix the docs. I would not recommend using For cases where folks want to get details about fatal crashes (ie implement their own WER or fatal crash detail uploader), I think we should be looking at introducing unmanaged C API to provide these details. |
I have taken a look why it exits silently. The issue is in this function: |
It seems it would be simple to change that to log the call stack and exception details for all exitCode values. |
Sounds to me like something that should be done. Jan do you have time? |
Yes, I can do it. |
To sum up all this:
Does that sum up the situation correctly? |
@cshung I tried your strange solution. I only spent an hour or so on it but I couldn't get it to work. Was quickly getting messy but I think it would technically work. Even if it's frankly too hacky for real use. |
@BaronKiko have you tried to set the |
@janvorli I tried setting it on the first line in main with: This didn't change anything but I'm assuming by the time it gets to main it's already too late. |
Yes, it needs to be done before running the app. |
It looks like the question has been answered. Feel free to re-open if needed. |
I know it outputs error info on a crash now, is this on .net core 2 or only on 3? Edit: Have the docs been updated? |
Perhaps my interest is very specialized, but might it be possible to opt into handling AV's and maybe SEH's for a particular memory region? I understand why this behavior is being made but I regret how completely it appears the goal is to try to erradicate any access at all. I am not interested in diagnostics or crash dumps and I would hope not to have to set that environment variable and launch a child process or tricks like that. I would be happy installing a vectored handler on top of the one of the CLR, were it not that the native code will spread like the plague because the native/managed transitions are wicked way too slow for my purpose. And the whole code path gets blocked on UWP because it does not have the one API to set the handler though it has all others that fit my needs. Short of going native all the way and get 4x faster AV's, but well...going native, wouldn't it be great for some scenario's to be able to let those AV's through in a |
The flag just allows you to catch the exceptions with a try catch so you can check the mem address then and handle it however you want. I'm pretty sure it gives you the address in the exception but worst case you can get it from the exception string. |
Setting the flag defeats all these pulls that change the behavior so that And it is just not suitable to have to force the flag on short of writing a custom CLR host, plus in UWP apps afaik there is no way to set the flag at all. |
@BaronKiko @jkotas @janvorli
What current state on this problem? What you will advice? |
@kirsan31 we have not introduced any API for reporting fatal crashes yet. So you are still left with the |
Sadly to hear :( Any eta, and/or issue to track on this?
It's very strange, but It's not working for us (and not only for us).
or via launcher app: Environment.SetEnvironmentVariable("COMPlus_legacyCorruptedStateExceptionsPolicy", "1");
Process.Start("AccessViolationExceptionTest.exe"); and/or setting dword During all experiments, only in first attempt with |
@kirsan31 Note that if you use Interestingly, that seems to be caused by statically linking VC Runtime to coreclr.dll. In .NET Framework 4.x the AV call stack on x64 contains the following frames:
and AV's address is in the 'VCRUNTIME140_CLR0400' module. Compare to .NET Core 3.0:
where AV's address (the @kirsan31 Feel free to open a new issue for this defect. Mentioning @janvorli for awareness. |
@AntonLapounov Thank you very match for you answer. int AVE()
{
int ptr = *(int*)0 = 0;
return ptr;
} and calling it from .net core app generates AVE, that successfully captured... |
Hi
I would like to be able to capture an AccessViolationException to provide useful information about why the application crashed. I don't intend to continue running the application, I just want some of the information that would be available when run inside visual studio.
Currently the program silently closes without reporting anything when run outside visual studio. At the very least I would like a dialog box saying the application crashed due to an AccessViolationException.
Taking this example program: https://gist.github.com/gdkchan/bd18dea1679283ff6e2c152b5f836927
In .Net framework I can simply use a try/catch around line 115. (In 4.0 onward there is some tags needed)
I would like to be able to do that in Core however the tags aren't honored so it's not possible
Thank you for your time.
The text was updated successfully, but these errors were encountered: