libmemory icon indicating copy to clipboard operation
libmemory copied to clipboard

Support C11 free()

Open phillipjohnston opened this issue 6 years ago • 3 comments

With aligned_alloc() in the C11 standard, free() is called to free memory, rather than an equivalent aligned_free().

We should update our library with some logic that can be used to correctly call aligned_free() if free() is used instead.

phillipjohnston avatar Jul 16 '19 16:07 phillipjohnston

Maybe we waste a few extra bytes in the aligned space... need a "magic" marker that indicates that this was allocated by aligned_malloc(). If the sentinel matches, then we call the aligned version.

phillipjohnston avatar May 07 '20 23:05 phillipjohnston

👍 I would be all for this. It is good to mimic how GLIBC behaves. And I don't think the costs outweigh the benefit

belmeopmenieuwesim avatar Jun 14 '20 16:06 belmeopmenieuwesim

I implemented this in https://github.com/embeddedartistry/libmemory/pull/91 but it is mostly just posted for review at this moment as it needs more testing. I tried it out in emu test_0007_smp.exe where I use it to allocate save restore space for AVX registers using XSAVE/XRSTOR and that will fault if memory is not 64-byte aligned, and it appears to work, but I have not done exhaustive testing yet.

michaeljclark avatar Feb 25 '24 22:02 michaeljclark