Skip to content
Permalink
Browse files

IOS/USB_KBD: Add static assertion to enforce MessageData as trivially…

… copyable

MessageData must be a trivially copyable type, given it's copied into
emulated memory via our memory copy function CopyToEmu. Under the
covers, this function utilizes memcpy. One of memcpy's requirements is
that pointers to it point to types that are trivially copyable,
otherwise the behavior is undefined.

Given that, we can enforce this requirement at compile-time.
  • Loading branch information...
lioncash committed May 31, 2019
1 parent e0552e0 commit bcdc5b5f7e94ebee49ccc8de77cc54cb9d64b372
Showing with 3 additions and 0 deletions.
  1. +3 −0 Source/Core/Core/IOS/USB/USB_KBD.h
@@ -7,6 +7,7 @@
#include <array>
#include <queue>
#include <string>
#include <type_traits>

#include "Common/CommonTypes.h"
#include "Core/IOS/Device.h"
@@ -45,6 +46,8 @@ class USB_KBD : public Device

MessageData(u32 msg_type, u8 modifiers, PressedKeyData pressed_keys);
};
static_assert(std::is_trivially_copyable_v<MessageData>,
"MessageData must be trivially copyable, as it's copied into emulated memory.");
#pragma pack(pop)
std::queue<MessageData> m_MessageQueue;

0 comments on commit bcdc5b5

Please sign in to comment.
You can’t perform that action at this time.