I was wondering, what is the best way to get the head pointer of the given memory address? In example, if p is allocated at the address 0 with a size of 32 bytes how can I get back to 0 from the address 12? In other words, get back to the “main address” from an address further into its data structure. Is that possible?
Any help is welcome, thanks!
For structs this can be accomplished using
container_ofmacro provided you know its type and you have a pointer to a member of it (ex. to get the pointer of the struct if you are given a pointer to a member). For memory allocations done usingmallocthis is not possible unless you have the length you’ve traversed or offset you’re currently at.