[xboxkrnl] ExAcquireReadWriteLockExclusive fixes.

[xboxkrnl] ExAcquireReadWriteLockExclusive fixes:
- Don't unnecessarily double-load lock count.
- Don't release spin lock before we're done with the lock.
This commit is contained in:
gibbed 2022-01-07 09:12:54 -06:00 committed by Rick Gibbed
parent fa774f1d86
commit b4f35635c5
1 changed files with 8 additions and 6 deletions

View File

@ -1184,18 +1184,20 @@ DECLARE_XBOXKRNL_EXPORT1(ExInitializeReadWriteLock, kThreading, kImplemented);
void ExAcquireReadWriteLockExclusive(pointer_t<X_ERWLOCK> lock_ptr) { void ExAcquireReadWriteLockExclusive(pointer_t<X_ERWLOCK> lock_ptr) {
auto old_irql = xeKeKfAcquireSpinLock(&lock_ptr->spin_lock); auto old_irql = xeKeKfAcquireSpinLock(&lock_ptr->spin_lock);
lock_ptr->lock_count++;
xeKeKfReleaseSpinLock(&lock_ptr->spin_lock, old_irql);
if (!lock_ptr->lock_count) { int32_t lock_count = ++lock_ptr->lock_count;
if (!lock_count) {
xeKeKfReleaseSpinLock(&lock_ptr->spin_lock, old_irql);
return; return;
} }
lock_ptr->writers_waiting_count++; lock_ptr->writers_waiting_count++;
xeKeWaitForSingleObject(&lock_ptr->writer_event, 0, 0, 0, nullptr);
xeKeKfReleaseSpinLock(&lock_ptr->spin_lock, old_irql);
xeKeWaitForSingleObject(&lock_ptr->writer_event, 7, 0, 0, nullptr);
} }
DECLARE_XBOXKRNL_EXPORT3(ExAcquireReadWriteLockExclusive, kThreading, DECLARE_XBOXKRNL_EXPORT2(ExAcquireReadWriteLockExclusive, kThreading,
kImplemented, kBlocking, kSketchy); kImplemented, kBlocking);
void ExReleaseReadWriteLock(pointer_t<X_ERWLOCK> lock_ptr) { void ExReleaseReadWriteLock(pointer_t<X_ERWLOCK> lock_ptr) {
auto old_irql = xeKeKfAcquireSpinLock(&lock_ptr->spin_lock); auto old_irql = xeKeKfAcquireSpinLock(&lock_ptr->spin_lock);