From 5c32ec11ea213d908704431a41690f0e796e08a9 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sat, 9 Oct 2021 12:45:31 -0700 Subject: [PATCH] strat: refactor address taking of form &var[...] --- .../board/nintendo/nx/kern_secure_monitor.cpp | 4 ++-- .../sf/impl/sf_impl_command_serialization.hpp | 16 ++++++++-------- .../source/fssystem/fssystem_utility.cpp | 2 +- libstratosphere/source/spl/smc/spl_smc.cpp | 8 ++++---- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/libmesosphere/source/board/nintendo/nx/kern_secure_monitor.cpp b/libmesosphere/source/board/nintendo/nx/kern_secure_monitor.cpp index d95cd517..112524fa 100644 --- a/libmesosphere/source/board/nintendo/nx/kern_secure_monitor.cpp +++ b/libmesosphere/source/board/nintendo/nx/kern_secure_monitor.cpp @@ -186,7 +186,7 @@ namespace ams::kern::board::nintendo::nx::smc { MESOSPHERE_INIT_ABORT_UNLESS((static_cast(args.x[0]) == SmcResult::Success)); /* Copy output. */ - std::memcpy(dst, &args.x[1], size); + std::memcpy(dst, std::addressof(args.x[1]), size); } bool ReadWriteRegister(u32 *out, u64 address, u32 mask, u32 value) { @@ -255,7 +255,7 @@ namespace ams::kern::board::nintendo::nx::smc { MESOSPHERE_ABORT_UNLESS((static_cast(args.x[0]) == SmcResult::Success)); /* Copy output. */ - std::memcpy(dst, &args.x[1], size); + std::memcpy(dst, std::addressof(args.x[1]), size); } void NORETURN Panic(u32 color) { diff --git a/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp b/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp index 8af93d37..5659fefb 100644 --- a/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp +++ b/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp @@ -617,7 +617,7 @@ namespace ams::sf::impl { static_assert(Offset <= Size, "Offset <= Size"); static_assert(TypeSize <= Size, "TypeSize <= Size"); static_assert(Offset + TypeSize <= Size, "Offset + TypeSize <= Size"); - return reinterpret_cast(&data[Offset]); + return reinterpret_cast(std::addressof(data[Offset])); } constexpr inline void CopyTo(void *dst) const { @@ -760,7 +760,7 @@ namespace ams::sf::impl { template Out> GetOutObject() { auto sp = std::construct_at(GetOutObjectSharedPointer()); - return Out>(sp, &this->out_object_ids[Index]); + return Out>(sp, this->out_object_ids + Index); } template @@ -907,11 +907,11 @@ namespace ams::sf::impl { if constexpr (Attributes & SfBufferAttr_HipcMapAlias) { is_buffer_map_alias = true; if constexpr (Attributes & SfBufferAttr_In) { - const HipcBufferDescriptor *desc = &ctx.request.data.send_buffers[Info.send_map_alias_index]; + const HipcBufferDescriptor *desc = std::addressof(ctx.request.data.send_buffers[Info.send_map_alias_index]); buffer = cmif::PointerAndSize(hipcGetBufferAddress(desc), hipcGetBufferSize(desc)); if (!IsMapTransferModeValid(static_cast(desc->mode))) { map_alias_buffers_valid = false; } } else if constexpr (Attributes & SfBufferAttr_Out) { - const HipcBufferDescriptor *desc = &ctx.request.data.recv_buffers[Info.recv_map_alias_index]; + const HipcBufferDescriptor *desc = std::addressof(ctx.request.data.recv_buffers[Info.recv_map_alias_index]); buffer = cmif::PointerAndSize(hipcGetBufferAddress(desc), hipcGetBufferSize(desc)); if (!IsMapTransferModeValid(static_cast(desc->mode))) { map_alias_buffers_valid = false; } } else { @@ -920,7 +920,7 @@ namespace ams::sf::impl { } else if constexpr (Attributes & SfBufferAttr_HipcPointer) { is_buffer_map_alias = false; if constexpr (Attributes & SfBufferAttr_In) { - const HipcStaticDescriptor *desc = &ctx.request.data.send_statics[Info.send_pointer_index]; + const HipcStaticDescriptor *desc = std::addressof(ctx.request.data.send_statics[Info.send_pointer_index]); buffer = cmif::PointerAndSize(hipcGetStaticAddress(desc), hipcGetStaticSize(desc)); const size_t size = buffer.GetSize(); if (size) { @@ -943,8 +943,8 @@ namespace ams::sf::impl { } } else if constexpr (Attributes & SfBufferAttr_HipcAutoSelect) { if constexpr (Attributes & SfBufferAttr_In) { - const HipcBufferDescriptor *map_desc = &ctx.request.data.send_buffers[Info.send_map_alias_index]; - const HipcStaticDescriptor *ptr_desc = &ctx.request.data.send_statics[Info.send_pointer_index]; + const HipcBufferDescriptor *map_desc = std::addressof(ctx.request.data.send_buffers[Info.send_map_alias_index]); + const HipcStaticDescriptor *ptr_desc = std::addressof(ctx.request.data.send_statics[Info.send_pointer_index]); is_buffer_map_alias = hipcGetBufferAddress(map_desc) != 0; if (is_buffer_map_alias) { buffer = cmif::PointerAndSize(hipcGetBufferAddress(map_desc), hipcGetBufferSize(map_desc)); @@ -957,7 +957,7 @@ namespace ams::sf::impl { } } } else if constexpr (Attributes & SfBufferAttr_Out) { - const HipcBufferDescriptor *map_desc = &ctx.request.data.recv_buffers[Info.recv_map_alias_index]; + const HipcBufferDescriptor *map_desc = std::addressof(ctx.request.data.recv_buffers[Info.recv_map_alias_index]); is_buffer_map_alias = hipcGetBufferAddress(map_desc) != 0; if (is_buffer_map_alias) { buffer = cmif::PointerAndSize(hipcGetBufferAddress(map_desc), hipcGetBufferSize(map_desc)); diff --git a/libstratosphere/source/fssystem/fssystem_utility.cpp b/libstratosphere/source/fssystem/fssystem_utility.cpp index 1a6e4bce..78a896fa 100644 --- a/libstratosphere/source/fssystem/fssystem_utility.cpp +++ b/libstratosphere/source/fssystem/fssystem_utility.cpp @@ -123,7 +123,7 @@ namespace ams::fssystem { R_UNLESS(len >= 2, fs::ResultInvalidPathFormat()); /* Find previous separator, add null terminator */ - char *cur = &dst_path_buf[len - 2]; + char *cur = dst_path_buf + len - 2; while (!fs::PathNormalizer::IsSeparator(*cur) && cur > dst_path_buf) { cur--; } diff --git a/libstratosphere/source/spl/smc/spl_smc.cpp b/libstratosphere/source/spl/smc/spl_smc.cpp index e7aa92e4..d531eeb1 100644 --- a/libstratosphere/source/spl/smc/spl_smc.cpp +++ b/libstratosphere/source/spl/smc/spl_smc.cpp @@ -90,7 +90,7 @@ namespace ams::spl::smc { svc::CallSecureMonitor(std::addressof(args)); if (args.r[0] == static_cast(Result::Success) && (size <= sizeof(args) - sizeof(args.r[0]))) { - std::memcpy(out, &args.r[1], size); + std::memcpy(out, std::addressof(args.r[1]), size); } return static_cast(args.r[0]); } @@ -220,8 +220,8 @@ namespace ams::spl::smc { args.r[0] = static_cast(FunctionId::PrepareEsDeviceUniqueKey); args.r[1] = reinterpret_cast(base); args.r[2] = reinterpret_cast(mod); - std::memset(&args.r[3], 0, 4 * sizeof(args.r[3])); - std::memcpy(&args.r[3], label_digest, std::min(size_t(4 * sizeof(args.r[3])), label_digest_size)); + std::memset(std::addressof(args.r[3]), 0, 4 * sizeof(args.r[3])); + std::memcpy(std::addressof(args.r[3]), label_digest, std::min(size_t(4 * sizeof(args.r[3])), label_digest_size)); args.r[7] = option; svc::CallSecureMonitor(std::addressof(args)); @@ -358,7 +358,7 @@ namespace ams::spl::smc { args.r[2] = paths; svc::CallSecureMonitor(std::addressof(args)); - std::memcpy(out_config, &args.r[1], sizeof(args) - sizeof(args.r[0])); + std::memcpy(out_config, std::addressof(args.r[1]), sizeof(args) - sizeof(args.r[0])); return static_cast(args.r[0]); }