From 83b72722cf02567ffbb24f10e48f9ba19fb25db9 Mon Sep 17 00:00:00 2001 From: Nathaniel Filardo Date: Thu, 19 Nov 2020 21:35:32 +0000 Subject: [PATCH] NFC: Split InvalidPointer out of ds/dllist.h This lets us use Pagemaps without requiring dllists in scope --- src/ds/dllist.h | 48 +----------------------------------------- src/ds/invalidptr.h | 51 +++++++++++++++++++++++++++++++++++++++++++++ src/mem/pagemap.h | 1 + 3 files changed, 53 insertions(+), 47 deletions(-) create mode 100644 src/ds/invalidptr.h diff --git a/src/ds/dllist.h b/src/ds/dllist.h index ce40102..cdce56c 100644 --- a/src/ds/dllist.h +++ b/src/ds/dllist.h @@ -1,59 +1,13 @@ #pragma once #include "helpers.h" +#include "invalidptr.h" #include #include namespace snmalloc { - /** - * Invalid pointer class. This is similar to `std::nullptr_t`, but allows - * other values. - */ - template - struct InvalidPointer - { - /** - * Equality comparison. Two invalid pointer values with the same sentinel - * are always the same, invalid pointer values with different sentinels are - * always different. - */ - template - constexpr bool operator==(const InvalidPointer&) - { - return Sentinel == OtherSentinel; - } - /** - * Equality comparison. Two invalid pointer values with the same sentinel - * are always the same, invalid pointer values with different sentinels are - * always different. - */ - template - constexpr bool operator!=(const InvalidPointer&) - { - return Sentinel != OtherSentinel; - } - /** - * Implicit conversion, creates a pointer with the value of the sentinel. - * On CHERI and other provenance-tracking systems, this is a - * provenance-free integer and so will trap if dereferenced, on other - * systems the sentinel should be a value in unmapped memory. - */ - template - operator T*() const - { - return reinterpret_cast(Sentinel); - } - /** - * Implicit conversion to an address, returns the sentinel value. - */ - operator address_t() const - { - return Sentinel; - } - }; - template< class T, class Terminator = std::nullptr_t, diff --git a/src/ds/invalidptr.h b/src/ds/invalidptr.h new file mode 100644 index 0000000..b96be08 --- /dev/null +++ b/src/ds/invalidptr.h @@ -0,0 +1,51 @@ +#pragma once + +namespace snmalloc +{ + /** + * Invalid pointer class. This is similar to `std::nullptr_t`, but allows + * other values. + */ + template + struct InvalidPointer + { + /** + * Equality comparison. Two invalid pointer values with the same sentinel + * are always the same, invalid pointer values with different sentinels are + * always different. + */ + template + constexpr bool operator==(const InvalidPointer&) + { + return Sentinel == OtherSentinel; + } + /** + * Equality comparison. Two invalid pointer values with the same sentinel + * are always the same, invalid pointer values with different sentinels are + * always different. + */ + template + constexpr bool operator!=(const InvalidPointer&) + { + return Sentinel != OtherSentinel; + } + /** + * Implicit conversion, creates a pointer with the value of the sentinel. + * On CHERI and other provenance-tracking systems, this is a + * provenance-free integer and so will trap if dereferenced, on other + * systems the sentinel should be a value in unmapped memory. + */ + template + operator T*() const + { + return reinterpret_cast(Sentinel); + } + /** + * Implicit conversion to an address, returns the sentinel value. + */ + operator address_t() const + { + return Sentinel; + } + }; +} // namespace snmalloc diff --git a/src/mem/pagemap.h b/src/mem/pagemap.h index 345f687..ad462b7 100644 --- a/src/mem/pagemap.h +++ b/src/mem/pagemap.h @@ -2,6 +2,7 @@ #include "../ds/bits.h" #include "../ds/helpers.h" +#include "../ds/invalidptr.h" #include #include