@@ -188,11 +188,12 @@ INTERNAL_HIDDEN void _verify_zone(iso_alloc_zone_t *zone) {
188188 }
189189
190190 for (bitmap_index_t i = 0 ; i < zone -> max_bitmap_idx ; i ++ ) {
191+ bit_slot_t bsl = bm [i ];
191192 for (int64_t j = 1 ; j < BITS_PER_QWORD ; j += BITS_PER_CHUNK ) {
192193 /* If this bit is set it is either a free chunk or
193194 * a canary chunk. Either way it should have a set
194195 * of canaries we can verify */
195- if ((GET_BIT (bm [ i ] , j )) == 1 ) {
196+ if ((GET_BIT (bsl , j )) == 1 ) {
196197 bit_slot = (i << BITS_PER_QWORD_SHIFT ) + j ;
197198 const void * p = POINTER_FROM_BITSLOT (zone , bit_slot );
198199 check_canary (zone , p );
@@ -239,15 +240,17 @@ INTERNAL_HIDDEN INLINE void fill_free_bit_slot_cache(iso_alloc_zone_t *zone) {
239240 return ;
240241 }
241242
242- for (uint64_t j = 0 ; j < BITS_PER_QWORD ; j += BITS_PER_CHUNK ) {
243- if (free_bit_slot_cache_index >= BIT_SLOT_CACHE_SZ ) {
244- zone -> free_bit_slot_cache_index = free_bit_slot_cache_index ;
245- return ;
246- }
243+ bit_slot_t bmt = bm [bm_idx ];
247244
248- if ((GET_BIT (bm [bm_idx ], j )) == 0 ) {
245+ for (uint64_t j = 0 ; j < BITS_PER_QWORD ; j += BITS_PER_CHUNK ) {
246+ if ((GET_BIT (bmt , j )) == 0 ) {
249247 zone -> free_bit_slot_cache [free_bit_slot_cache_index ] = (bm_idx << BITS_PER_QWORD_SHIFT ) + j ;
250248 free_bit_slot_cache_index ++ ;
249+
250+ if (free_bit_slot_cache_index >= BIT_SLOT_CACHE_SZ ) {
251+ zone -> free_bit_slot_cache_index = free_bit_slot_cache_index ;
252+ return ;
253+ }
251254 }
252255 }
253256 }
@@ -295,6 +298,7 @@ INTERNAL_HIDDEN INLINE void insert_free_bit_slot(iso_alloc_zone_t *zone, int64_t
295298
296299 zone -> free_bit_slot_cache [zone -> free_bit_slot_cache_index ] = bit_slot ;
297300 zone -> free_bit_slot_cache_index ++ ;
301+ zone -> is_full = false;
298302}
299303
300304INTERNAL_HIDDEN bit_slot_t get_next_free_bit_slot (iso_alloc_zone_t * zone ) {
@@ -849,16 +853,17 @@ INTERNAL_HIDDEN bit_slot_t iso_scan_zone_free_slot(iso_alloc_zone_t *zone) {
849853 * and returns the first free bit position. In a heavily
850854 * used zone this function will be slow to search. We
851855 * speed it up by looking for a constant ALLOCATED_BITSLOTS
852- * that indicates there is at least 1 free bit slot */
856+ * that indicates there is at least 1 free bit slot */
853857INTERNAL_HIDDEN bit_slot_t iso_scan_zone_free_slot_slow (iso_alloc_zone_t * zone ) {
854858 const bitmap_index_t * bm = (bitmap_index_t * ) zone -> bitmap_start ;
855859
856860 for (bitmap_index_t i = 0 ; i < zone -> max_bitmap_idx ; i ++ ) {
861+ bit_slot_t bts = bm [i ];
857862 for (int64_t j = 0 ; j < BITS_PER_QWORD ; j += BITS_PER_CHUNK ) {
858863 /* We can easily check if every bitslot represented by
859864 * this qword is allocated with or without canaries */
860- if (bm [ i ] < ALLOCATED_BITSLOTS ) {
861- if ((GET_BIT (bm [ i ] , j )) == 0 ) {
865+ if (bts < ALLOCATED_BITSLOTS ) {
866+ if ((GET_BIT (bts , j )) == 0 ) {
862867 return ((i << BITS_PER_QWORD_SHIFT ) + j );
863868 }
864869 }
@@ -1565,7 +1570,7 @@ INTERNAL_HIDDEN INLINE void check_big_canary(iso_alloc_big_zone_t *big) {
15651570 return ;
15661571}
15671572
1568- INTERNAL_HIDDEN INLINE void write_canary (iso_alloc_zone_t * zone , const void * p ) {
1573+ INTERNAL_HIDDEN INLINE void write_canary (iso_alloc_zone_t * zone , void * p ) {
15691574 return ;
15701575}
15711576
@@ -1599,7 +1604,7 @@ INTERNAL_HIDDEN INLINE void check_big_canary(iso_alloc_big_zone_t *big) {
15991604 * freed, or when the API requests validation. We
16001605 * sacrifice the high byte in entropy to prevent
16011606 * unbounded string reads from leaking it */
1602- INTERNAL_HIDDEN INLINE void write_canary (iso_alloc_zone_t * zone , const void * p ) {
1607+ INTERNAL_HIDDEN INLINE void write_canary (iso_alloc_zone_t * zone , void * p ) {
16031608 const uint64_t canary = (zone -> canary_secret ^ (uint64_t ) p ) & CANARY_VALIDATE_MASK ;
16041609 * (uint64_t * ) p = canary ;
16051610 p += (zone -> chunk_size - sizeof (uint64_t ));
@@ -1749,7 +1754,6 @@ INTERNAL_HIDDEN void iso_free_chunk_from_zone(iso_alloc_zone_t *zone, void *rest
17491754 if (LIKELY (permanent == false)) {
17501755 UNSET_BIT (b , which_bit );
17511756 insert_free_bit_slot (zone , bit_slot );
1752- zone -> is_full = false;
17531757#if !ENABLE_ASAN && SANITIZE_CHUNKS
17541758 iso_clear_user_chunk (p , zone -> chunk_size );
17551759#endif
0 commit comments