MCPcopy Create free account
hub / github.com/Fable2Recomp/Fable2Recomp / InitNativeHeap

Function InitNativeHeap

src/heap.cpp:116–148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114namespace lh {
115
116bool InitNativeHeap() {
117 auto* mem = rex::system::kernel_memory();
118 if (!mem) {
119 REXLOG_ERROR("InitNativeHeap: kernel_memory() is null");
120 return false;
121 }
122
123 g_membase = mem->virtual_membase();
124
125 uint32_t guest_base = mem->SystemHeapAlloc(kHeapSize);
126 if (!guest_base) {
127 REXLOG_ERROR("InitNativeHeap: SystemHeapAlloc({}) failed", kHeapSize);
128 return false;
129 }
130
131 uint8_t* host_base = mem->TranslateVirtual<uint8_t*>(guest_base);
132 g_arena_base = guest_base;
133 g_arena_end = guest_base + kHeapSize;
134 REXLOG_INFO("InitNativeHeap: guest=0x{:08X}-0x{:08X} host={} size={}MB",
135 g_arena_base, g_arena_end, (void*)host_base, kHeapSize / (1024 * 1024));
136
137 g_mspace = create_mspace_with_base(host_base, kHeapSize, 1);
138 if (!g_mspace) {
139 REXLOG_ERROR("InitNativeHeap: create_mspace_with_base failed");
140 mem->SystemHeapFree(guest_base);
141 return false;
142 }
143
144 mspace_set_footprint_limit(g_mspace, kHeapSize);
145
146 REXLOG_INFO("InitNativeHeap: dlmalloc mspace ready");
147 return true;
148}
149
150} // namespace lh

Callers 1

OnInitializeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected