From 7f4265834a3112e53133783d62627d683611ba71 Mon Sep 17 00:00:00 2001 From: TheTurtle Date: Thu, 12 Dec 2024 03:33:49 +0200 Subject: [PATCH] hot-fix: Fix race in rwlock Resetting the owner should be before the lock is unlocked, otherwise a waiter might lock and set a new owner before its reset. --- src/core/libraries/kernel/threads/rwlock.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/libraries/kernel/threads/rwlock.cpp b/src/core/libraries/kernel/threads/rwlock.cpp index affaaf99..ff211e48 100644 --- a/src/core/libraries/kernel/threads/rwlock.cpp +++ b/src/core/libraries/kernel/threads/rwlock.cpp @@ -177,13 +177,13 @@ int PS4_SYSV_ABI posix_pthread_rwlock_unlock(PthreadRwlockT* rwlock) { } if (prwlock->owner == curthread) { - prwlock->lock.unlock(); prwlock->owner = nullptr; + prwlock->lock.unlock(); } else { - prwlock->lock.unlock_shared(); if (prwlock->owner == nullptr) { curthread->rdlock_count--; } + prwlock->lock.unlock_shared(); } return 0;