From cf9bb90ae358846e671b6c923fe3745f26ebb2cd Mon Sep 17 00:00:00 2001 From: GPUCode <47210458+GPUCode@users.noreply.github.com> Date: Fri, 7 Jul 2023 01:52:40 +0300 Subject: [PATCH] code: Use std::span where appropriate (#6658) * code: Use std::span when possible * code: Prefix memcpy and memcmp with std:: --- src/android/app/src/main/jni/game_info.cpp | 2 +- src/audio_core/dsp_interface.h | 6 +-- src/audio_core/hle/hle.cpp | 8 ++-- src/audio_core/hle/hle.h | 4 +- src/audio_core/lle/lle.cpp | 12 +++--- src/audio_core/lle/lle.h | 5 ++- .../configuration/configure_per_game.cpp | 2 +- .../graphics/graphics_vertex_shader.cpp | 2 +- src/citra_qt/debugger/ipc/record_dialog.cpp | 2 +- src/citra_qt/debugger/ipc/record_dialog.h | 3 +- src/citra_qt/debugger/wait_tree.cpp | 2 +- src/citra_qt/debugger/wait_tree.h | 3 +- src/citra_qt/dumping/dumping_dialog.h | 1 + src/citra_qt/game_list_p.h | 10 +++-- src/citra_qt/loading_screen.cpp | 2 +- src/common/file_util.cpp | 2 +- src/common/file_util.h | 2 +- src/common/linear_disk_cache.h | 2 +- src/common/ring_buffer.h | 3 +- src/common/x64/cpu_detect.cpp | 2 +- src/common/zstd_compression.cpp | 15 ++++--- src/common/zstd_compression.h | 10 ++--- src/core/cheats/gateway_cheat.cpp | 3 +- src/core/dumping/ffmpeg_backend.cpp | 3 +- src/core/file_sys/archive_extsavedata.cpp | 5 +-- src/core/file_sys/archive_extsavedata.h | 3 +- src/core/file_sys/archive_ncch.cpp | 2 +- src/core/file_sys/cia_container.cpp | 19 ++++----- src/core/file_sys/cia_container.h | 12 +++--- src/core/file_sys/ncch_container.cpp | 42 ++++++++----------- src/core/file_sys/plugin_3gx.cpp | 14 +++---- src/core/file_sys/plugin_3gx.h | 5 ++- src/core/file_sys/ticket.cpp | 6 +-- src/core/file_sys/ticket.h | 3 +- src/core/file_sys/title_metadata.cpp | 18 ++++---- src/core/file_sys/title_metadata.h | 3 +- src/core/gdbstub/gdbstub.cpp | 10 ++--- src/core/gdbstub/gdbstub.h | 1 + src/core/gdbstub/hio.cpp | 2 +- src/core/hle/applets/erreula.cpp | 2 +- src/core/hle/applets/mii_selector.cpp | 4 +- src/core/hle/applets/mint.cpp | 2 +- src/core/hle/applets/swkbd.cpp | 4 +- src/core/hle/ipc_helpers.h | 2 +- src/core/hle/kernel/kernel.h | 3 +- src/core/hle/kernel/svc.cpp | 12 +++--- src/core/hle/kernel/thread.cpp | 4 +- src/core/hle/kernel/thread.h | 3 +- src/core/hle/lock.cpp | 2 +- src/core/hle/service/am/am.cpp | 6 +-- src/core/hle/service/apt/apt.cpp | 2 +- src/core/hle/service/apt/bcfnt/bcfnt.cpp | 40 +++++++++--------- src/core/hle/service/cecd/cecd.cpp | 4 +- src/core/hle/service/cecd/cecd.h | 8 ++-- src/core/hle/service/cfg/cfg.cpp | 21 +++++----- src/core/hle/service/cfg/cfg.h | 4 +- src/core/hle/service/fs/archive.cpp | 7 ++-- src/core/hle/service/fs/archive.h | 4 +- src/core/hle/service/gsp/gsp_gpu.cpp | 7 ++-- src/core/hle/service/ir/extra_hid.cpp | 6 +-- src/core/hle/service/ir/extra_hid.h | 7 ++-- src/core/hle/service/ir/ir_user.cpp | 20 +++++---- src/core/hle/service/ir/ir_user.h | 10 ++--- src/core/hle/service/mic_u.cpp | 3 +- src/core/hle/service/nwm/nwm_uds.cpp | 24 +++++------ src/core/hle/service/nwm/nwm_uds.h | 6 +-- src/core/hle/service/nwm/uds_connection.cpp | 6 +-- src/core/hle/service/nwm/uds_connection.h | 5 ++- src/core/hle/service/nwm/uds_data.cpp | 26 ++++++------ src/core/hle/service/nwm/uds_data.h | 13 +++--- src/core/hle/service/soc_u.cpp | 16 +++---- src/core/hw/aes/ccm.cpp | 4 +- src/core/hw/aes/ccm.h | 5 ++- src/core/hw/gpu.cpp | 6 +-- src/core/hw/lcd.cpp | 2 +- src/core/hw/rsa/rsa.cpp | 6 +-- src/core/hw/rsa/rsa.h | 7 ++-- src/core/loader/3dsx.cpp | 2 +- src/core/loader/elf.cpp | 2 +- src/core/loader/ncch.cpp | 19 +++++---- src/core/loader/ncch.h | 2 +- src/core/loader/smdh.cpp | 7 ++-- src/core/loader/smdh.h | 3 +- src/core/movie.cpp | 5 +-- src/core/movie.h | 3 +- src/core/rpc/packet.h | 3 +- src/core/rpc/rpc_server.cpp | 17 ++++---- src/core/rpc/rpc_server.h | 3 +- src/core/savestate.cpp | 4 +- src/core/tracer/recorder.cpp | 2 +- src/core/tracer/recorder.h | 1 + src/tests/audio_core/decoder_tests.cpp | 2 +- src/tests/audio_core/hle/hle.cpp | 4 +- src/tests/audio_core/lle/lle.cpp | 2 +- src/tests/common/file_util.cpp | 4 +- src/video_core/debug_utils/debug_utils.cpp | 6 +-- src/video_core/gpu_debugger.h | 2 +- src/video_core/pica.cpp | 2 +- .../renderer_opengl/gl_resource_manager.cpp | 5 ++- .../renderer_opengl/gl_resource_manager.h | 3 +- .../renderer_opengl/gl_shader_disk_cache.cpp | 4 +- .../renderer_opengl/gl_shader_manager.cpp | 8 ++-- .../renderer_opengl/gl_shader_util.cpp | 2 +- .../renderer_opengl/gl_shader_util.h | 4 +- src/video_core/renderer_vulkan/vk_instance.h | 2 +- src/video_core/texture/texture_decode.cpp | 4 +- 106 files changed, 362 insertions(+), 329 deletions(-) diff --git a/src/android/app/src/main/jni/game_info.cpp b/src/android/app/src/main/jni/game_info.cpp index ca0ff355c..0f64b34a3 100644 --- a/src/android/app/src/main/jni/game_info.cpp +++ b/src/android/app/src/main/jni/game_info.cpp @@ -67,7 +67,7 @@ JNIEXPORT jlong JNICALL Java_org_citra_citra_1emu_model_GameInfo_initialize(JNIE Loader::SMDH* smdh = nullptr; if (Loader::IsValidSMDH(smdh_data)) { smdh = new Loader::SMDH; - memcpy(smdh, smdh_data.data(), sizeof(Loader::SMDH)); + std::memcpy(smdh, smdh_data.data(), sizeof(Loader::SMDH)); } return reinterpret_cast(smdh); } diff --git a/src/audio_core/dsp_interface.h b/src/audio_core/dsp_interface.h index 2c99f71cc..f1b315e38 100644 --- a/src/audio_core/dsp_interface.h +++ b/src/audio_core/dsp_interface.h @@ -5,7 +5,7 @@ #pragma once #include -#include +#include #include #include "audio_core/audio_types.h" #include "audio_core/time_stretch.h" @@ -80,7 +80,7 @@ public: * @param pipe_number The Pipe ID * @param buffer The data to write to the pipe. */ - virtual void PipeWrite(DspPipe pipe_number, const std::vector& buffer) = 0; + virtual void PipeWrite(DspPipe pipe_number, std::span buffer) = 0; /// Returns a reference to the array backing DSP memory virtual std::array& GetDspMemory() = 0; @@ -89,7 +89,7 @@ public: virtual void SetServiceToInterrupt(std::weak_ptr dsp) = 0; /// Loads the DSP program - virtual void LoadComponent(const std::vector& buffer) = 0; + virtual void LoadComponent(std::span buffer) = 0; /// Unloads the DSP program virtual void UnloadComponent() = 0; diff --git a/src/audio_core/hle/hle.cpp b/src/audio_core/hle/hle.cpp index 964477ed3..78551a7f7 100644 --- a/src/audio_core/hle/hle.cpp +++ b/src/audio_core/hle/hle.cpp @@ -66,7 +66,7 @@ public: bool RecvDataIsReady(u32 register_number) const; std::vector PipeRead(DspPipe pipe_number, std::size_t length); std::size_t GetPipeReadableSize(DspPipe pipe_number) const; - void PipeWrite(DspPipe pipe_number, const std::vector& buffer); + void PipeWrite(DspPipe pipe_number, std::span buffer); std::array& GetDspMemory(); @@ -244,7 +244,7 @@ size_t DspHle::Impl::GetPipeReadableSize(DspPipe pipe_number) const { return pipe_data[pipe_index].size(); } -void DspHle::Impl::PipeWrite(DspPipe pipe_number, const std::vector& buffer) { +void DspHle::Impl::PipeWrite(DspPipe pipe_number, std::span buffer) { switch (pipe_number) { case DspPipe::Audio: { if (buffer.size() != 4) { @@ -494,7 +494,7 @@ size_t DspHle::GetPipeReadableSize(DspPipe pipe_number) const { return impl->GetPipeReadableSize(pipe_number); } -void DspHle::PipeWrite(DspPipe pipe_number, const std::vector& buffer) { +void DspHle::PipeWrite(DspPipe pipe_number, std::span buffer) { impl->PipeWrite(pipe_number, buffer); } @@ -506,7 +506,7 @@ void DspHle::SetServiceToInterrupt(std::weak_ptr dsp) { impl->SetServiceToInterrupt(std::move(dsp)); } -void DspHle::LoadComponent(const std::vector& component_data) { +void DspHle::LoadComponent(std::span component_data) { // HLE doesn't need DSP program. Only log some info here LOG_INFO(Service_DSP, "Firmware hash: {:#018x}", Common::ComputeHash64(component_data.data(), component_data.size())); diff --git a/src/audio_core/hle/hle.h b/src/audio_core/hle/hle.h index ff0ac4781..ea0577bad 100644 --- a/src/audio_core/hle/hle.h +++ b/src/audio_core/hle/hle.h @@ -30,13 +30,13 @@ public: void SetSemaphore(u16 semaphore_value) override; std::vector PipeRead(DspPipe pipe_number, std::size_t length) override; std::size_t GetPipeReadableSize(DspPipe pipe_number) const override; - void PipeWrite(DspPipe pipe_number, const std::vector& buffer) override; + void PipeWrite(DspPipe pipe_number, std::span buffer) override; std::array& GetDspMemory() override; void SetServiceToInterrupt(std::weak_ptr dsp) override; - void LoadComponent(const std::vector& buffer) override; + void LoadComponent(std::span buffer) override; void UnloadComponent() override; private: diff --git a/src/audio_core/lle/lle.cpp b/src/audio_core/lle/lle.cpp index 884ae80d4..fd30f0c5a 100644 --- a/src/audio_core/lle/lle.cpp +++ b/src/audio_core/lle/lle.cpp @@ -26,7 +26,7 @@ enum class SegmentType : u8 { class Dsp1 { public: - explicit Dsp1(const std::vector& raw); + explicit Dsp1(std::span raw); struct Header { std::array signature; @@ -65,7 +65,7 @@ public: bool recv_data_on_start; }; -Dsp1::Dsp1(const std::vector& raw) { +Dsp1::Dsp1(std::span raw) { Header header; std::memcpy(&header, raw.data(), sizeof(header)); recv_data_on_start = header.recv_data_on_start != 0; @@ -220,7 +220,7 @@ struct DspLle::Impl final { } } - void WritePipe(u8 pipe_index, const std::vector& data) { + void WritePipe(u8 pipe_index, std::span data) { PipeStatus pipe_status = GetPipeStatus(pipe_index, PipeDirection::CPUtoDSP); bool need_update = false; const u8* buffer_ptr = data.data(); @@ -304,7 +304,7 @@ struct DspLle::Impl final { return size & PipeStatus::PtrMask; } - void LoadComponent(const std::vector& buffer) { + void LoadComponent(std::span buffer) { if (loaded) { LOG_ERROR(Audio_DSP, "Component already loaded!"); return; @@ -400,7 +400,7 @@ std::size_t DspLle::GetPipeReadableSize(DspPipe pipe_number) const { return impl->GetPipeReadableSize(static_cast(pipe_number)); } -void DspLle::PipeWrite(DspPipe pipe_number, const std::vector& buffer) { +void DspLle::PipeWrite(DspPipe pipe_number, std::span buffer) { impl->WritePipe(static_cast(pipe_number), buffer); } @@ -476,7 +476,7 @@ void DspLle::SetRecvDataHandler(u8 index, std::function handler) { impl->teakra.SetRecvDataHandler(index, handler); } -void DspLle::LoadComponent(const std::vector& buffer) { +void DspLle::LoadComponent(std::span buffer) { impl->LoadComponent(buffer); } diff --git a/src/audio_core/lle/lle.h b/src/audio_core/lle/lle.h index 4b3f62bc9..7aec28da4 100644 --- a/src/audio_core/lle/lle.h +++ b/src/audio_core/lle/lle.h @@ -4,6 +4,7 @@ #pragma once +#include #include "audio_core/dsp_interface.h" namespace Core { @@ -22,7 +23,7 @@ public: void SetSemaphore(u16 semaphore_value) override; std::vector PipeRead(DspPipe pipe_number, std::size_t length) override; std::size_t GetPipeReadableSize(DspPipe pipe_number) const override; - void PipeWrite(DspPipe pipe_number, const std::vector& buffer) override; + void PipeWrite(DspPipe pipe_number, std::span buffer) override; std::array& GetDspMemory() override; @@ -31,7 +32,7 @@ public: void SetSemaphoreHandler(std::function handler); void SetRecvDataHandler(u8 index, std::function handler); - void LoadComponent(const std::vector& buffer) override; + void LoadComponent(const std::span buffer) override; void UnloadComponent() override; private: diff --git a/src/citra_qt/configuration/configure_per_game.cpp b/src/citra_qt/configuration/configure_per_game.cpp index a0163dfa7..4b9f73822 100644 --- a/src/citra_qt/configuration/configure_per_game.cpp +++ b/src/citra_qt/configuration/configure_per_game.cpp @@ -129,7 +129,7 @@ void ConfigurePerGame::HandleApplyButtonClicked() { static QPixmap GetQPixmapFromSMDH(std::vector& smdh_data) { Loader::SMDH smdh; - memcpy(&smdh, smdh_data.data(), sizeof(Loader::SMDH)); + std::memcpy(&smdh, smdh_data.data(), sizeof(Loader::SMDH)); bool large = true; std::vector icon_data = smdh.GetIcon(large); diff --git a/src/citra_qt/debugger/graphics/graphics_vertex_shader.cpp b/src/citra_qt/debugger/graphics/graphics_vertex_shader.cpp index e8f0133fc..07e25be8c 100644 --- a/src/citra_qt/debugger/graphics/graphics_vertex_shader.cpp +++ b/src/citra_qt/debugger/graphics/graphics_vertex_shader.cpp @@ -487,7 +487,7 @@ void GraphicsVertexShaderWidget::Reload(bool replace_vertex_data, void* vertex_d if (replace_vertex_data) { if (vertex_data) { - memcpy(&input_vertex, vertex_data, sizeof(input_vertex)); + std::memcpy(&input_vertex, vertex_data, sizeof(input_vertex)); for (unsigned attr = 0; attr < 16; ++attr) { for (unsigned comp = 0; comp < 4; ++comp) { input_data[4 * attr + comp]->setText( diff --git a/src/citra_qt/debugger/ipc/record_dialog.cpp b/src/citra_qt/debugger/ipc/record_dialog.cpp index e528d2180..d4668a33d 100644 --- a/src/citra_qt/debugger/ipc/record_dialog.cpp +++ b/src/citra_qt/debugger/ipc/record_dialog.cpp @@ -18,7 +18,7 @@ QString RecordDialog::FormatObject(const IPCDebugger::ObjectInfo& object) const .arg(object.id, 8, 16, QLatin1Char('0')); } -QString RecordDialog::FormatCmdbuf(const std::vector& cmdbuf) const { +QString RecordDialog::FormatCmdbuf(std::span cmdbuf) const { QString result; for (std::size_t i = 0; i < cmdbuf.size(); ++i) { result.append( diff --git a/src/citra_qt/debugger/ipc/record_dialog.h b/src/citra_qt/debugger/ipc/record_dialog.h index 40618b925..37908e0af 100644 --- a/src/citra_qt/debugger/ipc/record_dialog.h +++ b/src/citra_qt/debugger/ipc/record_dialog.h @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -28,7 +29,7 @@ public: private: QString FormatObject(const IPCDebugger::ObjectInfo& object) const; - QString FormatCmdbuf(const std::vector& cmdbuf) const; + QString FormatCmdbuf(std::span cmdbuf) const; void UpdateCmdbufDisplay(); std::unique_ptr ui; diff --git a/src/citra_qt/debugger/wait_tree.cpp b/src/citra_qt/debugger/wait_tree.cpp index 6d09457fd..2e70e1cd3 100644 --- a/src/citra_qt/debugger/wait_tree.cpp +++ b/src/citra_qt/debugger/wait_tree.cpp @@ -64,7 +64,7 @@ WaitTreeItem* WaitTreeItem::Parent() const { return parent; } -const std::vector>& WaitTreeItem::Children() const { +std::span> WaitTreeItem::Children() const { return children; } diff --git a/src/citra_qt/debugger/wait_tree.h b/src/citra_qt/debugger/wait_tree.h index 8c8688c28..eca8534c5 100644 --- a/src/citra_qt/debugger/wait_tree.h +++ b/src/citra_qt/debugger/wait_tree.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include #include @@ -36,7 +37,7 @@ public: void Expand(); WaitTreeItem* Parent() const; - const std::vector>& Children() const; + std::span> Children() const; std::size_t Row() const; static std::vector> MakeThreadItemList(); diff --git a/src/citra_qt/dumping/dumping_dialog.h b/src/citra_qt/dumping/dumping_dialog.h index f0153f179..3ff976494 100644 --- a/src/citra_qt/dumping/dumping_dialog.h +++ b/src/citra_qt/dumping/dumping_dialog.h @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include #include "core/dumping/ffmpeg_backend.h" diff --git a/src/citra_qt/game_list_p.h b/src/citra_qt/game_list_p.h index 709aeff00..e7394609a 100644 --- a/src/citra_qt/game_list_p.h +++ b/src/citra_qt/game_list_p.h @@ -6,8 +6,10 @@ #include #include +#include #include #include +#include #include #include #include @@ -153,7 +155,7 @@ public: static constexpr int LongTitleRole = SortRole + 5; GameListItemPath() = default; - GameListItemPath(const QString& game_path, const std::vector& smdh_data, u64 program_id, + GameListItemPath(const QString& game_path, std::span smdh_data, u64 program_id, u64 extdata_id) { setData(type(), TypeRole); setData(game_path, FullPathRole); @@ -178,7 +180,7 @@ public: } Loader::SMDH smdh; - memcpy(&smdh, smdh_data.data(), sizeof(Loader::SMDH)); + std::memcpy(&smdh, smdh_data.data(), sizeof(Loader::SMDH)); // Get icon from SMDH if (UISettings::values.game_list_icon_size.GetValue() != @@ -286,7 +288,7 @@ public: class GameListItemRegion : public GameListItem { public: GameListItemRegion() = default; - explicit GameListItemRegion(const std::vector& smdh_data) { + explicit GameListItemRegion(std::span smdh_data) { setData(type(), TypeRole); if (!Loader::IsValidSMDH(smdh_data)) { @@ -295,7 +297,7 @@ public: } Loader::SMDH smdh; - memcpy(&smdh, smdh_data.data(), sizeof(Loader::SMDH)); + std::memcpy(&smdh, smdh_data.data(), sizeof(Loader::SMDH)); setText(GetRegionFromSMDH(smdh)); setData(GetRegionFromSMDH(smdh), SortRole); diff --git a/src/citra_qt/loading_screen.cpp b/src/citra_qt/loading_screen.cpp index 0cf6c23b7..0efb6f71a 100644 --- a/src/citra_qt/loading_screen.cpp +++ b/src/citra_qt/loading_screen.cpp @@ -80,7 +80,7 @@ const static std::unordered_map progr static QPixmap GetQPixmapFromSMDH(std::vector& smdh_data) { Loader::SMDH smdh; - memcpy(&smdh, smdh_data.data(), sizeof(Loader::SMDH)); + std::memcpy(&smdh, smdh_data.data(), sizeof(Loader::SMDH)); bool large = true; std::vector icon_data = smdh.GetIcon(large); diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 3fa335d35..18e4be629 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -855,7 +855,7 @@ const std::string& GetDefaultUserPath(UserPath path) { return g_default_paths[path]; } -const void UpdateUserPath(UserPath path, const std::string& filename) { +void UpdateUserPath(UserPath path, const std::string& filename) { if (filename.empty()) { return; } diff --git a/src/common/file_util.h b/src/common/file_util.h index 41e2af845..1d28c4864 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -191,7 +191,7 @@ void SetCurrentRomPath(const std::string& path); [[nodiscard]] const std::string& GetDefaultUserPath(UserPath path); // Update the Global Path with the new value -const void UpdateUserPath(UserPath path, const std::string& filename); +void UpdateUserPath(UserPath path, const std::string& filename); // Returns the path to where the sys file are [[nodiscard]] std::string GetSysDirectory(); diff --git a/src/common/linear_disk_cache.h b/src/common/linear_disk_cache.h index 61e4bd217..ee9cd5afa 100644 --- a/src/common/linear_disk_cache.h +++ b/src/common/linear_disk_cache.h @@ -154,7 +154,7 @@ private: struct Header { Header() : id(*(u32*)"DCAC"), key_t_size(sizeof(K)), value_t_size(sizeof(V)) { - memcpy(ver, scm_rev_git_str, 40); + std::memcpy(ver, scm_rev_git_str, 40); } const u32 id; diff --git a/src/common/ring_buffer.h b/src/common/ring_buffer.h index 29fc7f0cc..9b7e32b2c 100644 --- a/src/common/ring_buffer.h +++ b/src/common/ring_buffer.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include "common/common_types.h" @@ -57,7 +58,7 @@ public: return push_count; } - std::size_t Push(const std::vector& input) { + std::size_t Push(std::span input) { return Push(input.data(), input.size() / granularity); } diff --git a/src/common/x64/cpu_detect.cpp b/src/common/x64/cpu_detect.cpp index 2e301d377..0791a3f20 100644 --- a/src/common/x64/cpu_detect.cpp +++ b/src/common/x64/cpu_detect.cpp @@ -56,7 +56,7 @@ static CPUCaps Detect() { // Citra at all anyway int cpu_id[4]; - memset(caps.brand_string, 0, sizeof(caps.brand_string)); + std::memset(caps.brand_string, 0, sizeof(caps.brand_string)); // Detect CPU's CPUID capabilities and grab CPU string __cpuid(cpu_id, 0x00000000); diff --git a/src/common/zstd_compression.cpp b/src/common/zstd_compression.cpp index c61b52ee3..d77863fbf 100644 --- a/src/common/zstd_compression.cpp +++ b/src/common/zstd_compression.cpp @@ -5,19 +5,18 @@ #include #include -#include "common/assert.h" #include "common/zstd_compression.h" namespace Common::Compression { -std::vector CompressDataZSTD(const u8* source, std::size_t source_size, s32 compression_level) { +std::vector CompressDataZSTD(std::span source, s32 compression_level) { compression_level = std::clamp(compression_level, ZSTD_minCLevel(), ZSTD_maxCLevel()); - const std::size_t max_compressed_size = ZSTD_compressBound(source_size); + const std::size_t max_compressed_size = ZSTD_compressBound(source.size()); std::vector compressed(max_compressed_size); - const std::size_t compressed_size = - ZSTD_compress(compressed.data(), compressed.size(), source, source_size, compression_level); + const std::size_t compressed_size = ZSTD_compress( + compressed.data(), compressed.size(), source.data(), source.size(), compression_level); if (ZSTD_isError(compressed_size)) { // Compression failed @@ -29,11 +28,11 @@ std::vector CompressDataZSTD(const u8* source, std::size_t source_size, s32 return compressed; } -std::vector CompressDataZSTDDefault(const u8* source, std::size_t source_size) { - return CompressDataZSTD(source, source_size, ZSTD_CLEVEL_DEFAULT); +std::vector CompressDataZSTDDefault(std::span source) { + return CompressDataZSTD(source, ZSTD_CLEVEL_DEFAULT); } -std::vector DecompressDataZSTD(const std::vector& compressed) { +std::vector DecompressDataZSTD(std::span compressed) { const std::size_t decompressed_size = ZSTD_getFrameContentSize(compressed.data(), compressed.size()); std::vector decompressed(decompressed_size); diff --git a/src/common/zstd_compression.h b/src/common/zstd_compression.h index 3bef0072f..467b5d771 100644 --- a/src/common/zstd_compression.h +++ b/src/common/zstd_compression.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include "common/common_types.h" @@ -14,24 +15,21 @@ namespace Common::Compression { * Compresses a source memory region with Zstandard and returns the compressed data in a vector. * * @param source the uncompressed source memory region. - * @param source_size the size in bytes of the uncompressed source memory region. * @param compression_level the used compression level. Should be between 1 and 22. * * @return the compressed data. */ -[[nodiscard]] std::vector CompressDataZSTD(const u8* source, std::size_t source_size, - s32 compression_level); +[[nodiscard]] std::vector CompressDataZSTD(std::span source, s32 compression_level); /** * Compresses a source memory region with Zstandard with the default compression level and returns * the compressed data in a vector. * * @param source the uncompressed source memory region. - * @param source_size the size in bytes of the uncompressed source memory region. * * @return the compressed data. */ -[[nodiscard]] std::vector CompressDataZSTDDefault(const u8* source, std::size_t source_size); +[[nodiscard]] std::vector CompressDataZSTDDefault(std::span source); /** * Decompresses a source memory region with Zstandard and returns the uncompressed data in a vector. @@ -40,6 +38,6 @@ namespace Common::Compression { * * @return the decompressed data. */ -[[nodiscard]] std::vector DecompressDataZSTD(const std::vector& compressed); +[[nodiscard]] std::vector DecompressDataZSTD(std::span compressed); } // namespace Common::Compression diff --git a/src/core/cheats/gateway_cheat.cpp b/src/core/cheats/gateway_cheat.cpp index 1067b5718..b44d60477 100644 --- a/src/core/cheats/gateway_cheat.cpp +++ b/src/core/cheats/gateway_cheat.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -144,7 +145,7 @@ static inline void JokerOp(const GatewayCheat::CheatLine& line, State& state, } static inline void PatchOp(const GatewayCheat::CheatLine& line, State& state, Core::System& system, - const std::vector& cheat_lines) { + std::span cheat_lines) { if (state.if_flag > 0) { // Skip over the additional patch lines state.current_line_nr += static_cast(std::ceil(line.value / 8.0)); diff --git a/src/core/dumping/ffmpeg_backend.cpp b/src/core/dumping/ffmpeg_backend.cpp index caef31ca8..3a87fca06 100644 --- a/src/core/dumping/ffmpeg_backend.cpp +++ b/src/core/dumping/ffmpeg_backend.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include #include #include "common/assert.h" #include "common/file_util.h" @@ -892,7 +893,7 @@ std::string FormatDuration(s64 duration) { } std::string FormatDefaultValue(const AVOption* option, - const std::vector& named_constants) { + std::span named_constants) { // The following is taken and modified from libavutil code (opt.c) switch (option->type) { case AV_OPT_TYPE_BOOL: { diff --git a/src/core/file_sys/archive_extsavedata.cpp b/src/core/file_sys/archive_extsavedata.cpp index 7ace09a58..7ab54d39c 100644 --- a/src/core/file_sys/archive_extsavedata.cpp +++ b/src/core/file_sys/archive_extsavedata.cpp @@ -296,11 +296,10 @@ ResultVal ArchiveFactory_ExtSaveData::GetFormatInfo(const Pat return info; } -void ArchiveFactory_ExtSaveData::WriteIcon(const Path& path, const u8* icon_data, - std::size_t icon_size) { +void ArchiveFactory_ExtSaveData::WriteIcon(const Path& path, std::span icon) { std::string game_path = FileSys::GetExtSaveDataPath(GetMountPoint(), path); FileUtil::IOFile icon_file(game_path + "icon", "wb"); - icon_file.WriteBytes(icon_data, icon_size); + icon_file.WriteBytes(icon.data(), icon.size()); } } // namespace FileSys diff --git a/src/core/file_sys/archive_extsavedata.h b/src/core/file_sys/archive_extsavedata.h index e8d4e5f25..dec84ade9 100644 --- a/src/core/file_sys/archive_extsavedata.h +++ b/src/core/file_sys/archive_extsavedata.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include #include @@ -38,7 +39,7 @@ public: * @param icon_data Binary data of the icon * @param icon_size Size of the icon data */ - void WriteIcon(const Path& path, const u8* icon_data, std::size_t icon_size); + void WriteIcon(const Path& path, std::span icon); private: bool shared; ///< Whether this archive represents an ExtSaveData archive or a SharedExtSaveData diff --git a/src/core/file_sys/archive_ncch.cpp b/src/core/file_sys/archive_ncch.cpp index 7b0e4de58..49744efd2 100644 --- a/src/core/file_sys/archive_ncch.cpp +++ b/src/core/file_sys/archive_ncch.cpp @@ -249,7 +249,7 @@ ResultVal NCCHFile::Read(const u64 offset, const std::size_t length std::size_t available_size = static_cast(file_buffer.size() - offset); std::size_t copy_size = std::min(length, available_size); - memcpy(buffer, file_buffer.data() + offset, copy_size); + std::memcpy(buffer, file_buffer.data() + offset, copy_size); return copy_size; } diff --git a/src/core/file_sys/cia_container.cpp b/src/core/file_sys/cia_container.cpp index c2cfd36ad..b2092bcab 100644 --- a/src/core/file_sys/cia_container.cpp +++ b/src/core/file_sys/cia_container.cpp @@ -108,7 +108,7 @@ Loader::ResultStatus CIAContainer::Load(const std::string& filepath) { return Loader::ResultStatus::Success; } -Loader::ResultStatus CIAContainer::Load(const std::vector& file_data) { +Loader::ResultStatus CIAContainer::Load(std::span file_data) { Loader::ResultStatus result = LoadHeader(file_data); if (result != Loader::ResultStatus::Success) return result; @@ -133,30 +133,29 @@ Loader::ResultStatus CIAContainer::Load(const std::vector& file_data) { return Loader::ResultStatus::Success; } -Loader::ResultStatus CIAContainer::LoadHeader(const std::vector& header_data, - std::size_t offset) { - if (header_data.size() - offset < sizeof(Header)) +Loader::ResultStatus CIAContainer::LoadHeader(std::span header_data, std::size_t offset) { + if (header_data.size() - offset < sizeof(Header)) { return Loader::ResultStatus::Error; + } std::memcpy(&cia_header, header_data.data(), sizeof(Header)); return Loader::ResultStatus::Success; } -Loader::ResultStatus CIAContainer::LoadTicket(const std::vector& ticket_data, - std::size_t offset) { +Loader::ResultStatus CIAContainer::LoadTicket(std::span ticket_data, std::size_t offset) { return cia_ticket.Load(ticket_data, offset); } -Loader::ResultStatus CIAContainer::LoadTitleMetadata(const std::vector& tmd_data, +Loader::ResultStatus CIAContainer::LoadTitleMetadata(std::span tmd_data, std::size_t offset) { return cia_tmd.Load(tmd_data, offset); } -Loader::ResultStatus CIAContainer::LoadMetadata(const std::vector& meta_data, - std::size_t offset) { - if (meta_data.size() - offset < sizeof(Metadata)) +Loader::ResultStatus CIAContainer::LoadMetadata(std::span meta_data, std::size_t offset) { + if (meta_data.size() - offset < sizeof(Metadata)) { return Loader::ResultStatus::Error; + } std::memcpy(&cia_metadata, meta_data.data(), sizeof(Metadata)); diff --git a/src/core/file_sys/cia_container.h b/src/core/file_sys/cia_container.h index b50803514..4b284fc85 100644 --- a/src/core/file_sys/cia_container.h +++ b/src/core/file_sys/cia_container.h @@ -6,8 +6,8 @@ #include #include +#include #include -#include #include "common/common_types.h" #include "common/swap.h" #include "core/file_sys/ticket.h" @@ -39,13 +39,13 @@ public: // Load whole CIAs outright Loader::ResultStatus Load(const FileBackend& backend); Loader::ResultStatus Load(const std::string& filepath); - Loader::ResultStatus Load(const std::vector& header_data); + Loader::ResultStatus Load(std::span header_data); // Load parts of CIAs (for CIAs streamed in) - Loader::ResultStatus LoadHeader(const std::vector& header_data, std::size_t offset = 0); - Loader::ResultStatus LoadTicket(const std::vector& ticket_data, std::size_t offset = 0); - Loader::ResultStatus LoadTitleMetadata(const std::vector& tmd_data, std::size_t offset = 0); - Loader::ResultStatus LoadMetadata(const std::vector& meta_data, std::size_t offset = 0); + Loader::ResultStatus LoadHeader(std::span header_data, std::size_t offset = 0); + Loader::ResultStatus LoadTicket(std::span ticket_data, std::size_t offset = 0); + Loader::ResultStatus LoadTitleMetadata(std::span tmd_data, std::size_t offset = 0); + Loader::ResultStatus LoadMetadata(std::span meta_data, std::size_t offset = 0); const Ticket& GetTicket() const; const TitleMetadata& GetTitleMetadata() const; diff --git a/src/core/file_sys/ncch_container.cpp b/src/core/file_sys/ncch_container.cpp index 0df037f96..df9859b79 100644 --- a/src/core/file_sys/ncch_container.cpp +++ b/src/core/file_sys/ncch_container.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -36,10 +37,10 @@ u64 GetModId(u64 program_id) { * @param size Size of compressed buffer * @return Size of decompressed buffer */ -static u32 LZSS_GetDecompressedSize(const u8* buffer, u32 size) { +static std::size_t LZSS_GetDecompressedSize(std::span buffer) { u32 offset_size; - std::memcpy(&offset_size, buffer + size - sizeof(u32), sizeof(u32)); - return offset_size + size; + std::memcpy(&offset_size, buffer.data() + buffer.size() - sizeof(u32), sizeof(u32)); + return offset_size + buffer.size(); } /** @@ -50,19 +51,18 @@ static u32 LZSS_GetDecompressedSize(const u8* buffer, u32 size) { * @param decompressed_size Size of decompressed buffer * @return True on success, otherwise false */ -static bool LZSS_Decompress(const u8* compressed, u32 compressed_size, u8* decompressed, - u32 decompressed_size) { - const u8* footer = compressed + compressed_size - 8; +static bool LZSS_Decompress(std::span compressed, std::span decompressed) { + const u8* footer = compressed.data() + compressed.size() - 8; u32 buffer_top_and_bottom; std::memcpy(&buffer_top_and_bottom, footer, sizeof(u32)); - u32 out = decompressed_size; - u32 index = compressed_size - ((buffer_top_and_bottom >> 24) & 0xFF); - u32 stop_index = compressed_size - (buffer_top_and_bottom & 0xFFFFFF); + size_t out = decompressed.size(); + size_t index = compressed.size() - ((buffer_top_and_bottom >> 24) & 0xFF); + size_t stop_index = compressed.size() - (buffer_top_and_bottom & 0xFFFFFF); - memset(decompressed, 0, decompressed_size); - memcpy(decompressed, compressed, compressed_size); + std::memset(decompressed.data(), 0, decompressed.size()); + std::memcpy(decompressed.data(), compressed.data(), compressed.size()); while (index > stop_index) { u8 control = compressed[--index]; @@ -92,7 +92,7 @@ static bool LZSS_Decompress(const u8* compressed, u32 compressed_size, u8* decom for (unsigned j = 0; j < segment_size; j++) { // Check if compression is out of bounds - if (out + segment_offset >= decompressed_size) + if (out + segment_offset >= decompressed.size()) return false; u8 data = decompressed[out + segment_offset]; @@ -538,14 +538,9 @@ Loader::ResultStatus NCCHContainer::LoadSectionExeFS(const char* name, std::vect if (strcmp(section.name, ".code") == 0 && is_compressed) { // Section is compressed, read compressed .code section... - std::unique_ptr temp_buffer; - try { - temp_buffer.reset(new u8[section.size]); - } catch (std::bad_alloc&) { - return Loader::ResultStatus::ErrorMemoryAllocationFailed; - } - - if (exefs_file.ReadBytes(&temp_buffer[0], section.size) != section.size) + std::vector temp_buffer(section.size); + if (exefs_file.ReadBytes(temp_buffer.data(), temp_buffer.size()) != + temp_buffer.size()) return Loader::ResultStatus::Error; if (is_encrypted) { @@ -553,11 +548,10 @@ Loader::ResultStatus NCCHContainer::LoadSectionExeFS(const char* name, std::vect } // Decompress .code section... - u32 decompressed_size = LZSS_GetDecompressedSize(&temp_buffer[0], section.size); - buffer.resize(decompressed_size); - if (!LZSS_Decompress(&temp_buffer[0], section.size, buffer.data(), - decompressed_size)) + buffer.resize(LZSS_GetDecompressedSize(temp_buffer)); + if (!LZSS_Decompress(temp_buffer, buffer)) { return Loader::ResultStatus::ErrorInvalidFormat; + } } else { // Section is uncompressed... buffer.resize(section.size); diff --git a/src/core/file_sys/plugin_3gx.cpp b/src/core/file_sys/plugin_3gx.cpp index dcb73005e..f8a01be9b 100644 --- a/src/core/file_sys/plugin_3gx.cpp +++ b/src/core/file_sys/plugin_3gx.cpp @@ -142,8 +142,8 @@ Loader::ResultStatus FileSys::Plugin3GXLoader::Load( } exe_load_func.push_back(instruction); } - memcpy(exe_load_args, header.infos.builtin_load_exe_args, - sizeof(_3gx_Infos::builtin_load_exe_args)); + std::memcpy(exe_load_args, header.infos.builtin_load_exe_args, + sizeof(_3gx_Infos::builtin_load_exe_args)); } // Load code sections @@ -245,8 +245,8 @@ Loader::ResultStatus FileSys::Plugin3GXLoader::Map( plugin_header.plgldr_reply = plg_context.plg_reply; plugin_header.is_default_plugin = plg_context.is_default_path; if (plg_context.use_user_load_parameters) { - memcpy(plugin_header.config, plg_context.user_load_parameters.config, - sizeof(PluginHeader::config)); + std::memcpy(plugin_header.config, plg_context.user_load_parameters.config, + sizeof(PluginHeader::config)); } kernel.memory.WriteBlock(process, _3GX_exe_load_addr, &plugin_header, sizeof(PluginHeader)); @@ -286,8 +286,7 @@ Loader::ResultStatus FileSys::Plugin3GXLoader::Map( } void FileSys::Plugin3GXLoader::MapBootloader(Kernel::Process& process, Kernel::KernelSystem& kernel, - u32 memory_offset, - const std::vector& exe_load_func, + u32 memory_offset, std::span exe_load_func, const u32_le* exe_load_args, u32 checksum_size, u32 exe_checksum, bool no_flash) { @@ -296,7 +295,8 @@ void FileSys::Plugin3GXLoader::MapBootloader(Kernel::Process& process, Kernel::K sizeof(u32) * 2); std::array bootloader; - memcpy(bootloader.data(), g_plugin_loader_bootloader.data(), g_plugin_loader_bootloader.size()); + std::memcpy(bootloader.data(), g_plugin_loader_bootloader.data(), + g_plugin_loader_bootloader.size()); for (auto it = bootloader.begin(); it < bootloader.end(); it++) { switch (static_cast(*it)) { diff --git a/src/core/file_sys/plugin_3gx.h b/src/core/file_sys/plugin_3gx.h index 763a0395a..d4c2650e1 100644 --- a/src/core/file_sys/plugin_3gx.h +++ b/src/core/file_sys/plugin_3gx.h @@ -21,9 +21,10 @@ #pragma once -#include +#include #include "common/common_types.h" #include "common/swap.h" +#include "core/file_sys/archive_backend.h" #include "core/hle/kernel/process.h" #include "core/hle/service/plgldr/plgldr.h" @@ -71,7 +72,7 @@ private: static constexpr size_t bootloader_memory_size = 0x1000; static void MapBootloader(Kernel::Process& process, Kernel::KernelSystem& kernel, - u32 memory_offset, const std::vector& exe_load_func, + u32 memory_offset, std::span exe_load_func, const u32_le* exe_load_args, u32 checksum_size, u32 exe_checksum, bool no_flash); diff --git a/src/core/file_sys/ticket.cpp b/src/core/file_sys/ticket.cpp index 2b6926adc..3537a8cab 100644 --- a/src/core/file_sys/ticket.cpp +++ b/src/core/file_sys/ticket.cpp @@ -13,7 +13,7 @@ namespace FileSys { -Loader::ResultStatus Ticket::Load(const std::vector file_data, std::size_t offset) { +Loader::ResultStatus Ticket::Load(std::span file_data, std::size_t offset) { std::size_t total_size = static_cast(file_data.size() - offset); if (total_size < sizeof(u32)) return Loader::ResultStatus::Error; @@ -35,8 +35,8 @@ Loader::ResultStatus Ticket::Load(const std::vector file_data, std::size_t o // Read signature + ticket body ticket_signature.resize(signature_size); - memcpy(ticket_signature.data(), &file_data[offset + sizeof(u32)], signature_size); - memcpy(&ticket_body, &file_data[offset + body_start], sizeof(Body)); + std::memcpy(ticket_signature.data(), &file_data[offset + sizeof(u32)], signature_size); + std::memcpy(&ticket_body, &file_data[offset + body_start], sizeof(Body)); return Loader::ResultStatus::Success; } diff --git a/src/core/file_sys/ticket.h b/src/core/file_sys/ticket.h index 351a915c3..170493c64 100644 --- a/src/core/file_sys/ticket.h +++ b/src/core/file_sys/ticket.h @@ -6,6 +6,7 @@ #include #include +#include #include #include #include "common/common_funcs.h" @@ -47,7 +48,7 @@ public: static_assert(sizeof(Body) == 0x210, "Ticket body structure size is wrong"); #pragma pack(pop) - Loader::ResultStatus Load(const std::vector file_data, std::size_t offset = 0); + Loader::ResultStatus Load(std::span file_data, std::size_t offset = 0); std::optional> GetTitleKey() const; private: diff --git a/src/core/file_sys/title_metadata.cpp b/src/core/file_sys/title_metadata.cpp index fd9498870..d6bf079f3 100644 --- a/src/core/file_sys/title_metadata.cpp +++ b/src/core/file_sys/title_metadata.cpp @@ -29,12 +29,13 @@ Loader::ResultStatus TitleMetadata::Load(const std::string& file_path) { return result; } -Loader::ResultStatus TitleMetadata::Load(const std::vector& file_data, std::size_t offset) { +Loader::ResultStatus TitleMetadata::Load(std::span file_data, std::size_t offset) { std::size_t total_size = static_cast(file_data.size() - offset); - if (total_size < sizeof(u32_be)) + if (total_size < sizeof(u32_be)) { return Loader::ResultStatus::Error; + } - memcpy(&signature_type, &file_data[offset], sizeof(u32_be)); + std::memcpy(&signature_type, &file_data[offset], sizeof(u32_be)); // Signature lengths are variable, and the body follows the signature u32 signature_size = GetSignatureSize(signature_type); @@ -46,13 +47,14 @@ Loader::ResultStatus TitleMetadata::Load(const std::vector& file_data, std:: std::size_t body_start = Common::AlignUp(signature_size + sizeof(u32), 0x40); std::size_t body_end = body_start + sizeof(Body); - if (total_size < body_end) + if (total_size < body_end) { return Loader::ResultStatus::Error; + } // Read signature + TMD body, then load the amount of ContentChunks specified tmd_signature.resize(signature_size); - memcpy(tmd_signature.data(), &file_data[offset + sizeof(u32_be)], signature_size); - memcpy(&tmd_body, &file_data[offset + body_start], sizeof(TitleMetadata::Body)); + std::memcpy(tmd_signature.data(), &file_data[offset + sizeof(u32_be)], signature_size); + std::memcpy(&tmd_body, &file_data[offset + body_start], sizeof(TitleMetadata::Body)); std::size_t expected_size = body_start + sizeof(Body) + static_cast(tmd_body.content_count) * sizeof(ContentChunk); @@ -65,8 +67,8 @@ Loader::ResultStatus TitleMetadata::Load(const std::vector& file_data, std:: for (u16 i = 0; i < tmd_body.content_count; i++) { ContentChunk chunk; - memcpy(&chunk, &file_data[offset + body_end + (i * sizeof(ContentChunk))], - sizeof(ContentChunk)); + std::memcpy(&chunk, &file_data[offset + body_end + (i * sizeof(ContentChunk))], + sizeof(ContentChunk)); tmd_chunks.push_back(chunk); } diff --git a/src/core/file_sys/title_metadata.h b/src/core/file_sys/title_metadata.h index af7bbc541..cb52d22de 100644 --- a/src/core/file_sys/title_metadata.h +++ b/src/core/file_sys/title_metadata.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include #include "common/common_types.h" @@ -82,7 +83,7 @@ public: #pragma pack(pop) Loader::ResultStatus Load(const std::string& file_path); - Loader::ResultStatus Load(const std::vector& file_data, std::size_t offset = 0); + Loader::ResultStatus Load(std::span file_data, std::size_t offset = 0); Loader::ResultStatus Save(const std::string& file_path); u64 GetTitleID() const; diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp index 0fab5418b..592078aa2 100644 --- a/src/core/gdbstub/gdbstub.cpp +++ b/src/core/gdbstub/gdbstub.cpp @@ -491,7 +491,7 @@ void SendReply(const char* reply) { return; } - memset(command_buffer, 0, sizeof(command_buffer)); + std::memset(command_buffer, 0, sizeof(command_buffer)); command_length = static_cast(strlen(reply)); if (command_length + 4 > sizeof(command_buffer)) { @@ -499,7 +499,7 @@ void SendReply(const char* reply) { return; } - memcpy(command_buffer + 1, reply, command_length); + std::memcpy(command_buffer + 1, reply, command_length); u8 checksum = CalculateChecksum(command_buffer, command_length + 1); command_buffer[0] = GDB_STUB_START; @@ -639,7 +639,7 @@ static void SendSignal(Kernel::Thread* thread, u32 signal, bool full = true) { /// Read command from gdb client. static void ReadCommand() { command_length = 0; - memset(command_buffer, 0, sizeof(command_buffer)); + std::memset(command_buffer, 0, sizeof(command_buffer)); u8 c = ReadByte(); if (c == GDB_STUB_ACK) { @@ -711,7 +711,7 @@ static bool IsDataAvailable() { /// Send requested register to gdb client. static void ReadRegister() { static u8 reply[64]; - memset(reply, 0, sizeof(reply)); + std::memset(reply, 0, sizeof(reply)); u32 id = HexCharToValue(command_buffer[1]); if (command_buffer[2] != '\0') { @@ -737,7 +737,7 @@ static void ReadRegister() { /// Send all registers to the gdb client. static void ReadRegisters() { static u8 buffer[GDB_BUFFER_SIZE - 4]; - memset(buffer, 0, sizeof(buffer)); + std::memset(buffer, 0, sizeof(buffer)); u8* bufptr = buffer; diff --git a/src/core/gdbstub/gdbstub.h b/src/core/gdbstub/gdbstub.h index 33d6bd8f1..d361eb1ea 100644 --- a/src/core/gdbstub/gdbstub.h +++ b/src/core/gdbstub/gdbstub.h @@ -6,6 +6,7 @@ #pragma once +#include #include "common/common_types.h" #include "core/hle/kernel/thread.h" diff --git a/src/core/gdbstub/hio.cpp b/src/core/gdbstub/hio.cpp index 970225f31..c9c1cb161 100644 --- a/src/core/gdbstub/hio.cpp +++ b/src/core/gdbstub/hio.cpp @@ -115,7 +115,7 @@ void HandleHioReply(const u8* const command_buffer, const u32 command_length) { } // Skip 'F' header - auto* command_pos = command_buffer + 1; + const u8* command_pos = command_buffer + 1; if (*command_pos == 0 || *command_pos == ',') { LOG_WARNING(Debug_GDBStub, "bad HIO packet format position 0: {}", *command_pos); diff --git a/src/core/hle/applets/erreula.cpp b/src/core/hle/applets/erreula.cpp index 3ee74689d..66ace0f8a 100644 --- a/src/core/hle/applets/erreula.cpp +++ b/src/core/hle/applets/erreula.cpp @@ -23,7 +23,7 @@ ResultCode ErrEula::ReceiveParameterImpl(const Service::APT::MessageParameter& p Service::APT::CaptureBufferInfo capture_info; ASSERT(sizeof(capture_info) == parameter.buffer.size()); - memcpy(&capture_info, parameter.buffer.data(), sizeof(capture_info)); + std::memcpy(&capture_info, parameter.buffer.data(), sizeof(capture_info)); // TODO: allocated memory never released using Kernel::MemoryPermission; diff --git a/src/core/hle/applets/mii_selector.cpp b/src/core/hle/applets/mii_selector.cpp index 15dd2904c..f4ff0b408 100644 --- a/src/core/hle/applets/mii_selector.cpp +++ b/src/core/hle/applets/mii_selector.cpp @@ -31,7 +31,7 @@ ResultCode MiiSelector::ReceiveParameterImpl(const Service::APT::MessageParamete Service::APT::CaptureBufferInfo capture_info; ASSERT(sizeof(capture_info) == parameter.buffer.size()); - memcpy(&capture_info, parameter.buffer.data(), sizeof(capture_info)); + std::memcpy(&capture_info, parameter.buffer.data(), sizeof(capture_info)); using Kernel::MemoryPermission; // Create a SharedMemory that directly points to this heap block. @@ -54,7 +54,7 @@ ResultCode MiiSelector::Start(const Service::APT::MessageParameter& parameter) { ASSERT_MSG(parameter.buffer.size() == sizeof(config), "The size of the parameter (MiiConfig) is wrong"); - memcpy(&config, parameter.buffer.data(), parameter.buffer.size()); + std::memcpy(&config, parameter.buffer.data(), parameter.buffer.size()); using namespace Frontend; frontend_applet = Core::System::GetInstance().GetMiiSelector(); diff --git a/src/core/hle/applets/mint.cpp b/src/core/hle/applets/mint.cpp index 24975bd86..1a952d02e 100644 --- a/src/core/hle/applets/mint.cpp +++ b/src/core/hle/applets/mint.cpp @@ -23,7 +23,7 @@ ResultCode Mint::ReceiveParameterImpl(const Service::APT::MessageParameter& para Service::APT::CaptureBufferInfo capture_info; ASSERT(sizeof(capture_info) == parameter.buffer.size()); - memcpy(&capture_info, parameter.buffer.data(), sizeof(capture_info)); + std::memcpy(&capture_info, parameter.buffer.data(), sizeof(capture_info)); // TODO: allocated memory never released using Kernel::MemoryPermission; diff --git a/src/core/hle/applets/swkbd.cpp b/src/core/hle/applets/swkbd.cpp index df929f716..81e2eedb1 100644 --- a/src/core/hle/applets/swkbd.cpp +++ b/src/core/hle/applets/swkbd.cpp @@ -93,7 +93,7 @@ ResultCode SoftwareKeyboard::Start(Service::APT::MessageParameter const& paramet ASSERT_MSG(parameter.buffer.size() == sizeof(config), "The size of the parameter (SoftwareKeyboardConfig) is wrong"); - memcpy(&config, parameter.buffer.data(), parameter.buffer.size()); + std::memcpy(&config, parameter.buffer.data(), parameter.buffer.size()); text_memory = std::static_pointer_cast(parameter.object); DrawScreenKeyboard(); @@ -115,7 +115,7 @@ void SoftwareKeyboard::Update() { const KeyboardData& data = frontend_applet->ReceiveData(); std::u16string text = Common::UTF8ToUTF16(data.text); // Include a null terminator - memcpy(text_memory->GetPointer(), text.c_str(), (text.length() + 1) * sizeof(char16_t)); + std::memcpy(text_memory->GetPointer(), text.c_str(), (text.length() + 1) * sizeof(char16_t)); switch (config.num_buttons_m1) { case SoftwareKeyboardButtonConfig::SingleButton: config.return_code = SoftwareKeyboardResult::D0Click; diff --git a/src/core/hle/ipc_helpers.h b/src/core/hle/ipc_helpers.h index 8596a3514..7773e753c 100644 --- a/src/core/hle/ipc_helpers.h +++ b/src/core/hle/ipc_helpers.h @@ -38,7 +38,7 @@ public: void Skip(unsigned size_in_words, bool set_to_null) { if (set_to_null) - memset(cmdbuf + index, 0, size_in_words * sizeof(u32)); + std::memset(cmdbuf + index, 0, size_in_words * sizeof(u32)); index += size_in_words; } }; diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 600465241..680b10dee 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -230,7 +231,7 @@ public: /// Retrieves a process from the current list of processes. std::shared_ptr GetProcessById(u32 process_id) const; - const std::vector>& GetProcessList() const { + std::span> GetProcessList() const { return process_list; } diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index cf8564e38..ab7c663bc 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -543,13 +543,15 @@ void SVC::ExitProcess() { current_process->status = ProcessStatus::Exited; // Stop all the process threads that are currently waiting for objects. - auto& thread_list = kernel.GetCurrentThreadManager().GetThreadList(); + const auto thread_list = kernel.GetCurrentThreadManager().GetThreadList(); for (auto& thread : thread_list) { - if (thread->owner_process.lock() != current_process) + if (thread->owner_process.lock() != current_process) { continue; + } - if (thread.get() == kernel.GetCurrentThreadManager().GetCurrentThread()) + if (thread.get() == kernel.GetCurrentThreadManager().GetCurrentThread()) { continue; + } // TODO(Subv): When are the other running/ready threads terminated? ASSERT_MSG(thread->status == ThreadStatus::WaitSynchAny || @@ -695,7 +697,7 @@ ResultCode SVC::OpenThread(Handle* out_handle, Handle process_handle, u32 thread } for (u32 core_id = 0; core_id < system.GetNumCores(); core_id++) { - auto& thread_list = kernel.GetThreadManager(core_id).GetThreadList(); + const auto thread_list = kernel.GetThreadManager(core_id).GetThreadList(); for (auto& thread : thread_list) { if (thread->owner_process.lock() == process && thread.get()->thread_id == thread_id) { auto result_handle = kernel.GetCurrentProcess()->handle_table.Create(thread); @@ -2092,7 +2094,7 @@ ResultCode SVC::ControlProcess(Handle process_handle, u32 process_OP, u32 varg2, } case ControlProcessOP::PROCESSOP_SCHEDULE_THREADS_WITHOUT_TLS_MAGIC: { for (u32 core_id = 0; core_id < system.GetNumCores(); core_id++) { - auto& thread_list = kernel.GetThreadManager(core_id).GetThreadList(); + const auto thread_list = kernel.GetThreadManager(core_id).GetThreadList(); for (auto& thread : thread_list) { if (thread->owner_process.lock() != process) { continue; diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 2e6aebe21..10007849a 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -304,7 +304,7 @@ void ThreadManager::DebugThreadQueue() { * alloc_needed: Whether there's a need to allocate a new TLS page (All pages are full). */ static std::tuple GetFreeThreadLocalSlot( - const std::vector>& tls_slots) { + std::span> tls_slots) { // Iterate over all the allocated pages, and try to find one where not all slots are used. for (std::size_t page = 0; page < tls_slots.size(); ++page) { const auto& page_tls_slots = tls_slots[page]; @@ -527,7 +527,7 @@ ThreadManager::~ThreadManager() { } } -const std::vector>& ThreadManager::GetThreadList() { +std::span> ThreadManager::GetThreadList() { return thread_list; } diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index 72343e765..71cb978b8 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include #include @@ -113,7 +114,7 @@ public: /** * Get a const reference to the thread list for debug use */ - const std::vector>& GetThreadList(); + std::span> GetThreadList(); void SetCPU(ARM_Interface& cpu_) { cpu = &cpu_; diff --git a/src/core/hle/lock.cpp b/src/core/hle/lock.cpp index af0f0e31b..a9aae6635 100644 --- a/src/core/hle/lock.cpp +++ b/src/core/hle/lock.cpp @@ -2,7 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include +#include "core/hle/lock.h" namespace HLE { std::recursive_mutex g_hle_lock; diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index b1e111f91..05aaaf24a 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -223,7 +223,7 @@ ResultVal CIAFile::Write(u64 offset, std::size_t length, bool flush std::size_t buf_max_size = std::min(static_cast(offset + length), FileSys::CIA_HEADER_SIZE); data.resize(buf_max_size); - memcpy(data.data() + offset, buffer, buf_copy_size); + std::memcpy(data.data() + offset, buffer, buf_copy_size); // We have enough data to load a CIA header and parse it. if (written >= FileSys::CIA_HEADER_SIZE) { @@ -248,7 +248,7 @@ ResultVal CIAFile::Write(u64 offset, std::size_t length, bool flush buf_offset; std::size_t buf_max_size = std::min(offset + length, container.GetContentOffset()); data.resize(buf_max_size); - memcpy(data.data() + copy_offset, buffer + buf_offset, buf_copy_size); + std::memcpy(data.data() + copy_offset, buffer + buf_offset, buf_copy_size); } // TODO(shinyquagsire23): Write out .tik files to nand? @@ -850,7 +850,7 @@ void Module::Interface::GetProgramList(Kernel::HLERequestContext& ctx) { rb.PushMappedBuffer(title_ids_output); } -ResultCode GetTitleInfoFromList(const std::vector& title_id_list, +ResultCode GetTitleInfoFromList(std::span title_id_list, Service::FS::MediaType media_type, Kernel::MappedBuffer& title_info_out) { std::size_t write_offset = 0; diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index 1daa3143d..8db5598ce 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp @@ -134,7 +134,7 @@ void Module::APTInterface::Initialize(Kernel::HLERequestContext& ctx) { static u32 DecompressLZ11(const u8* in, u8* out) { u32_le decompressed_size; - memcpy(&decompressed_size, in, sizeof(u32)); + std::memcpy(&decompressed_size, in, sizeof(u32)); in += 4; u8 type = decompressed_size & 0xFF; diff --git a/src/core/hle/service/apt/bcfnt/bcfnt.cpp b/src/core/hle/service/apt/bcfnt/bcfnt.cpp index 14916cc23..4df4cfccc 100644 --- a/src/core/hle/service/apt/bcfnt/bcfnt.cpp +++ b/src/core/hle/service/apt/bcfnt/bcfnt.cpp @@ -12,7 +12,7 @@ void RelocateSharedFont(std::shared_ptr shared_font, VAddr const u8* cfnt_ptr = shared_font->GetPointer(SharedFontStartOffset); CFNT cfnt; - memcpy(&cfnt, cfnt_ptr, sizeof(cfnt)); + std::memcpy(&cfnt, cfnt_ptr, sizeof(cfnt)); u32 assumed_cmap_offset = 0; u32 assumed_cwdh_offset = 0; @@ -27,17 +27,17 @@ void RelocateSharedFont(std::shared_ptr shared_font, VAddr const u8* data = shared_font->GetPointer(current_offset); SectionHeader section_header; - memcpy(§ion_header, data, sizeof(section_header)); + std::memcpy(§ion_header, data, sizeof(section_header)); - if (first_cmap_offset == 0 && memcmp(section_header.magic, "CMAP", 4) == 0) { + if (first_cmap_offset == 0 && std::memcmp(section_header.magic, "CMAP", 4) == 0) { first_cmap_offset = current_offset; - } else if (first_cwdh_offset == 0 && memcmp(section_header.magic, "CWDH", 4) == 0) { + } else if (first_cwdh_offset == 0 && std::memcmp(section_header.magic, "CWDH", 4) == 0) { first_cwdh_offset = current_offset; - } else if (first_tglp_offset == 0 && memcmp(section_header.magic, "TGLP", 4) == 0) { + } else if (first_tglp_offset == 0 && std::memcmp(section_header.magic, "TGLP", 4) == 0) { first_tglp_offset = current_offset; - } else if (memcmp(section_header.magic, "FINF", 4) == 0) { + } else if (std::memcmp(section_header.magic, "FINF", 4) == 0) { BCFNT::FINF finf; - memcpy(&finf, data, sizeof(finf)); + std::memcpy(&finf, data, sizeof(finf)); assumed_cmap_offset = finf.cmap_offset - sizeof(SectionHeader); assumed_cwdh_offset = finf.cwdh_offset - sizeof(SectionHeader); @@ -59,44 +59,44 @@ void RelocateSharedFont(std::shared_ptr shared_font, VAddr u8* data = shared_font->GetPointer(current_offset); SectionHeader section_header; - memcpy(§ion_header, data, sizeof(section_header)); + std::memcpy(§ion_header, data, sizeof(section_header)); - if (memcmp(section_header.magic, "FINF", 4) == 0) { + if (std::memcmp(section_header.magic, "FINF", 4) == 0) { BCFNT::FINF finf; - memcpy(&finf, data, sizeof(finf)); + std::memcpy(&finf, data, sizeof(finf)); // Relocate the offsets in the FINF section finf.cmap_offset += offset; finf.cwdh_offset += offset; finf.tglp_offset += offset; - memcpy(data, &finf, sizeof(finf)); - } else if (memcmp(section_header.magic, "CMAP", 4) == 0) { + std::memcpy(data, &finf, sizeof(finf)); + } else if (std::memcmp(section_header.magic, "CMAP", 4) == 0) { BCFNT::CMAP cmap; - memcpy(&cmap, data, sizeof(cmap)); + std::memcpy(&cmap, data, sizeof(cmap)); // Relocate the offsets in the CMAP section if (cmap.next_cmap_offset != 0) cmap.next_cmap_offset += offset; - memcpy(data, &cmap, sizeof(cmap)); - } else if (memcmp(section_header.magic, "CWDH", 4) == 0) { + std::memcpy(data, &cmap, sizeof(cmap)); + } else if (std::memcmp(section_header.magic, "CWDH", 4) == 0) { BCFNT::CWDH cwdh; - memcpy(&cwdh, data, sizeof(cwdh)); + std::memcpy(&cwdh, data, sizeof(cwdh)); // Relocate the offsets in the CWDH section if (cwdh.next_cwdh_offset != 0) cwdh.next_cwdh_offset += offset; - memcpy(data, &cwdh, sizeof(cwdh)); - } else if (memcmp(section_header.magic, "TGLP", 4) == 0) { + std::memcpy(data, &cwdh, sizeof(cwdh)); + } else if (std::memcmp(section_header.magic, "TGLP", 4) == 0) { BCFNT::TGLP tglp; - memcpy(&tglp, data, sizeof(tglp)); + std::memcpy(&tglp, data, sizeof(tglp)); // Relocate the offsets in the TGLP section tglp.sheet_data_offset += offset; - memcpy(data, &tglp, sizeof(tglp)); + std::memcpy(data, &tglp, sizeof(tglp)); } current_offset += section_header.section_size; diff --git a/src/core/hle/service/cecd/cecd.cpp b/src/core/hle/service/cecd/cecd.cpp index f6b27e122..b47ebbc1e 100644 --- a/src/core/hle/service/cecd/cecd.cpp +++ b/src/core/hle/service/cecd/cecd.cpp @@ -834,7 +834,7 @@ void Module::Interface::OpenAndRead(Kernel::HLERequestContext& ctx) { open_mode.check); } -std::string Module::EncodeBase64(const std::vector& in) const { +std::string Module::EncodeBase64(std::span in) const { using namespace CryptoPP; using Name::EncodingLookupArray; using Name::InsertLineBreaks; @@ -855,7 +855,7 @@ std::string Module::EncodeBase64(const std::vector& in) const { } std::string Module::GetCecDataPathTypeAsString(const CecDataPathType type, const u32 program_id, - const std::vector& msg_id) const { + std::span msg_id) const { switch (type) { case CecDataPathType::MboxList: return "/CEC/MBoxList____"; diff --git a/src/core/hle/service/cecd/cecd.h b/src/core/hle/service/cecd/cecd.h index 0870f31bf..2ad7cc056 100644 --- a/src/core/hle/service/cecd/cecd.h +++ b/src/core/hle/service/cecd/cecd.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include "common/bit_field.h" #include "common/common_funcs.h" #include "core/hle/kernel/event.h" @@ -610,10 +611,11 @@ private: 0x26, 0x00, 0x01, 0x00}; /// Encoding function used for the message id - std::string EncodeBase64(const std::vector& in) const; + std::string EncodeBase64(std::span in) const; - std::string GetCecDataPathTypeAsString(const CecDataPathType type, const u32 program_id, - const std::vector& msg_id = std::vector()) const; + std::string GetCecDataPathTypeAsString( + const CecDataPathType type, const u32 program_id, + std::span msg_id = std::span{}) const; std::string GetCecCommandAsString(const CecCommand command) const; diff --git a/src/core/hle/service/cfg/cfg.cpp b/src/core/hle/service/cfg/cfg.cpp index 52d35d3b2..c67827b88 100644 --- a/src/core/hle/service/cfg/cfg.cpp +++ b/src/core/hle/service/cfg/cfg.cpp @@ -285,8 +285,8 @@ void Module::Interface::GenHashConsoleUnique(Kernel::HLERequestContext& ctx) { std::array hash; CryptoPP::SHA256().CalculateDigest(hash.data(), buffer.data(), sizeof(buffer)); u32 low, high; - memcpy(&low, &hash[hash.size() - 8], sizeof(u32)); - memcpy(&high, &hash[hash.size() - 4], sizeof(u32)); + std::memcpy(&low, &hash[hash.size() - 8], sizeof(u32)); + std::memcpy(&high, &hash[hash.size() - 4], sizeof(u32)); rb.Push(low); rb.Push(high); } else { @@ -439,7 +439,7 @@ ResultVal Module::GetConfigInfoBlockPointer(u32 block_id, u32 size, u32 f ResultCode Module::GetConfigInfoBlock(u32 block_id, u32 size, u32 flag, void* output) { void* pointer = nullptr; CASCADE_RESULT(pointer, GetConfigInfoBlockPointer(block_id, size, flag)); - memcpy(output, pointer, size); + std::memcpy(output, pointer, size); return RESULT_SUCCESS; } @@ -447,7 +447,7 @@ ResultCode Module::GetConfigInfoBlock(u32 block_id, u32 size, u32 flag, void* ou ResultCode Module::SetConfigInfoBlock(u32 block_id, u32 size, u32 flag, const void* input) { void* pointer = nullptr; CASCADE_RESULT(pointer, GetConfigInfoBlockPointer(block_id, size, flag)); - memcpy(pointer, input, size); + std::memcpy(pointer, input, size); return RESULT_SUCCESS; } @@ -473,10 +473,10 @@ ResultCode Module::CreateConfigInfoBlk(u32 block_id, u16 size, u16 flags, const config->block_entries[config->total_entries].offset_or_data = offset; // Write the data at the new offset - memcpy(&cfg_config_file_buffer[offset], data, size); + std::memcpy(&cfg_config_file_buffer[offset], data, size); } else { // The offset_or_data field in the header contains the data itself if it's 4 bytes or less - memcpy(&config->block_entries[config->total_entries].offset_or_data, data, size); + std::memcpy(&config->block_entries[config->total_entries].offset_or_data, data, size); } ++config->total_entries; @@ -721,7 +721,7 @@ Module::~Module() = default; /// Checks if the language is available in the chosen region, and returns a proper one static std::tuple AdjustLanguageInfoBlock( - const std::vector& region_code, SystemLanguage language) { + std::span region_code, SystemLanguage language) { static const std::array, 7> region_languages{{ // JPN {LANGUAGE_JP}, @@ -750,13 +750,14 @@ static std::tuple AdjustLanguageInfoBlock( } // The language is not available in any available region, so default to the first region and // language - u32 default_region = region_code[0]; + const u32 default_region = region_code[0]; return {default_region, region_languages[default_region][0]}; } -void Module::SetPreferredRegionCodes(const std::vector& region_codes) { +void Module::SetPreferredRegionCodes(std::span region_codes) { const SystemLanguage current_language = GetSystemLanguage(); - auto [region, adjusted_language] = AdjustLanguageInfoBlock(region_codes, current_language); + const auto [region, adjusted_language] = + AdjustLanguageInfoBlock(region_codes, current_language); preferred_region_code = region; LOG_INFO(Service_CFG, "Preferred region code set to {}", preferred_region_code); diff --git a/src/core/hle/service/cfg/cfg.h b/src/core/hle/service/cfg/cfg.h index 65085aa09..63f383879 100644 --- a/src/core/hle/service/cfg/cfg.h +++ b/src/core/hle/service/cfg/cfg.h @@ -6,9 +6,9 @@ #include #include +#include #include #include -#include #include "common/common_types.h" #include "core/hle/service/service.h" @@ -345,7 +345,7 @@ public: * setting is auto. * @param region_codes the preferred region codes to set */ - void SetPreferredRegionCodes(const std::vector& region_codes); + void SetPreferredRegionCodes(std::span region_codes); // Utilities for frontend to set config data. // Note: UpdateConfigNANDSavegame should be called after making changes to config data. diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp index 3e58133ed..ba98ce045 100644 --- a/src/core/hle/service/fs/archive.cpp +++ b/src/core/hle/service/fs/archive.cpp @@ -230,7 +230,7 @@ ResultVal ArchiveManager::GetArchiveFormatInfo( } ResultCode ArchiveManager::CreateExtSaveData(MediaType media_type, u32 high, u32 low, - const std::vector& smdh_icon, + std::span smdh_icon, const FileSys::ArchiveFormatInfo& format_info, u64 program_id) { // Construct the binary path to the archive first @@ -247,10 +247,11 @@ ResultCode ArchiveManager::CreateExtSaveData(MediaType media_type, u32 high, u32 auto ext_savedata = static_cast(archive->second.get()); ResultCode result = ext_savedata->Format(path, format_info, program_id); - if (result.IsError()) + if (result.IsError()) { return result; + } - ext_savedata->WriteIcon(path, smdh_icon.data(), smdh_icon.size()); + ext_savedata->WriteIcon(path, smdh_icon); return RESULT_SUCCESS; } diff --git a/src/core/hle/service/fs/archive.h b/src/core/hle/service/fs/archive.h index b11167807..f4604803b 100644 --- a/src/core/hle/service/fs/archive.h +++ b/src/core/hle/service/fs/archive.h @@ -5,9 +5,9 @@ #pragma once #include +#include #include #include -#include #include #include #include "common/common_types.h" @@ -219,7 +219,7 @@ public: * @return ResultCode 0 on success or the corresponding code on error */ ResultCode CreateExtSaveData(MediaType media_type, u32 high, u32 low, - const std::vector& smdh_icon, + std::span smdh_icon, const FileSys::ArchiveFormatInfo& format_info, u64 program_id); /** diff --git a/src/core/hle/service/gsp/gsp_gpu.cpp b/src/core/hle/service/gsp/gsp_gpu.cpp index c72381657..7ef0fe355 100644 --- a/src/core/hle/service/gsp/gsp_gpu.cpp +++ b/src/core/hle/service/gsp/gsp_gpu.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include #include #include "common/archives.h" #include "common/bit_field.h" @@ -142,7 +143,7 @@ static void WriteSingleHWReg(u32 base_address, u32 data) { * @param data A vector containing the source data * @return RESULT_SUCCESS if the parameters are valid, error code otherwise */ -static ResultCode WriteHWRegs(u32 base_address, u32 size_in_bytes, const std::vector& data) { +static ResultCode WriteHWRegs(u32 base_address, u32 size_in_bytes, std::span data) { // This magic number is verified to be done by the gsp module const u32 max_size_in_bytes = 0x80; @@ -185,8 +186,8 @@ static ResultCode WriteHWRegs(u32 base_address, u32 size_in_bytes, const std::ve * @param masks A vector containing the masks * @return RESULT_SUCCESS if the parameters are valid, error code otherwise */ -static ResultCode WriteHWRegsWithMask(u32 base_address, u32 size_in_bytes, - const std::vector& data, const std::vector& masks) { +static ResultCode WriteHWRegsWithMask(u32 base_address, u32 size_in_bytes, std::span data, + std::span masks) { // This magic number is verified to be done by the gsp module const u32 max_size_in_bytes = 0x80; diff --git a/src/core/hle/service/ir/extra_hid.cpp b/src/core/hle/service/ir/extra_hid.cpp index 4709f70cf..cddcd2edb 100644 --- a/src/core/hle/service/ir/extra_hid.cpp +++ b/src/core/hle/service/ir/extra_hid.cpp @@ -164,7 +164,7 @@ void ExtraHID::OnDisconnect() { timing.UnscheduleEvent(hid_polling_callback_id, 0); } -void ExtraHID::HandleConfigureHIDPollingRequest(const std::vector& request) { +void ExtraHID::HandleConfigureHIDPollingRequest(std::span request) { if (request.size() != 3) { LOG_ERROR(Service_IR, "Wrong request size ({}): {}", request.size(), fmt::format("{:02x}", fmt::join(request, " "))); @@ -177,7 +177,7 @@ void ExtraHID::HandleConfigureHIDPollingRequest(const std::vector& request) timing.ScheduleEvent(msToCycles(hid_period), hid_polling_callback_id); } -void ExtraHID::HandleReadCalibrationDataRequest(const std::vector& request_buf) { +void ExtraHID::HandleReadCalibrationDataRequest(std::span request_buf) { struct ReadCalibrationDataRequest { RequestID request_id; u8 expected_response_time; @@ -213,7 +213,7 @@ void ExtraHID::HandleReadCalibrationDataRequest(const std::vector& request_b Send(response); } -void ExtraHID::OnReceive(const std::vector& data) { +void ExtraHID::OnReceive(std::span data) { switch (static_cast(data[0])) { case RequestID::ConfigureHIDPolling: HandleConfigureHIDPollingRequest(data); diff --git a/src/core/hle/service/ir/extra_hid.h b/src/core/hle/service/ir/extra_hid.h index d498c471f..02974517d 100644 --- a/src/core/hle/service/ir/extra_hid.h +++ b/src/core/hle/service/ir/extra_hid.h @@ -6,6 +6,7 @@ #include #include +#include #include #include "common/bit_field.h" #include "common/swap.h" @@ -47,15 +48,15 @@ public: void OnConnect() override; void OnDisconnect() override; - void OnReceive(const std::vector& data) override; + void OnReceive(std::span data) override; /// Requests input devices reload from current settings. Called when the input settings change. void RequestInputDevicesReload(); private: void SendHIDStatus(); - void HandleConfigureHIDPollingRequest(const std::vector& request); - void HandleReadCalibrationDataRequest(const std::vector& request); + void HandleConfigureHIDPollingRequest(std::span request); + void HandleReadCalibrationDataRequest(std::span request); void LoadInputDevices(); Core::Timing& timing; diff --git a/src/core/hle/service/ir/ir_user.cpp b/src/core/hle/service/ir/ir_user.cpp index 81d631f94..5e921bfdf 100644 --- a/src/core/hle/service/ir/ir_user.cpp +++ b/src/core/hle/service/ir/ir_user.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include #include #include @@ -98,9 +99,10 @@ public: * @params packet The data of the packet to put. * @returns whether the operation is successful. */ - bool Put(const std::vector& packet) { - if (info.packet_count == max_packet_count) + bool Put(std::span packet) { + if (info.packet_count == max_packet_count) { return false; + } u32 write_offset; @@ -182,12 +184,12 @@ private: } void SetPacketInfo(u32 index, const PacketInfo& packet_info) { - memcpy(GetPacketInfoPointer(index), &packet_info, sizeof(PacketInfo)); + std::memcpy(GetPacketInfoPointer(index), &packet_info, sizeof(PacketInfo)); } PacketInfo GetPacketInfo(u32 index) { PacketInfo packet_info; - memcpy(&packet_info, GetPacketInfoPointer(index), sizeof(PacketInfo)); + std::memcpy(&packet_info, GetPacketInfoPointer(index), sizeof(PacketInfo)); return packet_info; } @@ -198,7 +200,7 @@ private: void UpdateBufferInfo() { if (info_offset) { - memcpy(shared_memory->GetPointer(info_offset), &info, sizeof(info)); + std::memcpy(shared_memory->GetPointer(info_offset), &info, sizeof(info)); } } @@ -225,7 +227,7 @@ private: }; /// Wraps the payload into packet and puts it to the receive buffer -void IR_USER::PutToReceive(const std::vector& payload) { +void IR_USER::PutToReceive(std::span payload) { LOG_TRACE(Service_IR, "called, data={}", fmt::format("{:02x}", fmt::join(payload, " "))); std::size_t size = payload.size(); @@ -464,8 +466,8 @@ IR_USER::IR_USER(Core::System& system) : ServiceFramework("ir:USER", 1) { send_event = system.Kernel().CreateEvent(ResetType::OneShot, "IR:SendEvent"); receive_event = system.Kernel().CreateEvent(ResetType::OneShot, "IR:ReceiveEvent"); - extra_hid = std::make_unique( - [this](const std::vector& data) { PutToReceive(data); }, system.CoreTiming()); + extra_hid = std::make_unique([this](std::span data) { PutToReceive(data); }, + system.CoreTiming()); } IR_USER::~IR_USER() { @@ -481,7 +483,7 @@ void IR_USER::ReloadInputDevices() { IRDevice::IRDevice(SendFunc send_func_) : send_func(send_func_) {} IRDevice::~IRDevice() = default; -void IRDevice::Send(const std::vector& data) { +void IRDevice::Send(std::span data) { send_func(data); } diff --git a/src/core/hle/service/ir/ir_user.h b/src/core/hle/service/ir/ir_user.h index afb9be4f7..e724e9dc5 100644 --- a/src/core/hle/service/ir/ir_user.h +++ b/src/core/hle/service/ir/ir_user.h @@ -6,7 +6,7 @@ #include #include -#include +#include #include "core/hle/service/service.h" namespace Kernel { @@ -26,7 +26,7 @@ public: * A function object that implements the method to send data to the 3DS, which takes a vector of * data to send. */ - using SendFunc = std::function& data)>; + using SendFunc = std::function data)>; explicit IRDevice(SendFunc send_func); virtual ~IRDevice(); @@ -38,11 +38,11 @@ public: virtual void OnDisconnect() = 0; /// Called when data is received from the 3DS. This is invoked by the ir:USER send function. - virtual void OnReceive(const std::vector& data) = 0; + virtual void OnReceive(std::span data) = 0; protected: /// Sends data to the 3DS. The actual sending method is specified in the constructor - void Send(const std::vector& data); + void Send(std::span data); private: // NOTE: This value is *not* serialized because it's always passed in the constructor @@ -161,7 +161,7 @@ private: */ void ReleaseReceivedData(Kernel::HLERequestContext& ctx); - void PutToReceive(const std::vector& payload); + void PutToReceive(std::span payload); std::shared_ptr conn_status_event, send_event, receive_event; std::shared_ptr shared_memory; diff --git a/src/core/hle/service/mic_u.cpp b/src/core/hle/service/mic_u.cpp index ba229ae0a..c52627a22 100644 --- a/src/core/hle/service/mic_u.cpp +++ b/src/core/hle/service/mic_u.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include #include #include "audio_core/input.h" #include "audio_core/input_details.h" @@ -77,7 +78,7 @@ struct State { u8 sample_size = 0; SampleRate sample_rate = SampleRate::Rate16360; - void WriteSamples(const std::vector& samples) { + void WriteSamples(std::span samples) { u32 bytes_total_written = 0; const std::size_t remaining_space = size - offset; std::size_t bytes_to_write = std::min(samples.size(), remaining_space); diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index 857a6ba79..e22b9d780 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp @@ -843,14 +843,14 @@ void NWM_UDS::Unbind(Kernel::HLERequestContext& ctx) { rb.Push(0); } -ResultCode NWM_UDS::BeginHostingNetwork(const u8* network_info_buffer, - std::size_t network_info_size, std::vector passphrase) { +ResultCode NWM_UDS::BeginHostingNetwork(std::span network_info_buffer, + std::vector passphrase) { // TODO(Subv): Store the passphrase and verify it when attempting a connection. { std::lock_guard lock(connection_status_mutex); network_info = {}; - std::memcpy(&network_info, network_info_buffer, network_info_size); + std::memcpy(&network_info, network_info_buffer.data(), network_info_buffer.size()); // The real UDS module throws a fatal error if this assert fails. ASSERT_MSG(network_info.max_nodes > 1, "Trying to host a network of only one member."); @@ -921,8 +921,7 @@ void NWM_UDS::BeginHostingNetwork(Kernel::HLERequestContext& ctx) { ASSERT(passphrase.size() == passphrase_size); LOG_DEBUG(Service_NWM, "called"); - auto result = BeginHostingNetwork(network_info_buffer.data(), network_info_buffer.size(), - std::move(passphrase)); + auto result = BeginHostingNetwork(network_info_buffer, std::move(passphrase)); LOG_DEBUG(Service_NWM, "An UDS network has been created."); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); @@ -940,8 +939,7 @@ void NWM_UDS::BeginHostingNetworkDeprecated(Kernel::HLERequestContext& ctx) { ASSERT(passphrase.size() == passphrase_size); LOG_DEBUG(Service_NWM, "called"); - auto result = BeginHostingNetwork(network_info_buffer.data(), network_info_buffer.size(), - std::move(passphrase)); + auto result = BeginHostingNetwork(network_info_buffer, std::move(passphrase)); LOG_DEBUG(Service_NWM, "An UDS network has been created."); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); @@ -1277,10 +1275,10 @@ private: }; void NWM_UDS::ConnectToNetwork(Kernel::HLERequestContext& ctx, u16 command_id, - const u8* network_info_buffer, std::size_t network_info_size, - u8 connection_type, std::vector passphrase) { + std::span network_info_buffer, u8 connection_type, + std::vector passphrase) { network_info = {}; - std::memcpy(&network_info, network_info_buffer, network_info_size); + std::memcpy(&network_info, network_info_buffer.data(), network_info_buffer.size()); // Start the connection sequence StartConnectionSequence(network_info.host_mac_address); @@ -1304,8 +1302,7 @@ void NWM_UDS::ConnectToNetwork(Kernel::HLERequestContext& ctx) { std::vector passphrase = rp.PopStaticBuffer(); - ConnectToNetwork(ctx, 0x1E, network_info_buffer.data(), network_info_buffer.size(), - connection_type, std::move(passphrase)); + ConnectToNetwork(ctx, 0x1E, network_info_buffer, connection_type, std::move(passphrase)); LOG_DEBUG(Service_NWM, "called"); } @@ -1322,8 +1319,7 @@ void NWM_UDS::ConnectToNetworkDeprecated(Kernel::HLERequestContext& ctx) { std::vector passphrase = rp.PopStaticBuffer(); - ConnectToNetwork(ctx, 0x09, network_info_buffer.data(), network_info_buffer.size(), - connection_type, std::move(passphrase)); + ConnectToNetwork(ctx, 0x09, network_info_buffer, connection_type, std::move(passphrase)); LOG_DEBUG(Service_NWM, "called"); } diff --git a/src/core/hle/service/nwm/nwm_uds.h b/src/core/hle/service/nwm/nwm_uds.h index 738d42a9b..45395b1be 100644 --- a/src/core/hle/service/nwm/nwm_uds.h +++ b/src/core/hle/service/nwm/nwm_uds.h @@ -452,12 +452,12 @@ private: u32 sharedmem_size, const NodeInfo& node, u16 version, std::shared_ptr sharedmem); - ResultCode BeginHostingNetwork(const u8* network_info_buffer, std::size_t network_info_size, + ResultCode BeginHostingNetwork(std::span network_info_buffer, std::vector passphrase); void ConnectToNetwork(Kernel::HLERequestContext& ctx, u16 command_id, - const u8* network_info_buffer, std::size_t network_info_size, - u8 connection_type, std::vector passphrase); + std::span network_info_buffer, u8 connection_type, + std::vector passphrase); void BeaconBroadcastCallback(std::uintptr_t user_data, s64 cycles_late); diff --git a/src/core/hle/service/nwm/uds_connection.cpp b/src/core/hle/service/nwm/uds_connection.cpp index b3f77fcf0..0fd12a6c0 100644 --- a/src/core/hle/service/nwm/uds_connection.cpp +++ b/src/core/hle/service/nwm/uds_connection.cpp @@ -22,7 +22,7 @@ std::vector GenerateAuthenticationFrame(AuthenticationSeq seq) { return data; } -AuthenticationSeq GetAuthenticationSeqNumber(const std::vector& body) { +AuthenticationSeq GetAuthenticationSeqNumber(std::span body) { AuthenticationFrame frame; std::memcpy(&frame, body.data(), sizeof(frame)); @@ -74,9 +74,9 @@ std::vector GenerateAssocResponseFrame(AssocStatus status, u16 association_i return data; } -std::tuple GetAssociationResult(const std::vector& body) { +std::tuple GetAssociationResult(std::span body) { AssociationResponseFrame frame; - memcpy(&frame, body.data(), sizeof(frame)); + std::memcpy(&frame, body.data(), sizeof(frame)); constexpr u16 AssociationIdMask = 0x3FFF; return std::make_tuple(frame.status_code, frame.assoc_id & AssociationIdMask); diff --git a/src/core/hle/service/nwm/uds_connection.h b/src/core/hle/service/nwm/uds_connection.h index 60f8e3cfb..423e33374 100644 --- a/src/core/hle/service/nwm/uds_connection.h +++ b/src/core/hle/service/nwm/uds_connection.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include #include "common/common_types.h" @@ -41,7 +42,7 @@ static_assert(sizeof(AssociationResponseFrame) == 6, "AssociationResponseFrame h std::vector GenerateAuthenticationFrame(AuthenticationSeq seq); /// Returns the sequence number from the body of an Authentication frame. -AuthenticationSeq GetAuthenticationSeqNumber(const std::vector& body); +AuthenticationSeq GetAuthenticationSeqNumber(std::span body); /// Generates an 802.11 association response frame with the specified status, association id and /// network id, starting at the frame body. @@ -49,6 +50,6 @@ std::vector GenerateAssocResponseFrame(AssocStatus status, u16 association_i /// Returns a tuple of (association status, association id) from the body of an AssociationResponse /// frame. -std::tuple GetAssociationResult(const std::vector& body); +std::tuple GetAssociationResult(std::span body); } // namespace Service::NWM diff --git a/src/core/hle/service/nwm/uds_data.cpp b/src/core/hle/service/nwm/uds_data.cpp index 396bc8548..abf2b36f9 100644 --- a/src/core/hle/service/nwm/uds_data.cpp +++ b/src/core/hle/service/nwm/uds_data.cpp @@ -28,7 +28,7 @@ static std::vector GenerateLLCHeader(EtherType protocol) { header.protocol = protocol; std::vector buffer(sizeof(header)); - memcpy(buffer.data(), &header, sizeof(header)); + std::memcpy(buffer.data(), &header, sizeof(header)); return buffer; } @@ -53,7 +53,7 @@ static std::vector GenerateSecureDataHeader(u16 data_size, u8 channel, u16 d header.src_node_id = src_node_id; std::vector buffer(sizeof(header)); - memcpy(buffer.data(), &header, sizeof(header)); + std::memcpy(buffer.data(), &header, sizeof(header)); return buffer; } @@ -83,7 +83,7 @@ static std::array GetDataCryptoCTR( * @returns The key used for data frames crypto. */ [[maybe_unused]] static std::array GenerateDataCCMPKey( - const std::vector& passphrase, const NetworkInfo& network_info) { + std::span passphrase, const NetworkInfo& network_info) { // Calculate the MD5 hash of the input passphrase. std::array passphrase_hash; CryptoPP::Weak::MD5().CalculateDigest(passphrase_hash.data(), passphrase.data(), @@ -158,9 +158,9 @@ static std::vector GenerateCCMPAAD(const MacAddress& sender, const MacAddres * @returns The decrypted payload. */ [[maybe_unused]] static std::vector DecryptDataFrame( - const std::vector& encrypted_payload, - const std::array& ccmp_key, const MacAddress& sender, - const MacAddress& receiver, const MacAddress& bssid, u16 sequence_number, u16 frame_control) { + std::span encrypted_payload, const std::array& ccmp_key, + const MacAddress& sender, const MacAddress& receiver, const MacAddress& bssid, + u16 sequence_number, u16 frame_control) { // Reference: IEEE 802.11-2007 @@ -218,7 +218,7 @@ static std::vector GenerateCCMPAAD(const MacAddress& sender, const MacAddres * @returns The encrypted payload. */ [[maybe_unused]] static std::vector EncryptDataFrame( - const std::vector& payload, const std::array& ccmp_key, + std::span payload, const std::array& ccmp_key, const MacAddress& sender, const MacAddress& receiver, const MacAddress& bssid, u16 sequence_number, u16 frame_control) { // Reference: IEEE 802.11-2007 @@ -266,7 +266,7 @@ static std::vector GenerateCCMPAAD(const MacAddress& sender, const MacAddres return {}; } -std::vector GenerateDataPayload(const std::vector& data, u8 channel, u16 dest_node, +std::vector GenerateDataPayload(std::span data, u8 channel, u16 dest_node, u16 src_node, u16 sequence_number) { std::vector buffer = GenerateLLCHeader(EtherType::SecureData); std::vector securedata_header = GenerateSecureDataHeader( @@ -277,7 +277,7 @@ std::vector GenerateDataPayload(const std::vector& data, u8 channel, u16 return buffer; } -SecureDataHeader ParseSecureDataHeader(const std::vector& data) { +SecureDataHeader ParseSecureDataHeader(std::span data) { SecureDataHeader header; // Skip the LLC header @@ -308,20 +308,20 @@ std::vector GenerateEAPoLStartFrame(u16 association_id, const NodeInfo& node return buffer; } -EtherType GetFrameEtherType(const std::vector& frame) { +EtherType GetFrameEtherType(std::span frame) { LLCHeader header; std::memcpy(&header, frame.data(), sizeof(header)); return header.protocol; } -u16 GetEAPoLFrameType(const std::vector& frame) { +u16 GetEAPoLFrameType(std::span frame) { // Ignore the LLC header u16_be eapol_type; std::memcpy(&eapol_type, frame.data() + sizeof(LLCHeader), sizeof(eapol_type)); return eapol_type; } -NodeInfo DeserializeNodeInfoFromFrame(const std::vector& frame) { +NodeInfo DeserializeNodeInfoFromFrame(std::span frame) { EAPoLStartPacket eapol_start; // Skip the LLC header @@ -372,7 +372,7 @@ std::vector GenerateEAPoLLogoffFrame(const MacAddress& mac_address, u16 netw return buffer; } -EAPoLLogoffPacket ParseEAPoLLogoffFrame(const std::vector& frame) { +EAPoLLogoffPacket ParseEAPoLLogoffFrame(std::span frame) { EAPoLLogoffPacket eapol_logoff; // Skip the LLC header diff --git a/src/core/hle/service/nwm/uds_data.h b/src/core/hle/service/nwm/uds_data.h index 6f57f25a8..291cca0f5 100644 --- a/src/core/hle/service/nwm/uds_data.h +++ b/src/core/hle/service/nwm/uds_data.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include "common/common_types.h" #include "common/swap.h" @@ -118,13 +119,13 @@ static_assert(sizeof(EAPoLLogoffPacket) == 0x298, "EAPoLLogoffPacket has the wro * Generates an unencrypted 802.11 data payload. * @returns The generated frame payload. */ -std::vector GenerateDataPayload(const std::vector& data, u8 channel, u16 dest_node, +std::vector GenerateDataPayload(std::span data, u8 channel, u16 dest_node, u16 src_node, u16 sequence_number); /* * Returns the SecureDataHeader stored in an 802.11 data frame. */ -SecureDataHeader ParseSecureDataHeader(const std::vector& data); +SecureDataHeader ParseSecureDataHeader(std::span data); /* * Generates an unencrypted 802.11 data frame body with the EAPoL-Start format for UDS @@ -136,19 +137,19 @@ std::vector GenerateEAPoLStartFrame(u16 association_id, const NodeInfo& node /* * Returns the EtherType of the specified 802.11 frame. */ -EtherType GetFrameEtherType(const std::vector& frame); +EtherType GetFrameEtherType(std::span frame); /* * Returns the EAPoL type (Start / Logoff) of the specified 802.11 frame. * Note: The frame *must* be an EAPoL frame. */ -u16 GetEAPoLFrameType(const std::vector& frame); +u16 GetEAPoLFrameType(std::span frame); /* * Returns a deserialized NodeInfo structure from the information inside an EAPoL-Start packet * encapsulated in an 802.11 data frame. */ -NodeInfo DeserializeNodeInfoFromFrame(const std::vector& frame); +NodeInfo DeserializeNodeInfoFromFrame(std::span frame); /* * Returns a NodeInfo constructed from the data in the specified EAPoLNodeInfo. @@ -166,6 +167,6 @@ std::vector GenerateEAPoLLogoffFrame(const MacAddress& mac_address, u16 netw /* * Returns a EAPoLLogoffPacket representing the specified 802.11-encapsulated data frame. */ -EAPoLLogoffPacket ParseEAPoLLogoffFrame(const std::vector& frame); +EAPoLLogoffPacket ParseEAPoLLogoffFrame(std::span frame); } // namespace Service::NWM diff --git a/src/core/hle/service/soc_u.cpp b/src/core/hle/service/soc_u.cpp index eba312ee3..581652ae8 100644 --- a/src/core/hle/service/soc_u.cpp +++ b/src/core/hle/service/soc_u.cpp @@ -312,7 +312,7 @@ static void TranslateSockOptDataToPlatform(std::vector& out, const std::vect linger_out.l_linger = static_cast( reinterpret_cast(in.data())->l_linger); out.resize(sizeof(linger)); - memcpy(out.data(), &linger_out, sizeof(linger)); + std::memcpy(out.data(), &linger_out, sizeof(linger)); return; } // Other options should have the size of an int, even for booleans @@ -332,7 +332,7 @@ static void TranslateSockOptDataToPlatform(std::vector& out, const std::vect return; } out.resize(sizeof(int)); - memcpy(out.data(), &value, sizeof(int)); + std::memcpy(out.data(), &value, sizeof(int)); } static u32 TranslateSockOptSizeToPlatform(int platform_level, int platform_opt) { @@ -349,7 +349,7 @@ static void TranslateSockOptDataFromPlatform(std::vector& out, const std::ve reinterpret_cast(in.data())->l_onoff); linger_out.l_linger = static_cast( reinterpret_cast(in.data())->l_linger); - memcpy(out.data(), &linger_out, std::min(out.size(), sizeof(CTRLinger))); + std::memcpy(out.data(), &linger_out, std::min(out.size(), sizeof(CTRLinger))); return; } if (out.size() == sizeof(u8) && in.size() == sizeof(int)) { @@ -569,7 +569,7 @@ union CTRSockAddr { ASSERT_MSG(ctr_addr.raw.len == sizeof(CTRSockAddrIn), "Unhandled address size (len) in CTRSockAddr::ToPlatform"); result.sa_family = SocketDomainToPlatform(ctr_addr.raw.sa_family); - memset(result.sa_data, 0, sizeof(result.sa_data)); + std::memset(result.sa_data, 0, sizeof(result.sa_data)); // We can not guarantee ABI compatibility between platforms so we copy the fields manually switch (result.sa_family) { @@ -577,7 +577,7 @@ union CTRSockAddr { sockaddr_in* result_in = reinterpret_cast(&result); result_in->sin_port = ctr_addr.in.sin_port; result_in->sin_addr.s_addr = ctr_addr.in.sin_addr; - memset(result_in->sin_zero, 0, sizeof(result_in->sin_zero)); + std::memset(result_in->sin_zero, 0, sizeof(result_in->sin_zero)); break; } default: @@ -1542,7 +1542,7 @@ void SOC_U::GetNetworkOpt(Kernel::HLERequestContext& ctx) { case NetworkOpt::NETOPT_MAC_ADDRESS: { if (opt_len >= 6) { std::array fake_mac = {0}; - memcpy(opt_data.data(), fake_mac.data(), fake_mac.size()); + std::memcpy(opt_data.data(), fake_mac.data(), fake_mac.size()); } LOG_WARNING(Service_SOC, "(STUBBED) called, level={} opt_name={}", level, opt_name); err = 0; @@ -1777,8 +1777,8 @@ std::optional SOC_U::GetDefaultInterfaceInfo() { int num_interfaces = bytes_used / sizeof(INTERFACE_INFO); for (int i = 0; i < num_interfaces; i++) { if (((sockaddr*)&(interface_list[i].iiAddress))->sa_family == AF_INET && - memcmp(&((sockaddr_in*)&(interface_list[i].iiAddress))->sin_addr.s_addr, - &s_info.sin_addr.s_addr, sizeof(s_info.sin_addr.s_addr)) == 0) { + std::memcmp(&((sockaddr_in*)&(interface_list[i].iiAddress))->sin_addr.s_addr, + &s_info.sin_addr.s_addr, sizeof(s_info.sin_addr.s_addr)) == 0) { ret.address = ((sockaddr_in*)&(interface_list[i].iiAddress))->sin_addr.s_addr; ret.netmask = ((sockaddr_in*)&(interface_list[i].iiNetmask))->sin_addr.s_addr; ret.broadcast = diff --git a/src/core/hw/aes/ccm.cpp b/src/core/hw/aes/ccm.cpp index fca260a96..c1d357267 100644 --- a/src/core/hw/aes/ccm.cpp +++ b/src/core/hw/aes/ccm.cpp @@ -42,7 +42,7 @@ public: } // namespace -std::vector EncryptSignCCM(const std::vector& pdata, const CCMNonce& nonce, +std::vector EncryptSignCCM(std::span pdata, const CCMNonce& nonce, std::size_t slot_id) { if (!IsNormalKeyAvailable(slot_id)) { LOG_ERROR(HW_AES, "Key slot {} not available. Will use zero key.", slot_id); @@ -63,7 +63,7 @@ std::vector EncryptSignCCM(const std::vector& pdata, const CCMNonce& non return cipher; } -std::vector DecryptVerifyCCM(const std::vector& cipher, const CCMNonce& nonce, +std::vector DecryptVerifyCCM(std::span cipher, const CCMNonce& nonce, std::size_t slot_id) { if (!IsNormalKeyAvailable(slot_id)) { LOG_ERROR(HW_AES, "Key slot {} not available. Will use zero key.", slot_id); diff --git a/src/core/hw/aes/ccm.h b/src/core/hw/aes/ccm.h index 605a5f3aa..3c9473a00 100644 --- a/src/core/hw/aes/ccm.h +++ b/src/core/hw/aes/ccm.h @@ -6,6 +6,7 @@ #include #include +#include #include #include "common/common_types.h" @@ -23,7 +24,7 @@ using CCMNonce = std::array; * @param slot_id The slot ID of the key to use for encryption * @returns a vector of u8 containing the encrypted data with MAC at the end */ -std::vector EncryptSignCCM(const std::vector& pdata, const CCMNonce& nonce, +std::vector EncryptSignCCM(std::span pdata, const CCMNonce& nonce, std::size_t slot_id); /** @@ -33,7 +34,7 @@ std::vector EncryptSignCCM(const std::vector& pdata, const CCMNonce& non * @param slot_id The slot ID of the key to use for decryption * @returns a vector of u8 containing the decrypted data; an empty vector if the verification fails */ -std::vector DecryptVerifyCCM(const std::vector& cipher, const CCMNonce& nonce, +std::vector DecryptVerifyCCM(std::span cipher, const CCMNonce& nonce, std::size_t slot_id); } // namespace HW::AES diff --git a/src/core/hw/gpu.cpp b/src/core/hw/gpu.cpp index b2619986f..6525605da 100644 --- a/src/core/hw/gpu.cpp +++ b/src/core/hw/gpu.cpp @@ -116,13 +116,13 @@ static void MemoryFill(const Regs::MemoryFillConfig& config) { u32 value = config.value_32bit; std::size_t len = (end - start) / sizeof(u32); for (std::size_t i = 0; i < len; ++i) - memcpy(&start[i * sizeof(u32)], &value, sizeof(u32)); + std::memcpy(&start[i * sizeof(u32)], &value, sizeof(u32)); } } else { // fill with 16-bit values u16 value_16bit = config.value_16bit.Value(); for (u8* ptr = start; ptr < end; ptr += sizeof(u16)) - memcpy(ptr, &value_16bit, sizeof(u16)); + std::memcpy(ptr, &value_16bit, sizeof(u16)); } } @@ -521,7 +521,7 @@ static void VBlankCallback(std::uintptr_t user_data, s64 cycles_late) { /// Initialize hardware void Init(Memory::MemorySystem& memory) { g_memory = &memory; - memset(&g_regs, 0, sizeof(g_regs)); + std::memset(&g_regs, 0, sizeof(g_regs)); auto& framebuffer_top = g_regs.framebuffer_config[0]; auto& framebuffer_sub = g_regs.framebuffer_config[1]; diff --git a/src/core/hw/lcd.cpp b/src/core/hw/lcd.cpp index b7e86dd42..0eabf9507 100644 --- a/src/core/hw/lcd.cpp +++ b/src/core/hw/lcd.cpp @@ -64,7 +64,7 @@ template void Write(u32 addr, const u8 data); /// Initialize hardware void Init() { - memset(&g_regs, 0, sizeof(g_regs)); + std::memset(&g_regs, 0, sizeof(g_regs)); LOG_DEBUG(HW_LCD, "initialized OK"); } diff --git a/src/core/hw/rsa/rsa.cpp b/src/core/hw/rsa/rsa.cpp index b4179fd69..1a96d5523 100644 --- a/src/core/hw/rsa/rsa.cpp +++ b/src/core/hw/rsa/rsa.cpp @@ -31,7 +31,7 @@ std::vector HexToBytes(const std::string& hex) { constexpr std::size_t SlotSize = 4; std::array rsa_slots; -std::vector RsaSlot::GetSignature(const std::vector& message) const { +std::vector RsaSlot::GetSignature(std::span message) const { CryptoPP::Integer sig = CryptoPP::ModularExponentiation(CryptoPP::Integer(message.data(), message.size()), CryptoPP::Integer(exponent.data(), exponent.size()), @@ -85,7 +85,7 @@ RsaSlot GetSlot(std::size_t slot_id) { return rsa_slots[slot_id]; } -std::vector CreateASN1Message(const std::vector& data) { +std::vector CreateASN1Message(std::span data) { static constexpr std::array asn1_header = { {0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, @@ -110,4 +110,4 @@ std::vector CreateASN1Message(const std::vector& data) { return message; } -} // namespace HW::RSA \ No newline at end of file +} // namespace HW::RSA diff --git a/src/core/hw/rsa/rsa.h b/src/core/hw/rsa/rsa.h index 26dc84cb1..0c94171a9 100644 --- a/src/core/hw/rsa/rsa.h +++ b/src/core/hw/rsa/rsa.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include "common/common_types.h" @@ -14,7 +15,7 @@ public: RsaSlot() = default; RsaSlot(std::vector exponent, std::vector modulus) : init(true), exponent(std::move(exponent)), modulus(std::move(modulus)) {} - std::vector GetSignature(const std::vector& message) const; + std::vector GetSignature(std::span message) const; explicit operator bool() const { // TODO(B3N30): Maybe check if exponent and modulus are vailid @@ -31,6 +32,6 @@ void InitSlots(); RsaSlot GetSlot(std::size_t slot_id); -std::vector CreateASN1Message(const std::vector& data); +std::vector CreateASN1Message(std::span data); -} // namespace HW::RSA \ No newline at end of file +} // namespace HW::RSA diff --git a/src/core/loader/3dsx.cpp b/src/core/loader/3dsx.cpp index 99d920951..1a7bd4494 100644 --- a/src/core/loader/3dsx.cpp +++ b/src/core/loader/3dsx.cpp @@ -149,7 +149,7 @@ static THREEDSX_Error Load3DSXFile(FileUtil::IOFile& file, u32 base_addr, return ERROR_READ; // BSS clear - memset((char*)loadinfo.seg_ptrs[2] + hdr.data_seg_size - hdr.bss_size, 0, hdr.bss_size); + std::memset((char*)loadinfo.seg_ptrs[2] + hdr.data_seg_size - hdr.bss_size, 0, hdr.bss_size); // Relocate the segments for (unsigned int current_segment = 0; current_segment < NUM_SEGMENTS; ++current_segment) { diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp index 0fb3de6e2..788c94134 100644 --- a/src/core/loader/elf.cpp +++ b/src/core/loader/elf.cpp @@ -327,7 +327,7 @@ std::shared_ptr ElfReader::LoadInto(u32 vaddr) { codeset_segment->addr = segment_addr; codeset_segment->size = aligned_size; - memcpy(&program_image[current_image_position], GetSegmentPtr(i), p->p_filesz); + std::memcpy(&program_image[current_image_position], GetSegmentPtr(i), p->p_filesz); current_image_position += aligned_size; } } diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp index 6fcac276a..73b06529c 100644 --- a/src/core/loader/ncch.cpp +++ b/src/core/loader/ncch.cpp @@ -171,7 +171,7 @@ void AppLoader_NCCH::ParseRegionLockoutInfo(u64 program_id) { std::vector smdh_buffer; if (ReadIcon(smdh_buffer) == ResultStatus::Success && smdh_buffer.size() >= sizeof(SMDH)) { SMDH smdh; - memcpy(&smdh, smdh_buffer.data(), sizeof(SMDH)); + std::memcpy(&smdh, smdh_buffer.data(), sizeof(SMDH)); u32 region_lockout = smdh.region_lockout; constexpr u32 REGION_COUNT = 7; std::vector regions; @@ -185,15 +185,20 @@ void AppLoader_NCCH::ParseRegionLockoutInfo(u64 program_id) { } else { const auto region = Core::GetSystemTitleRegion(program_id); if (region.has_value()) { - cfg->SetPreferredRegionCodes({region.value()}); + const std::array regions{region.value()}; + cfg->SetPreferredRegionCodes(regions); } } } -bool AppLoader_NCCH::IsGbaVirtualConsole(const std::vector& code) { - const u32* gbaVcHeader = reinterpret_cast(code.data() + code.size() - 0x10); - return code.size() >= 0x10 && gbaVcHeader[0] == MakeMagic('.', 'C', 'A', 'A') && - gbaVcHeader[1] == 1; +bool AppLoader_NCCH::IsGbaVirtualConsole(std::span code) { + if (code.size() < 0x10) [[unlikely]] { + return false; + } + + u32 gbaVcHeader[2]; + std::memcpy(gbaVcHeader, code.data() + code.size() - 0x10, sizeof(gbaVcHeader)); + return gbaVcHeader[0] == MakeMagic('.', 'C', 'A', 'A') && gbaVcHeader[1] == 1; } ResultStatus AppLoader_NCCH::Load(std::shared_ptr& process) { @@ -317,7 +322,7 @@ ResultStatus AppLoader_NCCH::ReadTitle(std::string& title) { return ResultStatus::ErrorInvalidFormat; } - memcpy(&smdh, data.data(), sizeof(Loader::SMDH)); + std::memcpy(&smdh, data.data(), sizeof(Loader::SMDH)); const auto& short_title = smdh.GetShortTitle(SMDH::TitleLanguage::English); auto title_end = std::find(short_title.begin(), short_title.end(), u'\0'); diff --git a/src/core/loader/ncch.h b/src/core/loader/ncch.h index 93cd22056..fa7fa7e16 100644 --- a/src/core/loader/ncch.h +++ b/src/core/loader/ncch.h @@ -78,7 +78,7 @@ private: void ParseRegionLockoutInfo(u64 program_id); /// Detects whether the NCCH contains GBA Virtual Console. - bool IsGbaVirtualConsole(const std::vector& code); + bool IsGbaVirtualConsole(std::span code); FileSys::NCCHContainer base_ncch; FileSys::NCCHContainer update_ncch; diff --git a/src/core/loader/smdh.cpp b/src/core/loader/smdh.cpp index 4306a1f1b..68eb2f1ee 100644 --- a/src/core/loader/smdh.cpp +++ b/src/core/loader/smdh.cpp @@ -11,12 +11,13 @@ namespace Loader { -bool IsValidSMDH(const std::vector& smdh_data) { - if (smdh_data.size() < sizeof(Loader::SMDH)) +bool IsValidSMDH(std::span smdh_data) { + if (smdh_data.size() < sizeof(Loader::SMDH)) { return false; + } u32 magic; - memcpy(&magic, smdh_data.data(), sizeof(u32)); + std::memcpy(&magic, smdh_data.data(), sizeof(u32)); return Loader::MakeMagic('S', 'M', 'D', 'H') == magic; } diff --git a/src/core/loader/smdh.h b/src/core/loader/smdh.h index ec37c4bba..9f157a68a 100644 --- a/src/core/loader/smdh.h +++ b/src/core/loader/smdh.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include "common/common_funcs.h" #include "common/common_types.h" @@ -17,7 +18,7 @@ namespace Loader { * @param smdh_data data buffer to test * @return bool test result */ -bool IsValidSMDH(const std::vector& smdh_data); +bool IsValidSMDH(std::span smdh_data); /// SMDH data structure that contains titles, icons etc. See https://www.3dbrew.org/wiki/SMDH struct SMDH { diff --git a/src/core/movie.cpp b/src/core/movie.cpp index 83264ea35..0453dbec7 100644 --- a/src/core/movie.cpp +++ b/src/core/movie.cpp @@ -130,7 +130,7 @@ struct CTMHeader { static_assert(sizeof(CTMHeader) == 256, "CTMHeader should be 256 bytes"); #pragma pack(pop) -static u64 GetInputCount(const std::vector& input) { +static u64 GetInputCount(std::span input) { u64 input_count = 0; for (std::size_t pos = 0; pos < input.size(); pos += sizeof(ControllerState)) { if (input.size() < pos + sizeof(ControllerState)) { @@ -476,8 +476,7 @@ Movie::ValidationResult Movie::ValidateHeader(const CTMHeader& header) const { return ValidationResult::OK; } -Movie::ValidationResult Movie::ValidateInput(const std::vector& input, - u64 expected_count) const { +Movie::ValidationResult Movie::ValidateInput(std::span input, u64 expected_count) const { return GetInputCount(input) == expected_count ? ValidationResult::OK : ValidationResult::InputCountDismatch; } diff --git a/src/core/movie.h b/src/core/movie.h index d4b615876..70b999b03 100644 --- a/src/core/movie.h +++ b/src/core/movie.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include "common/common_types.h" @@ -156,7 +157,7 @@ private: void Record(const Service::IR::ExtraHIDResponse& extra_hid_response); ValidationResult ValidateHeader(const CTMHeader& header) const; - ValidationResult ValidateInput(const std::vector& input, u64 expected_count) const; + ValidationResult ValidateInput(std::span input, u64 expected_count) const; PlayMode play_mode; diff --git a/src/core/rpc/packet.h b/src/core/rpc/packet.h index 8a2491d63..6f34f5c0b 100644 --- a/src/core/rpc/packet.h +++ b/src/core/rpc/packet.h @@ -6,6 +6,7 @@ #include #include +#include #include "common/common_types.h" namespace RPC { @@ -67,7 +68,7 @@ public: private: void HandleReadMemory(u32 address, u32 data_size); - void HandleWriteMemory(u32 address, const u8* data, u32 data_size); + void HandleWriteMemory(u32 address, std::span data); struct PacketHeader header; std::array packet_data; diff --git a/src/core/rpc/rpc_server.cpp b/src/core/rpc/rpc_server.cpp index a95c53fd7..04888b51e 100644 --- a/src/core/rpc/rpc_server.cpp +++ b/src/core/rpc/rpc_server.cpp @@ -37,18 +37,19 @@ void RPCServer::HandleReadMemory(Packet& packet, u32 address, u32 data_size) { packet.SendReply(); } -void RPCServer::HandleWriteMemory(Packet& packet, u32 address, const u8* data, u32 data_size) { +void RPCServer::HandleWriteMemory(Packet& packet, u32 address, std::span data) { // Only allow writing to certain memory regions if ((address >= Memory::PROCESS_IMAGE_VADDR && address <= Memory::PROCESS_IMAGE_VADDR_END) || (address >= Memory::HEAP_VADDR && address <= Memory::HEAP_VADDR_END) || (address >= Memory::N3DS_EXTRA_RAM_VADDR && address <= Memory::N3DS_EXTRA_RAM_VADDR_END)) { // Note: Memory write occurs asynchronously from the state of the emulator Core::System::GetInstance().Memory().WriteBlock( - *Core::System::GetInstance().Kernel().GetCurrentProcess(), address, data, data_size); + *Core::System::GetInstance().Kernel().GetCurrentProcess(), address, data.data(), + data.size()); // If the memory happens to be executable code, make sure the changes become visible // Is current core correct here? - Core::System::GetInstance().InvalidateCacheRange(address, data_size); + Core::System::GetInstance().InvalidateCacheRange(address, data.size()); } packet.SetPacketDataSize(0); packet.SendReply(); @@ -72,14 +73,14 @@ bool RPCServer::ValidatePacket(const PacketHeader& packet_header) { void RPCServer::HandleSingleRequest(std::unique_ptr request_packet) { bool success = false; + const auto& packet_data = request_packet->GetPacketData(); if (ValidatePacket(request_packet->GetHeader())) { // Currently, all request types use the address/data_size wire format u32 address = 0; u32 data_size = 0; - std::memcpy(&address, request_packet->GetPacketData().data(), sizeof(address)); - std::memcpy(&data_size, request_packet->GetPacketData().data() + sizeof(address), - sizeof(data_size)); + std::memcpy(&address, packet_data.data(), sizeof(address)); + std::memcpy(&data_size, packet_data.data() + sizeof(address), sizeof(data_size)); switch (request_packet->GetPacketType()) { case PacketType::ReadMemory: @@ -90,8 +91,8 @@ void RPCServer::HandleSingleRequest(std::unique_ptr request_packet) { break; case PacketType::WriteMemory: if (data_size > 0 && data_size <= MAX_PACKET_DATA_SIZE - (sizeof(u32) * 2)) { - const u8* data = request_packet->GetPacketData().data() + (sizeof(u32) * 2); - HandleWriteMemory(*request_packet, address, data, data_size); + const auto data = std::span{packet_data}.subspan(sizeof(u32) * 2, data_size); + HandleWriteMemory(*request_packet, address, data); success = true; } break; diff --git a/src/core/rpc/rpc_server.h b/src/core/rpc/rpc_server.h index 83fe4f60c..2c821f02b 100644 --- a/src/core/rpc/rpc_server.h +++ b/src/core/rpc/rpc_server.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "common/threadsafe_queue.h" #include "core/rpc/server.h" @@ -27,7 +28,7 @@ private: void Start(); void Stop(); void HandleReadMemory(Packet& packet, u32 address, u32 data_size); - void HandleWriteMemory(Packet& packet, u32 address, const u8* data, u32 data_size); + void HandleWriteMemory(Packet& packet, u32 address, std::span data); bool ValidatePacket(const PacketHeader& packet_header); void HandleSingleRequest(std::unique_ptr request); void HandleRequestsLoop(); diff --git a/src/core/savestate.cpp b/src/core/savestate.cpp index e791a27f7..ccaa8d4f1 100644 --- a/src/core/savestate.cpp +++ b/src/core/savestate.cpp @@ -108,8 +108,8 @@ void System::SaveState(u32 slot) const { oa&* this; const std::string& str{sstream.str()}; - auto buffer = Common::Compression::CompressDataZSTDDefault( - reinterpret_cast(str.data()), str.size()); + const auto data = std::span{reinterpret_cast(str.data()), str.size()}; + auto buffer = Common::Compression::CompressDataZSTDDefault(data); const auto path = GetSaveStatePath(title_id, slot); if (!FileUtil::CreateFullPath(path)) { diff --git a/src/core/tracer/recorder.cpp b/src/core/tracer/recorder.cpp index ca24ba149..a47632d5a 100644 --- a/src/core/tracer/recorder.cpp +++ b/src/core/tracer/recorder.cpp @@ -180,7 +180,7 @@ void Recorder::MemoryAccessed(const u8* data, u32 size, u32 physical_address) { element.uses_existing_data = (memory_regions.find(element.hash) != memory_regions.end()); if (!element.uses_existing_data) { element.extra_data.resize(size); - memcpy(element.extra_data.data(), data, size); + std::memcpy(element.extra_data.data(), data, size); memory_regions.insert({element.hash, 0}); // file offset will be initialized in Finish() } diff --git a/src/core/tracer/recorder.h b/src/core/tracer/recorder.h index e1cefd5fe..8b7c7d999 100644 --- a/src/core/tracer/recorder.h +++ b/src/core/tracer/recorder.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include #include diff --git a/src/tests/audio_core/decoder_tests.cpp b/src/tests/audio_core/decoder_tests.cpp index 2409e298c..41817cb7a 100644 --- a/src/tests/audio_core/decoder_tests.cpp +++ b/src/tests/audio_core/decoder_tests.cpp @@ -38,7 +38,7 @@ TEST_CASE("DSP HLE Audio Decoder", "[audio_core]") { request.header.cmd = AudioCore::HLE::DecoderCommand::EncodeDecode; u8* fcram = memory.GetFCRAMPointer(0); - memcpy(fcram, fixure_buffer, fixure_buffer_size); + std::memcpy(fcram, fixure_buffer, fixure_buffer_size); request.decode_aac_request.src_addr = Memory::FCRAM_PADDR; request.decode_aac_request.dst_addr_ch0 = Memory::FCRAM_PADDR + 1024; request.decode_aac_request.dst_addr_ch1 = Memory::FCRAM_PADDR + 1048576; // 1 MB diff --git a/src/tests/audio_core/hle/hle.cpp b/src/tests/audio_core/hle/hle.cpp index e70008917..ebc4cb361 100644 --- a/src/tests/audio_core/hle/hle.cpp +++ b/src/tests/audio_core/hle/hle.cpp @@ -78,7 +78,7 @@ TEST_CASE("DSP LLE vs HLE", "[audio_core][hle]") { std::vector lle_read_buffer; lle_read_buffer = lle.PipeRead(AudioCore::DspPipe::Audio, 2); u16 lle_size; - memcpy(&lle_size, lle_read_buffer.data(), sizeof(lle_size)); + std::memcpy(&lle_size, lle_read_buffer.data(), sizeof(lle_size)); lle_read_buffer = lle.PipeRead(AudioCore::DspPipe::Audio, lle_size * 2); // HLE @@ -89,7 +89,7 @@ TEST_CASE("DSP LLE vs HLE", "[audio_core][hle]") { std::vector hle_read_buffer(32); hle_read_buffer = hle.PipeRead(AudioCore::DspPipe::Audio, 2); u16 hle_size; - memcpy(&hle_size, hle_read_buffer.data(), sizeof(hle_size)); + std::memcpy(&hle_size, hle_read_buffer.data(), sizeof(hle_size)); hle_read_buffer = hle.PipeRead(AudioCore::DspPipe::Audio, hle_size * 2); REQUIRE(hle_size == lle_size); diff --git a/src/tests/audio_core/lle/lle.cpp b/src/tests/audio_core/lle/lle.cpp index 9396bb6e1..a9526b74a 100644 --- a/src/tests/audio_core/lle/lle.cpp +++ b/src/tests/audio_core/lle/lle.cpp @@ -70,7 +70,7 @@ TEST_CASE("DSP LLE Sanity", "[audio_core][lle]") { buffer = lle.PipeRead(AudioCore::DspPipe::Audio, 2); u16 size; - memcpy(&size, buffer.data(), sizeof(size)); + std::memcpy(&size, buffer.data(), sizeof(size)); // see AudioCore::DspHle::Impl::AudioPipeWriteStructAddresses() REQUIRE(size * 2 == 30); } diff --git a/src/tests/common/file_util.cpp b/src/tests/common/file_util.cpp index cecc6b7fa..8a9ea2a86 100644 --- a/src/tests/common/file_util.cpp +++ b/src/tests/common/file_util.cpp @@ -21,6 +21,6 @@ TEST_CASE("SplitFilename83 Sanity", "[common]") { std::string expected_short_name = filename.substr(0, 6).append("~1"); std::string expected_extension = filename.substr(filename.find('.') + 1, 3); - REQUIRE(memcmp(short_name.data(), expected_short_name.data(), short_name.size()) == 0); - REQUIRE(memcmp(extension.data(), expected_extension.data(), extension.size()) == 0); + REQUIRE(std::memcmp(short_name.data(), expected_short_name.data(), short_name.size()) == 0); + REQUIRE(std::memcmp(extension.data(), expected_extension.data(), extension.size()) == 0); } diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp index 24ec152f2..8284afc30 100644 --- a/src/video_core/debug_utils/debug_utils.cpp +++ b/src/video_core/debug_utils/debug_utils.cpp @@ -226,7 +226,7 @@ void DumpShader(const std::string& filename, const ShaderRegs& config, std::vector constant_table; for (unsigned i = 0; i < setup.uniforms.b.size(); ++i) { nihstro::ConstantInfo constant; - memset(&constant, 0, sizeof(constant)); + std::memset(&constant, 0, sizeof(constant)); constant.type = nihstro::ConstantInfo::Bool; constant.regid = i; constant.b = setup.uniforms.b[i]; @@ -234,7 +234,7 @@ void DumpShader(const std::string& filename, const ShaderRegs& config, } for (unsigned i = 0; i < setup.uniforms.i.size(); ++i) { nihstro::ConstantInfo constant; - memset(&constant, 0, sizeof(constant)); + std::memset(&constant, 0, sizeof(constant)); constant.type = nihstro::ConstantInfo::Int; constant.regid = i; constant.i.x = setup.uniforms.i[i].x; @@ -245,7 +245,7 @@ void DumpShader(const std::string& filename, const ShaderRegs& config, } for (unsigned i = 0; i < sizeof(setup.uniforms.f) / sizeof(setup.uniforms.f[0]); ++i) { nihstro::ConstantInfo constant; - memset(&constant, 0, sizeof(constant)); + std::memset(&constant, 0, sizeof(constant)); constant.type = nihstro::ConstantInfo::Float; constant.regid = i; constant.f.x = nihstro::to_float24(setup.uniforms.f[i].x.ToFloat32()); diff --git a/src/video_core/gpu_debugger.h b/src/video_core/gpu_debugger.h index 30b9236ff..33abab3d0 100644 --- a/src/video_core/gpu_debugger.h +++ b/src/video_core/gpu_debugger.h @@ -51,7 +51,7 @@ public: gx_command_history.emplace_back(); Service::GSP::Command& cmd = gx_command_history.back(); - memcpy(&cmd, command_data, sizeof(Service::GSP::Command)); + std::memcpy(&cmd, command_data, sizeof(Service::GSP::Command)); ForEachObserver([this](DebuggerObserver* observer) { observer->GXCommandProcessed(static_cast(this->gx_command_history.size())); diff --git a/src/video_core/pica.cpp b/src/video_core/pica.cpp index f0263136d..2f7ae0d6f 100644 --- a/src/video_core/pica.cpp +++ b/src/video_core/pica.cpp @@ -33,7 +33,7 @@ void Shutdown() { template void Zero(T& o) { static_assert(std::is_trivial_v, "It's undefined behavior to memset a non-trivial type"); - memset(&o, 0, sizeof(o)); + std::memset(&o, 0, sizeof(o)); } State::State() : geometry_pipeline(*this) { diff --git a/src/video_core/renderer_opengl/gl_resource_manager.cpp b/src/video_core/renderer_opengl/gl_resource_manager.cpp index 9a1e4a6dd..87a53ccdf 100644 --- a/src/video_core/renderer_opengl/gl_resource_manager.cpp +++ b/src/video_core/renderer_opengl/gl_resource_manager.cpp @@ -122,7 +122,7 @@ void OGLShader::Release() { handle = 0; } -void OGLProgram::Create(bool separable_program, const std::vector& shaders) { +void OGLProgram::Create(bool separable_program, std::span shaders) { if (handle != 0) return; @@ -136,7 +136,8 @@ void OGLProgram::Create(std::string_view vert_shader, std::string_view frag_shad frag.Create(frag_shader, GL_FRAGMENT_SHADER); MICROPROFILE_SCOPE(OpenGL_ResourceCreation); - Create(false, {vert.handle, frag.handle}); + const std::array shaders{vert.handle, frag.handle}; + Create(false, shaders); } void OGLProgram::Release() { diff --git a/src/video_core/renderer_opengl/gl_resource_manager.h b/src/video_core/renderer_opengl/gl_resource_manager.h index aa859549a..2d168a85a 100644 --- a/src/video_core/renderer_opengl/gl_resource_manager.h +++ b/src/video_core/renderer_opengl/gl_resource_manager.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include #include @@ -129,7 +130,7 @@ public: } /// Creates a new program from given shader objects - void Create(bool separable_program, const std::vector& shaders); + void Create(bool separable_program, std::span shaders); /// Creates a new program from given shader soruce code void Create(std::string_view vert_shader, std::string_view frag_shader); diff --git a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp index d62164131..8099ab016 100644 --- a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp @@ -507,8 +507,8 @@ void ShaderDiskCache::SavePrecompiledHeaderToVirtualPrecompiledCache() { void ShaderDiskCache::SaveVirtualPrecompiledFile() { decompressed_precompiled_cache_offset = 0; - const std::vector& compressed = Common::Compression::CompressDataZSTDDefault( - decompressed_precompiled_cache.data(), decompressed_precompiled_cache.size()); + const auto compressed = + Common::Compression::CompressDataZSTDDefault(decompressed_precompiled_cache); const auto precompiled_path{GetPrecompiledPath()}; diff --git a/src/video_core/renderer_opengl/gl_shader_manager.cpp b/src/video_core/renderer_opengl/gl_shader_manager.cpp index 9246c8660..0b0f38b24 100644 --- a/src/video_core/renderer_opengl/gl_shader_manager.cpp +++ b/src/video_core/renderer_opengl/gl_shader_manager.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -174,7 +175,7 @@ public: OGLShader shader; shader.Create(source, type); OGLProgram& program = std::get(shader_or_program); - program.Create(true, {shader.handle}); + program.Create(true, std::array{shader.handle}); SetShaderUniformBlockBindings(program.handle); if (type == GL_FRAGMENT_SHADER) { @@ -449,7 +450,8 @@ void ShaderProgramManager::ApplyTo(OpenGLState& state) { const u64 unique_identifier = impl->current.GetConfigHash(); OGLProgram& cached_program = impl->program_cache[unique_identifier]; if (cached_program.handle == 0) { - cached_program.Create(false, {impl->current.vs, impl->current.gs, impl->current.fs}); + cached_program.Create(false, + std::array{impl->current.vs, impl->current.gs, impl->current.fs}); auto& disk_cache = impl->disk_cache; disk_cache.SaveDumpToFile(unique_identifier, cached_program.handle, VideoCore::g_hw_shader_accurate_mul); @@ -492,7 +494,7 @@ void ShaderProgramManager::LoadDiskCache(const std::atomic_bool& stop_loading, std::vector load_raws_index; // Loads both decompiled and precompiled shaders from the cache. If either one is missing for const auto LoadPrecompiledShader = [&](std::size_t begin, std::size_t end, - const std::vector& raw_cache, + std::span raw_cache, const ShaderDecompiledMap& decompiled_map, const ShaderDumpsMap& dump_map) { for (std::size_t i = begin; i < end; ++i) { diff --git a/src/video_core/renderer_opengl/gl_shader_util.cpp b/src/video_core/renderer_opengl/gl_shader_util.cpp index 2e488262c..294c0b67e 100644 --- a/src/video_core/renderer_opengl/gl_shader_util.cpp +++ b/src/video_core/renderer_opengl/gl_shader_util.cpp @@ -70,7 +70,7 @@ GLuint LoadShader(std::string_view source, GLenum type) { return shader_id; } -GLuint LoadProgram(bool separable_program, const std::vector& shaders) { +GLuint LoadProgram(bool separable_program, std::span shaders) { // Link the program LOG_DEBUG(Render_OpenGL, "Linking program..."); diff --git a/src/video_core/renderer_opengl/gl_shader_util.h b/src/video_core/renderer_opengl/gl_shader_util.h index f4e38faf3..78c6fb71e 100644 --- a/src/video_core/renderer_opengl/gl_shader_util.h +++ b/src/video_core/renderer_opengl/gl_shader_util.h @@ -4,7 +4,7 @@ #pragma once -#include +#include #include namespace OpenGL { @@ -37,6 +37,6 @@ GLuint LoadShader(std::string_view source, GLenum type); * @param shaders ID of shaders to attach to the program * @returns Handle of the newly created OpenGL program object */ -GLuint LoadProgram(bool separable_program, const std::vector& shaders); +GLuint LoadProgram(bool separable_program, std::span shaders); } // namespace OpenGL diff --git a/src/video_core/renderer_vulkan/vk_instance.h b/src/video_core/renderer_vulkan/vk_instance.h index d7aa2b26e..b75bb1d3e 100644 --- a/src/video_core/renderer_vulkan/vk_instance.h +++ b/src/video_core/renderer_vulkan/vk_instance.h @@ -181,7 +181,7 @@ public: } /// Returns the list of available extensions. - const std::vector& GetAvailableExtensions() const { + std::span GetAvailableExtensions() const { return available_extensions; } diff --git a/src/video_core/texture/texture_decode.cpp b/src/video_core/texture/texture_decode.cpp index e36b789ca..90ce45726 100644 --- a/src/video_core/texture/texture_decode.cpp +++ b/src/video_core/texture/texture_decode.cpp @@ -191,7 +191,7 @@ Common::Vec4 LookupTexelInTile(const u8* source, unsigned int x, unsigned in u8 alpha = 255; if (has_alpha) { u64_le packed_alpha; - memcpy(&packed_alpha, subtile_ptr, sizeof(u64)); + std::memcpy(&packed_alpha, subtile_ptr, sizeof(u64)); subtile_ptr += sizeof(u64); alpha = @@ -199,7 +199,7 @@ Common::Vec4 LookupTexelInTile(const u8* source, unsigned int x, unsigned in } u64_le subtile_data; - memcpy(&subtile_data, subtile_ptr, sizeof(u64)); + std::memcpy(&subtile_data, subtile_ptr, sizeof(u64)); return Common::MakeVec(SampleETC1Subtile(subtile_data, x, y), disable_alpha ? (u8)255 : alpha);