From 2243e226302e1c5cce5d084db5a258c01a761402 Mon Sep 17 00:00:00 2001 From: Eladash Date: Mon, 27 Sep 2021 19:25:20 +0300 Subject: [PATCH] sys_fs: Fix race in file stream API --- rpcs3/Emu/Cell/lv2/sys_fs.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rpcs3/Emu/Cell/lv2/sys_fs.cpp b/rpcs3/Emu/Cell/lv2/sys_fs.cpp index b2f8d187f0..acc04fd45a 100644 --- a/rpcs3/Emu/Cell/lv2/sys_fs.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_fs.cpp @@ -3125,6 +3125,7 @@ error_code sys_fs_lsn_lock(ppu_thread&, u32 fd) return CELL_OK; } + std::lock_guard lock(file->mp->mutex); file->lock.compare_and_swap(0, 1); return CELL_OK; } @@ -3140,7 +3141,14 @@ error_code sys_fs_lsn_unlock(ppu_thread&, u32 fd) return CELL_EBADF; } + // See sys_fs_lsn_lock + if (file->mp == &g_mp_sys_dev_hdd0 || file->mp->flags & lv2_mp_flag::strict_get_block_size) + { + return CELL_OK; + } + // Unlock unconditionally + std::lock_guard lock(file->mp->mutex); file->lock.compare_and_swap(1, 0); return CELL_OK; }