1#include "HeapCommon.hh"
5namespace Abstract::Memory {
7MEMList &MEMiHeapHead::getChildList() {
11void *MEMiHeapHead::getHeapStart() {
15void *MEMiHeapHead::getHeapEnd() {
19MEMList &MEMiHeapHead::getRootList() {
23u32 MEMiHeapHead::getFillVal(FillType type) {
24 size_t t =
static_cast<std::underlying_type_t<FillType>
>(type);
30MEMiHeapHead *MEMiHeapHead::findContainHeap(
const void *block) {
31 return findContainHeap(&s_rootList, block);
35MEMiHeapHead::MEMiHeapHead(u32 signature,
void *heapStart,
void *heapEnd,
const OptFlag &opt)
36 : m_childList(MEMList(getLinkOffset())) {
37 m_signature = signature;
38 m_heapStart = heapStart;
42 fillNoUseMemory(heapStart, GetAddrNum(heapEnd) - GetAddrNum(heapStart));
44 findListContainHeap().append(
this);
48MEMiHeapHead::~MEMiHeapHead() {
49 findListContainHeap().remove(
this);
53void MEMiHeapHead::fillNoUseMemory(
void *address, u32 size) {
54 if (m_optFlag.onBit(eOptFlag::DebugFillAlloc)) {
55 memset(address, getFillVal(FillType::NoUse), size);
59void MEMiHeapHead::fillAllocMemory(
void *address, u32 size) {
60 if (m_optFlag.onBit(eOptFlag::DebugFillAlloc)) {
61 memset(address, getFillVal(FillType::Alloc), size);
62 }
else if (m_optFlag.onBit(eOptFlag::ZeroFillAlloc)) {
63 memset(address, 0, size);
67void MEMiHeapHead::fillFreeMemory(
void *address, u32 size) {
68 if (m_optFlag.onBit(eOptFlag::DebugFillAlloc)) {
69 memset(address, getFillVal(FillType::Free), size);
74MEMiHeapHead *MEMiHeapHead::findContainHeap(MEMList *list,
const void *block) {
75 MEMiHeapHead *heap =
nullptr;
77 while ((heap =
reinterpret_cast<MEMiHeapHead *
>(list->getNext(heap)))) {
78 if (GetAddrNum(heap->m_heapStart) > GetAddrNum(block) ||
79 GetAddrNum(block) >= GetAddrNum(heap->m_heapEnd)) {
83 MEMiHeapHead *search = findContainHeap(&heap->m_childList, block);
94MEMList &MEMiHeapHead::findListContainHeap()
const {
95 MEMiHeapHead *containHeap = findContainHeap(
this);
96 return containHeap ? containHeap->getChildList() : getRootList();
99MEMList MEMiHeapHead::s_rootList = MEMList(MEMiHeapHead::getLinkOffset());