@@ -76,37 +76,23 @@ impl Heap {
7676 critical_section:: with ( |cs| {
7777 let mut heap = self . heap . borrow_ref_mut ( cs) ;
7878 assert ! ( !heap. initialized) ;
79- // Work around https://github.com/yvt/rlsf/pull/21 by aligning block before passing
80- // it to `Tlsf::insert_free_block_ptr`.
81- if let Some ( ( aligned_start_addr , usable_size ) ) = Self :: align ( start_addr , size ) {
79+ let block : NonNull < [ u8 ] > =
80+ NonNull :: slice_from_raw_parts ( NonNull :: new_unchecked ( start_addr as * mut u8 ) , size ) ;
81+ if let Some ( actual_size ) = heap . tlsf . insert_free_block_ptr ( block ) {
8282 let block: NonNull < [ u8 ] > = NonNull :: slice_from_raw_parts (
83- NonNull :: new_unchecked ( aligned_start_addr as * mut u8 ) ,
84- usable_size ,
83+ NonNull :: new_unchecked ( start_addr as * mut u8 ) ,
84+ actual_size . get ( ) ,
8585 ) ;
86- if heap. tlsf . insert_free_block_ptr ( block) . is_some ( ) {
87- heap. initialized = true ;
88- heap. raw_block = Some ( block) ;
89- heap. raw_block_size = size;
90- }
86+ heap. initialized = true ;
87+ heap. raw_block = Some ( block) ;
88+ heap. raw_block_size = size;
9189 }
9290 if !heap. initialized {
9391 panic ! ( "Allocation too small for heap" ) ;
9492 }
9593 } ) ;
9694 }
9795
98- /// Align `start_addr` to `rlsf::GRANULARITY` and make
99- /// `size` a multiple of `2*rlsf::GRANULARITY`.
100- fn align ( start_addr : usize , size : usize ) -> Option < ( usize , usize ) > {
101- let align_offset: usize = ( start_addr as * const u8 ) . align_offset ( rlsf:: GRANULARITY ) ;
102- if align_offset >= size {
103- return None ;
104- }
105- let reduced_size: usize = size - align_offset;
106- let usable_size: usize = reduced_size - ( reduced_size % ( rlsf:: GRANULARITY * 2 ) ) ;
107- Some ( ( start_addr + align_offset, usable_size) )
108- }
109-
11096 fn alloc ( & self , layout : Layout ) -> Option < NonNull < u8 > > {
11197 critical_section:: with ( |cs| self . heap . borrow_ref_mut ( cs) . tlsf . allocate ( layout) )
11298 }
0 commit comments