From 0f67c689939f035c926dba7f772c89e32295db5d Mon Sep 17 00:00:00 2001 From: Eladash Date: Sat, 26 Sep 2020 20:06:06 +0300 Subject: [PATCH] sys_mmapper: return ENOMEM on memory greater than UINT32_MAX (#8982) --- rpcs3/Emu/Cell/lv2/sys_memory.h | 7 ++++--- rpcs3/Emu/Cell/lv2/sys_mmapper.cpp | 28 ++++++++++++++-------------- rpcs3/Emu/Cell/lv2/sys_mmapper.h | 8 ++++---- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/rpcs3/Emu/Cell/lv2/sys_memory.h b/rpcs3/Emu/Cell/lv2/sys_memory.h index dcf4c66f1a..a6cb319357 100644 --- a/rpcs3/Emu/Cell/lv2/sys_memory.h +++ b/rpcs3/Emu/Cell/lv2/sys_memory.h @@ -59,14 +59,15 @@ struct lv2_memory_container } // Try to get specified amount of "physical" memory - u32 take(u32 amount) + // Values greater than UINT32_MAX will fail + u32 take(u64 amount) { auto [_, result] = used.fetch_op([&](u32& value) -> u32 { if (size - value >= amount) { - value += amount; - return amount; + value += static_cast(amount); + return static_cast(amount); } return 0; diff --git a/rpcs3/Emu/Cell/lv2/sys_mmapper.cpp b/rpcs3/Emu/Cell/lv2/sys_mmapper.cpp index 84eb52b643..d04a1a9c26 100644 --- a/rpcs3/Emu/Cell/lv2/sys_mmapper.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_mmapper.cpp @@ -24,12 +24,12 @@ lv2_memory::lv2_memory(u32 size, u32 align, u64 flags, lv2_memory_container* ct) template<> DECLARE(ipc_manager::g_ipc) {}; template -error_code create_lv2_shm(bool pshared, u64 ipc_key, u32 size, u32 align, u64 flags, lv2_memory_container* ct) +error_code create_lv2_shm(bool pshared, u64 ipc_key, u64 size, u32 align, u64 flags, lv2_memory_container* ct) { if (auto error = lv2_obj::create(pshared ? SYS_SYNC_PROCESS_SHARED : SYS_SYNC_NOT_PROCESS_SHARED, ipc_key, exclusive ? SYS_SYNC_NEWLY_CREATED : SYS_SYNC_NOT_CARE, [&]() { return std::make_shared( - size, + static_cast(size), align, flags, ct); @@ -45,7 +45,7 @@ error_code sys_mmapper_allocate_address(ppu_thread& ppu, u64 size, u64 flags, u6 { ppu.state += cpu_flag::wait; - sys_mmapper.error("sys_mmapper_allocate_address(size=0x%llx, flags=0x%llx, alignment=0x%llx, alloc_addr=*0x%x)", size, flags, alignment, alloc_addr); + sys_mmapper.error("sys_mmapper_allocate_address(size=0x%x, flags=0x%x, alignment=0x%x, alloc_addr=*0x%x)", size, flags, alignment, alloc_addr); if (size % 0x10000000) { @@ -98,11 +98,11 @@ error_code sys_mmapper_allocate_fixed_address(ppu_thread& ppu) return CELL_OK; } -error_code sys_mmapper_allocate_shared_memory(ppu_thread& ppu, u64 ipc_key, u32 size, u64 flags, vm::ptr mem_id) +error_code sys_mmapper_allocate_shared_memory(ppu_thread& ppu, u64 ipc_key, u64 size, u64 flags, vm::ptr mem_id) { ppu.state += cpu_flag::wait; - sys_mmapper.warning("sys_mmapper_allocate_shared_memory(ipc_key=0x%llx, size=0x%x, flags=0x%llx, mem_id=*0x%x)", ipc_key, size, flags, mem_id); + sys_mmapper.warning("sys_mmapper_allocate_shared_memory(ipc_key=0x%x, size=0x%x, flags=0x%x, mem_id=*0x%x)", ipc_key, size, flags, mem_id); if (size == 0) { @@ -155,11 +155,11 @@ error_code sys_mmapper_allocate_shared_memory(ppu_thread& ppu, u64 ipc_key, u32 return CELL_OK; } -error_code sys_mmapper_allocate_shared_memory_from_container(ppu_thread& ppu, u64 ipc_key, u32 size, u32 cid, u64 flags, vm::ptr mem_id) +error_code sys_mmapper_allocate_shared_memory_from_container(ppu_thread& ppu, u64 ipc_key, u64 size, u32 cid, u64 flags, vm::ptr mem_id) { ppu.state += cpu_flag::wait; - sys_mmapper.warning("sys_mmapper_allocate_shared_memory_from_container(ipc_key=0x%llx, size=0x%x, cid=0x%x, flags=0x%llx, mem_id=*0x%x)", ipc_key, size, cid, flags, mem_id); + sys_mmapper.warning("sys_mmapper_allocate_shared_memory_from_container(ipc_key=0x%x, size=0x%x, cid=0x%x, flags=0x%x, mem_id=*0x%x)", ipc_key, size, cid, flags, mem_id); if (size == 0) { @@ -225,7 +225,7 @@ error_code sys_mmapper_allocate_shared_memory_from_container(ppu_thread& ppu, u6 return CELL_OK; } -error_code sys_mmapper_allocate_shared_memory_ext(ppu_thread& ppu, u64 ipc_key, u32 size, u32 flags, vm::ptr entries, s32 entry_count, vm::ptr mem_id) +error_code sys_mmapper_allocate_shared_memory_ext(ppu_thread& ppu, u64 ipc_key, u64 size, u32 flags, vm::ptr entries, s32 entry_count, vm::ptr mem_id) { ppu.state += cpu_flag::wait; @@ -280,7 +280,7 @@ error_code sys_mmapper_allocate_shared_memory_ext(ppu_thread& ppu, u64 ipc_key, const u64 type = entries[i].type; // The whole structure contents are unknown - sys_mmapper.todo("sys_mmapper_allocate_shared_memory_ext(): entry type = 0x%llx", type); + sys_mmapper.todo("sys_mmapper_allocate_shared_memory_ext(): entry type = 0x%x", type); switch (type) { @@ -329,7 +329,7 @@ error_code sys_mmapper_allocate_shared_memory_ext(ppu_thread& ppu, u64 ipc_key, return CELL_OK; } -error_code sys_mmapper_allocate_shared_memory_from_container_ext(ppu_thread& ppu, u64 ipc_key, u32 size, u64 flags, u32 cid, vm::ptr entries, s32 entry_count, vm::ptr mem_id) +error_code sys_mmapper_allocate_shared_memory_from_container_ext(ppu_thread& ppu, u64 ipc_key, u64 size, u64 flags, u32 cid, vm::ptr entries, s32 entry_count, vm::ptr mem_id) { ppu.state += cpu_flag::wait; @@ -379,7 +379,7 @@ error_code sys_mmapper_allocate_shared_memory_from_container_ext(ppu_thread& ppu { const u64 type = entries[i].type; - sys_mmapper.todo("sys_mmapper_allocate_shared_memory_from_container_ext(): entry type = 0x%llx", type); + sys_mmapper.todo("sys_mmapper_allocate_shared_memory_from_container_ext(): entry type = 0x%x", type); switch (type) { @@ -445,7 +445,7 @@ error_code sys_mmapper_change_address_access_right(ppu_thread& ppu, u32 addr, u6 { ppu.state += cpu_flag::wait; - sys_mmapper.todo("sys_mmapper_change_address_access_right(addr=0x%x, flags=0x%llx)", addr, flags); + sys_mmapper.todo("sys_mmapper_change_address_access_right(addr=0x%x, flags=0x%x)", addr, flags); return CELL_OK; } @@ -544,7 +544,7 @@ error_code sys_mmapper_map_shared_memory(ppu_thread& ppu, u32 addr, u32 mem_id, { ppu.state += cpu_flag::wait; - sys_mmapper.warning("sys_mmapper_map_shared_memory(addr=0x%x, mem_id=0x%x, flags=0x%llx)", addr, mem_id, flags); + sys_mmapper.warning("sys_mmapper_map_shared_memory(addr=0x%x, mem_id=0x%x, flags=0x%x)", addr, mem_id, flags); const auto area = vm::get(vm::any, addr); @@ -594,7 +594,7 @@ error_code sys_mmapper_search_and_map(ppu_thread& ppu, u32 start_addr, u32 mem_i { ppu.state += cpu_flag::wait; - sys_mmapper.warning("sys_mmapper_search_and_map(start_addr=0x%x, mem_id=0x%x, flags=0x%llx, alloc_addr=*0x%x)", start_addr, mem_id, flags, alloc_addr); + sys_mmapper.warning("sys_mmapper_search_and_map(start_addr=0x%x, mem_id=0x%x, flags=0x%x, alloc_addr=*0x%x)", start_addr, mem_id, flags, alloc_addr); const auto area = vm::get(vm::any, start_addr); diff --git a/rpcs3/Emu/Cell/lv2/sys_mmapper.h b/rpcs3/Emu/Cell/lv2/sys_mmapper.h index 053b920a40..e3d1fe093b 100644 --- a/rpcs3/Emu/Cell/lv2/sys_mmapper.h +++ b/rpcs3/Emu/Cell/lv2/sys_mmapper.h @@ -80,10 +80,10 @@ error_code mmapper_thread_recover_page_fault(cpu_thread* cpu); // SysCalls error_code sys_mmapper_allocate_address(ppu_thread&, u64 size, u64 flags, u64 alignment, vm::ptr alloc_addr); error_code sys_mmapper_allocate_fixed_address(ppu_thread&); -error_code sys_mmapper_allocate_shared_memory(ppu_thread&, u64 ipc_key, u32 size, u64 flags, vm::ptr mem_id); -error_code sys_mmapper_allocate_shared_memory_from_container(ppu_thread&, u64 ipc_key, u32 size, u32 cid, u64 flags, vm::ptr mem_id); -error_code sys_mmapper_allocate_shared_memory_ext(ppu_thread&, u64 ipc_key, u32 size, u32 flags, vm::ptr src, s32 count, vm::ptr mem_id); -error_code sys_mmapper_allocate_shared_memory_from_container_ext(ppu_thread&, u64 ipc_key, u32 size, u64 flags, u32 mc_id, vm::ptr entries, s32 entry_count, vm::ptr mem_id); +error_code sys_mmapper_allocate_shared_memory(ppu_thread&, u64 ipc_key, u64 size, u64 flags, vm::ptr mem_id); +error_code sys_mmapper_allocate_shared_memory_from_container(ppu_thread&, u64 ipc_key, u64 size, u32 cid, u64 flags, vm::ptr mem_id); +error_code sys_mmapper_allocate_shared_memory_ext(ppu_thread&, u64 ipc_key, u64 size, u32 flags, vm::ptr src, s32 count, vm::ptr mem_id); +error_code sys_mmapper_allocate_shared_memory_from_container_ext(ppu_thread&, u64 ipc_key, u64 size, u64 flags, u32 mc_id, vm::ptr entries, s32 entry_count, vm::ptr mem_id); error_code sys_mmapper_change_address_access_right(ppu_thread&, u32 addr, u64 flags); error_code sys_mmapper_free_address(ppu_thread&, u32 addr); error_code sys_mmapper_free_shared_memory(ppu_thread&, u32 mem_id);