diff --git a/core/libs/prx/libkernel_sys/Export.cpp b/core/libs/prx/libkernel_sys/Export.cpp index c528908a6b..2b069f18cb 100644 --- a/core/libs/prx/libkernel_sys/Export.cpp +++ b/core/libs/prx/libkernel_sys/Export.cpp @@ -385,7 +385,8 @@ int APS5_VABI sceKernelGetOpenPsIdForSystem(void* id) { int APS5_VABI sceKernelGetCpumodeGame(int* mode) { if (mode == nullptr) throw std::runtime_error("sceKernelGetCpumodeGame: a null output faults on the console"); - *mode = g_gameCpumode.load(std::memory_order_relaxed); + const int val = g_gameCpumode.load(std::memory_order_relaxed); + if (!GuestCopyOut_nid_no_patch(mode, &val, sizeof(val))) return SCE_KERNEL_ERROR_EFAULT; return 0; } diff --git a/core/libs/tests/GuestKernelSysCpumode.cpp b/core/libs/tests/GuestKernelSysCpumode.cpp index 3c5cb4fd65..76d4db0923 100644 --- a/core/libs/tests/GuestKernelSysCpumode.cpp +++ b/core/libs/tests/GuestKernelSysCpumode.cpp @@ -37,6 +37,7 @@ int main() { Require(Throws([] { sceKernelSetCpumodeGame(8); }), "an unmeasured mode did not throw"); Require(Throws([] { sceKernelSetCpumodeGame(-1); }), "a negative mode did not throw"); Require(Throws([] { sceKernelGetCpumodeGame(nullptr); }), "a null output did not throw"); + Require(sceKernelGetCpumodeGame(reinterpret_cast(0x10)) == static_cast(0x8002000Eu), "unwritable mode did not return EFAULT"); std::puts("game CPU mode tests passed"); return 0; }