Open jugonz opened 9 years ago
so this is actually a good deal harder than I thought it would be.
malloc_tagged()
can be implemented but needs to go and change the tag on every word of memory allocated. currently the settag
instruction operates on registers, like all non load/store instructions, so this means that the proper tag needs to be loaded into a value in a register, and then an sd
instruction FOR EACH WORD needs to be run to store the appropriate tag to that memory location. ugh. a settag
instruction that operates on memory might be more appropriate.
the real problem is with free_tagged()
, though. because C's free()
doesn't take the size of the memory region originally allocated as an argument , we have to find that size using metadata from malloc()
. Doing so with the glibc malloc()
implementation now might not be a good priority, as it's one of the more complicated systems functions I've ever seen. There exist more lightweight malloc()
implementations and I'm certainly down to getting my hands dirty, but we may want to wait on this for a bit.
on the bright side, we can set tags to 0 en masse by just zeroing out memory from C (calling memset()
), as the way we've defined tags allows sd
and all other storing instructions to set the tag to 0 easily.
As an alternative: we could look at how AddressSanitizer does this? https://code.google.com/p/address-sanitizer/wiki/AddressSanitizerAlgorithm
and maybe piggy-back off of their implementation in clang for simplicity
malloc()
andfree()
finished so that we can play around with temporal tags