Skip to content

Commit

Permalink
remotealloc: can_dequeue needs both domesticators
Browse files Browse the repository at this point in the history
If we're running with the freelist_backward_edge mitigation turned on, then
we're going to follow the pointer, not just de-obfuscate it (in freelist's
atomic_read_next), so even if the queue heads are tame, we still need to
do this domestication.
  • Loading branch information
nwf-msr committed Jan 5, 2024
1 parent fffc945 commit 24b7926
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
28 changes: 17 additions & 11 deletions src/snmalloc/mem/corealloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,19 +450,25 @@ namespace snmalloc
*/
SNMALLOC_FAST_PATH bool has_messages()
{
auto domesticate = [local_state = backend_state_ptr()](
freelist::QueuePtr p) SNMALLOC_FAST_PATH_LAMBDA {
if constexpr (Config::Options.QueueHeadsAreTame)
{
return freelist::HeadPtr::unsafe_from(p.unsafe_ptr());
}
else
{
auto local_state = backend_state_ptr();
auto domesticate_head =
[local_state](freelist::QueuePtr p) SNMALLOC_FAST_PATH_LAMBDA {
if constexpr (Config::Options.QueueHeadsAreTame)
{
UNUSED(local_state);
return freelist::HeadPtr::unsafe_from(p.unsafe_ptr());
}
else
{
return capptr_domesticate<Config>(local_state, p);
}
};
auto domesticate_queue =
[local_state](freelist::QueuePtr p) SNMALLOC_FAST_PATH_LAMBDA {
return capptr_domesticate<Config>(local_state, p);
}
};
};

return message_queue().can_dequeue(domesticate);
return message_queue().can_dequeue(domesticate_head, domesticate_queue);
}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/snmalloc/mem/remoteallocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ namespace snmalloc
return fnt;
}

template<typename Domesticator_head>
inline bool can_dequeue(Domesticator_head domesticate_head)
template<typename Domesticator_head, typename Domesticator_queue>
inline bool can_dequeue(
Domesticator_head domesticate_head, Domesticator_queue domesticate_queue)
{
return domesticate_head(front.load())
->atomic_read_next(key_global, domesticate_head) != nullptr;
->atomic_read_next(key_global, domesticate_queue) != nullptr;
}

/**
Expand Down

0 comments on commit 24b7926

Please sign in to comment.