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

Switch from AddVectoredExceptionHandler to SetUnhandledExceptionFilter to avoid false positives #2334

Merged
merged 1 commit into from
Jan 3, 2022
Merged

Conversation

Alan-Jowett
Copy link
Contributor

Description

What

Catch2 incorrectly registers for SIGSEGV and other signals on Windows. The correct behavior is to register as the top-level unhandled exception filter so that it is notified last after the application has had an opportunity to handle the exception and after the debugger has been notified. The previous behavior was to register a vectored exception handler which results in Catch2 being notified prior to the application being able to handle the exception.

Why

Visual Studio 2022 uses structured exceptions to implement address sanitization (/fsanitize=address). This issue results in Catch2 being incompatible with a key bug-finding feature of VS 2022.

GitHub Issues

Closes #2332

Notes for maintainers

I didn't see any Windows-specific tests and I am unsure how to validate the new behavior in the CI/CD pipeline. I manually verified the change fixes the issue but would prefer to add a new test to the CI/CD pipeline if possible.

Signed-off-by: Alan Jowett alanjo@microsoft.com

@codecov
Copy link

codecov bot commented Dec 15, 2021

Codecov Report

Merging #2334 (f923304) into devel (54e89e8) will decrease coverage by 0.25%.
The diff coverage is 60.00%.

❗ Current head f923304 differs from pull request most recent head f004061. Consider uploading reports for the commit f004061 to get more accurate results

@@            Coverage Diff             @@
##            devel    #2334      +/-   ##
==========================================
- Coverage   91.13%   90.88%   -0.25%     
==========================================
  Files         152      151       -1     
  Lines        7316     7229      -87     
==========================================
- Hits         6667     6570      -97     
- Misses        649      659      +10     

@horenmar
Copy link
Member

Do I assume correctly that this will also fix #2286 and probably #898 as well?

@Alan-Jowett
Copy link
Contributor Author

Added test to Misc.tests.cpp to validate modified SEH handling behavior on Windows. If this is the wrong test to add it to, let me know and I can move it.

@Alan-Jowett
Copy link
Contributor Author

Do I assume correctly that this will also fix #2286 and probably #898 as well?

It should based on the description in the issues.

@horenmar
Copy link
Member

Can you also add a test that unhandled exception still fails tests? To hide the test from standard run, add [.approvals] tag to it. ([approvals] is a special tag for tests that shouldn't be run as part of approval tests, . prefix is a short for [.] which hides the test unless it is explicitly selected).

Otherwise LGTM.

@horenmar
Copy link
Member

I rebased the PR to contain the changes to JIT debugging, but the issue is still there: exception escaping the binary into CTest still causes wait until timeout.

@Alan-Jowett
Copy link
Contributor Author

Let me take a look and see what is happening.

@Alan-Jowett
Copy link
Contributor Author

Will take a look at this when I get back next year. Have a great new year.

@horenmar
Copy link
Member

horenmar commented Jan 3, 2022

@Alan-Jowett Thanks for the PR, I am going to drop the failing test and merge the other parts.

It would be appreciated if you still tried to solve the issue with the JIT debugger on AppVeyor, but even without that this is still an improvement over what is there right now.

This avoids issues with Catch2's handler firing too early, on
structured exceptions that would be handled later. This issue
meant that the old attempts at structured exception handling
were incompatible with Windows's ASan, because it throws
continuable `C0000005` exception, which it then handles.

With the new handling, Catch2 is only notified if nothing else,
including the debugger, has handled the exception.

Signed-off-by: Alan Jowett <alanjo@microsoft.com>

Closes #2332
Closes #2286
Closes #898
@alvinhochun
Copy link

Is it possible to backport this change to v2.x? I have hit the same issue with ASAN using LLVM/Clang.

@horenmar
Copy link
Member

I am willing to merge a PR that does the backport (inc. tests)

@ScottHutchinson
Copy link
Contributor

Is it possible to backport this change to v2.x?

My team will try to do this, unless @alvinhochun or somebody else is already working on it.

@alvinhochun
Copy link

Thanks, I haven't started backporting this for real, so you can do it if you would like to.

@ScottHutchinson
Copy link
Contributor

I have manually tested the fix locally and it works. I expect to submit a PR by Monday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Catch2 fails tests when exception C00000005 is thrown then caught
4 participants