From 9b75481755c8d566bc666465d659115bba2b2578 Mon Sep 17 00:00:00 2001 From: David <25727384+ogniK5377@users.noreply.github.com> Date: Mon, 3 Aug 2020 21:28:54 +1000 Subject: ipc: Allow all trivially copyable objects to be passed directly into WriteBuffer (#4465) * ipc: Allow all trivially copyable objects to be passed directly into WriteBuffer With the support of C++20, we can use concepts to deduce if a type is an STL container or not. * More agressive concept for stl containers * Add -fconcepts * Move to common namespace * Add Common::IsBaseOf --- src/core/hle/service/acc/acc.cpp | 6 ++---- src/core/hle/service/audio/hwopus.cpp | 2 +- src/core/hle/service/bcat/module.cpp | 2 +- src/core/hle/service/es/es.cpp | 2 +- src/core/hle/service/nfp/nfp.cpp | 8 ++++---- src/core/hle/service/set/set.cpp | 2 +- src/core/hle/service/time/time.cpp | 4 ++-- src/core/hle/service/time/time_zone_service.cpp | 4 ++-- 8 files changed, 14 insertions(+), 16 deletions(-) (limited to 'src/core/hle/service') diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp index 8ac856ec3..63e4aeca0 100644 --- a/src/core/hle/service/acc/acc.cpp +++ b/src/core/hle/service/acc/acc.cpp @@ -286,9 +286,7 @@ protected: ProfileBase profile_base{}; ProfileData data{}; if (profile_manager.GetProfileBaseAndData(user_id, profile_base, data)) { - std::array raw_data; - std::memcpy(raw_data.data(), &data, sizeof(ProfileData)); - ctx.WriteBuffer(raw_data); + ctx.WriteBuffer(data); IPC::ResponseBuilder rb{ctx, 16}; rb.Push(RESULT_SUCCESS); rb.PushRaw(profile_base); @@ -333,7 +331,7 @@ protected: std::vector buffer(size); image.ReadBytes(buffer.data(), buffer.size()); - ctx.WriteBuffer(buffer.data(), buffer.size()); + ctx.WriteBuffer(buffer); rb.Push(size); } diff --git a/src/core/hle/service/audio/hwopus.cpp b/src/core/hle/service/audio/hwopus.cpp index d19513cbb..f1d81602c 100644 --- a/src/core/hle/service/audio/hwopus.cpp +++ b/src/core/hle/service/audio/hwopus.cpp @@ -92,7 +92,7 @@ private: if (performance) { rb.Push(*performance); } - ctx.WriteBuffer(samples.data(), samples.size() * sizeof(s16)); + ctx.WriteBuffer(samples); } bool DecodeOpusData(u32& consumed, u32& sample_count, const std::vector& input, diff --git a/src/core/hle/service/bcat/module.cpp b/src/core/hle/service/bcat/module.cpp index 603b64d4f..db0e06ca1 100644 --- a/src/core/hle/service/bcat/module.cpp +++ b/src/core/hle/service/bcat/module.cpp @@ -112,7 +112,7 @@ private: void GetImpl(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_BCAT, "called"); - ctx.WriteBuffer(&impl, sizeof(DeliveryCacheProgressImpl)); + ctx.WriteBuffer(impl); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); diff --git a/src/core/hle/service/es/es.cpp b/src/core/hle/service/es/es.cpp index a41c73c48..c2737a365 100644 --- a/src/core/hle/service/es/es.cpp +++ b/src/core/hle/service/es/es.cpp @@ -160,7 +160,7 @@ private: return; } - ctx.WriteBuffer(key.data(), key.size()); + ctx.WriteBuffer(key); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); diff --git a/src/core/hle/service/nfp/nfp.cpp b/src/core/hle/service/nfp/nfp.cpp index 4b79eb81d..5e2d769a4 100644 --- a/src/core/hle/service/nfp/nfp.cpp +++ b/src/core/hle/service/nfp/nfp.cpp @@ -127,7 +127,7 @@ private: const u32 array_size = rp.Pop(); LOG_DEBUG(Service_NFP, "called, array_size={}", array_size); - ctx.WriteBuffer(&device_handle, sizeof(device_handle)); + ctx.WriteBuffer(device_handle); IPC::ResponseBuilder rb{ctx, 3}; rb.Push(RESULT_SUCCESS); @@ -220,7 +220,7 @@ private: tag_info.protocol = 1; // TODO(ogniK): Figure out actual values tag_info.tag_type = 2; - ctx.WriteBuffer(&tag_info, sizeof(TagInfo)); + ctx.WriteBuffer(tag_info); rb.Push(RESULT_SUCCESS); } @@ -237,7 +237,7 @@ private: IPC::ResponseBuilder rb{ctx, 2}; auto amiibo = nfp_interface.GetAmiiboBuffer(); - ctx.WriteBuffer(&amiibo.model_info, sizeof(amiibo.model_info)); + ctx.WriteBuffer(amiibo.model_info); rb.Push(RESULT_SUCCESS); } @@ -283,7 +283,7 @@ private: CommonInfo common_info{}; common_info.application_area_size = 0; - ctx.WriteBuffer(&common_info, sizeof(CommonInfo)); + ctx.WriteBuffer(common_info); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); diff --git a/src/core/hle/service/set/set.cpp b/src/core/hle/service/set/set.cpp index 34fe2fd82..e64777668 100644 --- a/src/core/hle/service/set/set.cpp +++ b/src/core/hle/service/set/set.cpp @@ -106,7 +106,7 @@ void GetKeyCodeMapImpl(Kernel::HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); - ctx.WriteBuffer(&layout, sizeof(KeyboardLayout)); + ctx.WriteBuffer(layout); } } // Anonymous namespace diff --git a/src/core/hle/service/time/time.cpp b/src/core/hle/service/time/time.cpp index 13e4b3818..ee4fa4b48 100644 --- a/src/core/hle/service/time/time.cpp +++ b/src/core/hle/service/time/time.cpp @@ -290,7 +290,7 @@ void Module::Interface::GetClockSnapshot(Kernel::HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); - ctx.WriteBuffer(&clock_snapshot, sizeof(Clock::ClockSnapshot)); + ctx.WriteBuffer(clock_snapshot); } void Module::Interface::GetClockSnapshotFromSystemClockContext(Kernel::HLERequestContext& ctx) { @@ -313,7 +313,7 @@ void Module::Interface::GetClockSnapshotFromSystemClockContext(Kernel::HLEReques IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); - ctx.WriteBuffer(&clock_snapshot, sizeof(Clock::ClockSnapshot)); + ctx.WriteBuffer(clock_snapshot); } void Module::Interface::CalculateStandardUserSystemClockDifferenceByUser( diff --git a/src/core/hle/service/time/time_zone_service.cpp b/src/core/hle/service/time/time_zone_service.cpp index db57ae069..ff3a10b3e 100644 --- a/src/core/hle/service/time/time_zone_service.cpp +++ b/src/core/hle/service/time/time_zone_service.cpp @@ -142,7 +142,7 @@ void ITimeZoneService::ToPosixTime(Kernel::HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 3}; rb.Push(RESULT_SUCCESS); rb.PushRaw(1); // Number of times we're returning - ctx.WriteBuffer(&posix_time, sizeof(s64)); + ctx.WriteBuffer(posix_time); } void ITimeZoneService::ToPosixTimeWithMyRule(Kernel::HLERequestContext& ctx) { @@ -164,7 +164,7 @@ void ITimeZoneService::ToPosixTimeWithMyRule(Kernel::HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 3}; rb.Push(RESULT_SUCCESS); rb.PushRaw(1); // Number of times we're returning - ctx.WriteBuffer(&posix_time, sizeof(s64)); + ctx.WriteBuffer(posix_time); } } // namespace Service::Time -- cgit v1.2.3