Skip to content

mw/com: Use pointer instead of copy for EventDataControlComposite#454

Draft
ahmed0mousa wants to merge 4 commits into
eclipse-score:mainfrom
ahmed0mousa:ahmo_fix_samle_allocatee_ptr
Draft

mw/com: Use pointer instead of copy for EventDataControlComposite#454
ahmed0mousa wants to merge 4 commits into
eclipse-score:mainfrom
ahmed0mousa:ahmo_fix_samle_allocatee_ptr

Conversation

@ahmed0mousa

@ahmed0mousa ahmed0mousa commented May 20, 2026

Copy link
Copy Markdown
Contributor

Changed SampleAllocateePtr to hold pointer to SkeletonEvent's EventDataControlComposite
Added SampleAllocateeTracker/Guard to track outstanding allocations
SkeletonEvent terminates if destroyed while SampleAllocateePtr instances exist
Update unit tests

Fixes state synchronization issues and prevents dangling pointer access.

Issue: SWP-62366

@ahmed0mousa ahmed0mousa force-pushed the ahmo_fix_samle_allocatee_ptr branch 3 times, most recently from a818e1c to 35d61d0 Compare May 20, 2026 14:17
@ahmed0mousa ahmed0mousa changed the title Ahmo fix samle allocatee ptr SampleAllocatePtr/SamplePtr shall not contain EventDataControlComposite May 21, 2026
@ahmed0mousa ahmed0mousa changed the title SampleAllocatePtr/SamplePtr shall not contain EventDataControlComposite mw/com: Use pointer instead of copy for EventDataControlComposite May 21, 2026
@ahmed0mousa ahmed0mousa force-pushed the ahmo_fix_samle_allocatee_ptr branch 4 times, most recently from 7e056e5 to 4bae17f Compare May 26, 2026 13:00
SampleAllocateeTracker counts outstanding SampleAllocateePtr instances and
terminates if any outlive the SkeletonEvent, symmetric with
SampleReferenceTracker for subscribers. SampleAllocateeGuard is a move-only
RAII type backed by utils::ScopeExit that decrements the tracker on destruction.

Issue: SWP-62366
…in lola SampleAllocateePtr

SampleAllocateePtr previously copied the EventDataControlComposite into an
std::optional on every allocation. Replace the field with a non-owning raw
pointer, the composite is owned by SkeletonEvent and guaranteed to outlive all
SampleAllocateePtr instances via SampleAllocateeTracker. Delete copy/move on
EventDataControlComposite with static_asserts to prevent use-after-free.

Issue: SWP-62366
…SampleAllocateePtr lifetime

Add SampleAllocateeTracker to SkeletonEventBase and pass a SampleAllocateeGuard
into every Allocate() and Send() call down through the binding interfaces and
implementations. The guard is stored inside the resulting SampleAllocateePtr so
the tracker count stays elevated for as long as any SampleAllocateePtr is alive,
aborting the application if the SkeletonEvent is destroyed first.

Issue: SWP-62366
The C++ LolaSampleAllocateePtrBinding changed event_data_control from a
CxxOptional<EventDataControlComposite> to a raw pointer. Update the Rust struct
accordingly and replace the UniquePtr union variant with a MockBinding variant
to match the mock_binding::SampleAllocateePtr memory layout.

Issue: SWP-62366
@ahmed0mousa ahmed0mousa force-pushed the ahmo_fix_samle_allocatee_ptr branch from 4bae17f to ab9677e Compare May 27, 2026 09:03
/// any SampleAllocateePtr instances created from it. The SampleAllocateeTracker ensures this by terminating
/// if SampleAllocateePtr instances outlive the SkeletonEvent. Can only be a nullptr if SampleAllocateePtr is
/// default constructed.
EventDataControlComposite<>* event_data_control_ptr_;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should have static asserts here that EventDataControlComposite is not movable / copyable.

/// \details In production code, guards must be obtained via SampleAllocateeTracker::Allocate() so that
/// every allocation is tracked. Direct default construction produces a no-op guard and is therefore
/// only intended for use in tests, where a real SampleAllocateeTracker is not available.
SampleAllocateeGuard() = default;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class should use "score/scope_exit/scope_exit.h" for handling deallocation on destruction so that we're not reimplementing the behaviour here. You can also then remove the move tests if you add a static assert that ScopeExit is used. See "score/mw/com/impl/bindings/lola/transaction_log_registration_guard.h" and the test in this pr as an example: #268

"//score/mw/com:__subpackages__",
],
deps = [":common_rs"],
deps = [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please ask @bharatGoswami8 or @darkwisebear to double check the rust changes

/// In production, guards must be obtained from SampleAllocateeTracker::Allocate(); use MakeSampleAllocateePtr
/// with a guard instead.
template <typename T>
auto MakeSampleAllocateePtr(T ptr) noexcept -> SampleAllocateePtr<typename T::element_type>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this now be renamed to MakeTestSampleAllocateePtr?

/// \details This is a non-owning pointer. The SkeletonEvent owns the EventDataControlComposite and must outlive
/// any SampleAllocateePtr instances created from it. The SampleAllocateeTracker ensures this by terminating
/// if SampleAllocateePtr instances outlive the SkeletonEvent. Can only be a nullptr if SampleAllocateePtr is
/// default constructed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment is different to the latest state of https://cc-github.bmwgroup.net/swh/safe-posix-platform/pull/17115/. Can you please make sure that you ported the latest version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants