Hello,
We are attempting to do some crash analyse on our product and want to analyze the heap allocations, basically separating all the nodes allocated vs free and then print those with some additional information. With DSP/BIOS the free list is tracked but we would like to also be able to pick out the allocated nodes. I know that every node has a MEM_Header structure:
typedef struct MEM_Header {
struct MEM_Header *next; /* form a free memory link list */
MEM_sizep size; /* size of the free memory */
} MEM_Header;
I was hoping that it would be as easy as starting at the beginning of the heap memory, reading in this structure, store it, increment the pointer by the size which would point to the next structure, store it, repeat, until you get to the end of the heap space. One detail that I have found from examining the provided malloc function is that the size stored in this structure is the size requested + sizeof (MEM_Header) but in addition to this the actual size of the node is rounded up to be aligned with the sizeof MEM_Header (8). So say I was to read a MEM_Header structure and it has a size of 0xC the actual node size would be 0x10. 0x10 size includes the size of the header. Just to test out this heap walking method after powerup we went ahead and allocated as many nodes of size 2 as possible until the heap was full and then took a system dump. I am only able to traverse for a few nodes until I hit one node that has a size that would increment the pointer back to the position of the free list. If I continue to look through the memory to find another location that seems to be a MEM_Header I also am able to manually parse through a few blocks until I hit yet another node that has a size that increments back to point at the free node list. One may think that these are free nodes but this is a heap that has been fully allocated. The free node list has a next of 0 and size of 8. I have a memory dump that I can provide in a fairly nice format for example:
C11FFFF0 00 00 00 00 00000000 ....
C11FFFF4 08 00 00 00 00000008 ....
C11FFFF8 F0 FF 1F C1 C11FFFF0 ....
C11FFFFC F8 FF 1F 00 001FFFF8 ....
Our heap starts at 0xC1000000 and is 0x200000 long (verified from reading this info from the memory segment structure) and the free node start is at address 0xC11FFFF8. So as you can see from the memory above the free node list next pointer is 0 with size 8 which is just the structure size. Any hints on this? I feel like I am overlooking something since at numerous points through the heap there are size values that point directly back to free node structure example:
C1000130 00 00 00 00 00000000 ....
C1000134 C8 FE 1F 00 001FFEC8 ....
(0xC1000130 + 0x1FFEC8 = 0xC11FFFF8)
and that seems to be too much of a coincidence to be a mistake. Thanks for your time and I can provide this dump if needed as well as any other details or structure information in our system. Thanks again.