NFC: CapPtr in external_pointer; drop capptr_rebound
capptr_rebound was only ever going to be used for external_pointer, which now operates entirely using pointer_offset. So instead, just make external_pointer use capptr::AllocWild<void>, capptr_from_client, and a new capptr_reveal_wild.
This commit is contained in:
committed by
Nathaniel Wesley Filardo
parent
3462c53983
commit
c54d2b527d
@@ -202,21 +202,6 @@ namespace snmalloc
|
||||
UNUSED(size);
|
||||
return CapPtr<T, BOut>(a.template as_static<T>().unsafe_capptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* For architectures which do not enforce StrictProvenance, there's nothing
|
||||
* to be done, so just return the pointer unmodified with new annotation.
|
||||
*/
|
||||
template<
|
||||
typename T,
|
||||
SNMALLOC_CONCEPT(capptr::ConceptBound) BOut,
|
||||
SNMALLOC_CONCEPT(capptr::ConceptBound) BIn>
|
||||
static SNMALLOC_FAST_PATH CapPtr<T, BOut>
|
||||
capptr_rebound(CapPtr<void, BOut> a, CapPtr<T, BIn> r) noexcept
|
||||
{
|
||||
UNUSED(a);
|
||||
return CapPtr<T, BOut>(r.unsafe_capptr);
|
||||
}
|
||||
};
|
||||
} // namespace snmalloc
|
||||
|
||||
|
||||
@@ -53,12 +53,6 @@ namespace snmalloc
|
||||
{ AAL::template capptr_bound<void, capptr::bounds::Chunk>(auth, sz) }
|
||||
noexcept
|
||||
-> ConceptSame<capptr::Chunk<void>>;
|
||||
|
||||
/**
|
||||
* Construct a copy of auth with its target set to that of ret.
|
||||
*/
|
||||
{ AAL::capptr_rebound(auth, ret) } noexcept
|
||||
-> ConceptSame<capptr::Chunk<void>>;
|
||||
};
|
||||
|
||||
template<typename AAL>
|
||||
|
||||
@@ -371,6 +371,16 @@ namespace snmalloc
|
||||
return p.unsafe_capptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Like capptr_reveal, but sometimes we do mean to reveal wild pointers
|
||||
* (specifically in external_pointer, where we're revealing something
|
||||
* architecturally derived from a user pointer).
|
||||
*/
|
||||
inline SNMALLOC_FAST_PATH void* capptr_reveal_wild(capptr::AllocWild<void> p)
|
||||
{
|
||||
return p.unsafe_capptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a void* from the client, it's fine to call it AllocWild.
|
||||
* Roughly dual to capptr_reveal().
|
||||
|
||||
@@ -628,26 +628,28 @@ namespace snmalloc
|
||||
// be implicit domestication through the `SharedStateHandle::Pagemap` or
|
||||
// we could just leave well enough alone.
|
||||
|
||||
// TODO bring back the CHERI bits. Wes to review if required.
|
||||
capptr::AllocWild<void> p = capptr_from_client(p_raw);
|
||||
|
||||
MetaEntry entry =
|
||||
SharedStateHandle::Pagemap::template get_metaentry<true>(
|
||||
core_alloc->backend_state_ptr(), address_cast(p_raw));
|
||||
core_alloc->backend_state_ptr(), address_cast(p));
|
||||
auto sizeclass = entry.get_sizeclass();
|
||||
if (likely(entry.get_remote() != SharedStateHandle::fake_large_remote))
|
||||
{
|
||||
auto rsize = sizeclass_to_size(sizeclass);
|
||||
auto offset =
|
||||
address_cast(p_raw) & (sizeclass_to_slab_size(sizeclass) - 1);
|
||||
auto offset = address_cast(p) & (sizeclass_to_slab_size(sizeclass) - 1);
|
||||
auto start_offset = round_by_sizeclass(sizeclass, offset);
|
||||
if constexpr (location == Start)
|
||||
{
|
||||
UNUSED(rsize);
|
||||
return pointer_offset(p_raw, start_offset - offset);
|
||||
return capptr_reveal_wild(pointer_offset(p, start_offset - offset));
|
||||
}
|
||||
else if constexpr (location == End)
|
||||
return pointer_offset(p_raw, rsize + start_offset - offset - 1);
|
||||
return capptr_reveal_wild(
|
||||
pointer_offset(p, rsize + start_offset - offset - 1));
|
||||
else
|
||||
return pointer_offset(p_raw, rsize + start_offset - offset);
|
||||
return capptr_reveal_wild(
|
||||
pointer_offset(p, rsize + start_offset - offset));
|
||||
}
|
||||
|
||||
// Sizeclass zero of a large allocation is used for not managed by us.
|
||||
@@ -655,13 +657,13 @@ namespace snmalloc
|
||||
{
|
||||
// This is a large allocation, find start by masking.
|
||||
auto rsize = bits::one_at_bit(sizeclass);
|
||||
auto start = pointer_align_down(p_raw, rsize);
|
||||
auto start = pointer_align_down(p, rsize);
|
||||
if constexpr (location == Start)
|
||||
return start;
|
||||
return capptr_reveal_wild(start);
|
||||
else if constexpr (location == End)
|
||||
return pointer_offset(start, rsize - 1);
|
||||
return capptr_reveal_wild(pointer_offset(start, rsize - 1));
|
||||
else
|
||||
return pointer_offset(start, rsize);
|
||||
return capptr_reveal_wild(pointer_offset(start, rsize));
|
||||
}
|
||||
#else
|
||||
UNUSED(p_raw);
|
||||
|
||||
Reference in New Issue
Block a user