Isolate memory manager

This commit is contained in:
momo5502
2025-02-09 17:52:47 +01:00
parent 11dbe6dfc1
commit 6263353438
19 changed files with 983 additions and 924 deletions

View File

@@ -704,8 +704,8 @@ namespace
{
constexpr auto shared_section_size = 0x10000;
const auto address = c.emu.find_free_allocation_base(shared_section_size);
c.emu.allocate_memory(address, shared_section_size, memory_permission::read_write);
const auto address = c.win_emu.memory().find_free_allocation_base(shared_section_size);
c.win_emu.memory().allocate_memory(address, shared_section_size, memory_permission::read_write);
const std::u16string_view windows_dir = c.proc.kusd.get().NtSystemRoot.arr;
const auto windows_dir_size = windows_dir.size() * 2;
@@ -789,7 +789,7 @@ namespace
}
const auto protection = map_nt_to_emulator_protection(section_entry->section_page_protection);
const auto address = c.emu.allocate_memory(size, protection);
const auto address = c.win_emu.memory().allocate_memory(size, protection);
if (!file_data.empty())
{
@@ -850,7 +850,7 @@ namespace
const emulator_object<EMU_MEMORY_BASIC_INFORMATION64> info{c.emu, memory_information};
info.access([&](EMU_MEMORY_BASIC_INFORMATION64& image_info) {
const auto region_info = c.emu.get_region_info(base_address);
const auto region_info = c.win_emu.memory().get_region_info(base_address);
assert(!region_info.is_committed || region_info.is_reserved);
@@ -910,7 +910,7 @@ namespace
return STATUS_BUFFER_OVERFLOW;
}
const auto region_info = c.emu.get_region_info(base_address);
const auto region_info = c.win_emu.memory().get_region_info(base_address);
if (!region_info.is_reserved)
{
return STATUS_INVALID_ADDRESS;
@@ -2015,7 +2015,8 @@ namespace
try
{
c.emu.protect_memory(aligned_start, aligned_length, requested_protection, &old_protection_value);
c.win_emu.memory().protect_memory(aligned_start, aligned_length, requested_protection,
&old_protection_value);
}
catch (...)
{
@@ -2117,7 +2118,7 @@ namespace
auto potential_base = base_address.read();
if (!potential_base)
{
potential_base = c.emu.find_free_allocation_base(allocation_bytes);
potential_base = c.win_emu.memory().find_free_allocation_base(allocation_bytes);
}
if (!potential_base)
@@ -2137,7 +2138,7 @@ namespace
throw std::runtime_error("Unsupported allocation type!");
}
if (commit && !reserve && c.emu.commit_memory(potential_base, allocation_bytes, protection))
if (commit && !reserve && c.win_emu.memory().commit_memory(potential_base, allocation_bytes, protection))
{
c.win_emu.log.print(color::dark_gray, "--> Committed 0x%" PRIx64 " - 0x%" PRIx64 "\n", potential_base,
potential_base + allocation_bytes);
@@ -2148,7 +2149,7 @@ namespace
c.win_emu.log.print(color::dark_gray, "--> Allocated 0x%" PRIx64 " - 0x%" PRIx64 "\n", potential_base,
potential_base + allocation_bytes);
return c.emu.allocate_memory(potential_base, allocation_bytes, protection, !commit)
return c.win_emu.memory().allocate_memory(potential_base, allocation_bytes, protection, !commit)
? STATUS_SUCCESS
: STATUS_MEMORY_NOT_ALLOCATED;
}
@@ -2176,14 +2177,14 @@ namespace
if (free_type & MEM_RELEASE)
{
return c.emu.release_memory(allocation_base, allocation_size) ? STATUS_SUCCESS
: STATUS_MEMORY_NOT_ALLOCATED;
return c.win_emu.memory().release_memory(allocation_base, allocation_size) ? STATUS_SUCCESS
: STATUS_MEMORY_NOT_ALLOCATED;
}
if (free_type & MEM_DECOMMIT)
{
return c.emu.decommit_memory(allocation_base, allocation_size) ? STATUS_SUCCESS
: STATUS_MEMORY_NOT_ALLOCATED;
return c.win_emu.memory().decommit_memory(allocation_base, allocation_size) ? STATUS_SUCCESS
: STATUS_MEMORY_NOT_ALLOCATED;
}
throw std::runtime_error("Bad free type");
@@ -2260,7 +2261,7 @@ namespace
}
client_shared_memory.access([&](PORT_VIEW64& view) {
p.view_base = c.emu.allocate_memory(view.ViewSize, memory_permission::read_write);
p.view_base = c.win_emu.memory().allocate_memory(view.ViewSize, memory_permission::read_write);
view.ViewBase = p.view_base;
view.ViewRemoteBase = view.ViewBase;
});
@@ -2752,7 +2753,7 @@ namespace
}
const auto size = page_align_up(locale_file.size());
const auto base = c.emu.allocate_memory(size, memory_permission::read);
const auto base = c.win_emu.memory().allocate_memory(size, memory_permission::read);
c.emu.write_memory(base, locale_file.data(), locale_file.size());
base_address.write(base);
@@ -3445,7 +3446,7 @@ namespace
return STATUS_NOT_SUPPORTED;
}
const auto h = c.proc.create_thread(c.emu, start_routine, argument, stack_size);
const auto h = c.proc.create_thread(c.win_emu.memory(), start_routine, argument, stack_size);
thread_handle.write(h);
if (!attribute_list)