NFC: Introduce pointer domestication backend support

`capptr_domesticate<Backend>(Backend::LocalState*, CapPtr<T, B>)` is the
intended affordance for conversion to covert from a `CapPtr<T, B>` with
`B::wildness` `Wild` to a `CapPtr<>` with `B::with_wildness<Tame>` and thence
plumbed into the rest of the machinery.

David added the SFINAE wrapper so that `Backend`-s now don't need to implement a
domestication callback; instead, if the `Backend` does not provide a
`capptr_domesticate` function, a default, which just does an explicit type cast,
will be used instead.

This is not yet hooked into the rest of the tree.

Co-authored-by: David Chisnall <David.Chisnall@microsoft.com>
This commit is contained in:
Nathaniel Wesley Filardo
2021-08-16 21:03:29 +01:00
committed by Nathaniel Wesley Filardo
parent 7e53a2e82a
commit 1a608e6066
6 changed files with 133 additions and 1 deletions

View File

@@ -51,5 +51,33 @@ namespace snmalloc
{
Backend::init(local_state, base, length);
}
/* Verify that a pointer points into the region managed by this config */
template<typename T, SNMALLOC_CONCEPT(capptr::ConceptBound) B>
static SNMALLOC_FAST_PATH CapPtr<
T,
typename B::template with_wildness<capptr::dimension::Wildness::Tame>>
capptr_domesticate(typename Backend::LocalState* ls, CapPtr<T, B> p)
{
static_assert(B::wildness == capptr::dimension::Wildness::Wild);
static const size_t sz = sizeof(
std::conditional<std::is_same_v<std::remove_cv<T>, void>, void*, T>);
UNUSED(ls);
auto address = address_cast(p);
auto bounds = Backend::Pagemap::get_bounds(nullptr);
if (
(address < bounds.first) || (address > bounds.second) ||
((bounds.second - address) < sz))
{
return nullptr;
}
return CapPtr<
T,
typename B::template with_wildness<capptr::dimension::Wildness::Tame>>(
p.unsafe_ptr());
}
};
}