MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / PREFIX(malloc)

Function PREFIX(malloc)

Kernel/src/liballoc/liballoc.c:206–545  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

204}
205
206void *PREFIX(malloc)(size_t req_size)
207{
208 int startedBet = 0;
209 unsigned long long bestSize = 0;
210 void *p = NULL;
211 uintptr_t diff;
212 struct liballoc_major *maj;
213 struct liballoc_minor *min;
214 struct liballoc_minor *new_min;
215 unsigned long size = req_size;
216
217 // For alignment, we adjust size so there's enough space to align.
218 if (ALIGNMENT > 1)
219 {
220 size += ALIGNMENT + ALIGN_INFO;
221 }
222 // So, ideally, we really want an alignment of 0 or 1 in order
223 // to save space.
224
225 liballoc_lock();
226
227 if (size == 0)
228 {
229 l_warningCount += 1;
230#if defined DEBUG || defined INFO
231 kprintf("liballoc: WARNING: alloc( 0 ) called from %x\n");
232 FLUSH();
233#endif
234 liballoc_unlock();
235 return PREFIX(malloc)(1);
236 }
237
238 if (l_memRoot == NULL)
239 {
240#if defined DEBUG || defined INFO
241#ifdef DEBUG
242 kprintf("liballoc: initialization of liballoc " VERSION "\n");
243#endif
244 FLUSH();
245#endif
246
247 // This is the first time we are being used.
248 l_memRoot = allocate_new_page(size);
249 if (l_memRoot == NULL)
250 {
251 liballoc_unlock();
252#ifdef DEBUG
253 kprintf("liballoc: initial l_memRoot at %p initialization failed\n", p);
254 FLUSH();
255#endif
256 return NULL;
257 }
258
259#ifdef DEBUG
260 kprintf("liballoc: set up first memory major %x\n", l_memRoot);
261 FLUSH();
262#endif
263 }

Callers

nothing calls this directly

Calls 3

liballoc_lockFunction · 0.85
liballoc_unlockFunction · 0.85
allocate_new_pageFunction · 0.85

Tested by

no test coverage detected