Make the pagemap global typed.

The pagemap global is now an inline static of a template class, so that
we will see different symbols for the different types.

Issue #84 showed that it's possible to compile two compilation units
with different pagemaps, link them together, and have them attempt to
interpret the global pagemap as two different types.  This change should
make that impossible.

Also make the `pagemap()` function static so that it can be used from
static functions, avoiding other things that directly reference the
global pagemap.
This commit is contained in:
David Chisnall
2019-08-13 13:26:07 +01:00
committed by David Chisnall
parent 2efa4b14fb
commit d2dc653af2
2 changed files with 29 additions and 14 deletions

View File

@@ -210,14 +210,13 @@ extern "C"
SNMALLOC_EXPORT void* SNMALLOC_NAME_MANGLE(snmalloc_pagemap_global_get)(
PagemapConfig const** config)
{
auto& pm = GlobalPagemap::pagemap();
if (config)
{
*config = &decltype(snmalloc::global_pagemap)::config;
assert(
decltype(snmalloc::global_pagemap)::cast_to_pagemap(
&snmalloc::global_pagemap, *config) == &snmalloc::global_pagemap);
*config = &SuperslabPagemap::config;
assert(SuperslabPagemap::cast_to_pagemap(&pm, *config) == &pm);
}
return &snmalloc::global_pagemap;
return ±
}
#endif