diff --git a/rpcs3/Emu/Cell/Modules/cellPad.cpp b/rpcs3/Emu/Cell/Modules/cellPad.cpp index be14426db5..02a1646aae 100644 --- a/rpcs3/Emu/Cell/Modules/cellPad.cpp +++ b/rpcs3/Emu/Cell/Modules/cellPad.cpp @@ -73,7 +73,7 @@ void pad_info::save(utils::serial& ar) extern void send_sys_io_connect_event(usz index, u32 state); -void cellPad_NotifyStateChange(usz index, u32 /*state*/) +void cellPad_NotifyStateChange(usz index, u64 /*state*/) { auto info = g_fxo->try_get(); diff --git a/rpcs3/Emu/Cell/Modules/sys_io_.cpp b/rpcs3/Emu/Cell/Modules/sys_io_.cpp index ec43e5bc43..814b8b61b9 100644 --- a/rpcs3/Emu/Cell/Modules/sys_io_.cpp +++ b/rpcs3/Emu/Cell/Modules/sys_io_.cpp @@ -36,7 +36,7 @@ extern void sys_io_serialize(utils::serial& ar) g_fxo->get().save_or_load(ar); } -extern void cellPad_NotifyStateChange(usz index, u32 state); +extern void cellPad_NotifyStateChange(usz index, u64 state); void config_event_entry(ppu_thread& ppu) { diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index 62094955b1..b50dc913c2 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -1624,7 +1624,7 @@ std::vector> ppu_thread::dump_callstack_list() const inst_neg.resize(new_size); - if (!vm::try_access(inst_bound, &inst_neg[old_size], (new_size - old_size) * sizeof(be_t), false)) + if (!vm::try_access(inst_bound, &inst_neg[old_size], ::narrow((new_size - old_size) * sizeof(be_t)), false)) { // Failure (this would be detected as failure by zeroes) } @@ -1657,7 +1657,7 @@ std::vector> ppu_thread::dump_callstack_list() const inst_pos.resize(new_size); - if (!vm::try_access(pos, &inst_pos[old_size], (new_size - old_size) * sizeof(be_t), false)) + if (!vm::try_access(pos, &inst_pos[old_size], ::narrow((new_size - old_size) * sizeof(be_t)), false)) { // Failure (this would be detected as failure by zeroes) } @@ -3830,7 +3830,7 @@ extern void ppu_precompile(std::vector& dir_queue, std::vector& dir_queue, std::vectorfin(); } - usz index = 0; - usz max_count = 0; + u32 index = 0; + u32 max_count = 0; for (const auto& func : info.funcs) { @@ -4849,7 +4850,7 @@ bool ppu_initialize(const ppu_module& info, bool check_only, u64 file_size) } } - usz pending_progress = umax; + u32 pending_progress = umax; bool early_exit = false; diff --git a/rpcs3/Emu/Cell/PPUTranslator.cpp b/rpcs3/Emu/Cell/PPUTranslator.cpp index c0a55da26d..8072219c94 100644 --- a/rpcs3/Emu/Cell/PPUTranslator.cpp +++ b/rpcs3/Emu/Cell/PPUTranslator.cpp @@ -152,9 +152,9 @@ Function* PPUTranslator::Translate(const ppu_function& info) // Don't emit check in small blocks without terminator bool need_check = info.size >= 16; - for (u32 addr = m_addr; addr < m_addr + info.size; addr += 4) + for (u64 addr = m_addr; addr < m_addr + info.size; addr += 4) { - const u32 op = *ensure(m_info.get_ptr(addr + base)); + const u32 op = *ensure(m_info.get_ptr(::narrow(addr + base))); switch (g_ppu_itype.decode(op)) { @@ -250,7 +250,7 @@ Function* PPUTranslator::Translate(const ppu_function& info) // Reset MMIO hint m_may_be_mmio = true; - const u32 op = *ensure(m_info.get_ptr(m_addr + base)); + const u32 op = *ensure(m_info.get_ptr(::narrow(m_addr + base))); (this->*(s_ppu_decoder.decode(op)))({op}); @@ -368,11 +368,11 @@ void PPUTranslator::CallFunction(u64 target, Value* indirect) const u64 base = m_reloc ? m_reloc->addr : 0; const u32 caddr = m_info.segs[0].addr; const u32 cend = caddr + m_info.segs[0].size - 1; - const u64 _target = target + base; + const u32 _target = ::narrow(target + base); if (_target >= caddr && _target <= cend) { - std::unordered_set passed_targets{_target}; + std::unordered_set passed_targets{_target}; u32 target_last = _target; @@ -663,7 +663,7 @@ Value* PPUTranslator::ReadMemory(Value* addr, Type* type, bool is_be, u32 align) m_may_be_mmio = false; - if (auto ptr = m_info.get_ptr(std::max(m_info.segs[0].addr, (m_reloc ? m_reloc->addr : 0) + utils::sub_saturate(m_addr, sizeof(instructions_to_test) / 2)))) + if (auto ptr = m_info.get_ptr(std::max(m_info.segs[0].addr, (m_reloc ? m_reloc->addr : 0) + utils::sub_saturate(::narrow(m_addr), sizeof(instructions_to_test) / 2)))) { if (ppu_test_address_may_be_mmio(std::span(ptr->insts))) { @@ -726,11 +726,11 @@ void PPUTranslator::WriteMemory(Value* addr, Value* value, bool is_be, u32 align be_t insts[128]; }; - if (auto ptr = m_info.get_ptr(std::max(m_info.segs[0].addr, (m_reloc ? m_reloc->addr : 0) + utils::sub_saturate(m_addr, sizeof(instructions_to_test) / 2)))) + if (auto ptr = m_info.get_ptr(std::max(m_info.segs[0].addr, (m_reloc ? m_reloc->addr : 0) + utils::sub_saturate(::narrow(m_addr), sizeof(instructions_to_test) / 2)))) { if (ppu_test_address_may_be_mmio(std::span(ptr->insts))) { - ppu_log.notice("LLVM: Detected potential MMIO32 write at [0x%08x]", m_addr + (m_reloc ? m_reloc->addr : 0)); + ppu_log.notice("LLVM: Detected potential MMIO32 write at [0x%08x]", m_addr + m_reloc ? m_reloc->addr : 0); Call(GetType(), "__write_maybe_mmio32", m_base, addr, value); return; } @@ -1056,7 +1056,7 @@ void PPUTranslator::VMADDFP(ppu_opcode_t op) auto [a, b, c] = get_vrs(op.va, op.vb, op.vc); // Optimization: Emit only a floating multiply if the addend is zero - if (auto [ok, data] = get_const_vector(b.value, m_addr); ok) + if (auto [ok, data] = get_const_vector(b.value, ::narrow(m_addr)); ok) { if (data == v128::from32p(1u << 31)) { @@ -1348,7 +1348,7 @@ void PPUTranslator::VNMSUBFP(ppu_opcode_t op) auto [a, b, c] = get_vrs(op.va, op.vb, op.vc); // Optimization: Emit only a floating multiply if the addend is zero - if (const auto [ok, data] = get_const_vector(b.value, m_addr); ok) + if (const auto [ok, data] = get_const_vector(b.value, ::narrow(m_addr)); ok) { if (data == v128{}) { @@ -1552,7 +1552,7 @@ void PPUTranslator::VSEL(ppu_opcode_t op) const auto c = get_vr(op.vc); // Check if the constant mask doesn't require bit granularity - if (auto [ok, mask] = get_const_vector(c.value, m_addr); ok) + if (auto [ok, mask] = get_const_vector(c.value, ::narrow(m_addr)); ok) { bool sel_32 = true; for (u32 i = 0; i < 4; i++) @@ -3671,7 +3671,7 @@ void PPUTranslator::LWZ(ppu_opcode_t op) }; // Quick invalidation: expect exact MMIO address, so if the register is being reused with different offset than it's likely not MMIO - if (auto ptr = m_info.get_ptr(m_addr + 4 + (m_reloc ? m_reloc->addr : 0))) + if (auto ptr = m_info.get_ptr(::narrow(m_addr + 4 + (m_reloc ? m_reloc->addr : 0)))) { for (u32 inst : ptr->insts) { @@ -3774,7 +3774,7 @@ void PPUTranslator::STW(ppu_opcode_t op) }; // Quick invalidation: expect exact MMIO address, so if the register is being reused with different offset than it's likely not MMIO - if (auto ptr = m_info.get_ptr(m_addr + 4 + (m_reloc ? m_reloc->addr : 0))) + if (auto ptr = m_info.get_ptr(::narrow(m_addr + 4 + (m_reloc ? m_reloc->addr : 0)))) { for (u32 inst : ptr->insts) { diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index e347b7635d..140c7c67ac 100644 --- a/rpcs3/Emu/Cell/SPUThread.cpp +++ b/rpcs3/Emu/Cell/SPUThread.cpp @@ -6193,7 +6193,7 @@ spu_exec_object spu_thread::capture_memory_as_elf(std::span(a3), get_timebased_time()); // a4 is a pointer to status, non 0 on error - vm::write64(a4, 0); + vm::write64(::narrow(a4), 0); return CELL_OK; } else if (cmd == 0x3003) diff --git a/rpcs3/Emu/Memory/vm.cpp b/rpcs3/Emu/Memory/vm.cpp index a05cd65d87..ed0775d85f 100644 --- a/rpcs3/Emu/Memory/vm.cpp +++ b/rpcs3/Emu/Memory/vm.cpp @@ -492,7 +492,7 @@ namespace vm const auto diff = range_lock - g_range_lock_set; - if (bits != umax && !bits.bit_test_set(diff)) + if (bits != umax && !bits.bit_test_set(::narrow(diff))) { break; } @@ -557,7 +557,7 @@ namespace vm for (u64 hi = addr2 >> 16, max = (addr2 + size2 - 1) >> 16; hi <= max; hi++) { u64 addr3 = addr2; - u32 size3 = std::min(addr2 + size2, utils::align(addr2, 0x10000)) - addr2; + u64 size3 = std::min(addr2 + size2, utils::align(addr2, 0x10000)) - addr2; if (u64 is_shared = g_shmem[hi]) [[unlikely]] { @@ -2405,8 +2405,10 @@ void fmt_class_string>::format(std::string& out, return; } + const u32 addr = ::narrow(arg); + // Filter certainly invalid addresses - if (!vm::check_addr(arg, vm::page_readable)) + if (!vm::check_addr(addr, vm::page_readable)) { out += reinterpret_cast(u8"«INVALID_ADDRESS:"); fmt_class_string::format(out, arg); @@ -2418,7 +2420,7 @@ void fmt_class_string>::format(std::string& out, out += reinterpret_cast(u8"“"); - if (!vm::read_string(arg, umax, out, true)) + if (!vm::read_string(addr, umax, out, true)) { // Revert changes out.resize(start); diff --git a/rpcs3/Emu/RSX/Common/BufferUtils.cpp b/rpcs3/Emu/RSX/Common/BufferUtils.cpp index a624a6d4b8..5d404aeeb8 100644 --- a/rpcs3/Emu/RSX/Common/BufferUtils.cpp +++ b/rpcs3/Emu/RSX/Common/BufferUtils.cpp @@ -295,8 +295,8 @@ namespace r = upload_untouched_naive(src.data(), dst.data(), count); #endif - min_index = r; - max_index = r >> 32; + min_index = ::narrow(r); + max_index = ::narrow(r >> 32); return std::make_tuple(min_index, max_index, count); } @@ -401,8 +401,8 @@ namespace r = upload_untouched_naive(src.data(), dst.data(), count, restart_index); #endif - min_index = r; - max_index = r >> 32; + min_index = ::narrow(r); + max_index = ::narrow(r >> 32); return std::make_tuple(min_index, max_index, count); } diff --git a/rpcs3/Emu/RSX/RSXThread.cpp b/rpcs3/Emu/RSX/RSXThread.cpp index de304799b8..c8bc3c9528 100644 --- a/rpcs3/Emu/RSX/RSXThread.cpp +++ b/rpcs3/Emu/RSX/RSXThread.cpp @@ -3182,7 +3182,7 @@ namespace rsx if (count < 0) { - const u32 found_cmds_count = std::min(-count, ::size32(pcs_of_valid_cmds) - 1 - index_of_get); + const u32 found_cmds_count = static_cast(std::min(-count, pcs_of_valid_cmds.size() - 1LL - index_of_get)); return {found_cmds_count, pcs_of_valid_cmds[index_of_get + found_cmds_count]}; } diff --git a/rpcs3/util/vm_native.cpp b/rpcs3/util/vm_native.cpp index 6474ef68fd..87a1781f34 100644 --- a/rpcs3/util/vm_native.cpp +++ b/rpcs3/util/vm_native.cpp @@ -464,7 +464,7 @@ namespace utils , m_size(utils::align(size, 0x10000)) { #ifdef _WIN32 - m_handle = ensure(::CreateFileMappingW(INVALID_HANDLE_VALUE, nullptr, PAGE_EXECUTE_READWRITE, 0, m_size, nullptr)); + m_handle = ensure(::CreateFileMappingW(INVALID_HANDLE_VALUE, nullptr, PAGE_EXECUTE_READWRITE, 0, ::narrow(m_size), nullptr)); #elif defined(__linux__) || defined(__FreeBSD__) m_file = -1;