MCPcopy Create free account
hub / github.com/SmingHub/Sming / mc_malloc

Function mc_malloc

Sming/Components/malloc_count/malloc_count.cpp:220–250  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

218/****************************************************/
219
220extern "C" void* mc_malloc(size_t size)
221{
222 if(size == 0) {
223 return nullptr;
224 }
225
226 if(allocationLimit != 0 && stats.current + size > allocationLimit) {
227 log("malloc(%u) -> exceeds maximum (current is %u bytes)", size, stats.current);
228 return nullptr;
229 }
230
231 /* call read malloc procedure in libc */
232 void* ret = REAL(F_MALLOC)(alignment + size);
233
234 if(ret == nullptr) {
235 log("malloc(%u) failed", size);
236 return ret;
237 }
238
239 /* prepend allocation size and check sentinel */
240 *static_cast<size_t*>(ret) = size;
241 ret = offsetPointer(ret, alignment);
242 *getSentinel(ret) = sentinel;
243
244 inc_count(size);
245 if(size >= logThreshold) {
246 log("malloc(%u) = %p (cur %u)", size, ret, stats.current);
247 }
248
249 return ret;
250}
251
252extern "C" void* mc_zalloc(size_t size)
253{

Callers 5

mc_zallocFunction · 0.85
mc_reallocFunction · 0.85
operator newFunction · 0.85
operator new[]Function · 0.85
WRAP(strdup)Function · 0.85

Calls 3

offsetPointerFunction · 0.85
getSentinelFunction · 0.85
inc_countFunction · 0.85

Tested by

no test coverage detected