MCPcopy Create free account
hub / github.com/Supercip971/WingOS / PREFIX(malloc)

Function PREFIX(malloc)

src/liballoc/liballoc.c:227–558  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

225}
226
227void *PREFIX(malloc)(size_t req_size)
228{
229 int startedBet = 0;
230 unsigned long long bestSize = 0;
231 void *p = NULL;
232 uintptr_t diff;
233 struct liballoc_major *maj;
234 struct liballoc_minor *min;
235 struct liballoc_minor *new_min;
236 unsigned long size = req_size;
237
238 // For alignment, we adjust size so there's enough space to align.
239 if (ALIGNMENT > 1)
240 {
241 size += ALIGNMENT + ALIGN_INFO;
242 }
243 // So, ideally, we really want an alignment of 0 or 1 in order
244 // to save space.
245
246 liballoc_lock();
247
248 if (size == 0)
249 {
250 l_warningCount += 1;
251#if defined DEBUG || defined INFO
252 printf("liballoc: WARNING: alloc( 0 ) called from %x\n",
253 __builtin_return_address(0));
254 FLUSH();
255#endif
256 liballoc_unlock();
257 return PREFIX(malloc)(1);
258 }
259
260 if (l_memRoot == NULL)
261 {
262#if defined DEBUG || defined INFO
263# ifdef DEBUG
264 printf("liballoc: initialization of liballoc " VERSION "\n");
265# endif
266 atexit(liballoc_dump);
267 FLUSH();
268#endif
269
270 // This is the first time we are being used.
271 l_memRoot = allocate_new_page(size);
272 if (l_memRoot == NULL)
273 {
274 liballoc_unlock();
275#ifdef DEBUG
276 printf("liballoc: initial l_memRoot initialization failed\n", p);
277 FLUSH();
278#endif
279 return NULL;
280 }
281
282#ifdef DEBUG
283 printf("liballoc: set up first memory major %x\n", l_memRoot);
284 FLUSH();

Callers

nothing calls this directly

Calls 5

printfFunction · 0.85
allocate_new_pageFunction · 0.85
liballoc_dumpFunction · 0.85
liballoc_lockFunction · 0.50
liballoc_unlockFunction · 0.50

Tested by

no test coverage detected