Revert "Add type confusion protection to the default memory provider."

This reverts commit d56201e28d.
This commit is contained in:
David Chisnall
2019-09-12 17:16:48 +01:00
parent dbea595b6e
commit 0b2b4d68a2
6 changed files with 14 additions and 29 deletions

View File

@@ -42,25 +42,6 @@ namespace snmalloc
}
};
/**
* A singleton global. Used to allow globals in headers. Precisely one
* instance of the static field will exist in the final program, irrespective
* of the number of compilation units that reference the field.
*
* C++ globals do not have their types as part of the name mangling, so this
* allows a singleton instance of a specific type that won't be confused with
* other template instantiations of the same type.
*/
template<class T>
struct TypedSingleton
{
/**
* The global variable, which will have a mangled name that includes the
* type of `T`.
*/
static inline T global;
};
/**
* Wrapper for wrapping values.
*

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 typed singleton so that its name
* This class makes the global pagemap a static field 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,14 +69,21 @@ namespace snmalloc
* having two different types.
*/
template<typename T>
struct GlobalPagemapTemplate
class 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 TypedSingleton<SuperslabPagemap>::global;
return global_pagemap;
}
};

View File

@@ -38,7 +38,7 @@ namespace snmalloc
static AllocPool* make() noexcept
{
return AllocPool::make(default_memory_provider());
return make(default_memory_provider);
}
Alloc* acquire()

View File

@@ -405,8 +405,5 @@ namespace snmalloc
* The memory provider that will be used if no other provider is explicitly
* passed as an argument.
*/
inline GlobalVirtual& default_memory_provider()
{
return TypedSingleton<GlobalVirtual>::global;
}
inline GlobalVirtual default_memory_provider;
} // namespace snmalloc

View File

@@ -145,7 +145,7 @@ namespace snmalloc
if (e->compare_exchange_strong(
value, LOCKED_ENTRY, std::memory_order_relaxed))
{
auto& v = default_memory_provider();
auto& v = default_memory_provider;
value = v.alloc_chunk<PagemapEntry, OS_PAGE_SIZE>();
e->store(value, std::memory_order_release);
}

View File

@@ -19,7 +19,7 @@ namespace snmalloc
* required. This avoids a branch on the fast path.
*/
inline Alloc GlobalPlaceHolder(
default_memory_provider(), SNMALLOC_DEFAULT_PAGEMAP(), nullptr, true);
default_memory_provider, SNMALLOC_DEFAULT_PAGEMAP(), nullptr, true);
#ifdef SNMALLOC_EXTERNAL_THREAD_ALLOC
/**