Add type confusion protection to the default memory provider.

This commit is contained in:
David Chisnall
2019-08-13 15:01:30 +01:00
committed by David Chisnall
parent 6dbe24da2e
commit d56201e28d
6 changed files with 29 additions and 14 deletions

View File

@@ -60,7 +60,7 @@ namespace snmalloc
* variable. This should be used from within the library or program that
* owns the pagemap.
*
* This class makes the global pagemap a static field so that its name
* This class makes the global pagemap a typed singleton so that its name
* includes the type mangling. If two compilation units try to instantiate
* two different types of pagemap then they will see two distinct pagemaps.
* This will prevent allocating with one and freeing with the other (because
@@ -69,21 +69,14 @@ namespace snmalloc
* having two different types.
*/
template<typename T>
class GlobalPagemapTemplate
struct GlobalPagemapTemplate
{
/**
* The global pagemap variable. The name of this symbol will include the
* type of `T`.
*/
inline static T global_pagemap;
public:
/**
* Returns the pagemap.
*/
static SuperslabPagemap& pagemap()
{
return global_pagemap;
return TypedSingleton<SuperslabPagemap>::global;
}
};