mirror of
https://github.com/PabloMK7/citra.git
synced 2025-09-11 05:10:05 +00:00
code: Use std::span where appropriate (#6658)
* code: Use std::span when possible * code: Prefix memcpy and memcmp with std::
This commit is contained in:
parent
4ccd9f24fb
commit
cf9bb90ae3
106 changed files with 362 additions and 329 deletions
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<Kernel::SharedMemory, Kernel::Object>(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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <atomic>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
@ -230,7 +231,7 @@ public:
|
|||
/// Retrieves a process from the current list of processes.
|
||||
std::shared_ptr<Process> GetProcessById(u32 process_id) const;
|
||||
|
||||
const std::vector<std::shared_ptr<Process>>& GetProcessList() const {
|
||||
std::span<const std::shared_ptr<Process>> GetProcessList() const {
|
||||
return process_list;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<std::size_t, std::size_t, bool> GetFreeThreadLocalSlot(
|
||||
const std::vector<std::bitset<8>>& tls_slots) {
|
||||
std::span<const std::bitset<8>> 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<std::shared_ptr<Thread>>& ThreadManager::GetThreadList() {
|
||||
std::span<const std::shared_ptr<Thread>> ThreadManager::GetThreadList() {
|
||||
return thread_list;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
@ -113,7 +114,7 @@ public:
|
|||
/**
|
||||
* Get a const reference to the thread list for debug use
|
||||
*/
|
||||
const std::vector<std::shared_ptr<Thread>>& GetThreadList();
|
||||
std::span<const std::shared_ptr<Thread>> GetThreadList();
|
||||
|
||||
void SetCPU(ARM_Interface& cpu_) {
|
||||
cpu = &cpu_;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <core/hle/lock.h>
|
||||
#include "core/hle/lock.h"
|
||||
|
||||
namespace HLE {
|
||||
std::recursive_mutex g_hle_lock;
|
||||
|
|
|
@ -223,7 +223,7 @@ ResultVal<std::size_t> CIAFile::Write(u64 offset, std::size_t length, bool flush
|
|||
std::size_t buf_max_size =
|
||||
std::min(static_cast<std::size_t>(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<std::size_t> 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<u64>& title_id_list,
|
||||
ResultCode GetTitleInfoFromList(std::span<const u64> title_id_list,
|
||||
Service::FS::MediaType media_type,
|
||||
Kernel::MappedBuffer& title_info_out) {
|
||||
std::size_t write_offset = 0;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -12,7 +12,7 @@ void RelocateSharedFont(std::shared_ptr<Kernel::SharedMemory> 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<Kernel::SharedMemory> 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<Kernel::SharedMemory> 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;
|
||||
|
|
|
@ -834,7 +834,7 @@ void Module::Interface::OpenAndRead(Kernel::HLERequestContext& ctx) {
|
|||
open_mode.check);
|
||||
}
|
||||
|
||||
std::string Module::EncodeBase64(const std::vector<u8>& in) const {
|
||||
std::string Module::EncodeBase64(std::span<const u8> in) const {
|
||||
using namespace CryptoPP;
|
||||
using Name::EncodingLookupArray;
|
||||
using Name::InsertLineBreaks;
|
||||
|
@ -855,7 +855,7 @@ std::string Module::EncodeBase64(const std::vector<u8>& in) const {
|
|||
}
|
||||
|
||||
std::string Module::GetCecDataPathTypeAsString(const CecDataPathType type, const u32 program_id,
|
||||
const std::vector<u8>& msg_id) const {
|
||||
std::span<const u8> msg_id) const {
|
||||
switch (type) {
|
||||
case CecDataPathType::MboxList:
|
||||
return "/CEC/MBoxList____";
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <span>
|
||||
#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<u8>& in) const;
|
||||
std::string EncodeBase64(std::span<const u8> in) const;
|
||||
|
||||
std::string GetCecDataPathTypeAsString(const CecDataPathType type, const u32 program_id,
|
||||
const std::vector<u8>& msg_id = std::vector<u8>()) const;
|
||||
std::string GetCecDataPathTypeAsString(
|
||||
const CecDataPathType type, const u32 program_id,
|
||||
std::span<const u8> msg_id = std::span<const u8>{}) const;
|
||||
|
||||
std::string GetCecCommandAsString(const CecCommand command) const;
|
||||
|
||||
|
|
|
@ -285,8 +285,8 @@ void Module::Interface::GenHashConsoleUnique(Kernel::HLERequestContext& ctx) {
|
|||
std::array<u8, CryptoPP::SHA256::DIGESTSIZE> 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<void*> 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<u32 /*region*/, SystemLanguage> AdjustLanguageInfoBlock(
|
||||
const std::vector<u32>& region_code, SystemLanguage language) {
|
||||
std::span<const u32> region_code, SystemLanguage language) {
|
||||
static const std::array<std::vector<SystemLanguage>, 7> region_languages{{
|
||||
// JPN
|
||||
{LANGUAGE_JP},
|
||||
|
@ -750,13 +750,14 @@ static std::tuple<u32 /*region*/, SystemLanguage> 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<u32>& region_codes) {
|
||||
void Module::SetPreferredRegionCodes(std::span<const u32> 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);
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#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<u32>& region_codes);
|
||||
void SetPreferredRegionCodes(std::span<const u32> region_codes);
|
||||
|
||||
// Utilities for frontend to set config data.
|
||||
// Note: UpdateConfigNANDSavegame should be called after making changes to config data.
|
||||
|
|
|
@ -230,7 +230,7 @@ ResultVal<FileSys::ArchiveFormatInfo> ArchiveManager::GetArchiveFormatInfo(
|
|||
}
|
||||
|
||||
ResultCode ArchiveManager::CreateExtSaveData(MediaType media_type, u32 high, u32 low,
|
||||
const std::vector<u8>& smdh_icon,
|
||||
std::span<const u8> 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<FileSys::ArchiveFactory_ExtSaveData*>(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;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <boost/serialization/unique_ptr.hpp>
|
||||
#include <boost/serialization/unordered_map.hpp>
|
||||
#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<u8>& smdh_icon,
|
||||
std::span<const u8> smdh_icon,
|
||||
const FileSys::ArchiveFormatInfo& format_info, u64 program_id);
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <span>
|
||||
#include <vector>
|
||||
#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<u8>& data) {
|
||||
static ResultCode WriteHWRegs(u32 base_address, u32 size_in_bytes, std::span<const u8> 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<u8>& data, const std::vector<u8>& masks) {
|
||||
static ResultCode WriteHWRegsWithMask(u32 base_address, u32 size_in_bytes, std::span<const u8> data,
|
||||
std::span<const u8> masks) {
|
||||
// This magic number is verified to be done by the gsp module
|
||||
const u32 max_size_in_bytes = 0x80;
|
||||
|
||||
|
|
|
@ -164,7 +164,7 @@ void ExtraHID::OnDisconnect() {
|
|||
timing.UnscheduleEvent(hid_polling_callback_id, 0);
|
||||
}
|
||||
|
||||
void ExtraHID::HandleConfigureHIDPollingRequest(const std::vector<u8>& request) {
|
||||
void ExtraHID::HandleConfigureHIDPollingRequest(std::span<const u8> 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<u8>& request)
|
|||
timing.ScheduleEvent(msToCycles(hid_period), hid_polling_callback_id);
|
||||
}
|
||||
|
||||
void ExtraHID::HandleReadCalibrationDataRequest(const std::vector<u8>& request_buf) {
|
||||
void ExtraHID::HandleReadCalibrationDataRequest(std::span<const u8> request_buf) {
|
||||
struct ReadCalibrationDataRequest {
|
||||
RequestID request_id;
|
||||
u8 expected_response_time;
|
||||
|
@ -213,7 +213,7 @@ void ExtraHID::HandleReadCalibrationDataRequest(const std::vector<u8>& request_b
|
|||
Send(response);
|
||||
}
|
||||
|
||||
void ExtraHID::OnReceive(const std::vector<u8>& data) {
|
||||
void ExtraHID::OnReceive(std::span<const u8> data) {
|
||||
switch (static_cast<RequestID>(data[0])) {
|
||||
case RequestID::ConfigureHIDPolling:
|
||||
HandleConfigureHIDPollingRequest(data);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <span>
|
||||
#include <boost/serialization/array.hpp>
|
||||
#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<u8>& data) override;
|
||||
void OnReceive(std::span<const u8> 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<u8>& request);
|
||||
void HandleReadCalibrationDataRequest(const std::vector<u8>& request);
|
||||
void HandleConfigureHIDPollingRequest(std::span<const u8> request);
|
||||
void HandleReadCalibrationDataRequest(std::span<const u8> request);
|
||||
void LoadInputDevices();
|
||||
|
||||
Core::Timing& timing;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// Refer to the license.txt file included.
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <boost/crc.hpp>
|
||||
#include <boost/serialization/base_object.hpp>
|
||||
#include <boost/serialization/shared_ptr.hpp>
|
||||
|
@ -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<u8>& packet) {
|
||||
if (info.packet_count == max_packet_count)
|
||||
bool Put(std::span<const u8> 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<u8>& payload) {
|
||||
void IR_USER::PutToReceive(std::span<const u8> 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<ExtraHID>(
|
||||
[this](const std::vector<u8>& data) { PutToReceive(data); }, system.CoreTiming());
|
||||
extra_hid = std::make_unique<ExtraHID>([this](std::span<const u8> 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<u8>& data) {
|
||||
void IRDevice::Send(std::span<const u8> data) {
|
||||
send_func(data);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <span>
|
||||
#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<void(const std::vector<u8>& data)>;
|
||||
using SendFunc = std::function<void(std::span<const u8> 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<u8>& data) = 0;
|
||||
virtual void OnReceive(std::span<const u8> data) = 0;
|
||||
|
||||
protected:
|
||||
/// Sends data to the 3DS. The actual sending method is specified in the constructor
|
||||
void Send(const std::vector<u8>& data);
|
||||
void Send(std::span<const u8> 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<u8>& payload);
|
||||
void PutToReceive(std::span<const u8> payload);
|
||||
|
||||
std::shared_ptr<Kernel::Event> conn_status_event, send_event, receive_event;
|
||||
std::shared_ptr<Kernel::SharedMemory> shared_memory;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <span>
|
||||
#include <boost/serialization/weak_ptr.hpp>
|
||||
#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<u8>& samples) {
|
||||
void WriteSamples(std::span<const u8> 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);
|
||||
|
|
|
@ -843,14 +843,14 @@ void NWM_UDS::Unbind(Kernel::HLERequestContext& ctx) {
|
|||
rb.Push<u32>(0);
|
||||
}
|
||||
|
||||
ResultCode NWM_UDS::BeginHostingNetwork(const u8* network_info_buffer,
|
||||
std::size_t network_info_size, std::vector<u8> passphrase) {
|
||||
ResultCode NWM_UDS::BeginHostingNetwork(std::span<const u8> network_info_buffer,
|
||||
std::vector<u8> 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<u8> passphrase) {
|
||||
std::span<const u8> network_info_buffer, u8 connection_type,
|
||||
std::vector<u8> 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<u8> 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<u8> 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");
|
||||
}
|
||||
|
|
|
@ -452,12 +452,12 @@ private:
|
|||
u32 sharedmem_size, const NodeInfo& node, u16 version,
|
||||
std::shared_ptr<Kernel::SharedMemory> sharedmem);
|
||||
|
||||
ResultCode BeginHostingNetwork(const u8* network_info_buffer, std::size_t network_info_size,
|
||||
ResultCode BeginHostingNetwork(std::span<const u8> network_info_buffer,
|
||||
std::vector<u8> 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<u8> passphrase);
|
||||
std::span<const u8> network_info_buffer, u8 connection_type,
|
||||
std::vector<u8> passphrase);
|
||||
|
||||
void BeaconBroadcastCallback(std::uintptr_t user_data, s64 cycles_late);
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ std::vector<u8> GenerateAuthenticationFrame(AuthenticationSeq seq) {
|
|||
return data;
|
||||
}
|
||||
|
||||
AuthenticationSeq GetAuthenticationSeqNumber(const std::vector<u8>& body) {
|
||||
AuthenticationSeq GetAuthenticationSeqNumber(std::span<const u8> body) {
|
||||
AuthenticationFrame frame;
|
||||
std::memcpy(&frame, body.data(), sizeof(frame));
|
||||
|
||||
|
@ -74,9 +74,9 @@ std::vector<u8> GenerateAssocResponseFrame(AssocStatus status, u16 association_i
|
|||
return data;
|
||||
}
|
||||
|
||||
std::tuple<AssocStatus, u16> GetAssociationResult(const std::vector<u8>& body) {
|
||||
std::tuple<AssocStatus, u16> GetAssociationResult(std::span<const u8> 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);
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <span>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
#include "common/common_types.h"
|
||||
|
@ -41,7 +42,7 @@ static_assert(sizeof(AssociationResponseFrame) == 6, "AssociationResponseFrame h
|
|||
std::vector<u8> GenerateAuthenticationFrame(AuthenticationSeq seq);
|
||||
|
||||
/// Returns the sequence number from the body of an Authentication frame.
|
||||
AuthenticationSeq GetAuthenticationSeqNumber(const std::vector<u8>& body);
|
||||
AuthenticationSeq GetAuthenticationSeqNumber(std::span<const u8> 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<u8> GenerateAssocResponseFrame(AssocStatus status, u16 association_i
|
|||
|
||||
/// Returns a tuple of (association status, association id) from the body of an AssociationResponse
|
||||
/// frame.
|
||||
std::tuple<AssocStatus, u16> GetAssociationResult(const std::vector<u8>& body);
|
||||
std::tuple<AssocStatus, u16> GetAssociationResult(std::span<const u8> body);
|
||||
|
||||
} // namespace Service::NWM
|
||||
|
|
|
@ -28,7 +28,7 @@ static std::vector<u8> GenerateLLCHeader(EtherType protocol) {
|
|||
header.protocol = protocol;
|
||||
|
||||
std::vector<u8> 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<u8> GenerateSecureDataHeader(u16 data_size, u8 channel, u16 d
|
|||
header.src_node_id = src_node_id;
|
||||
|
||||
std::vector<u8> 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<u8, CryptoPP::Weak::MD5::DIGESTSIZE> GetDataCryptoCTR(
|
|||
* @returns The key used for data frames crypto.
|
||||
*/
|
||||
[[maybe_unused]] static std::array<u8, CryptoPP::AES::BLOCKSIZE> GenerateDataCCMPKey(
|
||||
const std::vector<u8>& passphrase, const NetworkInfo& network_info) {
|
||||
std::span<const u8> passphrase, const NetworkInfo& network_info) {
|
||||
// Calculate the MD5 hash of the input passphrase.
|
||||
std::array<u8, CryptoPP::Weak::MD5::DIGESTSIZE> passphrase_hash;
|
||||
CryptoPP::Weak::MD5().CalculateDigest(passphrase_hash.data(), passphrase.data(),
|
||||
|
@ -158,9 +158,9 @@ static std::vector<u8> GenerateCCMPAAD(const MacAddress& sender, const MacAddres
|
|||
* @returns The decrypted payload.
|
||||
*/
|
||||
[[maybe_unused]] static std::vector<u8> DecryptDataFrame(
|
||||
const std::vector<u8>& encrypted_payload,
|
||||
const std::array<u8, CryptoPP::AES::BLOCKSIZE>& ccmp_key, const MacAddress& sender,
|
||||
const MacAddress& receiver, const MacAddress& bssid, u16 sequence_number, u16 frame_control) {
|
||||
std::span<const u8> encrypted_payload, const std::array<u8, CryptoPP::AES::BLOCKSIZE>& 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<u8> GenerateCCMPAAD(const MacAddress& sender, const MacAddres
|
|||
* @returns The encrypted payload.
|
||||
*/
|
||||
[[maybe_unused]] static std::vector<u8> EncryptDataFrame(
|
||||
const std::vector<u8>& payload, const std::array<u8, CryptoPP::AES::BLOCKSIZE>& ccmp_key,
|
||||
std::span<const u8> payload, const std::array<u8, CryptoPP::AES::BLOCKSIZE>& 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<u8> GenerateCCMPAAD(const MacAddress& sender, const MacAddres
|
|||
return {};
|
||||
}
|
||||
|
||||
std::vector<u8> GenerateDataPayload(const std::vector<u8>& data, u8 channel, u16 dest_node,
|
||||
std::vector<u8> GenerateDataPayload(std::span<const u8> data, u8 channel, u16 dest_node,
|
||||
u16 src_node, u16 sequence_number) {
|
||||
std::vector<u8> buffer = GenerateLLCHeader(EtherType::SecureData);
|
||||
std::vector<u8> securedata_header = GenerateSecureDataHeader(
|
||||
|
@ -277,7 +277,7 @@ std::vector<u8> GenerateDataPayload(const std::vector<u8>& data, u8 channel, u16
|
|||
return buffer;
|
||||
}
|
||||
|
||||
SecureDataHeader ParseSecureDataHeader(const std::vector<u8>& data) {
|
||||
SecureDataHeader ParseSecureDataHeader(std::span<const u8> data) {
|
||||
SecureDataHeader header;
|
||||
|
||||
// Skip the LLC header
|
||||
|
@ -308,20 +308,20 @@ std::vector<u8> GenerateEAPoLStartFrame(u16 association_id, const NodeInfo& node
|
|||
return buffer;
|
||||
}
|
||||
|
||||
EtherType GetFrameEtherType(const std::vector<u8>& frame) {
|
||||
EtherType GetFrameEtherType(std::span<const u8> frame) {
|
||||
LLCHeader header;
|
||||
std::memcpy(&header, frame.data(), sizeof(header));
|
||||
return header.protocol;
|
||||
}
|
||||
|
||||
u16 GetEAPoLFrameType(const std::vector<u8>& frame) {
|
||||
u16 GetEAPoLFrameType(std::span<const u8> 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<u8>& frame) {
|
||||
NodeInfo DeserializeNodeInfoFromFrame(std::span<const u8> frame) {
|
||||
EAPoLStartPacket eapol_start;
|
||||
|
||||
// Skip the LLC header
|
||||
|
@ -372,7 +372,7 @@ std::vector<u8> GenerateEAPoLLogoffFrame(const MacAddress& mac_address, u16 netw
|
|||
return buffer;
|
||||
}
|
||||
|
||||
EAPoLLogoffPacket ParseEAPoLLogoffFrame(const std::vector<u8>& frame) {
|
||||
EAPoLLogoffPacket ParseEAPoLLogoffFrame(std::span<const u8> frame) {
|
||||
EAPoLLogoffPacket eapol_logoff;
|
||||
|
||||
// Skip the LLC header
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
#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<u8> GenerateDataPayload(const std::vector<u8>& data, u8 channel, u16 dest_node,
|
||||
std::vector<u8> GenerateDataPayload(std::span<const u8> 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<u8>& data);
|
||||
SecureDataHeader ParseSecureDataHeader(std::span<const u8> data);
|
||||
|
||||
/*
|
||||
* Generates an unencrypted 802.11 data frame body with the EAPoL-Start format for UDS
|
||||
|
@ -136,19 +137,19 @@ std::vector<u8> GenerateEAPoLStartFrame(u16 association_id, const NodeInfo& node
|
|||
/*
|
||||
* Returns the EtherType of the specified 802.11 frame.
|
||||
*/
|
||||
EtherType GetFrameEtherType(const std::vector<u8>& frame);
|
||||
EtherType GetFrameEtherType(std::span<const u8> 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<u8>& frame);
|
||||
u16 GetEAPoLFrameType(std::span<const u8> 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<u8>& frame);
|
||||
NodeInfo DeserializeNodeInfoFromFrame(std::span<const u8> frame);
|
||||
|
||||
/*
|
||||
* Returns a NodeInfo constructed from the data in the specified EAPoLNodeInfo.
|
||||
|
@ -166,6 +167,6 @@ std::vector<u8> GenerateEAPoLLogoffFrame(const MacAddress& mac_address, u16 netw
|
|||
/*
|
||||
* Returns a EAPoLLogoffPacket representing the specified 802.11-encapsulated data frame.
|
||||
*/
|
||||
EAPoLLogoffPacket ParseEAPoLLogoffFrame(const std::vector<u8>& frame);
|
||||
EAPoLLogoffPacket ParseEAPoLLogoffFrame(std::span<const u8> frame);
|
||||
|
||||
} // namespace Service::NWM
|
||||
|
|
|
@ -312,7 +312,7 @@ static void TranslateSockOptDataToPlatform(std::vector<u8>& out, const std::vect
|
|||
linger_out.l_linger = static_cast<decltype(linger_out.l_linger)>(
|
||||
reinterpret_cast<const CTRLinger*>(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<u8>& 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<u8>& out, const std::ve
|
|||
reinterpret_cast<const linger*>(in.data())->l_onoff);
|
||||
linger_out.l_linger = static_cast<decltype(linger_out.l_linger)>(
|
||||
reinterpret_cast<const linger*>(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<sockaddr_in*>(&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<u8, 6> 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::InterfaceInfo> 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 =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue