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
2 changes: 1 addition & 1 deletion Cargo.Bazel.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "78ee0c1e0f1e28fb03cfdcc395750365321533e43738066bd1bb08b78afff9ce",
"checksum": "aec5441bc2d908ea6fd0199c74f33839d730841211b5ebb82242f4310938f476",
"crates": {
"addr2line 0.24.2": {
"name": "addr2line",
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions doc/release-notes/iceoryx2-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@
[#223](https://github.com/eclipse-iceoryx/iceoryx2/issues/223)
* Remove rule suppression in clang-tidy
[#280](https://github.com/eclipse-iceoryx/iceoryx2/issues/280)
* Move BumpAllocator from iceoryx2-bb-memory into iceoryx2-bb-elementary
[#996](https://github.com/eclipse-iceoryx/iceoryx2/issues/996)
* Remove support for Bazel Workspaces
[#1263](https://github.com/eclipse-iceoryx/iceoryx2/issues/1263)
* Adjust test names to naming convention
Expand Down Expand Up @@ -314,3 +316,39 @@
// new
use iceoryx2_services_tunnel::{Config, Tunnel};
```

1. The `Bumpallocator` from iceoryx2-bb-memory crate has been
moved into the iceoryx2-bb-elementary crate and replaces it.
The `Bumpallocator` is re-exported in iceoryx2-bb-memory and
expects now a `NonNull<u8>` as start address and the size
of the memory that the Allocator manages.

```rust
// old
use iceoryx2_bb_elementary::bump_allocator::BumpAllocator;

let memory = [0u8; 8192];
let start_position: *mut u8 = memory.as_mut_ptr();
let sut = BumpAllocator::new(start_position);

// new
use iceoryx2_bb_elementary::bump_allocator::BumpAllocator;
use iceoryx2_bb_elementary_traits::{non_null::NonNull, non_null::NonNullCompat};

let memory = [0u8; 8192];
let sut = BumpAllocator::new(
<NonNull<u8> as NonNullCompat<u8>>::from_ref(&memory[0]),
memory.len(),
);
```

1. The `bump_allocator` module in the `iceoryx2-cal` package
has been renamed to shm_bump_allocator.

```rust
// old
use iceoryx2_cal::shm_allocator::bump_allocator::BumpAllocator;

// new
use iceoryx2_cal::shm_allocator::shm_bump_allocator::BumpAllocator;
```
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl iceoryx2::service::Service for CustomServiceVariant {
iceoryx2_cal::dynamic_storage::file::Storage<KeyType>;
// the blackboard payload is replaced with a file based version
type BlackboardPayload = iceoryx2_cal::shared_memory::file::Memory<
iceoryx2_cal::shm_allocator::bump_allocator::BumpAllocator,
iceoryx2_cal::shm_allocator::shm_bump_allocator::BumpAllocator,
>;
}

Expand Down
21 changes: 19 additions & 2 deletions iceoryx2-bb/container/src/flatmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,15 @@ impl<K: Eq, V: Clone, const CAPACITY: usize> PlacementDefault for FixedSizeFlatM
unsafe {
let map_ptr = core::ptr::addr_of_mut!((*ptr).map);
map_ptr.write(RelocatableFlatMap::new_uninit(CAPACITY));
let allocator = BumpAllocator::new((*ptr)._idx_to_data.as_mut_ptr().cast());

// SAFETY: Creating a pointer to an existing member is always not null
let data_ptr =
core::ptr::NonNull::<u8>::new_unchecked((*ptr)._idx_to_data.as_mut_ptr().cast());

let allocator = BumpAllocator::new(
data_ptr,
size_of::<Self>() - core::mem::offset_of!(Self, _idx_to_data),
);
(*ptr)
.map
.init(&allocator)
Expand Down Expand Up @@ -708,7 +716,16 @@ impl<K: Eq, V: Clone, const CAPACITY: usize> FixedSizeFlatMap<K, V, CAPACITY> {
_data: MaybeUninit::uninit(),
_data_next_free_index: MaybeUninit::uninit(),
};
let allocator = BumpAllocator::new(new_self._idx_to_data.as_mut_ptr().cast());

// SAFETY: Creating a pointer to an existing member is always not null
let data_ptr = unsafe {
core::ptr::NonNull::<u8>::new_unchecked(new_self._idx_to_data.as_mut_ptr().cast())
};

let allocator = BumpAllocator::new(
data_ptr,
size_of::<Self>() - core::mem::offset_of!(Self, _idx_to_data),
);
unsafe {
new_self
.map
Expand Down
25 changes: 21 additions & 4 deletions iceoryx2-bb/container/src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@
//! queue_memory: [const { MaybeUninit::uninit() }; QUEUE_CAPACITY] ,
//! };
//!
//! let allocator = BumpAllocator::new(new_self.queue_memory.as_mut_ptr().cast());
//! let data_ptr =
//! unsafe { core::ptr::NonNull::<u8>::new_unchecked(new_self.queue_memory.as_mut_ptr().cast()) };
//!
//! let allocator = BumpAllocator::new(data_ptr, core::mem::size_of_val(new_self.queue_memory.as_ref()));
//!
//! unsafe {
//! new_self.queue.init(&allocator).expect("Enough memory provided.")
//! };
Expand All @@ -103,7 +107,11 @@
//! const MEM_SIZE: usize = RelocatableQueue::<u128>::const_memory_size(QUEUE_CAPACITY);
//! let mut memory = [0u8; MEM_SIZE];
//!
//! let bump_allocator = BumpAllocator::new(memory.as_mut_ptr());
//! let bump_allocator = BumpAllocator::new(
//! core::ptr::NonNull::<u8>::new(memory.as_mut_ptr().cast())
//! .expect("Precondition failed: Pointer to memory is null"),
//! memory.len()
//! );
//!
//! let mut queue = unsafe { RelocatableQueue::<u128>::new_uninit(QUEUE_CAPACITY) };
//! unsafe { queue.init(&bump_allocator).expect("queue init failed") };
Expand Down Expand Up @@ -481,7 +489,11 @@ impl<T, const CAPACITY: usize> PlacementDefault for FixedSizeQueue<T, CAPACITY>
let state_ptr = core::ptr::addr_of_mut!((*ptr).state);
state_ptr.write(RelocatableQueue::new_uninit(CAPACITY));

let allocator = BumpAllocator::new((*ptr)._data.as_mut_ptr().cast());
// SAFETY: Creating a pointer to an existing member is always not null
let data_ptr =
core::ptr::NonNull::<u8>::new_unchecked((*ptr)._data.as_mut_ptr().cast());

let allocator = BumpAllocator::new(data_ptr, size_of::<[MaybeUninit<T>; CAPACITY]>());
(*ptr)
.state
.init(&allocator)
Expand All @@ -497,7 +509,12 @@ impl<T, const CAPACITY: usize> Default for FixedSizeQueue<T, CAPACITY> {
_data: unsafe { MaybeUninit::uninit().assume_init() },
};

let allocator = BumpAllocator::new(new_self._data.as_mut_ptr().cast());
// SAFETY: Creating a pointer to an existing member is always not null
let data_ptr =
unsafe { core::ptr::NonNull::<u8>::new_unchecked(new_self._data.as_mut_ptr().cast()) };

let allocator =
BumpAllocator::new(data_ptr, core::mem::size_of_val(new_self._data.as_ref()));
unsafe {
new_self
.state
Expand Down
20 changes: 18 additions & 2 deletions iceoryx2-bb/container/src/slotmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,14 @@ impl<T, const CAPACITY: usize> PlacementDefault for FixedSizeSlotMap<T, CAPACITY
unsafe {
let state_ptr = core::ptr::addr_of_mut!((*ptr).state);
state_ptr.write(RelocatableSlotMap::new_uninit(CAPACITY));
let allocator = BumpAllocator::new((*ptr)._idx_to_data.as_mut_ptr().cast());
// SAFETY: Creating a pointer to an existing member is always not null
let data_ptr =
core::ptr::NonNull::<u8>::new_unchecked((*ptr)._idx_to_data.as_mut_ptr().cast());

let allocator = BumpAllocator::new(
data_ptr,
size_of::<Self>() - core::mem::offset_of!(Self, _idx_to_data),
);
(*ptr)
.state
.init(&allocator)
Expand All @@ -632,7 +639,16 @@ impl<T, const CAPACITY: usize> Default for FixedSizeSlotMap<T, CAPACITY> {
state: unsafe { RelocatableSlotMap::new_uninit(CAPACITY) },
};

let allocator = BumpAllocator::new(new_self._idx_to_data.as_mut_ptr().cast());
// SAFETY: Creating a pointer to an existing member is always not null
let data_ptr = unsafe {
core::ptr::NonNull::<u8>::new_unchecked(new_self._idx_to_data.as_mut_ptr().cast())
};

let allocator = BumpAllocator::new(
data_ptr,
size_of::<Self>() - core::mem::offset_of!(Self, _idx_to_data),
);

unsafe {
new_self
.state
Expand Down
13 changes: 11 additions & 2 deletions iceoryx2-bb/container/src/string/relocatable_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@
//! str_memory: [const { MaybeUninit::uninit() }; STRING_CAPACITY + 1] ,
//! };
//!
//! let allocator = BumpAllocator::new(new_self.str_memory.as_mut_ptr().cast());
//! let allocator = BumpAllocator::new(
//! core::ptr::NonNull::<u8>::new(new_self.str_memory.as_mut_ptr().cast())
//! .expect("Precondition failed: Pointer to memory is null"),
//! new_self.str_memory.len()
//! );
//!
//! unsafe {
//! new_self.my_str.init(&allocator).expect("Enough memory provided.")
//! };
Expand All @@ -60,7 +65,11 @@
//! const MEM_SIZE: usize = RelocatableString::const_memory_size(STRING_CAPACITY);
//! let mut memory = [0u8; MEM_SIZE];
//!
//! let bump_allocator = BumpAllocator::new(memory.as_mut_ptr());
//! let bump_allocator = BumpAllocator::new(
//! core::ptr::NonNull::<u8>::new(memory.as_mut_ptr().cast())
//! .expect("Precondition failed: Pointer to memory is null"),
//! memory.len()
//! );
//!
//! let mut my_str = unsafe { RelocatableString::new_uninit(STRING_CAPACITY) };
//! unsafe { my_str.init(&bump_allocator).expect("string init failed") };
Expand Down
12 changes: 10 additions & 2 deletions iceoryx2-bb/container/src/vector/relocatable_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@
//! vec_memory: [const { MaybeUninit::uninit() }; VEC_CAPACITY] ,
//! };
//!
//! let allocator = BumpAllocator::new(new_self.vec_memory.as_mut_ptr().cast());
//! let allocator = BumpAllocator::new(
//! core::ptr::NonNull::<u8>::new(new_self.vec_memory.as_mut_ptr().cast())
//! .expect("Precondition failed: Pointer to memory is null"),
//! new_self.vec_memory.len()
//! );
//! unsafe {
//! new_self.vec.init(&allocator).expect("Enough memory provided.")
//! };
Expand All @@ -57,7 +61,11 @@
//! const MEM_SIZE: usize = RelocatableVec::<u128>::const_memory_size(VEC_CAPACITY);
//! let mut memory = [0u8; MEM_SIZE];
//!
//! let bump_allocator = BumpAllocator::new(memory.as_mut_ptr());
//! let bump_allocator = BumpAllocator::new(
//! core::ptr::NonNull::<u8>::new(memory.as_mut_ptr().cast())
//! .expect("Precondition failed: Pointer to memory is null"),
//! memory.len()
//! );
//!
//! let mut vec = unsafe { RelocatableVec::<u128>::new_uninit(VEC_CAPACITY) };
//! unsafe { vec.init(&bump_allocator).expect("vec init failed") };
Expand Down
6 changes: 5 additions & 1 deletion iceoryx2-bb/container/tests-common/src/flatmap_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,11 @@ pub fn double_init_call_causes_panic() {

const MEM_SIZE: usize = RelocatableFlatMap::<u8, u8>::const_memory_size(CAPACITY);
let mut memory = [0u8; MEM_SIZE];
let bump_allocator = BumpAllocator::new(memory.as_mut_ptr());
let bump_allocator = BumpAllocator::new(
core::ptr::NonNull::<u8>::new(memory.as_mut_ptr().cast())
.expect("Precondition failed: Pointer to memory is null"),
core::mem::size_of_val(&memory),
);

let mut sut = unsafe { RelocatableFlatMap::<u8, u8>::new_uninit(CAPACITY) };
unsafe { sut.init(&bump_allocator).expect("sut init failed") };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,17 @@ use iceoryx2_bb_testing::assert_that;
use iceoryx2_bb_testing_macros::test;

const SUT_CAPACITY: usize = 256;
const BUFFER_SIZE: usize = core::mem::size_of::<u8>() * (SUT_CAPACITY * 3);

struct Test {
raw_memory: UnsafeCell<Box<[u8; core::mem::size_of::<u8>() * (SUT_CAPACITY * 3)]>>,
raw_memory: UnsafeCell<Box<[u8; BUFFER_SIZE]>>,
allocator: UnsafeCell<Option<Box<BumpAllocator>>>,
}

impl Test {
fn new() -> Self {
Self {
raw_memory: UnsafeCell::new(Box::new(
[0u8; core::mem::size_of::<u8>() * (SUT_CAPACITY * 3)],
)),
raw_memory: UnsafeCell::new(Box::new([0u8; BUFFER_SIZE])),
allocator: UnsafeCell::new(None),
}
}
Expand All @@ -40,7 +39,9 @@ impl Test {
unsafe {
if (*self.allocator.get()).is_none() {
*self.allocator.get() = Some(Box::new(BumpAllocator::new(
(*self.raw_memory.get()).as_mut_ptr(),
core::ptr::NonNull::<u8>::new((*self.raw_memory.get()).as_mut_ptr().cast())
.expect("Precondition failed: Pointer to memory is null"),
BUFFER_SIZE,
)))
}
};
Expand Down
12 changes: 6 additions & 6 deletions iceoryx2-bb/container/tests-common/src/polymorphic_vec_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,16 @@ use iceoryx2_bb_testing::lifetime_tracker::LifetimeTracker;
use iceoryx2_bb_testing_macros::test;

const SUT_CAPACITY: usize = 10;

const BUFFER_SIZE: usize = core::mem::size_of::<LifetimeTracker>() * (SUT_CAPACITY * 3);
struct Test {
raw_memory: UnsafeCell<Box<[u8; core::mem::size_of::<LifetimeTracker>() * (SUT_CAPACITY * 3)]>>,
raw_memory: UnsafeCell<Box<[u8; BUFFER_SIZE]>>,
allocator: UnsafeCell<Option<Box<BumpAllocator>>>,
}

impl Test {
fn new() -> Self {
Self {
raw_memory: UnsafeCell::new(Box::new(
[0u8; core::mem::size_of::<LifetimeTracker>() * (SUT_CAPACITY * 3)],
)),
raw_memory: UnsafeCell::new(Box::new([0u8; BUFFER_SIZE])),
allocator: UnsafeCell::new(None),
}
}
Expand All @@ -41,7 +39,9 @@ impl Test {
unsafe {
if (*self.allocator.get()).is_none() {
*self.allocator.get() = Some(Box::new(BumpAllocator::new(
(*self.raw_memory.get()).as_mut_ptr(),
core::ptr::NonNull::<u8>::new((*self.raw_memory.get()).as_mut_ptr().cast())
.expect("Precondition failed: Pointer to memory is null"),
BUFFER_SIZE,
)))
}
};
Expand Down
25 changes: 18 additions & 7 deletions iceoryx2-bb/container/tests-common/src/queue_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

use iceoryx2_bb_container::queue::*;
use iceoryx2_bb_elementary::bump_allocator::BumpAllocator;
use iceoryx2_bb_elementary_traits::placement_default::PlacementDefault;
use iceoryx2_bb_elementary_traits::{
non_null::NonNull, non_null::NonNullCompat, placement_default::PlacementDefault,
};
use iceoryx2_bb_testing::lifetime_tracker::LifetimeTracker;
use iceoryx2_bb_testing::{assert_that, memory::RawMemory};
use iceoryx2_bb_testing_macros::test;
Expand All @@ -22,8 +24,11 @@ type Sut = FixedSizeQueue<usize, SUT_CAPACITY>;

#[test]
pub fn relocatable_push_pop_works_with_uninitialized_memory() {
let mut memory = [0u8; 1024];
let allocator = BumpAllocator::new(memory.as_mut_ptr());
let memory = [0u8; 1024];
let allocator = BumpAllocator::new(
<NonNull<u8> as NonNullCompat<u8>>::from_ref(&memory[0]),
memory.len(),
);

let mut sut = unsafe { RelocatableQueue::<usize>::new_uninit(SUT_CAPACITY) };
unsafe { assert_that!(sut.init(&allocator), is_ok) };
Expand Down Expand Up @@ -51,8 +56,11 @@ pub fn relocatable_push_pop_works_with_uninitialized_memory() {

#[test]
pub fn relocatable_clear_empties_queue() {
let mut memory = [0u8; 1024];
let allocator = BumpAllocator::new(memory.as_mut_ptr());
let memory = [0u8; 1024];
let allocator = BumpAllocator::new(
<NonNull<u8> as NonNullCompat<u8>>::from_ref(&memory[0]),
memory.len(),
);

let mut sut = unsafe { RelocatableQueue::<usize>::new_uninit(SUT_CAPACITY) };
unsafe { assert_that!(sut.init(&allocator), is_ok) };
Expand Down Expand Up @@ -330,8 +338,11 @@ pub fn peek_works() {
#[should_panic]
pub fn double_init_call_causes_panic() {
const MEM_SIZE: usize = RelocatableQueue::<usize>::const_memory_size(SUT_CAPACITY);
let mut memory = [0u8; MEM_SIZE];
let bump_allocator = BumpAllocator::new(memory.as_mut_ptr());
let memory = [0u8; MEM_SIZE];
let bump_allocator = BumpAllocator::new(
<NonNull<u8> as NonNullCompat<u8>>::from_ref(&memory[0]),
memory.len(),
);

let mut sut = unsafe { RelocatableQueue::<usize>::new_uninit(SUT_CAPACITY) };
unsafe { sut.init(&bump_allocator).expect("sut init failed") };
Expand Down
Loading
Loading