-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Ensure Debug Help library calls on Windows are made in as thread-safe a manner as possible by wrapping them in a scoped lock. #40815
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
Ensure Debug Help library calls on Windows are made in as thread-safe a manner as possible by wrapping them in a scoped lock. #40815
Conversation
/// calls into it from the Swift runtime and stdlib should route through this | ||
/// function. | ||
SWIFT_RUNTIME_STDLIB_SPI | ||
bool _swift_withDebugHelpLibrary( |
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.
This function should be exported so that it can be used by other Swift libraries in the repo if needed. It's not sufficient for those libraries to do their own locking; they would need to use the same lock to ensure thread safety.
@swift-ci please test |
09ef4b9
to
d7ed5eb
Compare
@swift-ci please test |
d7ed5eb
to
52126d6
Compare
@swift-ci please test |
52126d6
to
896d484
Compare
@swift-ci please test |
/// On Windows, the Debug Help library (DbgHelp.lib) is not thread-safe. All | ||
/// calls into it from the Swift runtime and stdlib should route through this | ||
/// function. | ||
template < |
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.
And this is where I'd put my if constexpr
… if I had one. (Only available in C++17, must use std::enable_if
in its absence.)
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.
Blarg.
Quite. |
… a manner as possible by wrapping them in a scoped lock.
896d484
to
0db7b5a
Compare
@swift-ci please smoke test |
Ensure Debug Help library calls on Windows are made in as thread-safe a manner as possible by wrapping them in a scoped lock.
According to the Win32 documentation, the functions in the Debug Help library (DbgHelp.lib) are not thread-safe. That means that calling them across threads may blow up the process.
While we don't have a mechanism to control the use of this library outside the runtime/stdlib, we can at least ensure that all uses of it within the runtime/stdlib are thread-safe. We do so by exposing a new C++ runtime function,
swift::withDebugHelpLibrary()
, that callers can invoke. This function acquires a lock and ensuresSymInitialize()
has been called and has succeeded before any work is done that relies on the library.