From c1bf5a804af9586b200f8ad59f5f122c2813a4f0 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Thu, 4 Aug 2022 23:22:56 +0100 Subject: [PATCH] Extend `stateMutex` scope inside `Buffer::SynchronizeHost` The code is much simpler to reason about when reading the code as it doesn't require evaluating all the potential edge cases of trap handlers in different states. It should be noted that this should not change behavior in any meaningful way, at most it can prevent a minor race where the protection could be upgraded after being downgraded by the signal handler leading to a redundant trap. --- app/src/main/cpp/skyline/gpu/buffer.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/cpp/skyline/gpu/buffer.cpp b/app/src/main/cpp/skyline/gpu/buffer.cpp index aafd7e35..d3e7cda7 100644 --- a/app/src/main/cpp/skyline/gpu/buffer.cpp +++ b/app/src/main/cpp/skyline/gpu/buffer.cpp @@ -161,12 +161,13 @@ namespace skyline::gpu { dirtyState = DirtyState::Clean; WaitOnFence(); + + AdvanceSequence(); // We are modifying GPU backing contents so advance to the next sequence + + if (!skipTrap) + gpu.state.nce->TrapRegions(*trapHandle, true); // Trap any future CPU writes to this buffer, must be done before the memcpy so that any modifications during the copy are tracked } - AdvanceSequence(); // We are modifying GPU backing contents so advance to the next sequence - - if (!skipTrap) - gpu.state.nce->TrapRegions(*trapHandle, true); // Trap any future CPU writes to this buffer, must be done before the memcpy so that any modifications during the copy are tracked std::memcpy(backing.data(), mirror.data(), mirror.size()); }