Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor UB fix #6099

Merged
merged 2 commits into from Jun 16, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 14 additions & 13 deletions rpcs3/Emu/Cell/PPUThread.cpp
Expand Up @@ -169,9 +169,10 @@ static void ppu_initialize2(class jit_compiler& jit, const ppu_module& module_pa
extern void ppu_execute_syscall(ppu_thread& ppu, u64 code);

// Get pointer to executable cache
static u64& ppu_ref(u32 addr)
template<typename T = u64>
static T& ppu_ref(u32 addr)
{
return *reinterpret_cast<u64*>(vm::g_exec_addr + (u64)addr * 2);
return *reinterpret_cast<T*>(vm::g_exec_addr + (u64)addr * 2);
}

// Get interpreter cache value
Expand Down Expand Up @@ -288,7 +289,7 @@ extern void ppu_register_function_at(u32 addr, u32 size, ppu_function_t ptr)
// Initialize specific function
if (ptr)
{
*reinterpret_cast<u32*>(&ppu_ref(addr)) = ::narrow<u32>(reinterpret_cast<std::uintptr_t>(ptr));
ppu_ref<u32>(addr) = ::narrow<u32>(reinterpret_cast<std::uintptr_t>(ptr));
return;
}

Expand All @@ -312,7 +313,7 @@ extern void ppu_register_function_at(u32 addr, u32 size, ppu_function_t ptr)

while (size)
{
if ((u32)ppu_ref(addr) == fallback)
if (ppu_ref<u32>(addr) == fallback)
{
ppu_ref(addr) = ppu_cache(addr);
}
Expand Down Expand Up @@ -357,7 +358,7 @@ extern void ppu_breakpoint(u32 addr, bool isAdding)
if (isAdding)
{
// Set breakpoint
*reinterpret_cast<u32*>(&ppu_ref(addr)) = _break;
ppu_ref<u32>(addr) = _break;
}
else
{
Expand All @@ -376,9 +377,9 @@ extern void ppu_set_breakpoint(u32 addr)

const auto _break = ::narrow<u32>(reinterpret_cast<std::uintptr_t>(&ppu_break));

if ((u32)ppu_ref(addr) != _break)
if (ppu_ref<u32>(addr) != _break)
{
*reinterpret_cast<u32*>(&ppu_ref(addr)) = _break;
ppu_ref<u32>(addr) = _break;
}
}

Expand All @@ -392,7 +393,7 @@ extern void ppu_remove_breakpoint(u32 addr)

const auto _break = ::narrow<u32>(reinterpret_cast<std::uintptr_t>(&ppu_break));

if ((u32)ppu_ref(addr) == _break)
if (ppu_ref<u32>(addr) == _break)
{
ppu_ref(addr) = ppu_cache(addr);
}
Expand Down Expand Up @@ -420,7 +421,7 @@ extern bool ppu_patch(u32 addr, u32 value)
const u32 _break = ::narrow<u32>(reinterpret_cast<std::uintptr_t>(&ppu_break));
const u32 fallback = ::narrow<u32>(reinterpret_cast<std::uintptr_t>(&ppu_fallback));

if ((u32)ppu_ref(addr) != _break && (u32)ppu_ref(addr) != fallback)
if (ppu_ref<u32>(addr) != _break && ppu_ref<u32>(addr) != fallback)
{
ppu_ref(addr) = ppu_cache(addr);
}
Expand Down Expand Up @@ -622,7 +623,7 @@ void ppu_thread::exec_task()
{
while (!(state & (cpu_flag::ret + cpu_flag::exit + cpu_flag::stop + cpu_flag::dbg_global_stop)))
{
reinterpret_cast<ppu_function_t>(static_cast<std::uintptr_t>((u32)ppu_ref(cia)))(*this);
reinterpret_cast<ppu_function_t>(static_cast<std::uintptr_t>(ppu_ref<u32>(cia)))(*this);
}

return;
Expand Down Expand Up @@ -1339,7 +1340,7 @@ extern void ppu_initialize(const ppu_module& info)
if (g_cfg.core.ppu_debug && func.size && func.toc != -1)
{
s_ppu_toc->emplace(func.addr, func.toc);
*reinterpret_cast<u32*>(&ppu_ref(func.addr)) = ::narrow<u32>(reinterpret_cast<std::uintptr_t>(&ppu_check_toc));
ppu_ref<u32>(func.addr) = ::narrow<u32>(reinterpret_cast<std::uintptr_t>(&ppu_check_toc));
}
}

Expand Down Expand Up @@ -1695,7 +1696,7 @@ extern void ppu_initialize(const ppu_module& info)
{
const u64 addr = jit->get(fmt::format("__0x%x", block.first - reloc));
jit_mod.funcs.emplace_back(reinterpret_cast<ppu_function_t>(addr));
*reinterpret_cast<u32*>(&ppu_ref(block.first)) = ::narrow<u32>(addr);
ppu_ref<u32>(block.first) = ::narrow<u32>(addr);
}
}
}
Expand Down Expand Up @@ -1726,7 +1727,7 @@ extern void ppu_initialize(const ppu_module& info)
{
if (block.second)
{
*reinterpret_cast<u32*>(&ppu_ref(block.first)) = ::narrow<u32>(reinterpret_cast<uptr>(jit_mod.funcs[index++]));
ppu_ref<u32>(block.first) = ::narrow<u32>(reinterpret_cast<uptr>(jit_mod.funcs[index++]));
}
}
}
Expand Down