Skip to content
Open
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
10 changes: 9 additions & 1 deletion score/memory/shared/fake/my_bounded_memory_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ class MyBoundedMemoryResource final : public ManagedMemoryResource
MyBoundedMemoryResource& operator=(const MyBoundedMemoryResource&) noexcept = default;
MyBoundedMemoryResource& operator=(MyBoundedMemoryResource&&) noexcept = default;

MemoryResourceProxy* getMemoryResourceProxy() noexcept override
const MemoryResourceProxy* getMemoryResourceProxy() const noexcept override
{
return manager_;
}

[[deprecated(
"SCORE_DEPRECATION: Please use const getMemoryResourceProxy() const noexcept instead, which is the "
"non-deprecated version of this function. This function will be removed in a future release.")]]
const MemoryResourceProxy* getMemoryResourceProxy() noexcept override
{
return manager_;
}
Expand Down
10 changes: 9 additions & 1 deletion score/memory/shared/fake/my_bounded_shared_memory_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,15 @@ class MyBoundedSharedMemoryResource final : public ISharedMemoryResource
return false;
}

MemoryResourceProxy* getMemoryResourceProxy() noexcept override
[[deprecated(
"SCORE_DEPRECATION: Please use const getMemoryResourceProxy() const noexcept instead, which is the "
"non-deprecated version of this function. This function will be removed in a future release.")]]
const MemoryResourceProxy* getMemoryResourceProxy() noexcept override
{
return resource_.getMemoryResourceProxy();
}

const MemoryResourceProxy* getMemoryResourceProxy() const noexcept override
{
return resource_.getMemoryResourceProxy();
}
Expand Down
14 changes: 11 additions & 3 deletions score/memory/shared/fake/my_memory_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,20 @@ class MyMemoryResource : public ManagedMemoryResource
memoryResourceId_{instanceId++},
manager_{memoryResourceId_}
{
MemoryResourceRegistry::getInstance().clear();
score::cpp::ignore = MemoryResourceRegistry::getInstance().insert_resource({memoryResourceId_, this});
}

MemoryResourceProxy* getMemoryResourceProxy() noexcept override
[[deprecated(
"SCORE_DEPRECATION: Please use const getMemoryResourceProxy() const noexcept instead, which is the "
"non-deprecated version of this function. This function will be removed in a future release.")]]
const MemoryResourceProxy* getMemoryResourceProxy() noexcept override
{
return &this->manager_;
}

const MemoryResourceProxy* getMemoryResourceProxy() const noexcept override
{
MemoryResourceRegistry::getInstance().clear();
score::cpp::ignore = MemoryResourceRegistry::getInstance().insert_resource({memoryResourceId_, this});
return &this->manager_;
}

Expand Down
21 changes: 18 additions & 3 deletions score/memory/shared/managed_memory_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,25 @@ class ManagedMemoryResource : public ::score::cpp::pmr::memory_resource
* pointer into an OffsetPtr if it shall be stored in shared memory.
* @return MemoryResourceProxy* that identifies _this_ memory_resource.
*/

/// \todo: getMemoryResourceProxy should not return a non const pointer and the method should also be marked const.
/// This issue will be investigated and fixed in Ticket-146625"
[[deprecated(
"SCORE_DEPRECATION: Please use const getMemoryResourceProxy() const noexcept instead, which is the "
"non-deprecated version of this function. This function will be removed in a future release.")]]
virtual const MemoryResourceProxy* getMemoryResourceProxy() noexcept = 0;

