diff options
| author | 2017-08-23 18:17:44 -0600 | |
|---|---|---|
| committer | 2017-08-23 18:17:44 -0600 | |
| commit | 61442d6afba2f7528ddf3bbee64e8c2d86a4f4a8 (patch) | |
| tree | b4b16a86d9959e14c01e43f68400342d7224c5a8 /src/core/hle | |
| parent | Merge pull request #2893 from Subv/not_schedule_main_thread (diff) | |
| parent | Kernel/Memory: Acquire the global HLE lock when a memory read/write operation... (diff) | |
| download | yuzu-61442d6afba2f7528ddf3bbee64e8c2d86a4f4a8.tar.gz yuzu-61442d6afba2f7528ddf3bbee64e8c2d86a4f4a8.tar.xz yuzu-61442d6afba2f7528ddf3bbee64e8c2d86a4f4a8.zip | |
Merge pull request #2839 from Subv/global_kernel_lock
Kernel/HLE: Use a mutex to synchronize access to the HLE kernel state between the cpu thread and any other possible threads that might touch the kernel (network thread, etc).
Diffstat (limited to 'src/core/hle')
| -rw-r--r-- | src/core/hle/kernel/kernel.h | 2 | ||||
| -rw-r--r-- | src/core/hle/lock.cpp | 11 | ||||
| -rw-r--r-- | src/core/hle/lock.h | 18 | ||||
| -rw-r--r-- | src/core/hle/svc.cpp | 8 |
4 files changed, 36 insertions, 3 deletions
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 142bb84b2..73fab3981 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h | |||
| @@ -132,4 +132,4 @@ void Init(u32 system_mode); | |||
| 132 | /// Shutdown the kernel | 132 | /// Shutdown the kernel |
| 133 | void Shutdown(); | 133 | void Shutdown(); |
| 134 | 134 | ||
| 135 | } // namespace | 135 | } // namespace Kernel |
diff --git a/src/core/hle/lock.cpp b/src/core/hle/lock.cpp new file mode 100644 index 000000000..082f689c8 --- /dev/null +++ b/src/core/hle/lock.cpp | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | // Copyright 2017 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <core/hle/lock.h> | ||
| 8 | |||
| 9 | namespace HLE { | ||
| 10 | std::mutex g_hle_lock; | ||
| 11 | } | ||
diff --git a/src/core/hle/lock.h b/src/core/hle/lock.h new file mode 100644 index 000000000..8265621e1 --- /dev/null +++ b/src/core/hle/lock.h | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | // Copyright 2017 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <mutex> | ||
| 8 | |||
| 9 | namespace HLE { | ||
| 10 | /* | ||
| 11 | * Synchronizes access to the internal HLE kernel structures, it is acquired when a guest | ||
| 12 | * application thread performs a syscall. It should be acquired by any host threads that read or | ||
| 13 | * modify the HLE kernel state. Note: Any operation that directly or indirectly reads from or writes | ||
| 14 | * to the emulated memory is not protected by this mutex, and should be avoided in any threads other | ||
| 15 | * than the CPU thread. | ||
| 16 | */ | ||
| 17 | extern std::mutex g_hle_lock; | ||
| 18 | } // namespace HLE | ||
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index e4b803046..b98938cb4 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp | |||
| @@ -31,6 +31,7 @@ | |||
| 31 | #include "core/hle/kernel/timer.h" | 31 | #include "core/hle/kernel/timer.h" |
| 32 | #include "core/hle/kernel/vm_manager.h" | 32 | #include "core/hle/kernel/vm_manager.h" |
| 33 | #include "core/hle/kernel/wait_object.h" | 33 | #include "core/hle/kernel/wait_object.h" |
| 34 | #include "core/hle/lock.h" | ||
| 34 | #include "core/hle/result.h" | 35 | #include "core/hle/result.h" |
| 35 | #include "core/hle/service/service.h" | 36 | #include "core/hle/service/service.h" |
| 36 | 37 | ||
| @@ -1188,7 +1189,7 @@ struct FunctionDef { | |||
| 1188 | Func* func; | 1189 | Func* func; |
| 1189 | const char* name; | 1190 | const char* name; |
| 1190 | }; | 1191 | }; |
| 1191 | } | 1192 | } // namespace |
| 1192 | 1193 | ||
| 1193 | static const FunctionDef SVC_Table[] = { | 1194 | static const FunctionDef SVC_Table[] = { |
| 1194 | {0x00, nullptr, "Unknown"}, | 1195 | {0x00, nullptr, "Unknown"}, |
| @@ -1332,6 +1333,9 @@ MICROPROFILE_DEFINE(Kernel_SVC, "Kernel", "SVC", MP_RGB(70, 200, 70)); | |||
| 1332 | void CallSVC(u32 immediate) { | 1333 | void CallSVC(u32 immediate) { |
| 1333 | MICROPROFILE_SCOPE(Kernel_SVC); | 1334 | MICROPROFILE_SCOPE(Kernel_SVC); |
| 1334 | 1335 | ||
| 1336 | // Lock the global kernel mutex when we enter the kernel HLE. | ||
| 1337 | std::lock_guard<std::mutex> lock(HLE::g_hle_lock); | ||
| 1338 | |||
| 1335 | const FunctionDef* info = GetSVCInfo(immediate); | 1339 | const FunctionDef* info = GetSVCInfo(immediate); |
| 1336 | if (info) { | 1340 | if (info) { |
| 1337 | if (info->func) { | 1341 | if (info->func) { |
| @@ -1342,4 +1346,4 @@ void CallSVC(u32 immediate) { | |||
| 1342 | } | 1346 | } |
| 1343 | } | 1347 | } |
| 1344 | 1348 | ||
| 1345 | } // namespace | 1349 | } // namespace SVC |