From a77ee63f65ba34d91944e168a9ba29464cef12b1 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 5 Aug 2020 14:08:26 -0400 Subject: ipc_helpers: Only allow trivially copyable objects with PushRaw() and PopRaw() It's undefined behavior to use non-trivially copyable objects with std::memcpy, so we can add asserts to catch usages of these at compile-time. --- src/core/hle/ipc_helpers.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/core/hle/ipc_helpers.h') diff --git a/src/core/hle/ipc_helpers.h b/src/core/hle/ipc_helpers.h index 0dc6a4a43..1b503331f 100644 --- a/src/core/hle/ipc_helpers.h +++ b/src/core/hle/ipc_helpers.h @@ -229,6 +229,8 @@ inline void ResponseBuilder::Push(u32 value) { template void ResponseBuilder::PushRaw(const T& value) { + static_assert(std::is_trivially_copyable_v, + "It's undefined behavior to use memcpy with non-trivially copyable objects"); std::memcpy(cmdbuf + index, &value, sizeof(T)); index += (sizeof(T) + 3) / 4; // round up to word length } @@ -384,6 +386,8 @@ inline s32 RequestParser::Pop() { template void RequestParser::PopRaw(T& value) { + static_assert(std::is_trivially_copyable_v, + "It's undefined behavior to use memcpy with non-trivially copyable objects"); std::memcpy(&value, cmdbuf + index, sizeof(T)); index += (sizeof(T) + 3) / 4; // round up to word length } -- cgit v1.2.3