/**
* We need to return a raw pointer, since we need to convert this
* pointer into an OffsetPtr if it shall be stored in shared memory.
* @return MemoryResourceProxy* that identifies _this_ memory_resource.
*
* @note Not pure virtual yet: mw::com has a subclass that does not override this yet and cannot be
* updated until this change is consumed downstream. Returning nullptr is safe here since this
* is a private method only reachable by the friend classes above, which always operate on
* subclasses that provide their own override. Will be made pure virtual once downstream is updated.
*/
virtual const MemoryResourceProxy* getMemoryResourceProxy() const noexcept
{
return nullptr;
}
};

} // namespace score::memory::shared
Expand Down
8 changes: 8 additions & 0 deletions score/memory/shared/memory_resource_registry_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class BasicMemoryResource : public ManagedMemoryResource
{
return nullptr;
}
const MemoryResourceProxy* getMemoryResourceProxy() const noexcept override
{
return nullptr;
}
void* getBaseAddress() const noexcept override
{
return base_address_;
Expand Down Expand Up @@ -101,6 +105,10 @@ class BoundsCheckBypassingMemoryResource : public ManagedMemoryResource
{
return nullptr;
}
const MemoryResourceProxy* getMemoryResourceProxy() const noexcept override
{
return nullptr;
}
void* getBaseAddress() const noexcept override
{
return base_address_;
Expand Down
29 changes: 19 additions & 10 deletions score/memory/shared/new_delete_delegate_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ static_assert((PAGE_SIZE % alignof(std::max_align_t) == 0), "allocation_buffer_s
} // namespace

// coverity[autosar_cpp14_a3_3_1_violation] false-positive: declared in header, implemented here
NewDeleteDelegateMemoryResource::NewDeleteDelegateMemoryResource(const std::uint64_t mem_res_id,
score::cpp::pmr::memory_resource* upstream_resource) noexcept
NewDeleteDelegateMemoryResource::NewDeleteDelegateMemoryResource(
const std::uint64_t mem_res_id,
score::cpp::pmr::memory_resource* upstream_resource) noexcept
: ManagedMemoryResource{},
upstream_resource_{upstream_resource},
memory_resource_id_{mem_res_id},
Expand All @@ -48,7 +49,8 @@ NewDeleteDelegateMemoryResource::NewDeleteDelegateMemoryResource(const std::uint
current_upstream_allocations_{}
{
auto result = MemoryResourceRegistry::getInstance().insert_resource({memory_resource_id_, this});
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD_MESSAGE(result, "memory resource id clash! Inserting NewDeleteDelegateMemoryResource failed.");
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD_MESSAGE(
result, "memory resource id clash! Inserting NewDeleteDelegateMemoryResource failed.");
}

NewDeleteDelegateMemoryResource::~NewDeleteDelegateMemoryResource()
Expand Down Expand Up @@ -94,7 +96,11 @@ const void* NewDeleteDelegateMemoryResource::getEndAddress() const noexcept

const MemoryResourceProxy* NewDeleteDelegateMemoryResource::getMemoryResourceProxy() noexcept
{
// Suppress "AUTOSAR C++14 A9-3-1" rule finding: "Member functions shall not return non-const “raw” pointers or
// coverity[autosar_cpp14_a9_3_1_violation]
return &proxy_;
}
const MemoryResourceProxy* NewDeleteDelegateMemoryResource::getMemoryResourceProxy() const noexcept
{ // Suppress "AUTOSAR C++14 A9-3-1" rule finding: "Member functions shall not return non-const “raw” pointers or
// references to private or protected data owned by the class.".
// The function provides controlled access to the internal 'proxy_' member. 'proxy_' is part of the class's
// implementation details and is not meant for direct external access.
Expand All @@ -119,9 +125,9 @@ void* NewDeleteDelegateMemoryResource::do_allocate(const std::size_t bytes, std:
// the real allocation gets forwarded to upstream new-delete res.
auto* const result = upstream_resource_->allocate(bytes, alignment);

// LCOV_EXCL_START (Defensive programming: score::cpp::pmr::memory_resource already asserts that the allocate call on the
// underlying allocator does not return a nullptr so this branch can never be entered)
// LCOV_EXCL_BR_START (See line coverage suppression explanation)
// LCOV_EXCL_START (Defensive programming: score::cpp::pmr::memory_resource already asserts that the allocate call
// on the underlying allocator does not return a nullptr so this branch can never be entered) LCOV_EXCL_BR_START
// (See line coverage suppression explanation)
if (result == nullptr)
{
score::mw::log::LogError("shm")
Expand All @@ -134,7 +140,8 @@ void* NewDeleteDelegateMemoryResource::do_allocate(const std::size_t bytes, std:

const auto emplace_result = current_upstream_allocations_.emplace(
std::piecewise_construct, std::forward_as_tuple(result), std::forward_as_tuple(bytes, alignment));
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD_MESSAGE(emplace_result.second, "Could not emplace allocation in allocation map.");
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD_MESSAGE(emplace_result.second,
"Could not emplace allocation in allocation map.");

// calculation of how many bytes will be effectively needed is done here
// at the basis of how our (real) shared-mem resource allocation behavior! So the following alloc-approach exactly
Expand All @@ -155,7 +162,8 @@ void* NewDeleteDelegateMemoryResource::do_allocate(const std::size_t bytes, std:
safe_math::Add(bytes, alignment).and_then([](const auto max_required_padding) noexcept {
return safe_math::Subtract(max_required_padding, 1U);
});
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD_MESSAGE(max_required_padding_result.has_value(), "Calculating max required padding overflowed!");
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD_MESSAGE(max_required_padding_result.has_value(),
"Calculating max required padding overflowed!");

void* const end_memory_buffer =
// In our architecture we have a one-to-one mapping between pointers and integral values.
Expand All @@ -173,7 +181,8 @@ void* NewDeleteDelegateMemoryResource::do_allocate(const std::size_t bytes, std:
safe_math::Add(bytes, static_cast<std::size_t>(padding)).and_then([this](const auto allocated_bytes) noexcept {
return safe_math::Add(sum_allocated_bytes_, allocated_bytes);
});
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD_MESSAGE(allocated_bytes_result.has_value(), "Calculating allocated bytes overflowed!");
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD_MESSAGE(allocated_bytes_result.has_value(),
"Calculating allocated bytes overflowed!");
sum_allocated_bytes_ = allocated_bytes_result.value();

return result;
Expand Down
4 changes: 4 additions & 0 deletions score/memory/shared/new_delete_delegate_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ class NewDeleteDelegateMemoryResource : public score::memory::shared::ManagedMem

~NewDeleteDelegateMemoryResource() override;

[[deprecated(
"SCORE_DEPRECATION: Please use const getMemoryResourceProxy() const noexcept instead, which is the "
"non-deprecated version of this function. This function will be removed in a future release.")]]
const MemoryResourceProxy* getMemoryResourceProxy() noexcept override;
const MemoryResourceProxy* getMemoryResourceProxy() const noexcept override;
void* getBaseAddress() const noexcept override;
void* getUsableBaseAddress() const noexcept override;

Expand Down
2 changes: 1 addition & 1 deletion score/memory/shared/polymorphic_offset_ptr_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class PolymorphicOffsetPtrAllocator

// Non-explicit constructor is good enough for maintaining required implicit conversion
// NOLINTNEXTLINE(google-explicit-constructor): Tolerated, discard explicit.
PolymorphicOffsetPtrAllocator(ManagedMemoryResource& resource) noexcept : proxy_{resource.getMemoryResourceProxy()}
PolymorphicOffsetPtrAllocator(ManagedMemoryResource& resource) noexcept : proxy_{std::as_const(resource).getMemoryResourceProxy()}
{
}

Expand Down
Loading
Loading