[Base] Specify heap type on initialization
This commit is contained in:
parent
2cb7d26d62
commit
c071500ff4
|
@ -158,24 +158,26 @@ bool Memory::Initialize() {
|
||||||
physical_membase_ = mapping_base_ + 0x100000000ull;
|
physical_membase_ = mapping_base_ + 0x100000000ull;
|
||||||
|
|
||||||
// Prepare virtual heaps.
|
// Prepare virtual heaps.
|
||||||
heaps_.v00000000.Initialize(this, virtual_membase_, 0x00000000, 0x40000000,
|
heaps_.v00000000.Initialize(this, virtual_membase_, HeapType::kGuestVirtual,
|
||||||
4096);
|
0x00000000, 0x40000000, 4096);
|
||||||
heaps_.v40000000.Initialize(this, virtual_membase_, 0x40000000,
|
heaps_.v40000000.Initialize(this, virtual_membase_, HeapType::kGuestVirtual,
|
||||||
0x40000000 - 0x01000000, 64 * 1024);
|
0x40000000, 0x40000000 - 0x01000000, 64 * 1024);
|
||||||
heaps_.v80000000.Initialize(this, virtual_membase_, 0x80000000, 0x10000000,
|
heaps_.v80000000.Initialize(this, virtual_membase_, HeapType::kGuestXex,
|
||||||
64 * 1024);
|
0x80000000, 0x10000000, 64 * 1024);
|
||||||
heaps_.v90000000.Initialize(this, virtual_membase_, 0x90000000, 0x10000000,
|
heaps_.v90000000.Initialize(this, virtual_membase_, HeapType::kGuestXex,
|
||||||
4096);
|
0x90000000, 0x10000000, 4096);
|
||||||
|
|
||||||
// Prepare physical heaps.
|
// Prepare physical heaps.
|
||||||
heaps_.physical.Initialize(this, physical_membase_, 0x00000000, 0x20000000,
|
heaps_.physical.Initialize(this, physical_membase_, HeapType::kGuestPhysical,
|
||||||
4096);
|
0x00000000, 0x20000000, 4096);
|
||||||
heaps_.vA0000000.Initialize(this, virtual_membase_, 0xA0000000, 0x20000000,
|
heaps_.vA0000000.Initialize(this, virtual_membase_, HeapType::kGuestPhysical,
|
||||||
64 * 1024, &heaps_.physical);
|
0xA0000000, 0x20000000, 64 * 1024,
|
||||||
heaps_.vC0000000.Initialize(this, virtual_membase_, 0xC0000000, 0x20000000,
|
&heaps_.physical);
|
||||||
16 * 1024 * 1024, &heaps_.physical);
|
heaps_.vC0000000.Initialize(this, virtual_membase_, HeapType::kGuestPhysical,
|
||||||
heaps_.vE0000000.Initialize(this, virtual_membase_, 0xE0000000, 0x1FD00000,
|
0xC0000000, 0x20000000, 16 * 1024 * 1024,
|
||||||
4096, &heaps_.physical);
|
&heaps_.physical);
|
||||||
|
heaps_.vE0000000.Initialize(this, virtual_membase_, HeapType::kGuestPhysical,
|
||||||
|
0xE0000000, 0x1FD00000, 4096, &heaps_.physical);
|
||||||
|
|
||||||
// Protect the first and last 64kb of memory.
|
// Protect the first and last 64kb of memory.
|
||||||
heaps_.v00000000.AllocFixed(
|
heaps_.v00000000.AllocFixed(
|
||||||
|
@ -633,11 +635,12 @@ BaseHeap::BaseHeap()
|
||||||
|
|
||||||
BaseHeap::~BaseHeap() = default;
|
BaseHeap::~BaseHeap() = default;
|
||||||
|
|
||||||
void BaseHeap::Initialize(Memory* memory, uint8_t* membase, uint32_t heap_base,
|
void BaseHeap::Initialize(Memory* memory, uint8_t* membase, HeapType heap_type,
|
||||||
uint32_t heap_size, uint32_t page_size,
|
uint32_t heap_base, uint32_t heap_size,
|
||||||
uint32_t host_address_offset) {
|
uint32_t page_size, uint32_t host_address_offset) {
|
||||||
memory_ = memory;
|
memory_ = memory;
|
||||||
membase_ = membase;
|
membase_ = membase;
|
||||||
|
heap_type_ = heap_type;
|
||||||
heap_base_ = heap_base;
|
heap_base_ = heap_base;
|
||||||
heap_size_ = heap_size;
|
heap_size_ = heap_size;
|
||||||
page_size_ = page_size;
|
page_size_ = page_size;
|
||||||
|
@ -1346,9 +1349,10 @@ VirtualHeap::VirtualHeap() = default;
|
||||||
VirtualHeap::~VirtualHeap() = default;
|
VirtualHeap::~VirtualHeap() = default;
|
||||||
|
|
||||||
void VirtualHeap::Initialize(Memory* memory, uint8_t* membase,
|
void VirtualHeap::Initialize(Memory* memory, uint8_t* membase,
|
||||||
uint32_t heap_base, uint32_t heap_size,
|
HeapType heap_type, uint32_t heap_base,
|
||||||
uint32_t page_size) {
|
uint32_t heap_size, uint32_t page_size) {
|
||||||
BaseHeap::Initialize(memory, membase, heap_base, heap_size, page_size);
|
BaseHeap::Initialize(memory, membase, heap_type, heap_base, heap_size,
|
||||||
|
page_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
PhysicalHeap::PhysicalHeap() : parent_heap_(nullptr) {}
|
PhysicalHeap::PhysicalHeap() : parent_heap_(nullptr) {}
|
||||||
|
@ -1356,8 +1360,9 @@ PhysicalHeap::PhysicalHeap() : parent_heap_(nullptr) {}
|
||||||
PhysicalHeap::~PhysicalHeap() = default;
|
PhysicalHeap::~PhysicalHeap() = default;
|
||||||
|
|
||||||
void PhysicalHeap::Initialize(Memory* memory, uint8_t* membase,
|
void PhysicalHeap::Initialize(Memory* memory, uint8_t* membase,
|
||||||
uint32_t heap_base, uint32_t heap_size,
|
HeapType heap_type, uint32_t heap_base,
|
||||||
uint32_t page_size, VirtualHeap* parent_heap) {
|
uint32_t heap_size, uint32_t page_size,
|
||||||
|
VirtualHeap* parent_heap) {
|
||||||
uint32_t host_address_offset;
|
uint32_t host_address_offset;
|
||||||
if (heap_base >= 0xE0000000 &&
|
if (heap_base >= 0xE0000000 &&
|
||||||
xe::memory::allocation_granularity() > 0x1000) {
|
xe::memory::allocation_granularity() > 0x1000) {
|
||||||
|
@ -1366,8 +1371,8 @@ void PhysicalHeap::Initialize(Memory* memory, uint8_t* membase,
|
||||||
host_address_offset = 0;
|
host_address_offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseHeap::Initialize(memory, membase, heap_base, heap_size, page_size,
|
BaseHeap::Initialize(memory, membase, heap_type, heap_base, heap_size,
|
||||||
host_address_offset);
|
page_size, host_address_offset);
|
||||||
parent_heap_ = parent_heap;
|
parent_heap_ = parent_heap;
|
||||||
system_page_size_ = uint32_t(xe::memory::page_size());
|
system_page_size_ = uint32_t(xe::memory::page_size());
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,13 @@ enum SystemHeapFlag : uint32_t {
|
||||||
kSystemHeapDefault = kSystemHeapVirtual,
|
kSystemHeapDefault = kSystemHeapVirtual,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class HeapType : uint8_t {
|
||||||
|
kGuestVirtual,
|
||||||
|
kGuestXex,
|
||||||
|
kGuestPhysical,
|
||||||
|
kHostPhysical,
|
||||||
|
};
|
||||||
|
|
||||||
enum MemoryAllocationFlag : uint32_t {
|
enum MemoryAllocationFlag : uint32_t {
|
||||||
kMemoryAllocationReserve = 1 << 0,
|
kMemoryAllocationReserve = 1 << 0,
|
||||||
kMemoryAllocationCommit = 1 << 1,
|
kMemoryAllocationCommit = 1 << 1,
|
||||||
|
@ -106,6 +113,9 @@ class BaseHeap {
|
||||||
// Size of each page within the heap range in bytes.
|
// Size of each page within the heap range in bytes.
|
||||||
uint32_t page_size() const { return page_size_; }
|
uint32_t page_size() const { return page_size_; }
|
||||||
|
|
||||||
|
// Type of specified heap
|
||||||
|
HeapType heap_type() const { return heap_type_; }
|
||||||
|
|
||||||
// Offset added to the virtual addresses to convert them to host addresses
|
// Offset added to the virtual addresses to convert them to host addresses
|
||||||
// (not including membase).
|
// (not including membase).
|
||||||
uint32_t host_address_offset() const { return host_address_offset_; }
|
uint32_t host_address_offset() const { return host_address_offset_; }
|
||||||
|
@ -188,12 +198,13 @@ class BaseHeap {
|
||||||
protected:
|
protected:
|
||||||
BaseHeap();
|
BaseHeap();
|
||||||
|
|
||||||
void Initialize(Memory* memory, uint8_t* membase, uint32_t heap_base,
|
void Initialize(Memory* memory, uint8_t* membase, HeapType heap_type,
|
||||||
uint32_t heap_size, uint32_t page_size,
|
uint32_t heap_base, uint32_t heap_size, uint32_t page_size,
|
||||||
uint32_t host_address_offset = 0);
|
uint32_t host_address_offset = 0);
|
||||||
|
|
||||||
Memory* memory_;
|
Memory* memory_;
|
||||||
uint8_t* membase_;
|
uint8_t* membase_;
|
||||||
|
HeapType heap_type_;
|
||||||
uint32_t heap_base_;
|
uint32_t heap_base_;
|
||||||
uint32_t heap_size_;
|
uint32_t heap_size_;
|
||||||
uint32_t page_size_;
|
uint32_t page_size_;
|
||||||
|
@ -209,8 +220,8 @@ class VirtualHeap : public BaseHeap {
|
||||||
~VirtualHeap() override;
|
~VirtualHeap() override;
|
||||||
|
|
||||||
// Initializes the heap properties and allocates the page table.
|
// Initializes the heap properties and allocates the page table.
|
||||||
void Initialize(Memory* memory, uint8_t* membase, uint32_t heap_base,
|
void Initialize(Memory* memory, uint8_t* membase, HeapType heap_type,
|
||||||
uint32_t heap_size, uint32_t page_size);
|
uint32_t heap_base, uint32_t heap_size, uint32_t page_size);
|
||||||
};
|
};
|
||||||
|
|
||||||
// A heap for ranges of memory that are mapped to physical ranges.
|
// A heap for ranges of memory that are mapped to physical ranges.
|
||||||
|
@ -226,8 +237,8 @@ class PhysicalHeap : public BaseHeap {
|
||||||
~PhysicalHeap() override;
|
~PhysicalHeap() override;
|
||||||
|
|
||||||
// Initializes the heap properties and allocates the page table.
|
// Initializes the heap properties and allocates the page table.
|
||||||
void Initialize(Memory* memory, uint8_t* membase, uint32_t heap_base,
|
void Initialize(Memory* memory, uint8_t* membase, HeapType heap_type,
|
||||||
uint32_t heap_size, uint32_t page_size,
|
uint32_t heap_base, uint32_t heap_size, uint32_t page_size,
|
||||||
VirtualHeap* parent_heap);
|
VirtualHeap* parent_heap);
|
||||||
|
|
||||||
bool Alloc(uint32_t size, uint32_t alignment, uint32_t allocation_type,
|
bool Alloc(uint32_t size, uint32_t alignment, uint32_t allocation_type,
|
||||||
|
|
Loading…
Reference in New Issue