From 1cc1c33a159b36e4c731f00e2c83f1140dd7c561 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 12 May 2022 00:23:23 -0400 Subject: [PATCH 1/7] common: Resolve C4267 warning on MSVC Also removes Timer::GetDoubleTime() as it is unused. --- src/common/alignment.h | 2 +- src/common/texture.cpp | 6 +++--- src/common/texture.h | 2 +- src/common/timer.cpp | 20 -------------------- src/common/timer.h | 1 - src/common/x64/xbyak_abi.h | 4 ++-- 6 files changed, 7 insertions(+), 28 deletions(-) diff --git a/src/common/alignment.h b/src/common/alignment.h index 64fafd2e8..15f981d73 100644 --- a/src/common/alignment.h +++ b/src/common/alignment.h @@ -10,7 +10,7 @@ namespace Common { template [[nodiscard]] constexpr T AlignUp(T value, std::size_t size) { static_assert(std::is_unsigned_v, "T must be an unsigned value."); - auto mod{value % size}; + auto mod{static_cast(value % size)}; value -= mod; return static_cast(mod == T{0} ? value : value + size); } diff --git a/src/common/texture.cpp b/src/common/texture.cpp index 2ec939288..75b6a2cee 100644 --- a/src/common/texture.cpp +++ b/src/common/texture.cpp @@ -8,10 +8,10 @@ #include "common/common_types.h" namespace Common { -void FlipRGBA8Texture(std::vector& tex, u64 width, u64 height) { +void FlipRGBA8Texture(std::vector& tex, u32 width, u32 height) { ASSERT(tex.size() == width * height * 4); - const u64 line_size = width * 4; - for (u64 line = 0; line < height / 2; line++) { + const u32 line_size = width * 4; + for (u32 line = 0; line < height / 2; line++) { const u32 offset_1 = line * line_size; const u32 offset_2 = (height - line - 1) * line_size; // Swap lines diff --git a/src/common/texture.h b/src/common/texture.h index 2de56bc09..de53433b4 100644 --- a/src/common/texture.h +++ b/src/common/texture.h @@ -8,5 +8,5 @@ #include "common/common_types.h" namespace Common { -void FlipRGBA8Texture(std::vector& tex, u64 width, u64 height); +void FlipRGBA8Texture(std::vector& tex, u32 width, u32 height); } diff --git a/src/common/timer.cpp b/src/common/timer.cpp index 50c859cca..7a4250246 100644 --- a/src/common/timer.cpp +++ b/src/common/timer.cpp @@ -137,24 +137,4 @@ std::string Timer::GetTimeFormatted() { return fmt::format("{}:{:03}", tmp, milliseconds); } -// Returns a timestamp with decimals for precise time comparisons -// ---------------- -double Timer::GetDoubleTime() { - // Get continuous timestamp - u64 TmpSeconds = static_cast(Common::Timer::GetTimeSinceJan1970().count()); - double ms = static_cast(GetTimeMs().count()) % 1000; - - // Remove a few years. We only really want enough seconds to make - // sure that we are detecting actual actions, perhaps 60 seconds is - // enough really, but I leave a year of seconds anyway, in case the - // user's clock is incorrect or something like that. - TmpSeconds = TmpSeconds - (38 * 365 * 24 * 60 * 60); - - // Make a smaller integer that fits in the double - u32 Seconds = static_cast(TmpSeconds); - double TmpTime = Seconds + ms; - - return TmpTime; -} - } // Namespace Common diff --git a/src/common/timer.h b/src/common/timer.h index 8894a143d..826e21a42 100644 --- a/src/common/timer.h +++ b/src/common/timer.h @@ -24,7 +24,6 @@ public: [[nodiscard]] static std::chrono::seconds GetTimeSinceJan1970(); [[nodiscard]] static std::chrono::seconds GetLocalTimeSinceJan1970(); - [[nodiscard]] static double GetDoubleTime(); [[nodiscard]] static std::string GetTimeFormatted(); [[nodiscard]] std::string GetTimeElapsedFormatted() const; diff --git a/src/common/x64/xbyak_abi.h b/src/common/x64/xbyak_abi.h index 0139db232..235952a1e 100644 --- a/src/common/x64/xbyak_abi.h +++ b/src/common/x64/xbyak_abi.h @@ -158,10 +158,10 @@ struct ABIFrameInfo { inline ABIFrameInfo ABI_CalculateFrameSize(std::bitset<32> regs, std::size_t rsp_alignment, std::size_t needed_frame_size) { - int count = (regs & ABI_ALL_GPRS).count(); + const auto count = (regs & ABI_ALL_GPRS).count(); rsp_alignment -= count * 8; std::size_t subtraction = 0; - int xmm_count = (regs & ABI_ALL_XMMS).count(); + const auto xmm_count = (regs & ABI_ALL_XMMS).count(); if (xmm_count) { // If we have any XMMs to save, we must align the stack here. subtraction = rsp_alignment & 0xF; From 4e73ff39781c269acf812a198986e3b7ca08528d Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 12 May 2022 02:49:52 -0400 Subject: [PATCH 2/7] input_common: Resolve C4267 warning on MSVC --- src/input_common/sdl/sdl_impl.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp index 998cafdf1..4f7a78461 100644 --- a/src/input_common/sdl/sdl_impl.cpp +++ b/src/input_common/sdl/sdl_impl.cpp @@ -335,7 +335,8 @@ std::shared_ptr SDLState::GetSDLJoystickBySDLID(SDL_JoystickID sdl_ } // There is no SDLJoystick without a mapped SDL_Joystick // Create a new SDLJoystick - auto joystick = std::make_shared(guid, map_it->second.size(), sdl_joystick); + auto joystick = std::make_shared(guid, static_cast(map_it->second.size()), + sdl_joystick); return map_it->second.emplace_back(std::move(joystick)); } auto joystick = std::make_shared(guid, 0, sdl_joystick); @@ -483,7 +484,8 @@ void SDLState::InitJoystick(int joystick_index) { (*it)->SetSDLJoystick(sdl_joystick); return; } - auto joystick = std::make_shared(guid, joystick_guid_list.size(), sdl_joystick); + auto joystick = std::make_shared(guid, static_cast(joystick_guid_list.size()), + sdl_joystick); joystick_guid_list.emplace_back(std::move(joystick)); } @@ -519,8 +521,8 @@ void SDLState::InitGameController(int controller_index) { (*it)->SetSDLGameController(sdl_controller); return; } - auto controller = - std::make_shared(guid, controller_guid_list.size(), sdl_controller); + auto controller = std::make_shared( + guid, static_cast(controller_guid_list.size()), sdl_controller); controller_guid_list.emplace_back(std::move(controller)); } From 3a43475149dabce8ad7a0ad5f01136bb50befdf9 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 12 May 2022 00:23:36 -0400 Subject: [PATCH 3/7] core: Resolve C4267 warning on MSVC --- src/core/dumping/backend.cpp | 3 ++- src/core/dumping/ffmpeg_backend.cpp | 2 +- src/core/file_sys/seed_db.cpp | 2 +- src/core/hle/kernel/ipc.cpp | 5 +++-- src/core/hle/kernel/thread.cpp | 11 ++++++----- src/core/hle/service/dsp/dsp_dsp.cpp | 2 +- src/core/hle/service/nfc/nfc.cpp | 2 +- 7 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/core/dumping/backend.cpp b/src/core/dumping/backend.cpp index 88686b7a2..16cd1d908 100644 --- a/src/core/dumping/backend.cpp +++ b/src/core/dumping/backend.cpp @@ -8,7 +8,8 @@ namespace VideoDumper { VideoFrame::VideoFrame(std::size_t width_, std::size_t height_, u8* data_) - : width(width_), height(height_), stride(width * 4), data(data_, data_ + width * height * 4) {} + : width(width_), height(height_), stride(static_cast(width * 4)), + data(data_, data_ + width * height * 4) {} Backend::~Backend() = default; NullBackend::~NullBackend() = default; diff --git a/src/core/dumping/ffmpeg_backend.cpp b/src/core/dumping/ffmpeg_backend.cpp index 28c33639b..cad321d87 100644 --- a/src/core/dumping/ffmpeg_backend.cpp +++ b/src/core/dumping/ffmpeg_backend.cpp @@ -354,7 +354,7 @@ void FFmpegAudioStream::ProcessFrame(const VariableAudioFrame& channel0, } auto resampled_count = swr_convert(swr_context.get(), dst_data.data(), frame_size - offset, - src_data.data(), channel0.size()); + src_data.data(), static_cast(channel0.size())); if (resampled_count < 0) { LOG_ERROR(Render, "Audio frame dropped: Could not resample data"); return; diff --git a/src/core/file_sys/seed_db.cpp b/src/core/file_sys/seed_db.cpp index f5b38fb0e..1e29a203b 100644 --- a/src/core/file_sys/seed_db.cpp +++ b/src/core/file_sys/seed_db.cpp @@ -143,7 +143,7 @@ u32 GetSeedCount() { if (!db.Load()) { return 0; } - return db.GetCount(); + return static_cast(db.GetCount()); } } // namespace FileSys diff --git a/src/core/hle/kernel/ipc.cpp b/src/core/hle/kernel/ipc.cpp index ca7bce97e..817f58216 100644 --- a/src/core/hle/kernel/ipc.cpp +++ b/src/core/hle/kernel/ipc.cpp @@ -209,7 +209,8 @@ ResultCode TranslateCommandBuffer(Kernel::KernelSystem& kernel, Memory::MemorySy target_address = dst_process->vm_manager .MapBackingMemoryToBase(Memory::IPC_MAPPING_VADDR, Memory::IPC_MAPPING_SIZE, - buffer, buffer->GetSize(), Kernel::MemoryState::Shared) + buffer, static_cast(buffer->GetSize()), + Kernel::MemoryState::Shared) .Unwrap(); cmd_buf[i++] = target_address + page_offset; @@ -217,7 +218,7 @@ ResultCode TranslateCommandBuffer(Kernel::KernelSystem& kernel, Memory::MemorySy // Reserve a page of memory after the mapped buffer dst_process->vm_manager.MapBackingMemoryToBase( Memory::IPC_MAPPING_VADDR, Memory::IPC_MAPPING_SIZE, reserve_buffer, - reserve_buffer->GetSize(), Kernel::MemoryState::Reserved); + static_cast(reserve_buffer->GetSize()), Kernel::MemoryState::Reserved); mapped_buffer_context.push_back({permissions, size, source_address, target_address + page_offset, std::move(buffer), diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 2920dc2ce..0d1d8d6ff 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -389,15 +389,16 @@ ResultVal> KernelSystem::CreateThread( auto& vm_manager = owner_process->vm_manager; // Map the page to the current process' address space. - vm_manager.MapBackingMemory(Memory::TLS_AREA_VADDR + available_page * Memory::PAGE_SIZE, - memory.GetFCRAMRef(*offset), Memory::PAGE_SIZE, - MemoryState::Locked); + vm_manager.MapBackingMemory( + Memory::TLS_AREA_VADDR + static_cast(available_page) * Memory::PAGE_SIZE, + memory.GetFCRAMRef(*offset), Memory::PAGE_SIZE, MemoryState::Locked); } // Mark the slot as used tls_slots[available_page].set(available_slot); - thread->tls_address = Memory::TLS_AREA_VADDR + available_page * Memory::PAGE_SIZE + - available_slot * Memory::TLS_ENTRY_SIZE; + thread->tls_address = Memory::TLS_AREA_VADDR + + static_cast(available_page) * Memory::PAGE_SIZE + + static_cast(available_slot) * Memory::TLS_ENTRY_SIZE; memory.ZeroBlock(*owner_process, thread->tls_address, Memory::TLS_ENTRY_SIZE); diff --git a/src/core/hle/service/dsp/dsp_dsp.cpp b/src/core/hle/service/dsp/dsp_dsp.cpp index ff6fecb3b..607b4a363 100644 --- a/src/core/hle/service/dsp/dsp_dsp.cpp +++ b/src/core/hle/service/dsp/dsp_dsp.cpp @@ -161,7 +161,7 @@ void DSP_DSP::ReadPipeIfPossible(Kernel::HLERequestContext& ctx) { IPC::RequestBuilder rb = rp.MakeBuilder(2, 2); rb.Push(RESULT_SUCCESS); - rb.Push(pipe_buffer.size()); + rb.Push(static_cast(pipe_buffer.size())); rb.PushStaticBuffer(std::move(pipe_buffer), 0); LOG_DEBUG(Service_DSP, "channel={}, peer={}, size=0x{:04X}, pipe_readable_size=0x{:04X}", diff --git a/src/core/hle/service/nfc/nfc.cpp b/src/core/hle/service/nfc/nfc.cpp index e02a5ad0a..388ea771f 100644 --- a/src/core/hle/service/nfc/nfc.cpp +++ b/src/core/hle/service/nfc/nfc.cpp @@ -141,7 +141,7 @@ void Module::Interface::GetTagInfo(Kernel::HLERequestContext& ctx) { TagInfo tag_info{}; tag_info.uuid = nfc->amiibo_data.uuid; - tag_info.id_offset_size = tag_info.uuid.size(); + tag_info.id_offset_size = static_cast(tag_info.uuid.size()); tag_info.unk1 = 0x0; tag_info.unk2 = 0x2; From de1374c1b9ff66f06eb43f3bb00ff8d7ccabb422 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 12 May 2022 00:23:46 -0400 Subject: [PATCH 4/7] video_core: Resolve C4267 warning on MSVC --- src/video_core/renderer_opengl/gl_rasterizer.cpp | 2 +- .../renderer_opengl/texture_downloader_es.cpp | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 2f04412a4..1d5dcbb14 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -798,7 +798,7 @@ bool RasterizerOpenGL::Draw(bool accelerate, bool is_indexed) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glBindTexture(GL_TEXTURE_2D, state.texture_units[0].texture_2d); - for (std::size_t level{0}; level <= color_surface->max_level; ++level) { + for (u32 level{0}; level <= color_surface->max_level; ++level) { glCopyImageSubData(color_surface->texture.handle, GL_TEXTURE_2D, level, 0, 0, 0, temp_tex.handle, GL_TEXTURE_2D, level, 0, 0, 0, color_surface->GetScaledWidth() >> level, diff --git a/src/video_core/renderer_opengl/texture_downloader_es.cpp b/src/video_core/renderer_opengl/texture_downloader_es.cpp index 11663512e..1119ad65e 100644 --- a/src/video_core/renderer_opengl/texture_downloader_es.cpp +++ b/src/video_core/renderer_opengl/texture_downloader_es.cpp @@ -50,16 +50,18 @@ void TextureDownloaderES::Test() { state.Apply(); original_data.resize(tex_size * tex_size); - for (std::size_t idx = 0; idx < original_data.size(); ++idx) + for (std::size_t idx = 0; idx < original_data.size(); ++idx) { original_data[idx] = data_generator(idx); - glTexStorage2D(GL_TEXTURE_2D, 1, tuple.internal_format, tex_size, tex_size); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, tex_size, tex_size, tuple.format, tuple.type, + } + GLsizei tex_sizei = static_cast(tex_size); + glTexStorage2D(GL_TEXTURE_2D, 1, tuple.internal_format, tex_sizei, tex_sizei); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, tex_sizei, tex_sizei, tuple.format, tuple.type, original_data.data()); decltype(original_data) new_data(original_data.size()); glFinish(); auto start = std::chrono::high_resolution_clock::now(); - GetTexImage(GL_TEXTURE_2D, 0, tuple.format, tuple.type, tex_size, tex_size, + GetTexImage(GL_TEXTURE_2D, 0, tuple.format, tuple.type, tex_sizei, tex_sizei, new_data.data()); glFinish(); auto time = std::chrono::high_resolution_clock::now() - start; From 0d955c452bb8a76fe0e68a04fe7e779b646e768f Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 12 May 2022 00:23:57 -0400 Subject: [PATCH 5/7] citra_qt: Resolve C4267 warning on MSVC --- src/citra_qt/cheats.cpp | 5 +++-- src/citra_qt/configuration/config.cpp | 4 ++-- src/citra_qt/configuration/configure_camera.cpp | 2 +- src/citra_qt/debugger/ipc/recorder.cpp | 2 +- src/citra_qt/multiplayer/chat_room.cpp | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/citra_qt/cheats.cpp b/src/citra_qt/cheats.cpp index 25379b72c..25e173687 100644 --- a/src/citra_qt/cheats.cpp +++ b/src/citra_qt/cheats.cpp @@ -48,10 +48,11 @@ CheatDialog::~CheatDialog() = default; void CheatDialog::LoadCheats() { cheats = Core::System::GetInstance().CheatEngine().GetCheats(); + const int cheats_count = static_cast(cheats.size()); - ui->tableCheats->setRowCount(cheats.size()); + ui->tableCheats->setRowCount(cheats_count); - for (size_t i = 0; i < cheats.size(); i++) { + for (int i = 0; i < cheats_count; i++) { QCheckBox* enabled = new QCheckBox(); enabled->setChecked(cheats[i]->IsEnabled()); enabled->setStyleSheet(QStringLiteral("margin-left:7px;")); diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index 770a7fe30..f318b2825 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -950,14 +950,14 @@ void Config::SaveMultiplayerValues() { // Write ban list qt_config->beginWriteArray(QStringLiteral("username_ban_list")); for (std::size_t i = 0; i < UISettings::values.ban_list.first.size(); ++i) { - qt_config->setArrayIndex(i); + qt_config->setArrayIndex(static_cast(i)); WriteSetting(QStringLiteral("username"), QString::fromStdString(UISettings::values.ban_list.first[i])); } qt_config->endArray(); qt_config->beginWriteArray(QStringLiteral("ip_ban_list")); for (std::size_t i = 0; i < UISettings::values.ban_list.second.size(); ++i) { - qt_config->setArrayIndex(i); + qt_config->setArrayIndex(static_cast(i)); WriteSetting(QStringLiteral("ip"), QString::fromStdString(UISettings::values.ban_list.second[i])); } diff --git a/src/citra_qt/configuration/configure_camera.cpp b/src/citra_qt/configuration/configure_camera.cpp index a89dc3151..b58ea95d3 100644 --- a/src/citra_qt/configuration/configure_camera.cpp +++ b/src/citra_qt/configuration/configure_camera.cpp @@ -256,7 +256,7 @@ void ConfigureCamera::SetConfiguration() { int index = GetSelectedCameraIndex(); for (std::size_t i = 0; i < Implementations.size(); i++) { if (Implementations[i] == camera_name[index]) { - ui->image_source->setCurrentIndex(i); + ui->image_source->setCurrentIndex(static_cast(i)); } } if (camera_name[index] == "image") { diff --git a/src/citra_qt/debugger/ipc/recorder.cpp b/src/citra_qt/debugger/ipc/recorder.cpp index b4ed84ad0..1ec281ae2 100644 --- a/src/citra_qt/debugger/ipc/recorder.cpp +++ b/src/citra_qt/debugger/ipc/recorder.cpp @@ -115,7 +115,7 @@ void IPCRecorderWidget::SetEnabled(bool enabled) { } void IPCRecorderWidget::Clear() { - id_offset += records.size(); + id_offset += static_cast(records.size()); records.clear(); ui->main->invisibleRootItem()->takeChildren(); diff --git a/src/citra_qt/multiplayer/chat_room.cpp b/src/citra_qt/multiplayer/chat_room.cpp index 440736978..ffd9a0b68 100644 --- a/src/citra_qt/multiplayer/chat_room.cpp +++ b/src/citra_qt/multiplayer/chat_room.cpp @@ -390,7 +390,7 @@ void ChatRoom::SetPlayerList(const Network::RoomMember::MemberList& member_list) return; QPixmap pixmap; if (!pixmap.loadFromData(reinterpret_cast(result.data()), - result.size())) + static_cast(result.size()))) return; icon_cache[avatar_url] = pixmap.scaled(48, 48, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); From adcc786ef23efdaaa8ad69ae63210857559d2d0f Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 12 May 2022 00:24:03 -0400 Subject: [PATCH 6/7] tests: Resolve C4267 warning on MSVC --- src/tests/core/hle/kernel/hle_ipc.cpp | 42 +++++++++++++---------- src/tests/core/memory/vm_manager.cpp | 48 +++++++++++++++------------ 2 files changed, 52 insertions(+), 38 deletions(-) diff --git a/src/tests/core/hle/kernel/hle_ipc.cpp b/src/tests/core/hle/kernel/hle_ipc.cpp index 890343cd8..4f7d35f7a 100644 --- a/src/tests/core/hle/kernel/hle_ipc.cpp +++ b/src/tests/core/hle/kernel/hle_ipc.cpp @@ -142,8 +142,8 @@ TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel std::fill(buffer.GetPtr(), buffer.GetPtr() + buffer.GetSize(), 0xAB); VAddr target_address = 0x10000000; - auto result = process->vm_manager.MapBackingMemory(target_address, buffer, buffer.GetSize(), - MemoryState::Private); + auto result = process->vm_manager.MapBackingMemory( + target_address, buffer, static_cast(buffer.GetSize()), MemoryState::Private); REQUIRE(result.Code() == RESULT_SUCCESS); const u32_le input[]{ @@ -156,7 +156,8 @@ TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel CHECK(context.GetStaticBuffer(0) == mem->Vector()); - REQUIRE(process->vm_manager.UnmapRange(target_address, buffer.GetSize()) == RESULT_SUCCESS); + REQUIRE(process->vm_manager.UnmapRange( + target_address, static_cast(buffer.GetSize())) == RESULT_SUCCESS); } SECTION("translates MappedBuffer descriptors") { @@ -165,8 +166,8 @@ TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel std::fill(buffer.GetPtr(), buffer.GetPtr() + buffer.GetSize(), 0xCD); VAddr target_address = 0x10000000; - auto result = process->vm_manager.MapBackingMemory(target_address, buffer, buffer.GetSize(), - MemoryState::Private); + auto result = process->vm_manager.MapBackingMemory( + target_address, buffer, static_cast(buffer.GetSize()), MemoryState::Private); const u32_le input[]{ IPC::MakeHeader(0, 0, 2), @@ -181,7 +182,8 @@ TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel CHECK(other_buffer == mem->Vector()); - REQUIRE(process->vm_manager.UnmapRange(target_address, buffer.GetSize()) == RESULT_SUCCESS); + REQUIRE(process->vm_manager.UnmapRange( + target_address, static_cast(buffer.GetSize())) == RESULT_SUCCESS); } SECTION("translates mixed params") { @@ -195,12 +197,14 @@ TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel VAddr target_address_static = 0x10000000; auto result = process->vm_manager.MapBackingMemory( - target_address_static, buffer_static, buffer_static.GetSize(), MemoryState::Private); + target_address_static, buffer_static, static_cast(buffer_static.GetSize()), + MemoryState::Private); REQUIRE(result.Code() == RESULT_SUCCESS); VAddr target_address_mapped = 0x20000000; - result = process->vm_manager.MapBackingMemory( - target_address_mapped, buffer_mapped, buffer_mapped.GetSize(), MemoryState::Private); + result = process->vm_manager.MapBackingMemory(target_address_mapped, buffer_mapped, + static_cast(buffer_mapped.GetSize()), + MemoryState::Private); REQUIRE(result.Code() == RESULT_SUCCESS); auto a = MakeObject(kernel); @@ -230,9 +234,11 @@ TEST_CASE("HLERequestContext::PopulateFromIncomingCommandBuffer", "[core][kernel context.GetMappedBuffer(0).Read(other_buffer.data(), 0, buffer_mapped.GetSize()); CHECK(other_buffer == mem_mapped->Vector()); - REQUIRE(process->vm_manager.UnmapRange(target_address_static, buffer_static.GetSize()) == + REQUIRE(process->vm_manager.UnmapRange(target_address_static, + static_cast(buffer_static.GetSize())) == RESULT_SUCCESS); - REQUIRE(process->vm_manager.UnmapRange(target_address_mapped, buffer_mapped.GetSize()) == + REQUIRE(process->vm_manager.UnmapRange(target_address_mapped, + static_cast(buffer_mapped.GetSize())) == RESULT_SUCCESS); } } @@ -325,7 +331,8 @@ TEST_CASE("HLERequestContext::WriteToOutgoingCommandBuffer", "[core][kernel]") { VAddr target_address = 0x10000000; auto result = process->vm_manager.MapBackingMemory( - target_address, output_buffer, output_buffer.GetSize(), MemoryState::Private); + target_address, output_buffer, static_cast(output_buffer.GetSize()), + MemoryState::Private); REQUIRE(result.Code() == RESULT_SUCCESS); input[0] = IPC::MakeHeader(0, 0, 2); @@ -343,8 +350,8 @@ TEST_CASE("HLERequestContext::WriteToOutgoingCommandBuffer", "[core][kernel]") { context.WriteToOutgoingCommandBuffer(output_cmdbuff.data(), *process); CHECK(output_mem->Vector() == input_buffer); - REQUIRE(process->vm_manager.UnmapRange(target_address, output_buffer.GetSize()) == - RESULT_SUCCESS); + REQUIRE(process->vm_manager.UnmapRange( + target_address, static_cast(output_buffer.GetSize())) == RESULT_SUCCESS); } SECTION("translates StaticBuffer descriptors") { @@ -356,7 +363,8 @@ TEST_CASE("HLERequestContext::WriteToOutgoingCommandBuffer", "[core][kernel]") { VAddr target_address = 0x10000000; auto result = process->vm_manager.MapBackingMemory( - target_address, output_buffer, output_buffer.GetSize(), MemoryState::Private); + target_address, output_buffer, static_cast(output_buffer.GetSize()), + MemoryState::Private); REQUIRE(result.Code() == RESULT_SUCCESS); const u32_le input_cmdbuff[]{ @@ -378,8 +386,8 @@ TEST_CASE("HLERequestContext::WriteToOutgoingCommandBuffer", "[core][kernel]") { CHECK(output[1] == IPC::MappedBufferDesc(output_buffer.GetSize(), IPC::W)); CHECK(output[2] == target_address); CHECK(output_mem->Vector() == input_buffer); - REQUIRE(process->vm_manager.UnmapRange(target_address, output_buffer.GetSize()) == - RESULT_SUCCESS); + REQUIRE(process->vm_manager.UnmapRange( + target_address, static_cast(output_buffer.GetSize())) == RESULT_SUCCESS); } } diff --git a/src/tests/core/memory/vm_manager.cpp b/src/tests/core/memory/vm_manager.cpp index 5a8e8b788..1bcdb4376 100644 --- a/src/tests/core/memory/vm_manager.cpp +++ b/src/tests/core/memory/vm_manager.cpp @@ -16,13 +16,14 @@ TEST_CASE("Memory Basics", "[kernel][memory]") { SECTION("mapping memory") { // Because of the PageTable, Kernel::VMManager is too big to be created on the stack. auto manager = std::make_unique(memory); - auto result = manager->MapBackingMemory(Memory::HEAP_VADDR, block, block.GetSize(), - Kernel::MemoryState::Private); + auto result = + manager->MapBackingMemory(Memory::HEAP_VADDR, block, static_cast(block.GetSize()), + Kernel::MemoryState::Private); REQUIRE(result.Code() == RESULT_SUCCESS); auto vma = manager->FindVMA(Memory::HEAP_VADDR); CHECK(vma != manager->vma_map.end()); - CHECK(vma->second.size == block.GetSize()); + CHECK(vma->second.size == static_cast(block.GetSize())); CHECK(vma->second.type == Kernel::VMAType::BackingMemory); CHECK(vma->second.backing_memory.GetPtr() == block.GetPtr()); CHECK(vma->second.meminfo_state == Kernel::MemoryState::Private); @@ -31,11 +32,13 @@ TEST_CASE("Memory Basics", "[kernel][memory]") { SECTION("unmapping memory") { // Because of the PageTable, Kernel::VMManager is too big to be created on the stack. auto manager = std::make_unique(memory); - auto result = manager->MapBackingMemory(Memory::HEAP_VADDR, block, block.GetSize(), - Kernel::MemoryState::Private); + auto result = + manager->MapBackingMemory(Memory::HEAP_VADDR, block, static_cast(block.GetSize()), + Kernel::MemoryState::Private); REQUIRE(result.Code() == RESULT_SUCCESS); - ResultCode code = manager->UnmapRange(Memory::HEAP_VADDR, block.GetSize()); + ResultCode code = + manager->UnmapRange(Memory::HEAP_VADDR, static_cast(block.GetSize())); REQUIRE(code == RESULT_SUCCESS); auto vma = manager->FindVMA(Memory::HEAP_VADDR); @@ -47,36 +50,39 @@ TEST_CASE("Memory Basics", "[kernel][memory]") { SECTION("changing memory permissions") { // Because of the PageTable, Kernel::VMManager is too big to be created on the stack. auto manager = std::make_unique(memory); - auto result = manager->MapBackingMemory(Memory::HEAP_VADDR, block, block.GetSize(), - Kernel::MemoryState::Private); + auto result = + manager->MapBackingMemory(Memory::HEAP_VADDR, block, static_cast(block.GetSize()), + Kernel::MemoryState::Private); REQUIRE(result.Code() == RESULT_SUCCESS); - ResultCode code = manager->ReprotectRange(Memory::HEAP_VADDR, block.GetSize(), - Kernel::VMAPermission::Execute); + ResultCode code = manager->ReprotectRange( + Memory::HEAP_VADDR, static_cast(block.GetSize()), Kernel::VMAPermission::Execute); CHECK(code == RESULT_SUCCESS); auto vma = manager->FindVMA(Memory::HEAP_VADDR); CHECK(vma != manager->vma_map.end()); CHECK(vma->second.permissions == Kernel::VMAPermission::Execute); - code = manager->UnmapRange(Memory::HEAP_VADDR, block.GetSize()); + code = manager->UnmapRange(Memory::HEAP_VADDR, static_cast(block.GetSize())); REQUIRE(code == RESULT_SUCCESS); } SECTION("changing memory state") { // Because of the PageTable, Kernel::VMManager is too big to be created on the stack. auto manager = std::make_unique(memory); - auto result = manager->MapBackingMemory(Memory::HEAP_VADDR, block, block.GetSize(), - Kernel::MemoryState::Private); + auto result = + manager->MapBackingMemory(Memory::HEAP_VADDR, block, static_cast(block.GetSize()), + Kernel::MemoryState::Private); REQUIRE(result.Code() == RESULT_SUCCESS); - ResultCode code = manager->ReprotectRange(Memory::HEAP_VADDR, block.GetSize(), - Kernel::VMAPermission::ReadWrite); + ResultCode code = + manager->ReprotectRange(Memory::HEAP_VADDR, static_cast(block.GetSize()), + Kernel::VMAPermission::ReadWrite); REQUIRE(code == RESULT_SUCCESS); SECTION("with invalid address") { ResultCode code = manager->ChangeMemoryState( - 0xFFFFFFFF, block.GetSize(), Kernel::MemoryState::Locked, + 0xFFFFFFFF, static_cast(block.GetSize()), Kernel::MemoryState::Locked, Kernel::VMAPermission::ReadWrite, Kernel::MemoryState::Aliased, Kernel::VMAPermission::Execute); CHECK(code == Kernel::ERR_INVALID_ADDRESS); @@ -84,7 +90,7 @@ TEST_CASE("Memory Basics", "[kernel][memory]") { SECTION("ignoring the original permissions") { ResultCode code = manager->ChangeMemoryState( - Memory::HEAP_VADDR, block.GetSize(), Kernel::MemoryState::Private, + Memory::HEAP_VADDR, static_cast(block.GetSize()), Kernel::MemoryState::Private, Kernel::VMAPermission::None, Kernel::MemoryState::Locked, Kernel::VMAPermission::Write); CHECK(code == RESULT_SUCCESS); @@ -97,7 +103,7 @@ TEST_CASE("Memory Basics", "[kernel][memory]") { SECTION("enforcing the original permissions with correct expectations") { ResultCode code = manager->ChangeMemoryState( - Memory::HEAP_VADDR, block.GetSize(), Kernel::MemoryState::Private, + Memory::HEAP_VADDR, static_cast(block.GetSize()), Kernel::MemoryState::Private, Kernel::VMAPermission::ReadWrite, Kernel::MemoryState::Aliased, Kernel::VMAPermission::Execute); CHECK(code == RESULT_SUCCESS); @@ -110,7 +116,7 @@ TEST_CASE("Memory Basics", "[kernel][memory]") { SECTION("with incorrect permission expectations") { ResultCode code = manager->ChangeMemoryState( - Memory::HEAP_VADDR, block.GetSize(), Kernel::MemoryState::Private, + Memory::HEAP_VADDR, static_cast(block.GetSize()), Kernel::MemoryState::Private, Kernel::VMAPermission::Execute, Kernel::MemoryState::Aliased, Kernel::VMAPermission::Execute); CHECK(code == Kernel::ERR_INVALID_ADDRESS_STATE); @@ -123,7 +129,7 @@ TEST_CASE("Memory Basics", "[kernel][memory]") { SECTION("with incorrect state expectations") { ResultCode code = manager->ChangeMemoryState( - Memory::HEAP_VADDR, block.GetSize(), Kernel::MemoryState::Locked, + Memory::HEAP_VADDR, static_cast(block.GetSize()), Kernel::MemoryState::Locked, Kernel::VMAPermission::ReadWrite, Kernel::MemoryState::Aliased, Kernel::VMAPermission::Execute); CHECK(code == Kernel::ERR_INVALID_ADDRESS_STATE); @@ -134,7 +140,7 @@ TEST_CASE("Memory Basics", "[kernel][memory]") { CHECK(vma->second.meminfo_state == Kernel::MemoryState::Private); } - code = manager->UnmapRange(Memory::HEAP_VADDR, block.GetSize()); + code = manager->UnmapRange(Memory::HEAP_VADDR, static_cast(block.GetSize())); REQUIRE(code == RESULT_SUCCESS); } } From 77ce1c8f14b4a603c80b27cc0d7fbb31711f377e Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 12 May 2022 00:24:20 -0400 Subject: [PATCH 7/7] CMakeLists: Enforce C4267 on MSVC --- src/CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7ec5dc26a..8aedcf489 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -33,7 +33,6 @@ if (MSVC) # /Zc:throwingNew - Let codegen assume `operator new` (without std::nothrow) will never return null # /external:* - Suppress warnings from external headers add_compile_options( - /W3 /MP /permissive- /EHsc @@ -45,6 +44,10 @@ if (MSVC) /external:I "${CMAKE_SOURCE_DIR}/externals" /external:anglebrackets /external:W0 + + # Warnings + /W3 + /we4267 # 'var': conversion from 'size_t' to 'type', possible loss of data ) # Since MSVC's debugging information is not very deterministic, so we have to disable it