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

SEH for thread naming in Visual Studio build is not correct in 4.3.3 #4140

Closed
jakecobb opened this issue Feb 11, 2021 · 2 comments
Closed

SEH for thread naming in Visual Studio build is not correct in 4.3.3 #4140

jakecobb opened this issue Feb 11, 2021 · 2 comments

Comments

@jakecobb
Copy link
Contributor

Issue description

Issue #3586 and PR #3601 introduced a regression by faulty Structured Exception Handling (SEH) in Visual Studio / MSBuild environments. The change was trying to remove the MS-specific __try and __except that are used to set the thread name for debugging. This exception mechanism is the Microsoft way of setting the thread name, see:

https://docs.microsoft.com/en-us/visualstudio/debugger/how-to-set-a-thread-name-in-native-code?view=vs-2019#set-a-thread-name-by-throwing-an-exception

There is a newer SetThreadDescription API but it is not available in all supported versions of Windows.

The __try/__except form was replaced by a bunch of NT API calls that appear to be mimicking SEH. Under most circumstances it seems ok, e.g. running and debugging seem to work without error and the thread names are set when debugging in Visual Studio. However, in OpenCppCoverage it is triggering an unhandled SEH exception which leads to an abort:

OpenCppCoverage/OpenCppCoverage#141

Using ZeroMQ 4.3.2, no unhandled SEH exception is seen by OpenCppCoverage, so this change did not preserve the semantics of the __try/__except construct.

Environment

  • libzmq version: 4.3.3, 4.3.4
  • OS: Windows 10
  • Compiler: Visual Studio 2015

Minimal test code / Steps to reproduce the issue

Run the following under any recent OpenCppCoverage (e.g. 0.9.9.0):

#include <zmq.h>

int main(int argc, char**argv)
{
  void* context = zmq_ctx_new();
  void* socket = zmq_socket(context, ZMQ_PUB); // crash here with opencppcoverage

  zmq_close(socket);
  zmq_ctx_term(context);
  return 0;
}

What's the actual result? (include assertion message & call stack if applicable)

An unhandled exception (in the SEH sense, not the C++ exception sense) is detected by OpenCppCoverage and the program is aborted with:

----------------------------------------------------
*** Your application has thrown an unhandled exception. Code: 1080890248: Unknown
----------------------------------------------------

What's the expected result?

No error occurs and the program exits cleanly.

@bluca
Copy link
Member

bluca commented Feb 12, 2021

Can you send a PR?

@jakecobb
Copy link
Contributor Author

Duplicate of #4128.

Sorry, should have checked the unreleased branch before submitting, already fixed.

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

No branches or pull requests

2 participants