Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions score/mw/com/impl/bindings/lola/generic_skeleton_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ GenericSkeletonEvent::GenericSkeletonEvent(Skeleton& parent,

ResultBlank GenericSkeletonEvent::PrepareOffer() noexcept
{
std::tie(data_storage_, control_) = event_shared_impl_.GetParent().RegisterGeneric(
void* data_storage;
std::tie(data_storage, control_) = event_shared_impl_.GetParent().RegisterGeneric(
event_shared_impl_.GetElementFQId(), event_properties_, size_info_.size, size_info_.alignment);
data_storage_ = static_cast<std::uint8_t*>(data_storage);
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD(data_storage_ != nullptr);
event_shared_impl_.PrepareOfferCommon();

return {};
Expand Down Expand Up @@ -92,31 +95,22 @@ Result<score::mw::com::impl::SampleAllocateePtr<void>> GenericSkeletonEvent::All

if (slot.IsValidQM() || slot.IsValidAsilB())
{
// Get the actual CONTAINER object (using the max_align_t type we allocated it with!)
using StorageType = lola::EventDataStorage<std::max_align_t>;
StorageType* storage_ptr = data_storage_.get<StorageType>();
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD(storage_ptr != nullptr);

std::uint8_t* byte_ptr = reinterpret_cast<std::uint8_t*>(storage_ptr->data());

// Calculate the exact slot spacing based on alignment padding
const auto aligned_size = memory::shared::CalculateAlignedSize(size_info_.size, size_info_.alignment);
std::size_t offset = static_cast<std::size_t>(slot.GetIndex()) * aligned_size;
void* data_ptr = byte_ptr + offset;
void* data_ptr = static_cast<void*>(memory::shared::AddOffsetToPointer(data_storage_, offset));

auto lola_ptr = lola::SampleAllocateePtr<void>(data_ptr, control_.value(), slot);
return impl::MakeSampleAllocateePtr(std::move(lola_ptr));
}
else

if (!event_properties_.enforce_max_samples)
{
if (!event_properties_.enforce_max_samples)
{
::score::mw::log::LogError("lola")
<< "GenericSkeletonEvent: Allocation of event slot failed. Hint: enforceMaxSamples was "
"disabled by config. Might be the root cause!";
}
return MakeUnexpected(ComErrc::kBindingFailure);
::score::mw::log::LogError("lola")
<< "GenericSkeletonEvent: Allocation of event slot failed. Hint: enforceMaxSamples was "
"disabled by config. Might be the root cause!";
}
return MakeUnexpected(ComErrc::kBindingFailure);
}

std::pair<size_t, size_t> GenericSkeletonEvent::GetSizeInfo() const noexcept
Expand Down
2 changes: 1 addition & 1 deletion score/mw/com/impl/bindings/lola/generic_skeleton_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class GenericSkeletonEvent : public GenericSkeletonEventBinding
const SkeletonEventProperties event_properties_;
std::optional<EventDataControlComposite<>> control_{};
EventSlotStatus::EventTimeStamp current_timestamp_{1U};
score::memory::shared::OffsetPtr<void> data_storage_{nullptr};
std::uint8_t* data_storage_{nullptr};
bool qm_disconnect_{false};

SkeletonEventCommon event_shared_impl_;
Expand Down
47 changes: 20 additions & 27 deletions score/mw/com/impl/bindings/lola/skeleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1062,16 +1062,14 @@ EventDataControlComposite<> Skeleton::CreateEventControlComposite(
// coverity[autosar_cpp14_a3_8_1_violation]
control_asil_result = &iterator.first->second.data_control;
}
// clang-format off
// The lifetime of the "control_asil_result" object lasts as long as the Skeleton is alive.
// coverity[autosar_cpp14_m7_5_1_violation]
// coverity[autosar_cpp14_m7_5_2_violation]
// coverity[autosar_cpp14_a3_8_1_violation]
return EventDataControlComposite{&control_qm.first->second.data_control, control_asil_result};
}

std::pair<score::memory::shared::OffsetPtr<void>, EventDataControlComposite<>>
Skeleton::CreateEventDataFromOpenedSharedMemory(
std::pair<void*, EventDataControlComposite<>> Skeleton::CreateEventDataFromOpenedSharedMemory(
const ElementFqId element_fq_id,
const SkeletonEventProperties& element_properties,
size_t sample_size,
Expand All @@ -1082,11 +1080,11 @@ Skeleton::CreateEventDataFromOpenedSharedMemory(
if (sample_alignment > alignof(std::max_align_t))
{
score::mw::log::LogFatal("Skeleton")
<< "Requested sample alignment (" << sample_alignment
<< ") exceeds max_align_t (" << alignof(std::max_align_t)
<< "). Safe shared memory layout cannot be guaranteed.";
<< "Requested sample alignment (" << sample_alignment << ") exceeds max_align_t ("
<< alignof(std::max_align_t) << "). Safe shared memory layout cannot be guaranteed.";

SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD_MESSAGE(sample_alignment <= alignof(std::max_align_t),"Requested sample alignment exceeds maximum supported alignment.");
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD_MESSAGE(sample_alignment <= alignof(std::max_align_t),
"Requested sample alignment exceeds maximum supported alignment.");
}

// Calculate the aligned size for a single sample to ensure proper padding between slots
Expand All @@ -1097,30 +1095,28 @@ Skeleton::CreateEventDataFromOpenedSharedMemory(
const size_t num_max_align_elements =
(total_data_size_bytes + sizeof(std::max_align_t) - 1) / sizeof(std::max_align_t);

auto* data_storage = storage_resource_->construct<EventDataStorage<std::max_align_t>>(
num_max_align_elements,
memory::shared::PolymorphicOffsetPtrAllocator<std::max_align_t>(*storage_resource_));
auto* const data_storage = storage_resource_->construct<EventDataStorage<std::max_align_t>>(
num_max_align_elements, memory::shared::PolymorphicOffsetPtrAllocator<std::max_align_t>(*storage_resource_));

auto inserted_data_slots = storage_->events_.emplace(std::piecewise_construct,
std::forward_as_tuple(element_fq_id),
std::forward_as_tuple(data_storage));
auto inserted_data_slots = storage_->events_.emplace(
Copy link
Copy Markdown
Contributor

@crimson11 crimson11 Mar 30, 2026

Choose a reason for hiding this comment

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

Hm. Maybe I'm dumb ... but I'm asking myself, how your change should/could work at all?
So here you are inserting a "raw array" of n samples into the map ... this works, if later all accessors (proxy-events) - when accessing the map/reading out the storage would also expect such a "raw array" ... but they don't?
They are interpreting/expecting that the map contains an EventDataStorage<SampleType>, which definitely has a different layout than a "raw array"? See:

const auto* event_data_storage_ptr = event_entry->second.template get<EventDataStorage<EventSampleType>>();

What am I missing?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed that change. It uncovered a larger issue which we have with the GenericSkeleton implementation which prompted this ticket: #261

std::piecewise_construct, std::forward_as_tuple(element_fq_id), std::forward_as_tuple(data_storage));
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD_MESSAGE(inserted_data_slots.second,
"Couldn't register/emplace event-storage in data-section.");

"Couldn't register/emplace event-storage in data-section.");

const DataTypeMetaInfo sample_meta_info{sample_size, static_cast<std::uint8_t>(sample_alignment)};
void* const event_data_raw_array = data_storage->data();

auto inserted_meta_info = storage_->events_metainfo_.emplace(
std::piecewise_construct,
std::forward_as_tuple(element_fq_id),
std::forward_as_tuple(sample_meta_info, event_data_raw_array));
auto inserted_meta_info =
storage_->events_metainfo_.emplace(std::piecewise_construct,
std::forward_as_tuple(element_fq_id),
std::forward_as_tuple(sample_meta_info, event_data_raw_array));
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD_MESSAGE(inserted_meta_info.second,
"Couldn't register/emplace event-meta-info in data-section.");
"Couldn't register/emplace event-meta-info in data-section.");

return {score::memory::shared::OffsetPtr<void>(data_storage), CreateEventControlComposite(element_fq_id, element_properties)};
return {data_storage, CreateEventControlComposite(element_fq_id, element_properties)};
}
std::pair<score::memory::shared::OffsetPtr<void>, EventDataControlComposite<>> Skeleton::RegisterGeneric(

std::pair<void*, EventDataControlComposite<>> Skeleton::RegisterGeneric(
const ElementFqId element_fq_id,
const SkeletonEventProperties& element_properties,
const size_t sample_size,
Expand All @@ -1145,11 +1141,8 @@ std::pair<score::memory::shared::OffsetPtr<void>, EventDataControlComposite<>> S

return {data_storage, control_composite};
}
else
{
return CreateEventDataFromOpenedSharedMemory(
element_fq_id, element_properties, sample_size, sample_alignment);
}

return CreateEventDataFromOpenedSharedMemory(element_fq_id, element_properties, sample_size, sample_alignment);
}

ResultBlank Skeleton::OnServiceMethodsSubscribed(const ProxyInstanceIdentifier& proxy_instance_identifier,
Expand Down
28 changes: 11 additions & 17 deletions score/mw/com/impl/bindings/lola/skeleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,12 @@ class Skeleton final : public SkeletonBinding
/// \param sample_size The size of a single data sample in bytes.
/// \param sample_alignment The alignment requirement of the data sample in bytes.
/// \return A pair containing:
/// - An OffsetPtr to the allocated data storage (void*).
/// - An type erased pointer to the allocated data storage (void*).
/// - The EventDataControlComposite for managing the event's control data.
std::pair<score::memory::shared::OffsetPtr<void>, EventDataControlComposite<>> RegisterGeneric(
const ElementFqId element_fq_id,
const SkeletonEventProperties& element_properties,
const size_t sample_size,
const size_t sample_alignment) noexcept;
std::pair<void*, EventDataControlComposite<>> RegisterGeneric(const ElementFqId element_fq_id,
const SkeletonEventProperties& element_properties,
const size_t sample_size,
const size_t sample_alignment) noexcept;

/// \brief Enables dynamic registration of Events at the Skeleton.
/// \tparam SampleType The type of the event
Expand Down Expand Up @@ -209,11 +208,11 @@ class Skeleton final : public SkeletonBinding
/// \param sample_size The size of a single data sample.
/// \param sample_alignment The alignment of the data sample.
/// \return A pair containing the data storage pointer (void*) and the control composite.
std::pair<score::memory::shared::OffsetPtr<void>, EventDataControlComposite<>>
CreateEventDataFromOpenedSharedMemory(const ElementFqId element_fq_id,
const SkeletonEventProperties& element_properties,
size_t sample_size,
size_t sample_alignment) noexcept;
std::pair<void*, EventDataControlComposite<>> CreateEventDataFromOpenedSharedMemory(
const ElementFqId element_fq_id,
const SkeletonEventProperties& element_properties,
size_t sample_size,
size_t sample_alignment) noexcept;

class ShmResourceStorageSizes
{
Expand Down Expand Up @@ -360,13 +359,8 @@ auto Skeleton::Register(const ElementFqId element_fq_id, SkeletonEventProperties
}
return {typed_event_data_storage_ptr, event_data_control_composite};
}
else
{
auto [typed_event_data_storage_ptr, event_data_control_composite] =
CreateEventDataFromOpenedSharedMemory<SampleType>(element_fq_id, element_properties);

return {typed_event_data_storage_ptr, event_data_control_composite};
}
return CreateEventDataFromOpenedSharedMemory<SampleType>(element_fq_id, element_properties);
}

template <typename SampleType>
Expand Down
Loading