Apply ModArray to Metaslab data
Prevent bugs accessing outside the Slabs meta data.
This commit is contained in:
@@ -755,7 +755,7 @@ namespace snmalloc
|
|||||||
if ((allow_reserve == NoReserve) && (super == nullptr))
|
if ((allow_reserve == NoReserve) && (super == nullptr))
|
||||||
return super;
|
return super;
|
||||||
|
|
||||||
super->init(public_state(), large_allocator.memory_provider);
|
super->init(public_state());
|
||||||
pagemap().set_slab(super);
|
pagemap().set_slab(super);
|
||||||
super_available.insert(super);
|
super_available.insert(super);
|
||||||
return super;
|
return super;
|
||||||
|
|||||||
@@ -91,6 +91,15 @@ namespace snmalloc
|
|||||||
head = (uint16_t)~0;
|
head = (uint16_t)~0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void zero()
|
||||||
|
{
|
||||||
|
head = 0;
|
||||||
|
used = 0;
|
||||||
|
link = 0;
|
||||||
|
sizeclass = 0;
|
||||||
|
next = 0;
|
||||||
|
}
|
||||||
|
|
||||||
SlabLink* get_link(Slab* slab)
|
SlabLink* get_link(Slab* slab)
|
||||||
{
|
{
|
||||||
return (SlabLink*)((size_t)slab + link);
|
return (SlabLink*)((size_t)slab + link);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "metaslab.h"
|
#include "metaslab.h"
|
||||||
|
#include "../ds/helpers.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
namespace snmalloc
|
namespace snmalloc
|
||||||
@@ -37,7 +37,7 @@ namespace snmalloc
|
|||||||
// short slab would be 6 + 1 = 7
|
// short slab would be 6 + 1 = 7
|
||||||
uint16_t used;
|
uint16_t used;
|
||||||
|
|
||||||
Metaslab meta[SLAB_COUNT];
|
ModArray<SLAB_COUNT, Metaslab> meta;
|
||||||
|
|
||||||
// Used size_t as results in better code in MSVC
|
// Used size_t as results in better code in MSVC
|
||||||
size_t slab_to_index(Slab* slab)
|
size_t slab_to_index(Slab* slab)
|
||||||
@@ -74,8 +74,7 @@ namespace snmalloc
|
|||||||
return sizeclass <= h;
|
return sizeclass <= h;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename MemoryProvider>
|
void init(RemoteAllocator* alloc)
|
||||||
void init(RemoteAllocator* alloc, MemoryProvider& memory_provider)
|
|
||||||
{
|
{
|
||||||
allocator = alloc;
|
allocator = alloc;
|
||||||
|
|
||||||
@@ -91,10 +90,24 @@ namespace snmalloc
|
|||||||
{
|
{
|
||||||
// If this wasn't previously Fresh, we need to zero some things.
|
// If this wasn't previously Fresh, we need to zero some things.
|
||||||
used = 0;
|
used = 0;
|
||||||
memory_provider.zero(meta, SLAB_COUNT * sizeof(Metaslab));
|
for (auto i = 0; i < SLAB_COUNT; i++)
|
||||||
|
{
|
||||||
|
meta[i].zero();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#ifndef NDEBUG
|
||||||
|
auto curr = head;
|
||||||
|
for (auto i = 0; i < SLAB_COUNT - used - 1; i++)
|
||||||
|
{
|
||||||
|
curr = (curr + meta[curr].next + 1) & (SLAB_COUNT - 1);
|
||||||
|
}
|
||||||
|
assert (curr == 0);
|
||||||
|
|
||||||
meta[0].set_unused();
|
for (auto i = 0; i < SLAB_COUNT; i++)
|
||||||
|
{
|
||||||
|
assert(meta[i].is_unused());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user