If a sizeclass in the metadata is corrupted, then this can be used to
force an index beyond the end of these tables. This extends the tables
to the next power of two, and uses a mask on the index, so they are
always either a valid piece of data, or zero.
The union in Metaslab provides no benefit in size, as the single byte
it effectively saves will be removed due to padding.
By removing the union, we get stronger properties over sizeclass, and
remove an out-of-bounds access.
Move slow_allocator into a separate header in the snmalloc namespace and
rename it for consistency with the rest of the codebase. Delete its
copy and move constructors / assignment operators.
The encoding in the top bits for the size class did not respect kernel
pointers. Using an intptr_t means, we can use a signed shift to
maintain the kernel pointers.
This code assumes that 16bit uint wrapping can be used, rather than
masking by SLAB_SIZE-1. Add explicit mask, so we can change the
SLAB_SIZE to be smaller.
Provide a hook so that the exported malloc symbols can be weak. This is
mostly needed so that rtld, which statically links libc.a, can override
the symbols.
Add a bootstrap allocator so that statically linked binaries can have
their TLS space allocated before malloc is called and uses TLS.
The current pagemap assumes there is at least one level of indexing.
This commit introduces a new pagemap that is completely flat. This is
useful for 32bit, where there is no need to introduce the indexing
structure.
This pagemap is also considerably faster for 64bit platforms, but
does require a global allocation of 16MiB of the flat page map.
The design of Remote used the top bits of the allocator id to encode
the sizeclass of the deallocation. On 32bit, or on a platform that uses all the bits
we cannot use these bits for a sizeclass.
This commit uses the bottom bit of the allocator id (which is
guaranteed to be 0), to indicate if the object is the minimum
allocation size. If it is not the minimum allocation size the
subsequent byte is used to encode the sizeclass.
The code uses constexpr to decide which strategy to use.