1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
//
// Generated by dtk
// Translation Unit: JKRStdHeap.cpp
//
#include "JSystem/JSystem.h" // IWYU pragma: keep
#include "JSystem/JKernel/JKRStdHeap.h"
#include "JSystem/JUtility/JUTAssert.h"
#include "JSystem/JUtility/JUTConsole.h"
#include "new.h"
#include "global.h"
/* 802B0F34-802B0FE0 .text create__10JKRStdHeapFUlP7JKRHeapb */
JKRStdHeap* JKRStdHeap::create(u32 size, JKRHeap* parent, bool errorFlag) {
if (!parent) {
parent = sRootHeap;
}
if (size == -1) {
size = parent->getMaxAllocatableSize(0x20);
}
u32 alignedSize = ALIGN_PREV(size, 0x20);
if (alignedSize < 0xC0) {
return NULL;
}
u8* memory = (u8*)JKRAllocFromHeap(parent, alignedSize, 0x20);
u32 stdHeapSize = ALIGN_NEXT(sizeof(JKRStdHeap), 0x20);
u8* dataPtr = (memory + stdHeapSize);
if (!memory) {
return NULL;
}
JKRStdHeap* newHeap = new(memory) JKRStdHeap(dataPtr, alignedSize - stdHeapSize, parent, errorFlag);
return newHeap;
}
/* 802B0FE0-802B1040 .text do_destroy__10JKRStdHeapFv */
void JKRStdHeap::do_destroy() {
JKRHeap* heap = mChildTree.getParent()->getObject();
if (heap) {
this->~JKRStdHeap();
free(this, heap);
}
}
/* 802B1040-802B108C .text __ct__10JKRStdHeapFPvUlP7JKRHeapb */
JKRStdHeap::JKRStdHeap(void* data, u32 size, JKRHeap* parent, bool errorFlag) : JKRHeap(data, size, parent, errorFlag) {
mHeapHandle = OSCreateHeap(mStart, mEnd);
}
/* 802B108C-802B1104 .text __dt__10JKRStdHeapFv */
JKRStdHeap::~JKRStdHeap() {
dispose();
if (mHeapHandle != -1) {
OSDestroyHeap(mHeapHandle);
}
}
static void dummy() {
OSReport("JKRStdHeap.cpp");
OSReport("allocFixed from %x to %x in heap %x");
OSReport("allocFixed: cannot alloc memory (from %x to %x).\n");
}
/* 802B1104-802B11A4 .text do_alloc__10JKRStdHeapFUli */
void* JKRStdHeap::do_alloc(u32 size, int alignment) {
if (mHeapHandle == -1) {
return NULL;
}
void* ptr = OSAllocFromHeap(mHeapHandle, size);
if (!ptr) {
JUTWarningConsole_f("alloc: cannot alloc memory (0x%x byte).\n", size);
if (mErrorFlag == true && mErrorHandler) {
mErrorHandler(this, size, alignment);
}
}
return ptr;
}
/* 802B11A4-802B1228 .text do_free__10JKRStdHeapFPv */
void JKRStdHeap::do_free(void* ptr) {
if (mHeapHandle != -1) {
if (mStart <= ptr && ptr <= mEnd) {
OSFreeToHeap(mHeapHandle, ptr);
} else {
JUT_WARN(279, "free: memblock %x not in heap %x", ptr, this);
}
}
}
/* 802B1228-802B1278 .text do_freeAll__10JKRStdHeapFv */
void JKRStdHeap::do_freeAll() {
if (mHeapHandle == -1) {
return;
}
JKRHeap::callAllDisposer();
OSDestroyHeap(mHeapHandle);
mHeapHandle = OSCreateHeap(mStart, mEnd);
}
/* 802B1278-802B12A4 .text do_freeTail__10JKRStdHeapFv */
void JKRStdHeap::do_freeTail() {
JUTWarningConsole("freeTail: freeTail() is not work\n");
}
/* 802B12A4-802B12D8 .text do_resize__10JKRStdHeapFPvUl */
s32 JKRStdHeap::do_resize(void* ptr, u32 newSize) {
JUTWarningConsole_f("resize: cannot resize memory block (%08x: %d)\n", ptr, newSize);
return -1;
}
/* 802B12D8-802B1308 .text do_getFreeSize__10JKRStdHeapFv */
s32 JKRStdHeap::do_getFreeSize() {
JUTWarningConsole("getFreeSize: cannot get free size\n");
return -1;
}
/* 802B1308-802B1338 .text do_getMaxFreeBlock__10JKRStdHeapFv */
void* JKRStdHeap::do_getMaxFreeBlock() {
JUTWarningConsole("getFreeSize: cannot get free block");
return NULL;
}
/* 802B1338-802B13F0 .text state_register__10JKRStdHeapCFPQ27JKRHeap6TStateUl */
void JKRStdHeap::state_register(JKRHeap::TState* p, u32 id) const {
JUT_ASSERT(370, p != NULL);
JUT_ASSERT(371, p->getHeap() == this);
setState_u32ID_(p, id);
setState_uUsedSize_(p, 0);
setState_u32CheckCode_(p, 0);
}
/* 802B13F0-802B1490 .text state_compare__10JKRStdHeapCFRCQ27JKRHeap6TStateRCQ27JKRHeap6TState */
bool JKRStdHeap::state_compare(const JKRHeap::TState& r1, const JKRHeap::TState& r2) const {
JUT_ASSERT(394, r1.getHeap() == r2.getHeap());
bool result = true;
if (r1.mCheckCode != r2.mCheckCode) {
result = false;
}
if (r1.mUsedSize != r2.mUsedSize) {
result = false;
}
return result;
}
#if VERSION > VERSION_DEMO
/* 802B1490-802B1494 .text do_freeFill__10JKRStdHeapFv */
void JKRStdHeap::do_freeFill() {}
#endif
|