summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Lioncash2020-08-05 14:08:26 -0400
committerGravatar Lioncash2020-08-05 14:08:28 -0400
commita77ee63f65ba34d91944e168a9ba29464cef12b1 (patch)
tree707a3dfb4ed17b20f297ada3767f86e1b6fba319
parentMerge pull request #4466 from ogniK5377/loader-type-safe (diff)
downloadyuzu-a77ee63f65ba34d91944e168a9ba29464cef12b1.tar.gz
yuzu-a77ee63f65ba34d91944e168a9ba29464cef12b1.tar.xz
yuzu-a77ee63f65ba34d91944e168a9ba29464cef12b1.zip
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.
Diffstat (limited to '')
-rw-r--r--src/core/hle/ipc_helpers.h4
1 files changed, 4 insertions, 0 deletions
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) {
229 229
230template <typename T> 230template <typename T>
231void ResponseBuilder::PushRaw(const T& value) { 231void ResponseBuilder::PushRaw(const T& value) {
232 static_assert(std::is_trivially_copyable_v<T>,
233 "It's undefined behavior to use memcpy with non-trivially copyable objects");
232 std::memcpy(cmdbuf + index, &value, sizeof(T)); 234 std::memcpy(cmdbuf + index, &value, sizeof(T));
233 index += (sizeof(T) + 3) / 4; // round up to word length 235 index += (sizeof(T) + 3) / 4; // round up to word length
234} 236}
@@ -384,6 +386,8 @@ inline s32 RequestParser::Pop() {
384 386
385template <typename T> 387template <typename T>
386void RequestParser::PopRaw(T& value) { 388void RequestParser::PopRaw(T& value) {
389 static_assert(std::is_trivially_copyable_v<T>,
390 "It's undefined behavior to use memcpy with non-trivially copyable objects");
387 std::memcpy(&value, cmdbuf + index, sizeof(T)); 391 std::memcpy(&value, cmdbuf + index, sizeof(T));
388 index += (sizeof(T) + 3) / 4; // round up to word length 392 index += (sizeof(T) + 3) / 4; // round up to word length
389} 393}