Skip to content

Commit

Permalink
Kernel: Fix LOCK_DEBUG feature to work again
Browse files Browse the repository at this point in the history
- UBSAN detected cases where we were calling thread->holding_lock(..)
  but current_thread was nullptr.

- Fix Lock::force_unlock_if_locked to not pass the correct ref delta to
  holding_lock(..).
  • Loading branch information
bgianfo authored and awesomekling committed Apr 25, 2021
1 parent 35c0a6c commit 7481789
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Kernel/Lock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ void Lock::lock(Mode mode)
VERIFY(m_times_locked == 0);
m_times_locked++;
#if LOCK_DEBUG
current_thread->holding_lock(*this, 1, file, line);
if (current_thread) {
current_thread->holding_lock(*this, 1, file, line);
}
#endif
m_queue.should_block(true);
m_lock.store(false, AK::memory_order_release);
Expand Down Expand Up @@ -165,7 +167,9 @@ void Lock::unlock()
}

#if LOCK_DEBUG
current_thread->holding_lock(*this, -1);
if (current_thread) {
current_thread->holding_lock(*this, -1);
}
#endif

m_lock.store(false, AK::memory_order_release);
Expand Down Expand Up @@ -201,7 +205,7 @@ auto Lock::force_unlock_if_locked(u32& lock_count_to_restore) -> Mode

dbgln_if(LOCK_RESTORE_DEBUG, "Lock::force_unlock_if_locked @ {}: unlocking exclusive with lock count: {}", this, m_times_locked);
#if LOCK_DEBUG
m_holder->holding_lock(*this, -(int)lock_count_to_restore);
m_holder->holding_lock(*this, -(int)m_times_locked);
#endif
m_holder = nullptr;
VERIFY(m_times_locked > 0);
Expand Down

0 comments on commit 7481789

Please sign in to comment.