Skip to content

Commit f1314ca

Browse files
committed
Update align pointer macro
1 parent 5b45a92 commit f1314ca

File tree

1 file changed

+9
-3
lines changed
  • sdk/pinocchio/src/entrypoint

1 file changed

+9
-3
lines changed

sdk/pinocchio/src/entrypoint/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub use alloc::BumpAllocator;
1313
use core::{
1414
cmp::min,
1515
mem::{size_of, MaybeUninit},
16+
ptr::with_exposed_provenance_mut,
1617
slice::from_raw_parts,
1718
};
1819

@@ -195,9 +196,14 @@ macro_rules! program_entrypoint {
195196
/// Align a pointer to the BPF alignment of [`u128`].
196197
macro_rules! align_pointer {
197198
($ptr:ident) => {
198-
// integer-to-pointer cast: the resulting pointer will have the same provenance as
199-
// the original pointer and it follows the alignment requirement for the input.
200-
$ptr.with_addr((($ptr.addr() + (BPF_ALIGN_OF_U128 - 1)) & !(BPF_ALIGN_OF_U128 - 1)))
199+
// integer-to-pointer cast: calculate the aligned address as a usize first
200+
// since it is more CU efficient than `ptr::align_offset()` or strict Provenance
201+
// API (e.g., `ptr::with_addr()`); and then cast it back to a pointer. The runtime
202+
// guarantees that the resulting pointer is valid, since it follows the layout
203+
// serialized by the SVM loader.
204+
with_exposed_provenance_mut(
205+
($ptr.expose_provenance() + (BPF_ALIGN_OF_U128 - 1)) & !(BPF_ALIGN_OF_U128 - 1),
206+
)
201207
};
202208
}
203209

0 commit comments

Comments
 (0)