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

Function PREFIX(realloc)

Kernel/src/liballoc/liballoc.c:672–755  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

670}
671
672void* PREFIX(realloc)(void *p, size_t size)
673{
674 void *ptr;
675 struct liballoc_minor *min;
676 unsigned int real_size;
677
678 // Honour the case of size == 0 => free old and return NULL
679 if (size == 0)
680 {
681 PREFIX(free)(p);
682 return NULL;
683 }
684
685 // In the case of a NULL pointer, return a simple malloc.
686 if (p == NULL) return PREFIX(malloc)(size);
687
688 // Unalign the pointer if required.
689 ptr = p;
690 UNALIGN(ptr);
691
692 liballoc_lock(); // lockit
693
694 min = (struct liballoc_minor*)((uintptr_t)ptr - sizeof(struct liballoc_minor));
695
696 // Ensure it is a valid structure.
697 if (min->magic != LIBALLOC_MAGIC)
698 {
699 l_errorCount += 1;
700
701 // Check for overrun errors. For all bytes of LIBALLOC_MAGIC
702 if (
703 ((min->magic & 0xFFFFFF) == (LIBALLOC_MAGIC & 0xFFFFFF)) ||
704 ((min->magic & 0xFFFF) == (LIBALLOC_MAGIC & 0xFFFF)) ||
705 ((min->magic & 0xFF) == (LIBALLOC_MAGIC & 0xFF))
706 )
707 {
708 l_possibleOverruns += 1;
709#if defined DEBUG || defined INFO
710 kprintf("liballoc: ERROR: Possible 1-3 byte overrun for magic %x != %x\n",
711 min->magic,
712 LIBALLOC_MAGIC);
713 FLUSH();
714#endif
715 }
716
717
718 if (min->magic == LIBALLOC_DEAD)
719 {
720#if defined DEBUG || defined INFO
721 kprintf("liballoc: ERROR: multiple PREFIX(free)() attempt on %x from %x.\n",
722 ptr,
723 __builtin_return_address(0));
724 FLUSH();
725#endif
726 }
727 else
728 {
729 }

Callers

nothing calls this directly

Calls 3

liballoc_lockFunction · 0.85
liballoc_unlockFunction · 0.85
liballoc_memcpyFunction · 0.85

Tested by

no test coverage detected