mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2024-12-28 18:46:06 +00:00
memory: Handle 0 alignment in MemoryManager::Allocate (#1692)
This commit is contained in:
parent
aa5293e3ad
commit
bf41ab6c40
|
@ -96,12 +96,12 @@ PAddr MemoryManager::PoolExpand(PAddr search_start, PAddr search_end, size_t siz
|
||||||
PAddr MemoryManager::Allocate(PAddr search_start, PAddr search_end, size_t size, u64 alignment,
|
PAddr MemoryManager::Allocate(PAddr search_start, PAddr search_end, size_t size, u64 alignment,
|
||||||
int memory_type) {
|
int memory_type) {
|
||||||
std::scoped_lock lk{mutex};
|
std::scoped_lock lk{mutex};
|
||||||
|
alignment = alignment > 0 ? alignment : 16_KB;
|
||||||
|
|
||||||
auto dmem_area = FindDmemArea(search_start);
|
auto dmem_area = FindDmemArea(search_start);
|
||||||
|
|
||||||
const auto is_suitable = [&] {
|
const auto is_suitable = [&] {
|
||||||
const auto aligned_base = alignment > 0 ? Common::AlignUp(dmem_area->second.base, alignment)
|
const auto aligned_base = Common::AlignUp(dmem_area->second.base, alignment);
|
||||||
: dmem_area->second.base;
|
|
||||||
const auto alignment_size = aligned_base - dmem_area->second.base;
|
const auto alignment_size = aligned_base - dmem_area->second.base;
|
||||||
const auto remaining_size =
|
const auto remaining_size =
|
||||||
dmem_area->second.size >= alignment_size ? dmem_area->second.size - alignment_size : 0;
|
dmem_area->second.size >= alignment_size ? dmem_area->second.size - alignment_size : 0;
|
||||||
|
@ -114,7 +114,7 @@ PAddr MemoryManager::Allocate(PAddr search_start, PAddr search_end, size_t size,
|
||||||
|
|
||||||
// Align free position
|
// Align free position
|
||||||
PAddr free_addr = dmem_area->second.base;
|
PAddr free_addr = dmem_area->second.base;
|
||||||
free_addr = alignment > 0 ? Common::AlignUp(free_addr, alignment) : free_addr;
|
free_addr = Common::AlignUp(free_addr, alignment);
|
||||||
|
|
||||||
// Add the allocated region to the list and commit its pages.
|
// Add the allocated region to the list and commit its pages.
|
||||||
auto& area = CarveDmemArea(free_addr, size)->second;
|
auto& area = CarveDmemArea(free_addr, size)->second;
|
||||||
|
|
Loading…
Reference in a new issue