mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 21:52:45 +00:00 
			
		
		
		
	LibJS: Add some basic freelist validation for the GC heap
When using the freelist, we now validate that the entries are actual cell pointers within the current HeapBlock.
This commit is contained in:
		
							parent
							
								
									46e5890152
								
							
						
					
					
						commit
						e1dbf74f15
					
				
					 2 changed files with 8 additions and 0 deletions
				
			
		|  | @ -75,6 +75,8 @@ HeapBlock::HeapBlock(Heap& heap, size_t cell_size) | ||||||
| 
 | 
 | ||||||
| void HeapBlock::deallocate(Cell* cell) | void HeapBlock::deallocate(Cell* cell) | ||||||
| { | { | ||||||
|  |     ASSERT(is_valid_cell_pointer(cell)); | ||||||
|  |     ASSERT(!m_freelist || is_valid_cell_pointer(m_freelist)); | ||||||
|     ASSERT(cell->is_live()); |     ASSERT(cell->is_live()); | ||||||
|     ASSERT(!cell->is_marked()); |     ASSERT(!cell->is_marked()); | ||||||
|     cell->~Cell(); |     cell->~Cell(); | ||||||
|  |  | ||||||
|  | @ -51,6 +51,7 @@ public: | ||||||
|     { |     { | ||||||
|         if (!m_freelist) |         if (!m_freelist) | ||||||
|             return nullptr; |             return nullptr; | ||||||
|  |         ASSERT(is_valid_cell_pointer(m_freelist)); | ||||||
|         return exchange(m_freelist, m_freelist->next); |         return exchange(m_freelist, m_freelist->next); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -80,6 +81,11 @@ public: | ||||||
|         return cell(cell_index); |         return cell(cell_index); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     bool is_valid_cell_pointer(const Cell* cell) | ||||||
|  |     { | ||||||
|  |         return cell_from_possible_pointer((FlatPtr)cell); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     IntrusiveListNode m_list_node; |     IntrusiveListNode m_list_node; | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling