File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
sdk/pinocchio/src/entrypoint Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ pub use alloc::BumpAllocator;
1313use 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`].
196197macro_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: first compute the aligned address as a `usize`,
200+ // since this is more CU-efficient than using `ptr::align_offset()` or the
201+ // strict provenance API (e.g., `ptr::with_addr()`). Then cast the result
202+ // back to a pointer. The resulting pointer is guaranteed to be valid
203+ // becauseit follows the layout serialized by the runtime.
204+ with_exposed_provenance_mut(
205+ ( $ptr. expose_provenance( ) + ( BPF_ALIGN_OF_U128 - 1 ) ) & !( BPF_ALIGN_OF_U128 - 1 ) ,
206+ )
201207 } ;
202208}
203209
You can’t perform that action at this time.
0 commit comments