MCPcopy Create free account
hub / github.com/coreboot/coreboot / realloc

Function realloc

payloads/libpayload/libc/malloc.c:310–356  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

308}
309
310void *realloc(void *ptr, size_t size)
311{
312 void *ret, *pptr;
313 hdrtype_t volatile *block;
314 unsigned int osize;
315 struct memory_type *type = heap;
316
317 if (ptr == NULL)
318 return alloc(size, type);
319
320 pptr = ptr - HDRSIZE;
321
322 if (!HAS_MAGIC(*((hdrtype_t *) pptr)))
323 return NULL;
324
325 if (ptr < type->start || ptr >= type->end)
326 type = dma;
327
328 /* Get the original size of the block. */
329 osize = SIZE(*((hdrtype_t *) pptr));
330
331 /*
332 * Free the memory to update the tables - this won't touch the actual
333 * memory, so we can still use it for the copy after we have
334 * reallocated the new space.
335 */
336 free(ptr);
337
338 block = find_free_block(size, type);
339 if (block == NULL)
340 return NULL;
341
342 ret = (void *)((uintptr_t)block + HDRSIZE);
343
344 /*
345 * If ret == ptr, then no copy is needed. Otherwise, move the memory to
346 * the new location, which might be before the old one and overlap since
347 * the free() above includes a _consolidate().
348 */
349 if (ret != ptr)
350 memmove(ret, ptr, osize > size ? size : osize);
351
352 /* Mark the block as used. */
353 use_block(block, size);
354
355 return ret;
356}
357
358struct align_region_t
359{

Callers 13

storage_attach_deviceFunction · 0.85
mainFunction · 0.85
_selection_setFunction · 0.85
_set_selectionFunction · 0.85
sym_re_searchFunction · 0.85
dialog_inputboxFunction · 0.85
xreallocFunction · 0.85
add_targetFunction · 0.85
remalloc_foFunction · 0.85
find_loadable_segmentsFunction · 0.85
fmap_flags_to_stringFunction · 0.85

Calls 5

allocFunction · 0.85
find_free_blockFunction · 0.85
use_blockFunction · 0.85
freeFunction · 0.70
memmoveFunction · 0.50

Tested by

no test coverage detected