diff --git a/src/mem/freelist.h b/src/mem/freelist.h index 0b882a3..9dd8d9b 100644 --- a/src/mem/freelist.h +++ b/src/mem/freelist.h @@ -184,6 +184,17 @@ namespace snmalloc return p.template as_static>(); } + /** + * A container-of operation to convert &f->next_object to f + */ + template + static FreeObject::T* + from_next_ptr(CapPtr, BQueue>* ptr) + { + static_assert(offsetof(FreeObject::T, next_object) == 0); + return reinterpret_cast*>(ptr); + } + private: /** * Involutive encryption with raw pointers @@ -655,7 +666,7 @@ namespace snmalloc // to the actual object. This isn't true if the builder is // empty, but you are not allowed to call this in the empty case. auto last = FreeObject::HeadPtr( - reinterpret_cast*>(end[0])); + FreeObject::from_next_ptr(cast_end(0))); init(); return {first, last}; }