File tree Expand file tree Collapse file tree 1 file changed +10
-13
lines changed Expand file tree Collapse file tree 1 file changed +10
-13
lines changed Original file line number Diff line number Diff line change @@ -177,27 +177,24 @@ macro_rules! impl_sysvar_get {
177177
178178 match result {
179179 $crate:: __private:: SUCCESS => Ok ( var) ,
180- // Unexpected errors are folded into `UnsupportedSysvar`.
181180 _ => Err ( $crate:: __private:: ProgramError :: UnsupportedSysvar ) ,
182181 }
183182 }
184183 } ;
185184 ( $sysvar_id: expr) => {
186185 fn get( ) -> Result <Self , $crate:: __private:: ProgramError > {
187- // Allocate uninitialized memory for the sysvar struct
188186 let mut uninit = core:: mem:: MaybeUninit :: <Self >:: uninit( ) ;
189187 let size = core:: mem:: size_of:: <Self >( ) as u64 ;
190- // Safety: we build a mutable slice pointing to the uninitialized
191- // buffer. The `get_sysvar` syscall will fill exactly `size`
192- // bytes, after which the buffer is fully initialised.
193- let dst = unsafe {
194- core:: slice:: from_raw_parts_mut( uninit. as_mut_ptr( ) as * mut u8 , size as usize )
195- } ;
196- // Attempt to load the sysvar data using the provided sysvar id.
197- $crate:: get_sysvar( dst, & $sysvar_id, 0 , size) ?;
198- // Safety: `get_sysvar` succeeded and initialised the buffer.
199- let var = unsafe { uninit. assume_init( ) } ;
200- Ok ( var)
188+ let sysvar_id_ptr = ( & $sysvar_id) as * const _ as * const u8 ;
189+ unsafe {
190+ $crate:: get_sysvar_unchecked(
191+ uninit. as_mut_ptr( ) as * mut u8 ,
192+ sysvar_id_ptr,
193+ 0 ,
194+ size,
195+ ) ?;
196+ Ok ( uninit. assume_init( ) )
197+ }
201198 }
202199 } ;
203200}
You can’t perform that action at this time.
0 commit comments