diff options
Diffstat (limited to 'src')
26 files changed, 76 insertions, 82 deletions
diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h index 995938d0b..042c2c2aa 100644 --- a/src/common/common_funcs.h +++ b/src/common/common_funcs.h @@ -4,6 +4,8 @@ #pragma once +#include <string> + #if !defined(ARCHITECTURE_x86_64) && !defined(ARCHITECTURE_ARM) #include <cstdlib> // for exit #endif @@ -90,7 +92,7 @@ __declspec(dllimport) void __stdcall DebugBreak(void); // Call directly after the command or use the error num. // This function might change the error code. // Defined in Misc.cpp. -const char* GetLastErrorMsg(); +std::string GetLastErrorMsg(); namespace Common { diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index bf955386c..c882ab39f 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -592,7 +592,7 @@ std::string GetBundleDirectory() { #endif #ifdef _WIN32 -std::string& GetExeDirectory() { +const std::string& GetExeDirectory() { static std::string exe_path; if (exe_path.empty()) { wchar_t wchar_exe_path[2048]; diff --git a/src/common/file_util.h b/src/common/file_util.h index 026c84d94..1f38b1560 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -133,7 +133,7 @@ std::string GetBundleDirectory(); #endif #ifdef _WIN32 -std::string& GetExeDirectory(); +const std::string& GetExeDirectory(); std::string AppDataRoamingDirectory(); #endif diff --git a/src/common/logging/log.h b/src/common/logging/log.h index e96c90e16..e7115933f 100644 --- a/src/common/logging/log.h +++ b/src/common/logging/log.h @@ -103,7 +103,7 @@ template <typename... Args> void FmtLogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_num, const char* function, const char* format, const Args&... args) { FmtLogMessageImpl(log_class, log_level, filename, line_num, function, format, - fmt::make_args(args...)); + fmt::make_format_args(args...)); } } // namespace Log diff --git a/src/common/misc.cpp b/src/common/misc.cpp index 7be2235b0..217a87098 100644 --- a/src/common/misc.cpp +++ b/src/common/misc.cpp @@ -4,34 +4,28 @@ #include <cstddef> #ifdef _WIN32 -#include <windows.h> +#include <Windows.h> #else #include <cerrno> #include <cstring> #endif -// Neither Android nor OS X support TLS -#if defined(__APPLE__) || (ANDROID && __clang__) -#define __thread -#endif +#include "common/common_funcs.h" // Generic function to get last error message. // Call directly after the command or use the error num. // This function might change the error code. -const char* GetLastErrorMsg() { +std::string GetLastErrorMsg() { static const size_t buff_size = 255; + char err_str[buff_size]; #ifdef _WIN32 - static __declspec(thread) char err_str[buff_size] = {}; - FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), err_str, buff_size, nullptr); #else - static __thread char err_str[buff_size] = {}; - // Thread safe (XSI-compliant) strerror_r(errno, err_str, buff_size); #endif - return err_str; + return std::string(err_str, buff_size); } diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index 0027888c7..f3ad3d68a 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp @@ -34,18 +34,6 @@ std::string ToUpper(std::string str) { return str; } -// faster than sscanf -bool AsciiToHex(const char* _szValue, u32& result) { - char* endptr = nullptr; - const u32 value = strtoul(_szValue, &endptr, 16); - - if (!endptr || *endptr) - return false; - - result = value; - return true; -} - // For Debugging. Read out an u8 array. std::string ArrayToString(const u8* data, size_t size, int line_len, bool spaces) { std::ostringstream oss; diff --git a/src/common/string_util.h b/src/common/string_util.h index 1f5a383cb..daa071f83 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h @@ -57,9 +57,6 @@ static bool TryParse(const std::string& str, N* const output) { return false; } -// TODO: kill this -bool AsciiToHex(const char* _szValue, u32& result); - std::string TabsToSpaces(int tab_size, const std::string& in); void SplitString(const std::string& str, char delim, std::vector<std::string>& output); diff --git a/src/core/file_sys/content_archive.cpp b/src/core/file_sys/content_archive.cpp index 6cfef774d..d6b20c047 100644 --- a/src/core/file_sys/content_archive.cpp +++ b/src/core/file_sys/content_archive.cpp @@ -2,6 +2,9 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include <algorithm> +#include <utility> + #include "common/logging/log.h" #include "core/file_sys/content_archive.h" #include "core/file_sys/vfs_offset.h" @@ -61,7 +64,7 @@ struct RomFSSuperblock { }; static_assert(sizeof(RomFSSuperblock) == 0xE8, "RomFSSuperblock has incorrect size."); -NCA::NCA(VirtualFile file_) : file(file_) { +NCA::NCA(VirtualFile file_) : file(std::move(file_)) { if (sizeof(NCAHeader) != file->ReadObject(&header)) LOG_CRITICAL(Loader, "File reader errored out during header read."); diff --git a/src/core/file_sys/content_archive.h b/src/core/file_sys/content_archive.h index 129a70b97..0b8b9db61 100644 --- a/src/core/file_sys/content_archive.h +++ b/src/core/file_sys/content_archive.h @@ -4,6 +4,11 @@ #pragma once +#include <array> +#include <memory> +#include <string> +#include <vector> + #include "common/common_funcs.h" #include "common/common_types.h" #include "common/swap.h" @@ -48,7 +53,7 @@ struct NCAHeader { }; static_assert(sizeof(NCAHeader) == 0x400, "NCAHeader has incorrect size."); -inline bool IsDirectoryExeFS(std::shared_ptr<FileSys::VfsDirectory> pfs) { +inline bool IsDirectoryExeFS(const std::shared_ptr<VfsDirectory>& pfs) { // According to switchbrew, an exefs must only contain these two files: return pfs->GetFile("main") != nullptr && pfs->GetFile("main.npdm") != nullptr; } diff --git a/src/core/file_sys/partition_filesystem.cpp b/src/core/file_sys/partition_filesystem.cpp index 15b1fb946..d4097a510 100644 --- a/src/core/file_sys/partition_filesystem.cpp +++ b/src/core/file_sys/partition_filesystem.cpp @@ -11,6 +11,11 @@ namespace FileSys { +bool PartitionFilesystem::Header::HasValidMagicValue() const { + return magic == Common::MakeMagic('H', 'F', 'S', '0') || + magic == Common::MakeMagic('P', 'F', 'S', '0'); +} + PartitionFilesystem::PartitionFilesystem(std::shared_ptr<VfsFile> file) { // At least be as large as the header if (file->GetSize() < sizeof(Header)) { @@ -20,19 +25,17 @@ PartitionFilesystem::PartitionFilesystem(std::shared_ptr<VfsFile> file) { // For cartridges, HFSs can get very large, so we need to calculate the size up to // the actual content itself instead of just blindly reading in the entire file. - Header pfs_header; if (sizeof(Header) != file->ReadObject(&pfs_header)) { status = Loader::ResultStatus::Error; return; } - if (pfs_header.magic != Common::MakeMagic('H', 'F', 'S', '0') && - pfs_header.magic != Common::MakeMagic('P', 'F', 'S', '0')) { + if (!pfs_header.HasValidMagicValue()) { status = Loader::ResultStatus::ErrorInvalidFormat; return; } - bool is_hfs = pfs_header.magic == Common::MakeMagic('H', 'F', 'S', '0'); + is_hfs = pfs_header.magic == Common::MakeMagic('H', 'F', 'S', '0'); size_t entry_size = is_hfs ? sizeof(HFSEntry) : sizeof(PFSEntry); size_t metadata_size = @@ -40,27 +43,13 @@ PartitionFilesystem::PartitionFilesystem(std::shared_ptr<VfsFile> file) { // Actually read in now... std::vector<u8> file_data = file->ReadBytes(metadata_size); + const size_t total_size = file_data.size(); - if (file_data.size() != metadata_size) { - status = Loader::ResultStatus::Error; - return; - } - - size_t total_size = file_data.size(); - if (total_size < sizeof(Header)) { + if (total_size != metadata_size) { status = Loader::ResultStatus::Error; return; } - memcpy(&pfs_header, file_data.data(), sizeof(Header)); - if (pfs_header.magic != Common::MakeMagic('H', 'F', 'S', '0') && - pfs_header.magic != Common::MakeMagic('P', 'F', 'S', '0')) { - status = Loader::ResultStatus::ErrorInvalidFormat; - return; - } - - is_hfs = pfs_header.magic == Common::MakeMagic('H', 'F', 'S', '0'); - size_t entries_offset = sizeof(Header); size_t strtab_offset = entries_offset + (pfs_header.num_entries * entry_size); content_offset = strtab_offset + pfs_header.strtab_size; diff --git a/src/core/file_sys/partition_filesystem.h b/src/core/file_sys/partition_filesystem.h index 9656b40bf..7c7a75816 100644 --- a/src/core/file_sys/partition_filesystem.h +++ b/src/core/file_sys/partition_filesystem.h @@ -42,6 +42,8 @@ private: u32_le num_entries; u32_le strtab_size; INSERT_PADDING_BYTES(0x4); + + bool HasValidMagicValue() const; }; static_assert(sizeof(Header) == 0x10, "PFS/HFS header structure size is wrong"); @@ -73,11 +75,11 @@ private: #pragma pack(pop) - Loader::ResultStatus status; + Loader::ResultStatus status{}; - Header pfs_header; - bool is_hfs; - size_t content_offset; + Header pfs_header{}; + bool is_hfs = false; + size_t content_offset = 0; std::vector<VirtualFile> pfs_files; std::vector<VirtualDir> pfs_dirs; diff --git a/src/core/file_sys/savedata_factory.cpp b/src/core/file_sys/savedata_factory.cpp index 6a53b2b10..dfdca83d6 100644 --- a/src/core/file_sys/savedata_factory.cpp +++ b/src/core/file_sys/savedata_factory.cpp @@ -11,7 +11,7 @@ namespace FileSys { -std::string SaveDataDescriptor::DebugInfo() { +std::string SaveDataDescriptor::DebugInfo() const { return fmt::format("[type={:02X}, title_id={:016X}, user_id={:016X}{:016X}, save_id={:016X}]", static_cast<u8>(type), title_id, user_id[1], user_id[0], save_id); } diff --git a/src/core/file_sys/savedata_factory.h b/src/core/file_sys/savedata_factory.h index 53c69876f..e3a578c0f 100644 --- a/src/core/file_sys/savedata_factory.h +++ b/src/core/file_sys/savedata_factory.h @@ -37,7 +37,7 @@ struct SaveDataDescriptor { u64_le zero_2; u64_le zero_3; - std::string DebugInfo(); + std::string DebugInfo() const; }; static_assert(sizeof(SaveDataDescriptor) == 0x40, "SaveDataDescriptor has incorrect size."); diff --git a/src/core/file_sys/vfs.cpp b/src/core/file_sys/vfs.cpp index f859ef33f..16c8ad90b 100644 --- a/src/core/file_sys/vfs.cpp +++ b/src/core/file_sys/vfs.cpp @@ -116,14 +116,14 @@ bool VfsDirectory::IsRoot() const { size_t VfsDirectory::GetSize() const { const auto& files = GetFiles(); - const auto file_total = - std::accumulate(files.begin(), files.end(), 0ull, - [](const auto& f1, const auto& f2) { return f1 + f2->GetSize(); }); + const auto sum_sizes = [](const auto& range) { + return std::accumulate(range.begin(), range.end(), 0ULL, + [](const auto& f1, const auto& f2) { return f1 + f2->GetSize(); }); + }; + const auto file_total = sum_sizes(files); const auto& sub_dir = GetSubdirectories(); - const auto subdir_total = - std::accumulate(sub_dir.begin(), sub_dir.end(), 0ull, - [](const auto& f1, const auto& f2) { return f1 + f2->GetSize(); }); + const auto subdir_total = sum_sizes(sub_dir); return file_total + subdir_total; } diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cpp index d5df9590a..dcc68aabf 100644 --- a/src/core/hle/kernel/address_arbiter.cpp +++ b/src/core/hle/kernel/address_arbiter.cpp @@ -65,7 +65,7 @@ static void WakeThreads(std::vector<SharedPtr<Thread>>& waiting_threads, s32 num // Signal the waiting threads. for (size_t i = 0; i < last; i++) { - ASSERT(waiting_threads[i]->status = THREADSTATUS_WAIT_ARB); + ASSERT(waiting_threads[i]->status == THREADSTATUS_WAIT_ARB); waiting_threads[i]->SetWaitSynchronizationResult(RESULT_SUCCESS); waiting_threads[i]->arb_wait_address = 0; waiting_threads[i]->ResumeFromWait(); diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index b1e6f565b..b89c8c33d 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include <utility> + #include <boost/range/algorithm_ext/erase.hpp> #include "common/assert.h" #include "common/common_funcs.h" @@ -19,10 +21,10 @@ namespace Kernel { void SessionRequestHandler::ClientConnected(SharedPtr<ServerSession> server_session) { server_session->SetHleHandler(shared_from_this()); - connected_sessions.push_back(server_session); + connected_sessions.push_back(std::move(server_session)); } -void SessionRequestHandler::ClientDisconnected(SharedPtr<ServerSession> server_session) { +void SessionRequestHandler::ClientDisconnected(const SharedPtr<ServerSession>& server_session) { server_session->SetHleHandler(nullptr); boost::range::remove_erase(connected_sessions, server_session); } diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h index c6eca7404..88f93ad22 100644 --- a/src/core/hle/kernel/hle_ipc.h +++ b/src/core/hle/kernel/hle_ipc.h @@ -59,12 +59,12 @@ public: * associated ServerSession. * @param server_session ServerSession associated with the connection. */ - void ClientDisconnected(SharedPtr<ServerSession> server_session); + void ClientDisconnected(const SharedPtr<ServerSession>& server_session); protected: /// List of sessions that are connected to this handler. /// A ServerSession whose server endpoint is an HLE implementation is kept alive by this list - // for the duration of the connection. + /// for the duration of the connection. std::vector<SharedPtr<ServerSession>> connected_sessions; }; diff --git a/src/core/hle/kernel/object_address_table.cpp b/src/core/hle/kernel/object_address_table.cpp index ec97f6f8e..ca8a833a1 100644 --- a/src/core/hle/kernel/object_address_table.cpp +++ b/src/core/hle/kernel/object_address_table.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include <utility> + #include "common/assert.h" #include "core/hle/kernel/object_address_table.h" @@ -11,7 +13,7 @@ ObjectAddressTable g_object_address_table; void ObjectAddressTable::Insert(VAddr addr, SharedPtr<Object> obj) { ASSERT_MSG(objects.find(addr) == objects.end(), "Object already exists with addr=0x{:X}", addr); - objects[addr] = obj; + objects[addr] = std::move(obj); } void ObjectAddressTable::Close(VAddr addr) { diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cpp index ca8807e19..1f4abfbe8 100644 --- a/src/core/hle/kernel/scheduler.cpp +++ b/src/core/hle/kernel/scheduler.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include <utility> + #include "core/core.h" #include "core/core_timing.h" #include "core/hle/kernel/process.h" @@ -113,7 +115,7 @@ void Scheduler::Reschedule() { void Scheduler::AddThread(SharedPtr<Thread> thread, u32 priority) { std::lock_guard<std::mutex> lock(scheduler_mutex); - thread_list.push_back(thread); + thread_list.push_back(std::move(thread)); ready_queue.prepare(priority); } diff --git a/src/core/hle/kernel/server_session.cpp b/src/core/hle/kernel/server_session.cpp index 0d5cba1d9..19d17af4f 100644 --- a/src/core/hle/kernel/server_session.cpp +++ b/src/core/hle/kernel/server_session.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include <tuple> +#include <utility> #include "core/core.h" #include "core/hle/ipc_helpers.h" @@ -158,7 +159,7 @@ ServerSession::SessionPair ServerSession::CreateSessionPair(const std::string& n std::shared_ptr<Session> parent(new Session); parent->client = client_session.get(); parent->server = server_session.get(); - parent->port = port; + parent->port = std::move(port); client_session->parent = parent; server_session->parent = parent; diff --git a/src/core/hle/kernel/shared_memory.cpp b/src/core/hle/kernel/shared_memory.cpp index 93f7f2772..4bf11c7e2 100644 --- a/src/core/hle/kernel/shared_memory.cpp +++ b/src/core/hle/kernel/shared_memory.cpp @@ -2,7 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include <cstring> +#include <utility> #include "common/logging/log.h" #include "core/core.h" #include "core/hle/kernel/errors.h" @@ -21,7 +21,7 @@ SharedPtr<SharedMemory> SharedMemory::Create(SharedPtr<Process> owner_process, u MemoryRegion region, std::string name) { SharedPtr<SharedMemory> shared_memory(new SharedMemory); - shared_memory->owner_process = owner_process; + shared_memory->owner_process = std::move(owner_process); shared_memory->name = std::move(name); shared_memory->size = size; shared_memory->permissions = permissions; @@ -87,7 +87,7 @@ SharedPtr<SharedMemory> SharedMemory::CreateForApplet(std::shared_ptr<std::vecto shared_memory->size = size; shared_memory->permissions = permissions; shared_memory->other_permissions = other_permissions; - shared_memory->backing_block = heap_block; + shared_memory->backing_block = std::move(heap_block); shared_memory->backing_block_offset = offset; shared_memory->base_address = Memory::HEAP_VADDR + offset; diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 0b3c66428..e7fd6c842 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -400,7 +400,7 @@ SharedPtr<Thread> SetupMainThread(VAddr entry_point, u32 priority, // Initialize new "main" thread auto thread_res = Thread::Create("main", entry_point, priority, 0, THREADPROCESSORID_0, - Memory::STACK_AREA_VADDR_END, owner_process); + Memory::STACK_AREA_VADDR_END, std::move(owner_process)); SharedPtr<Thread> thread = std::move(thread_res).Unwrap(); diff --git a/src/core/hle/kernel/vm_manager.cpp b/src/core/hle/kernel/vm_manager.cpp index 10b3ebaca..9d26fd781 100644 --- a/src/core/hle/kernel/vm_manager.cpp +++ b/src/core/hle/kernel/vm_manager.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include <iterator> +#include <utility> #include "common/assert.h" #include "common/logging/log.h" #include "core/arm/arm_interface.h" @@ -107,7 +108,7 @@ ResultVal<VMManager::VMAHandle> VMManager::MapMemoryBlock(VAddr target, final_vma.type = VMAType::AllocatedMemoryBlock; final_vma.permissions = VMAPermission::ReadWrite; final_vma.meminfo_state = state; - final_vma.backing_block = block; + final_vma.backing_block = std::move(block); final_vma.offset = offset; UpdatePageTableForVMA(final_vma); @@ -150,7 +151,7 @@ ResultVal<VMManager::VMAHandle> VMManager::MapMMIO(VAddr target, PAddr paddr, u6 final_vma.permissions = VMAPermission::ReadWrite; final_vma.meminfo_state = state; final_vma.paddr = paddr; - final_vma.mmio_handler = mmio_handler; + final_vma.mmio_handler = std::move(mmio_handler); UpdatePageTableForVMA(final_vma); return MakeResult<VMAHandle>(MergeAdjacent(vma_handle)); diff --git a/src/core/hle/service/prepo/prepo.h b/src/core/hle/service/prepo/prepo.h index 3708e0dcb..f5a6aba6d 100644 --- a/src/core/hle/service/prepo/prepo.h +++ b/src/core/hle/service/prepo/prepo.h @@ -2,6 +2,8 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#pragma once + #include <memory> #include <string> #include "core/hle/kernel/event.h" diff --git a/src/core/memory.cpp b/src/core/memory.cpp index a18e27da0..e753e3436 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -5,6 +5,8 @@ #include <algorithm> #include <array> #include <cstring> +#include <utility> + #include <boost/optional.hpp> #include "common/assert.h" #include "common/common_types.h" @@ -74,7 +76,7 @@ void MapIoRegion(PageTable& page_table, VAddr base, u64 size, MemoryHookPointer MapPages(page_table, base / PAGE_SIZE, size / PAGE_SIZE, nullptr, PageType::Special); auto interval = boost::icl::discrete_interval<VAddr>::closed(base, base + size - 1); - SpecialRegion region{SpecialRegion::Type::IODevice, mmio_handler}; + SpecialRegion region{SpecialRegion::Type::IODevice, std::move(mmio_handler)}; page_table.special_regions.add(std::make_pair(interval, std::set<SpecialRegion>{region})); } @@ -89,13 +91,13 @@ void UnmapRegion(PageTable& page_table, VAddr base, u64 size) { void AddDebugHook(PageTable& page_table, VAddr base, u64 size, MemoryHookPointer hook) { auto interval = boost::icl::discrete_interval<VAddr>::closed(base, base + size - 1); - SpecialRegion region{SpecialRegion::Type::DebugHook, hook}; + SpecialRegion region{SpecialRegion::Type::DebugHook, std::move(hook)}; page_table.special_regions.add(std::make_pair(interval, std::set<SpecialRegion>{region})); } void RemoveDebugHook(PageTable& page_table, VAddr base, u64 size, MemoryHookPointer hook) { auto interval = boost::icl::discrete_interval<VAddr>::closed(base, base + size - 1); - SpecialRegion region{SpecialRegion::Type::DebugHook, hook}; + SpecialRegion region{SpecialRegion::Type::DebugHook, std::move(hook)}; page_table.special_regions.subtract(std::make_pair(interval, std::set<SpecialRegion>{region})); } diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 7e620584f..f75999557 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -795,7 +795,9 @@ void RasterizerOpenGL::SyncClipCoef() { void RasterizerOpenGL::SyncCullMode() { const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; - state.cull.enabled = regs.cull.enabled != 0; + // TODO(bunnei): Enable the below once more things work - until then, this may hide regressions + // state.cull.enabled = regs.cull.enabled != 0; + state.cull.enabled = false; if (state.cull.enabled) { state.cull.front_face = MaxwellToGL::FrontFace(regs.cull.front_face); |