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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ chronological order.
Recovery removes only validated older descriptors and preserves current
ownership and corruption checks. This is a compatible bug fix; public APIs,
ABI 2.0, and the SMS2 layout are unchanged.
- Fixed native lease and reservation projections remaining available after the
shared store leaves Ready. This is a patch-level correction with no API or
mapped protocol change.

## 3.0.0 - 2026-07-16

Expand Down
6 changes: 6 additions & 0 deletions docs/lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ Synchronize concurrent attempts to reopen or replace the same wrapper.

## Generations and Incarnations

Native lease and reservation accessors check the shared store's Ready state
before projecting memory. After shared corruption or another non-Ready state
is observed, validity is false, lengths are zero, and new borrowed spans are
empty. An already returned span cannot be revoked; its caller remains
responsible for observing the store and token lifetime.

Slots, leases, participants, directory operations, and their public tokens use
generation/incarnation identity. A transition compares the complete encoded
identity before exposing memory, helping, releasing, or reclaiming. Terminal
Expand Down
14 changes: 10 additions & 4 deletions src/cpp/src/store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,10 @@ bool Store::project_lease(
descriptor_length = 0;
sms::test_detail::reach_checkpoint(
sms::test_detail::CheckpointId::ProjectBeforeHandleValidation);
if (state_ == nullptr || !lease.valid()) return false;
if (state_ == nullptr || !lease.valid() ||
state_->control.ensure_ready() != SMS_STATUS_SUCCESS) {
return false;
}
std::uint64_t registry_binding{};
if (!state_->leases.try_get_active_slot_binding(
lease, registry_binding) ||
Expand Down Expand Up @@ -1317,7 +1320,8 @@ bool Store::reservation_valid(
LifecycleId lifecycle) noexcept {
LifecycleGate::Operation operation;
if (lifecycle_.try_enter(operation) != SMS_STATUS_SUCCESS ||
state_ == nullptr || !lifecycle.reservation_valid()) {
state_ == nullptr || !lifecycle.reservation_valid() ||
state_->control.ensure_ready() != SMS_STATUS_SUCCESS) {
return false;
}
IndexBinding binding{};
Expand All @@ -1339,7 +1343,8 @@ std::int32_t Store::reservation_bytes_written(
LifecycleId lifecycle) noexcept {
LifecycleGate::Operation operation;
if (lifecycle_.try_enter(operation) != SMS_STATUS_SUCCESS ||
state_ == nullptr || !lifecycle.reservation_valid()) {
state_ == nullptr || !lifecycle.reservation_valid() ||
state_->control.ensure_ready() != SMS_STATUS_SUCCESS) {
return 0;
}
IndexBinding binding{};
Expand All @@ -1355,7 +1360,8 @@ std::span<std::uint8_t> Store::reservation_buffer(
std::int32_t size_hint) noexcept {
LifecycleGate::Operation operation;
if (lifecycle_.try_enter(operation) != SMS_STATUS_SUCCESS ||
state_ == nullptr || !lifecycle.reservation_valid()) {
state_ == nullptr || !lifecycle.reservation_valid() ||
state_->control.ensure_ready() != SMS_STATUS_SUCCESS) {
return {};
}
IndexBinding binding{};
Expand Down
4 changes: 3 additions & 1 deletion tests/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set(
protocol_tests.cpp
store_tests.cpp
c_api_tests.cpp
projection_control_tests.cpp
lifecycle_tests.cpp
local_handle_tests.cpp
diagnostics_tests.cpp)
Expand Down Expand Up @@ -53,7 +54,8 @@ function(_sms_add_native_test source_name)
set(_target "sms_${_test_stem}")

add_executable(${_target} "${_source}")
if(_test_stem STREQUAL "protocol_tests")
if(_test_stem STREQUAL "protocol_tests" OR
_test_stem STREQUAL "projection_control_tests")
target_sources(
${_target}
PRIVATE "${PROJECT_SOURCE_DIR}/src/cpp/src/protocol.cpp")
Expand Down
40 changes: 40 additions & 0 deletions tests/cpp/projection_control_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "interop_faults.hpp"
#include "mapped_atomic.hpp"
#include "test_support.hpp"

int main() {
using namespace shared_memory_store;
using namespace sms::detail;

for (const auto control : {
sms2_store_initializing, sms2_store_corrupt, sms2_store_unsupported,
std::uint64_t{0xffff}}) {
auto options = sms_test_options("projection-control", 2, 2);
memory_store store;
SMS_CHECK(memory_store::try_create_or_open(options, store) == open_status::success);
SMS_CHECK(store.try_publish(sms_test_bytes("key"), sms_test_bytes("payload"),
sms_test_bytes("descriptor")) == status::success);
value_lease lease;
SMS_CHECK(store.try_acquire(sms_test_bytes("key"), lease) == status::success);
value_reservation reservation;
SMS_CHECK(store.try_reserve(sms_test_bytes("reserved"), 4, {}, reservation) ==
status::success);
SMS_CHECK(lease.valid() && lease.value().size() == 7 && lease.descriptor().size() == 10);
SMS_CHECK(reservation.valid() && reservation.buffer().size() == 4);
SMS_CHECK(reservation.advance(1) == status::success);
SMS_CHECK(reservation.payload_length() == 4 && reservation.bytes_written() == 1);

// Change the actual shared control after valid tokens have escaped.
sms::interop_test::raw_mapping mapping(options);
auto& header = sms::interop_test::validate_raw_mapping(mapping, options);
MappedAtomic64::store_release(header.Control, control);
SMS_CHECK(!lease.valid());
SMS_CHECK(lease.value().empty());
SMS_CHECK(lease.descriptor().empty());
SMS_CHECK(!reservation.valid());
SMS_CHECK(reservation.buffer().empty());
SMS_CHECK(reservation.payload_length() == 0 && reservation.bytes_written() == 0);
SMS_CHECK(MappedAtomic64::load_acquire(header.Control) == control);
}
return 0;
}
Loading