mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 09:12:45 +00:00 
			
		
		
		
	 1682f0b760
			
		
	
	
		1682f0b760
		
	
	
	
	
		
			
			SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
		
			
				
	
	
		
			52 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			52 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <AK/Traits.h>
 | |
| #include <AK/Vector.h>
 | |
| #include <Kernel/SpinLock.h>
 | |
| #include <Kernel/VM/Range.h>
 | |
| 
 | |
| namespace Kernel {
 | |
| 
 | |
| class RangeAllocator {
 | |
| public:
 | |
|     RangeAllocator();
 | |
|     ~RangeAllocator();
 | |
| 
 | |
|     void initialize_with_range(VirtualAddress, size_t);
 | |
|     void initialize_from_parent(const RangeAllocator&);
 | |
| 
 | |
|     Optional<Range> allocate_anywhere(size_t, size_t alignment = PAGE_SIZE);
 | |
|     Optional<Range> allocate_specific(VirtualAddress, size_t);
 | |
|     Optional<Range> allocate_randomized(size_t, size_t alignment);
 | |
|     void deallocate(const Range&);
 | |
| 
 | |
|     void dump() const;
 | |
| 
 | |
|     bool contains(const Range& range) const
 | |
|     {
 | |
|         ScopedSpinLock lock(m_lock);
 | |
|         return m_total_range.contains(range);
 | |
|     }
 | |
| 
 | |
| private:
 | |
|     void carve_at_index(int, const Range&);
 | |
| 
 | |
|     Vector<Range> m_available_ranges;
 | |
|     Range m_total_range;
 | |
|     mutable SpinLock<u8> m_lock;
 | |
| };
 | |
| 
 | |
| }
 | |
| 
 | |
| namespace AK {
 | |
| template<>
 | |
| struct Traits<Kernel::Range> : public GenericTraits<Kernel::Range> {
 | |
|     static constexpr bool is_trivial() { return true; }
 | |
| };
 | |
| }
 |