-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Windows: Mutex not properly initialized #53126
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
Comments
Seems like there is a bigger problem: We actually invoke UB on Windows by attempting to recursively lock an SRWLock. See #35836. |
#define SRWLOCK_INIT RTL_SRWLOCK_INIT
#define RTL_SRWLOCK_INIT {0} Therefore zero initializing the lock is in fact a valid way of initializing the lock. |
Well, that is exploiting an implementation detail. Admittedly, they can't really ever change this since it gets embedded in the compiled programs, but still -- we could at least have an |
What would the point of an The value of a constant is not an implementation detail, given that Microsoft provides strong stability guarantees about the values of constants in the headers. Therefore I fail to see any issue here. Besides, if we want to be able to initialize a lock in a constant expression, we have to use the constant and not the runtime function |
@retep998: agree, but what about using a constant rather than hardcoded zero and/or a comment with your explanation? |
Feel free to submit a PR that adds comments to that effect. |
It's different Rust code, so this is at least a basic sanity check. |
On Windows, a mutex is initialized with
and then, if
kind()
determines we are using SRWLock, the next thing that could happen isAcquireSRWLockExclusive
. However, the documentation for InitializeSRWLock says that the lock must be initialized before it is used.I am not at all an expert in the Windows API, but -- aren't we relying on undocumented behavior here, namely, that setting the lock to
0
is a proper way to initialize it?The text was updated successfully, but these errors were encountered: