vm: Make falloc return value bool

Allow to check properly for the success of 0 address allocation.
This commit is contained in:
Eladash
2021-10-16 12:13:29 +03:00
committed by Ivan
parent 653a9e6e7f
commit 64399d45c1
5 changed files with 33 additions and 16 deletions
+7 -3
View File
@@ -1423,6 +1423,11 @@ bool handle_access_violation(u32 addr, bool is_writing, ucontext_t* context) noe
{
g_tls_access_violation_recovered = true;
if (vm::check_addr(addr, is_writing ? vm::page_writable : vm::page_readable))
{
return true;
}
const auto area = vm::reserve_map(vm::any, addr & -0x10000, 0x10000);
if (!area)
@@ -1430,15 +1435,14 @@ bool handle_access_violation(u32 addr, bool is_writing, ucontext_t* context) noe
return false;
}
if (vm::writer_lock mlock; vm::check_addr(addr, 0))
if (vm::writer_lock mlock; area->flags & vm::preallocated || vm::check_addr(addr, 0))
{
// For allocated memory with protection lower than required (such as protection::no or read-only while writing to it)
utils::memory_protect(vm::base(addr & -0x1000), 0x1000, utils::protection::rw);
return true;
}
area->falloc(addr & -0x10000, 0x10000);
return vm::check_addr(addr, is_writing ? vm::page_writable : vm::page_readable);
return area->falloc(addr & -0x10000, 0x10000) || vm::check_addr(addr, is_writing ? vm::page_writable : vm::page_readable);
};
if (cpu && (cpu->id_type() == 1 || cpu->id_type() == 2))
+14 -1
View File
@@ -610,8 +610,21 @@ static usz apply_modification(std::basic_string<u32>& applied, const patch_engin
if (alloc_map)
{
if ((p.alloc_addr = alloc_map->falloc(alloc_at, alloc_size, nullptr, flags)))
if (alloc_map->falloc(alloc_at, alloc_size, nullptr, flags))
{
if (vm::check_addr(alloc_at, vm::page_1m_size))
{
p.alloc_addr = alloc_at & -0x100000;
}
else if (vm::check_addr(alloc_at, vm::page_64k_size))
{
p.alloc_addr = alloc_at & -0x10000;
}
else
{
p.alloc_addr = alloc_at & -0x1000;
}
if (flags & vm::alloc_executable)
{
ppu_register_range(alloc_at, alloc_size);