Skip to content

Commit

Permalink
Bugfix: get_buffer_aligned was returning unaligned buffers in the suc…
Browse files Browse the repository at this point in the history
…cess case
  • Loading branch information
Sewer56 committed Dec 26, 2023
1 parent c18787c commit a5774d9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src-rust/Cargo.lock

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

2 changes: 1 addition & 1 deletion src-rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "reloaded-memory-buffers"
version = "4.0.1"
version = "4.0.2"
edition = "2021"
authors = [ "sewer56" ]
description = "Shared, Concurrent, Permanent Memory Allocator tied to Process Lifetime"
Expand Down
17 changes: 5 additions & 12 deletions src-rust/src/buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::utilities::disable_write_xor_execute::{
};
use crate::utilities::icache_clear::clear_instruction_cache;
use crate::utilities::mathematics::round_up;
use core::cmp::max;
use core::ptr::{copy_nonoverlapping, NonNull};
use core::u8;

Expand Down Expand Up @@ -73,23 +74,15 @@ impl Buffers {
) -> Result<SafeLocatorItem, BufferSearchError> {
// Add expected size.
let mut new_settings = *settings;
new_settings.size += alignment;
new_settings.size += alignment.saturating_sub(1);

let result = Self::get_buffer(&new_settings);

if result.is_ok() {
// No error. (Hot Path)
return result;
}

// If we have an error, pass it back.
let result = Self::get_buffer(&new_settings)?;
unsafe {
let locator_item_cell = &result.as_ref().unwrap_unchecked().item;
let locator_item = locator_item_cell.get();
let locator_item = result.item.get();
let base_address = (*locator_item).base_address.value;
let aligned_address = round_up(base_address, alignment as usize);
(*locator_item).base_address.value = aligned_address;
result
Ok(result)
}
}

Expand Down

0 comments on commit a5774d9

Please sign in to comment.