|
|
|
@ -34,7 +34,7 @@ MAP_MEMBER_CONST()::FlatAddressSpaceMap(VaType va_limit_,
|
|
|
|
|
std::function<void(VaType, VaType)> unmap_callback_)
|
|
|
|
|
: va_limit{va_limit_}, unmap_callback{std::move(unmap_callback_)} {
|
|
|
|
|
if (va_limit > VaMaximum) {
|
|
|
|
|
UNREACHABLE_MSG("Invalid VA limit!");
|
|
|
|
|
ASSERT_MSG(false, "Invalid VA limit!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -42,14 +42,14 @@ MAP_MEMBER(void)::MapLocked(VaType virt, PaType phys, VaType size, ExtraBlockInf
|
|
|
|
|
VaType virt_end{virt + size};
|
|
|
|
|
|
|
|
|
|
if (virt_end > va_limit) {
|
|
|
|
|
UNREACHABLE_MSG(
|
|
|
|
|
"Trying to map a block past the VA limit: virt_end: 0x{:X}, va_limit: 0x{:X}", virt_end,
|
|
|
|
|
va_limit);
|
|
|
|
|
ASSERT_MSG(false,
|
|
|
|
|
"Trying to map a block past the VA limit: virt_end: 0x{:X}, va_limit: 0x{:X}",
|
|
|
|
|
virt_end, va_limit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto block_end_successor{std::lower_bound(blocks.begin(), blocks.end(), virt_end)};
|
|
|
|
|
if (block_end_successor == blocks.begin()) {
|
|
|
|
|
UNREACHABLE_MSG("Trying to map a block before the VA start: virt_end: 0x{:X}", virt_end);
|
|
|
|
|
ASSERT_MSG(false, "Trying to map a block before the VA start: virt_end: 0x{:X}", virt_end);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto block_end_predecessor{std::prev(block_end_successor)};
|
|
|
|
@ -124,7 +124,7 @@ MAP_MEMBER(void)::MapLocked(VaType virt, PaType phys, VaType size, ExtraBlockInf
|
|
|
|
|
|
|
|
|
|
// Check that the start successor is either the end block or something in between
|
|
|
|
|
if (block_start_successor->virt > virt_end) {
|
|
|
|
|
UNREACHABLE_MSG("Unsorted block in AS map: virt: 0x{:X}", block_start_successor->virt);
|
|
|
|
|
ASSERT_MSG(false, "Unsorted block in AS map: virt: 0x{:X}", block_start_successor->virt);
|
|
|
|
|
} else if (block_start_successor->virt == virt_end) {
|
|
|
|
|
// We need to create a new block as there are none spare that we would overwrite
|
|
|
|
|
blocks.insert(block_start_successor, Block(virt, phys, extra_info));
|
|
|
|
@ -149,14 +149,15 @@ MAP_MEMBER(void)::UnmapLocked(VaType virt, VaType size) {
|
|
|
|
|
VaType virt_end{virt + size};
|
|
|
|
|
|
|
|
|
|
if (virt_end > va_limit) {
|
|
|
|
|
UNREACHABLE_MSG(
|
|
|
|
|
"Trying to map a block past the VA limit: virt_end: 0x{:X}, va_limit: 0x{:X}", virt_end,
|
|
|
|
|
va_limit);
|
|
|
|
|
ASSERT_MSG(false,
|
|
|
|
|
"Trying to map a block past the VA limit: virt_end: 0x{:X}, va_limit: 0x{:X}",
|
|
|
|
|
virt_end, va_limit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto block_end_successor{std::lower_bound(blocks.begin(), blocks.end(), virt_end)};
|
|
|
|
|
if (block_end_successor == blocks.begin()) {
|
|
|
|
|
UNREACHABLE_MSG("Trying to unmap a block before the VA start: virt_end: 0x{:X}", virt_end);
|
|
|
|
|
ASSERT_MSG(false, "Trying to unmap a block before the VA start: virt_end: 0x{:X}",
|
|
|
|
|
virt_end);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto block_end_predecessor{std::prev(block_end_successor)};
|
|
|
|
@ -190,7 +191,7 @@ MAP_MEMBER(void)::UnmapLocked(VaType virt, VaType size) {
|
|
|
|
|
if (eraseEnd != blocks.end() &&
|
|
|
|
|
(eraseEnd == block_start_successor ||
|
|
|
|
|
(block_start_predecessor->Unmapped() && eraseEnd->Unmapped()))) {
|
|
|
|
|
UNREACHABLE_MSG("Multiple contiguous unmapped regions are unsupported!");
|
|
|
|
|
ASSERT_MSG(false, "Multiple contiguous unmapped regions are unsupported!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
blocks.erase(block_start_successor, eraseEnd);
|
|
|
|
@ -217,7 +218,7 @@ MAP_MEMBER(void)::UnmapLocked(VaType virt, VaType size) {
|
|
|
|
|
return; // The region is unmapped here and doesn't need splitting, bail out early
|
|
|
|
|
} else if (block_end_successor == blocks.end()) {
|
|
|
|
|
// This should never happen as the end should always follow an unmapped block
|
|
|
|
|
UNREACHABLE_MSG("Unexpected Memory Manager state!");
|
|
|
|
|
ASSERT_MSG(false, "Unexpected Memory Manager state!");
|
|
|
|
|
} else if (block_end_successor->virt != virt_end) {
|
|
|
|
|
// If one block is directly in front then we don't have to add a tail
|
|
|
|
|
|
|
|
|
@ -256,7 +257,7 @@ MAP_MEMBER(void)::UnmapLocked(VaType virt, VaType size) {
|
|
|
|
|
auto block_start_successor{std::next(block_start_predecessor)};
|
|
|
|
|
|
|
|
|
|
if (block_start_successor->virt > virt_end) {
|
|
|
|
|
UNREACHABLE_MSG("Unsorted block in AS map: virt: 0x{:X}", block_start_successor->virt);
|
|
|
|
|
ASSERT_MSG(false, "Unsorted block in AS map: virt: 0x{:X}", block_start_successor->virt);
|
|
|
|
|
} else if (block_start_successor->virt == virt_end) {
|
|
|
|
|
// There are no blocks between the start and the end that would let us skip inserting a new
|
|
|
|
|
// one for head
|
|
|
|
@ -298,7 +299,7 @@ ALLOC_MEMBER(VaType)::Allocate(VaType size) {
|
|
|
|
|
auto alloc_end_successor{
|
|
|
|
|
std::lower_bound(this->blocks.begin(), this->blocks.end(), alloc_end)};
|
|
|
|
|
if (alloc_end_successor == this->blocks.begin()) {
|
|
|
|
|
UNREACHABLE_MSG("First block in AS map is invalid!");
|
|
|
|
|
ASSERT_MSG(false, "First block in AS map is invalid!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto alloc_end_predecessor{std::prev(alloc_end_successor)};
|
|
|
|
@ -332,7 +333,7 @@ ALLOC_MEMBER(VaType)::Allocate(VaType size) {
|
|
|
|
|
current_linear_alloc_end = alloc_start + size;
|
|
|
|
|
} else { // If linear allocation overflows the AS then find a gap
|
|
|
|
|
if (this->blocks.size() <= 2) {
|
|
|
|
|
UNREACHABLE_MSG("Unexpected allocator state!");
|
|
|
|
|
ASSERT_MSG(false, "Unexpected allocator state!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto search_predecessor{this->blocks.begin()};
|
|
|
|
|