strat: refactor address taking of form &var[...]

This commit is contained in:
Michael Scire 2021-10-09 12:45:31 -07:00
parent e2df2f98a3
commit 5c32ec11ea
4 changed files with 15 additions and 15 deletions

View File

@ -186,7 +186,7 @@ namespace ams::kern::board::nintendo::nx::smc {
MESOSPHERE_INIT_ABORT_UNLESS((static_cast<SmcResult>(args.x[0]) == SmcResult::Success)); MESOSPHERE_INIT_ABORT_UNLESS((static_cast<SmcResult>(args.x[0]) == SmcResult::Success));
/* Copy output. */ /* 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) { 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<SmcResult>(args.x[0]) == SmcResult::Success)); MESOSPHERE_ABORT_UNLESS((static_cast<SmcResult>(args.x[0]) == SmcResult::Success));
/* Copy output. */ /* Copy output. */
std::memcpy(dst, &args.x[1], size); std::memcpy(dst, std::addressof(args.x[1]), size);
} }
void NORETURN Panic(u32 color) { void NORETURN Panic(u32 color) {

View File

@ -617,7 +617,7 @@ namespace ams::sf::impl {
static_assert(Offset <= Size, "Offset <= Size"); static_assert(Offset <= Size, "Offset <= Size");
static_assert(TypeSize <= Size, "TypeSize <= Size"); static_assert(TypeSize <= Size, "TypeSize <= Size");
static_assert(Offset + TypeSize <= Size, "Offset + TypeSize <= Size"); static_assert(Offset + TypeSize <= Size, "Offset + TypeSize <= Size");
return reinterpret_cast<uintptr_t>(&data[Offset]); return reinterpret_cast<uintptr_t>(std::addressof(data[Offset]));
} }
constexpr inline void CopyTo(void *dst) const { constexpr inline void CopyTo(void *dst) const {
@ -760,7 +760,7 @@ namespace ams::sf::impl {
template<size_t Index, typename Interface> template<size_t Index, typename Interface>
Out<SharedPointer<Interface>> GetOutObject() { Out<SharedPointer<Interface>> GetOutObject() {
auto sp = std::construct_at(GetOutObjectSharedPointer<Index, Interface>()); auto sp = std::construct_at(GetOutObjectSharedPointer<Index, Interface>());
return Out<SharedPointer<Interface>>(sp, &this->out_object_ids[Index]); return Out<SharedPointer<Interface>>(sp, this->out_object_ids + Index);
} }
template<size_t Index, typename Interface> template<size_t Index, typename Interface>
@ -907,11 +907,11 @@ namespace ams::sf::impl {
if constexpr (Attributes & SfBufferAttr_HipcMapAlias) { if constexpr (Attributes & SfBufferAttr_HipcMapAlias) {
is_buffer_map_alias = true; is_buffer_map_alias = true;
if constexpr (Attributes & SfBufferAttr_In) { 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)); buffer = cmif::PointerAndSize(hipcGetBufferAddress(desc), hipcGetBufferSize(desc));
if (!IsMapTransferModeValid<Attributes>(static_cast<u32>(desc->mode))) { map_alias_buffers_valid = false; } if (!IsMapTransferModeValid<Attributes>(static_cast<u32>(desc->mode))) { map_alias_buffers_valid = false; }
} else if constexpr (Attributes & SfBufferAttr_Out) { } 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)); buffer = cmif::PointerAndSize(hipcGetBufferAddress(desc), hipcGetBufferSize(desc));
if (!IsMapTransferModeValid<Attributes>(static_cast<u32>(desc->mode))) { map_alias_buffers_valid = false; } if (!IsMapTransferModeValid<Attributes>(static_cast<u32>(desc->mode))) { map_alias_buffers_valid = false; }
} else { } else {
@ -920,7 +920,7 @@ namespace ams::sf::impl {
} else if constexpr (Attributes & SfBufferAttr_HipcPointer) { } else if constexpr (Attributes & SfBufferAttr_HipcPointer) {
is_buffer_map_alias = false; is_buffer_map_alias = false;
if constexpr (Attributes & SfBufferAttr_In) { 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)); buffer = cmif::PointerAndSize(hipcGetStaticAddress(desc), hipcGetStaticSize(desc));
const size_t size = buffer.GetSize(); const size_t size = buffer.GetSize();
if (size) { if (size) {
@ -943,8 +943,8 @@ namespace ams::sf::impl {
} }
} else if constexpr (Attributes & SfBufferAttr_HipcAutoSelect) { } else if constexpr (Attributes & SfBufferAttr_HipcAutoSelect) {
if constexpr (Attributes & SfBufferAttr_In) { if constexpr (Attributes & SfBufferAttr_In) {
const HipcBufferDescriptor *map_desc = &ctx.request.data.send_buffers[Info.send_map_alias_index]; const HipcBufferDescriptor *map_desc = std::addressof(ctx.request.data.send_buffers[Info.send_map_alias_index]);
const HipcStaticDescriptor *ptr_desc = &ctx.request.data.send_statics[Info.send_pointer_index]; const HipcStaticDescriptor *ptr_desc = std::addressof(ctx.request.data.send_statics[Info.send_pointer_index]);
is_buffer_map_alias = hipcGetBufferAddress(map_desc) != 0; is_buffer_map_alias = hipcGetBufferAddress(map_desc) != 0;
if (is_buffer_map_alias) { if (is_buffer_map_alias) {
buffer = cmif::PointerAndSize(hipcGetBufferAddress(map_desc), hipcGetBufferSize(map_desc)); buffer = cmif::PointerAndSize(hipcGetBufferAddress(map_desc), hipcGetBufferSize(map_desc));
@ -957,7 +957,7 @@ namespace ams::sf::impl {
} }
} }
} else if constexpr (Attributes & SfBufferAttr_Out) { } 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; is_buffer_map_alias = hipcGetBufferAddress(map_desc) != 0;
if (is_buffer_map_alias) { if (is_buffer_map_alias) {
buffer = cmif::PointerAndSize(hipcGetBufferAddress(map_desc), hipcGetBufferSize(map_desc)); buffer = cmif::PointerAndSize(hipcGetBufferAddress(map_desc), hipcGetBufferSize(map_desc));

View File

@ -123,7 +123,7 @@ namespace ams::fssystem {
R_UNLESS(len >= 2, fs::ResultInvalidPathFormat()); R_UNLESS(len >= 2, fs::ResultInvalidPathFormat());
/* Find previous separator, add null terminator */ /* 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) { while (!fs::PathNormalizer::IsSeparator(*cur) && cur > dst_path_buf) {
cur--; cur--;
} }

View File

@ -90,7 +90,7 @@ namespace ams::spl::smc {
svc::CallSecureMonitor(std::addressof(args)); svc::CallSecureMonitor(std::addressof(args));
if (args.r[0] == static_cast<u64>(Result::Success) && (size <= sizeof(args) - sizeof(args.r[0]))) { if (args.r[0] == static_cast<u64>(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<Result>(args.r[0]); return static_cast<Result>(args.r[0]);
} }
@ -220,8 +220,8 @@ namespace ams::spl::smc {
args.r[0] = static_cast<u64>(FunctionId::PrepareEsDeviceUniqueKey); args.r[0] = static_cast<u64>(FunctionId::PrepareEsDeviceUniqueKey);
args.r[1] = reinterpret_cast<u64>(base); args.r[1] = reinterpret_cast<u64>(base);
args.r[2] = reinterpret_cast<u64>(mod); args.r[2] = reinterpret_cast<u64>(mod);
std::memset(&args.r[3], 0, 4 * sizeof(args.r[3])); std::memset(std::addressof(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::memcpy(std::addressof(args.r[3]), label_digest, std::min(size_t(4 * sizeof(args.r[3])), label_digest_size));
args.r[7] = option; args.r[7] = option;
svc::CallSecureMonitor(std::addressof(args)); svc::CallSecureMonitor(std::addressof(args));
@ -358,7 +358,7 @@ namespace ams::spl::smc {
args.r[2] = paths; args.r[2] = paths;
svc::CallSecureMonitor(std::addressof(args)); 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<Result>(args.r[0]); return static_cast<Result>(args.r[0]);
} }