From addd98e6db55a9453874f84022c73d71969d9f0a Mon Sep 17 00:00:00 2001 From: Nathaniel Filardo Date: Mon, 11 Jan 2021 18:04:59 +0000 Subject: [PATCH] NFC: Introduce Purpose parameter for PageMap wrappers Presently, GlobalPagemap and ExternalPagemap discriminate only by type. If it ever happened that multiple PageMap consumers instantiated the same type using these wrapper, they'd be conflated in the symbol table. Therefore, add an optional Purpose parameter that will be expanded into the symbols (but serves no other purpose). --- src/mem/chunkmap.h | 4 +++- src/mem/pagemap.h | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/mem/chunkmap.h b/src/mem/chunkmap.h index fd6b163..8d9f976 100644 --- a/src/mem/chunkmap.h +++ b/src/mem/chunkmap.h @@ -83,7 +83,9 @@ namespace snmalloc FlatPagemap, Pagemap>; - using GlobalChunkmap = GlobalPagemapTemplate; + struct ForChunkmap + {}; + using GlobalChunkmap = GlobalPagemapTemplate; /** * Optionally exported function that accesses the global chunkmap pagemap diff --git a/src/mem/pagemap.h b/src/mem/pagemap.h index f549553..345f687 100644 --- a/src/mem/pagemap.h +++ b/src/mem/pagemap.h @@ -422,13 +422,19 @@ namespace snmalloc * the memory will show up as not owned by any allocator in the other * compilation unit) but will prevent the same memory being interpreted as * having two different types. + * + * Simiarly, perhaps two modules wish to instantiate *different* pagemaps + * of the *same* type. Therefore, we add a `Purpose` parameter that can be + * used to pry symbols apart. By default, the `Purpose` is just the type of + * the pagemap; that is, pagemaps default to discrimination solely by their + * type. */ - template + template class GlobalPagemapTemplate { /** * The global pagemap variable. The name of this symbol will include the - * type of `T`. + * type of `T` and `U`. */ inline static T global_pagemap; @@ -448,8 +454,13 @@ namespace snmalloc * library (e.g. your C standard library) uses snmalloc and you wish to use a * different configuration in your program or library, but wish to share a * pagemap so that either version can deallocate memory. + * + * The `Purpose` parameter is as with `GlobalPgemapTemplate`. */ - template + template< + typename T, + void* (*raw_get)(const PagemapConfig**), + typename Purpose = T> class ExternalGlobalPagemapTemplate { /**