There are applications that uses SRWLOCK in an invalid way and then checks its binary representation. Specifically they releases an unlocked SRWLOCK then check its bit pattern is all-ones.
Tweak the representation a bit so they are happy.
-- v2: ntdll: Tweak the binary representation of SRWLOCK.
From: Yuxuan Shui yshui@codeweavers.com
There are applications that uses SRWLOCK in an invalid way and then checks its binary representation. Tweak our representation a bit so they are happy. --- dlls/ntdll/sync.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/dlls/ntdll/sync.c b/dlls/ntdll/sync.c index fa64917029a..90370abba09 100644 --- a/dlls/ntdll/sync.c +++ b/dlls/ntdll/sync.c @@ -473,8 +473,6 @@ DWORD WINAPI RtlRunOnceExecuteOnce( RTL_RUN_ONCE *once, PRTL_RUN_ONCE_INIT_FN fu
struct srw_lock { - short exclusive_waiters; - /* Number of shared owners, or -1 if owned exclusive. * * Sadly Windows has no equivalent to FUTEX_WAIT_BITSET, so in order to wake @@ -487,6 +485,8 @@ struct srw_lock * must not be the first element in the structure. */ short owners; + + short exclusive_waiters; }; C_ASSERT( sizeof(struct srw_lock) == 4 );
After some experimentation, I believe WeCom is doing 2 tests. The "releasing an unlocked SRWLOCK and see if it's all-1s" only happens after the first test fails. Swapping the 2 fields is enough to pass the first test.
I didn't notice `owners` can't be the first field... Is there a way around that?
On Mon Nov 6 16:28:16 2023 +0000, Yuxuan Shui wrote:
I didn't notice `owners` can't be the first field... Is there a way around that?
OK, I looked around a bit. `WaitOnAddress` has a size parameter, isn't that enough to indicate waiting on `owners` only? We don't need the non-four-byte-aligned-ness for that.