Always allocate system heap from top of heap

This commit is contained in:
Gliniak 2022-02-14 19:26:31 +01:00
parent dde8adc140
commit 3d96dfa359
4 changed files with 23 additions and 8 deletions

View File

@ -535,8 +535,7 @@ const std::filesystem::path Emulator::GetNewDiscPath(
{"All Files (*.*)", "*.*"},
});
if (file_picker->Show(
kernel_state()->emulator()->display_window()->native_handle())) {
if (file_picker->Show()) {
auto selected_files = file_picker->selected_files();
if (!selected_files.empty()) {
path = selected_files[0];

View File

@ -443,9 +443,9 @@ typedef struct {
} X_SWAPDISC_ERROR_MESSAGE;
static_assert_size(X_SWAPDISC_ERROR_MESSAGE, 12);
dword_result_t XamSwapDisc(dword_t disc_number,
pointer_t<X_KEVENT> completion_handle,
pointer_t<X_SWAPDISC_ERROR_MESSAGE> error_message) {
dword_result_t XamSwapDisc_entry(
dword_t disc_number, pointer_t<X_KEVENT> completion_handle,
pointer_t<X_SWAPDISC_ERROR_MESSAGE> error_message) {
xex2_opt_execution_info* info = nullptr;
kernel_state()->GetExecutableModule()->GetOptHeader(XEX_HEADER_EXECUTION_INFO,

View File

@ -555,7 +555,7 @@ uint32_t Memory::SystemHeapAlloc(uint32_t size, uint32_t alignment,
uint32_t address;
if (!heap->AllocSystemHeap(
size, alignment, kMemoryAllocationReserve | kMemoryAllocationCommit,
kMemoryProtectRead | kMemoryProtectWrite, false, &address)) {
kMemoryProtectRead | kMemoryProtectWrite, true, &address)) {
return 0;
}
Zero(address, size);
@ -823,10 +823,14 @@ bool BaseHeap::Alloc(uint32_t size, uint32_t alignment,
*out_address = 0;
size = xe::round_up(size, page_size_);
alignment = xe::round_up(alignment, page_size_);
uint32_t heap_virtual_guest_offset = 0;
if (heap_type_ == HeapType::kGuestVirtual) {
heap_virtual_guest_offset = 0x10000000;
}
uint32_t low_address = heap_base_;
uint32_t high_address =
heap_base_ + (heap_size_ - 1) -
(heap_type_ == HeapType::kGuestVirtual ? 0x10000000 : 0);
heap_base_ + (heap_size_ - 1) - heap_virtual_guest_offset;
return AllocRange(low_address, high_address, size, alignment, allocation_type,
protect, top_down, out_address);
}
@ -1523,6 +1527,12 @@ bool PhysicalHeap::AllocRange(uint32_t low_address, uint32_t high_address,
return true;
}
bool PhysicalHeap::AllocSystemHeap(uint32_t size, uint32_t alignment,
uint32_t allocation_type, uint32_t protect,
bool top_down, uint32_t* out_address) {
return Alloc(size, alignment, allocation_type, protect, top_down, out_address);
}
bool PhysicalHeap::Decommit(uint32_t address, uint32_t size) {
auto global_lock = global_critical_region_.Acquire();

View File

@ -165,6 +165,9 @@ class BaseHeap {
uint32_t allocation_type, uint32_t protect,
bool top_down, uint32_t* out_address);
virtual bool AllocSystemHeap(uint32_t size, uint32_t alignment,
uint32_t allocation_type, uint32_t protect,
bool top_down, uint32_t* out_address);
// Decommits pages in the given range.
// Partial overlapping pages will also be decommitted.
virtual bool Decommit(uint32_t address, uint32_t size);
@ -255,6 +258,9 @@ class PhysicalHeap : public BaseHeap {
uint32_t alignment, uint32_t allocation_type,
uint32_t protect, bool top_down,
uint32_t* out_address) override;
bool AllocSystemHeap(uint32_t size, uint32_t alignment,
uint32_t allocation_type, uint32_t protect,
bool top_down, uint32_t* out_address) override;
bool Decommit(uint32_t address, uint32_t size) override;
bool Release(uint32_t base_address,
uint32_t* out_region_size = nullptr) override;