5using namespace Abstract::Memory;
14 dynamicCastHandleToExp()->destroy();
18ExpHeap *ExpHeap::create(
void *startAddress,
size_t size,
u16 opt) {
19 ExpHeap *heap =
nullptr;
20 void *buffer = startAddress;
22 void *endAddress = RoundDown(AddOffset(startAddress, size), 4);
23 startAddress = RoundUp(startAddress, 4);
25 size_t addrRange = GetAddrNum(endAddress) - GetAddrNum(startAddress);
26 if (startAddress > endAddress || addrRange <
sizeof(ExpHeap) + 4) {
30 void *handleStart = AddOffset(startAddress,
sizeof(ExpHeap));
32 MEMiExpHeapHead::create(handleStart, addrRange -
sizeof(ExpHeap), opt);
34 heap =
new (startAddress) ExpHeap(handle);
35 heap->registerHeapBuffer(buffer);
42ExpHeap *ExpHeap::create(
size_t size, Heap *pHeap,
u16 opt) {
43 ExpHeap *heap =
nullptr;
46 pHeap = Heap::getCurrentHeap();
49 if (size == std::numeric_limits<size_t>::max()) {
50 size = pHeap->getAllocatableSize();
53 void *block = pHeap->alloc(size, 4);
55 heap = create(block, size, opt);
57 heap->setParentHeap(pHeap);
67void ExpHeap::destroy() {
68 Heap *pParent = getParentHeap();
76void *ExpHeap::alloc(
size_t size, s32 align) {
77 if (tstDisableAllocation()) {
78 PANIC(
"HEAP ALLOC FAIL (%p, %s): Heap is locked",
this, m_name);
81 return dynamicCastHandleToExp()->alloc(size, align);
85void ExpHeap::free(
void *block) {
86 dynamicCastHandleToExp()->free(block);
90u32 ExpHeap::getAllocatableSize(s32 align)
const {
91 return dynamicCastHandleToExp()->getAllocatableSize(align);
95void ExpHeap::addGroupSize(
void *block,
MEMiHeapHead * , uintptr_t param) {
98 u16 groupID = blockHead->m_attribute.fields.groupId;
100 GroupSizeRecord *record =
reinterpret_cast<GroupSizeRecord *
>(param);
101 record->addSize(groupID, blockHead->m_size);
105void ExpHeap::calcGroupSize(GroupSizeRecord *record) {
107 dynamicCastHandleToExp()->visitAllocated(addGroupSize, GetAddrNum(record));
111void ExpHeap::setGroupID(
u16 groupID) {
112 return dynamicCastHandleToExp()->setGroupID(groupID);
115u16 ExpHeap::getGroupID()
const {
116 return dynamicCastHandleToExp()->getGroupID();
128ExpHeap::GroupSizeRecord::GroupSizeRecord() {
133void ExpHeap::GroupSizeRecord::reset() {
134 for (
auto &entry : m_entries) {
139size_t ExpHeap::GroupSizeRecord::getGroupSize(
u16 groupID)
const {
140 return m_entries[groupID];
144void ExpHeap::GroupSizeRecord::addSize(
u16 groupID,
size_t size) {
145 m_entries[groupID] += size;
Low-level implementation of a memory heap for managing dynamic memory allocation. Allocation may occu...
A low-level representation of a memory heap for managing dynamic memory allocation....
Head of the memory block. Contains information about the block and a link in the corresponding used/f...