Skip to content

Commit 0931b96

Browse files
committed
add support for unassigning a mapping
This will permit repurposing an already assigned mapping, allowing multiboot to preemptively assigning "free memory" regions, resizing ranges by deleting and recreating them, or making temporary regions. Could also be useful for NUMA.
1 parent dcf40f6 commit 0931b96

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

api/kernel/memmap.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,12 @@ class Memory_map {
339339
*/
340340
Fixed_memory_range& assign_range(const Fixed_memory_range::size_type size);
341341

342+
/**
343+
* Removes a memory range previously defined
344+
* Useful to redefine the purpose of a range
345+
*/
346+
void unassign_range(const Fixed_memory_range& range);
347+
342348
/**
343349
* Check if an address is within a range in the map
344350
*

src/kernel/memmap.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,21 @@ Fixed_memory_range& Memory_map::assign_range(Fixed_memory_range&& rng) {
173173
return new_entry.first->second;
174174
}
175175

176+
///////////////////////////////////////////////////////////////////////////////
177+
void Memory_map::unassign_range(const Fixed_memory_range& range) {
178+
auto it = map_.find(range.addr_start());
179+
180+
if (it != map_.end()) {
181+
if (it->second.addr_end() == range.addr_end()) {
182+
map_.erase(it);
183+
} else {
184+
throw Memory_range_exception{"Range mismatch at address " + std::to_string(range.addr_start())};
185+
}
186+
} else {
187+
throw Memory_range_exception{"No range found to erase at " + std::to_string(range.addr_start())};
188+
}
189+
}
190+
176191
///////////////////////////////////////////////////////////////////////////////
177192
Fixed_memory_range& Memory_map::at(const Key key) {
178193
return const_cast<Fixed_memory_range&>(static_cast<const Memory_map*>(this)->at(key));

0 commit comments

Comments
 (0)