From 0fc52707024fb431a34fe402564abfe39541df3f Mon Sep 17 00:00:00 2001 From: Luke Usher Date: Fri, 27 Jul 2018 22:14:09 +0100 Subject: [PATCH] Prevent side-effects of the lock/unlock action for FS --- src/CxbxKrnl/EmuFS.cpp | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/src/CxbxKrnl/EmuFS.cpp b/src/CxbxKrnl/EmuFS.cpp index b4b491371..15b3026e9 100644 --- a/src/CxbxKrnl/EmuFS.cpp +++ b/src/CxbxKrnl/EmuFS.cpp @@ -130,35 +130,32 @@ xboxkrnl::KPCR* KeGetPcr(); uint32_t fs_lock = 0; -__declspec(naked) void LockFSInternal() -{ - __asm { - mov eax, 1 - xchg eax, [fs_lock] - test eax, eax - jnz LockFSInternal - ret - } -} - __declspec(naked) void LockFS() { - __asm { - push eax - call LockFSInternal - pop eax - ret + __asm { + pushfd + pushad + spinlock : + mov eax, 1 + xchg eax, fs_lock + test eax, eax + jnz spinlock + popad + popfd + ret } } __declspec(naked) void UnlockFS() { - __asm { - push eax - xor eax, eax - xchg eax, [fs_lock] - pop eax - ret + __asm { + pushfd + pushad + xor eax, eax + xchg eax, fs_lock + popad + popfd + ret } }