orbis: fix dmem::notifyUnmap & do not accept invalid region in blockpool::expand

This commit is contained in:
DH 2025-12-02 04:59:38 +03:00
parent c10d82f73a
commit df56a34832
2 changed files with 19 additions and 7 deletions

View file

@ -7,6 +7,7 @@
#include "rx/MemoryTable.hpp"
#include "rx/die.hpp"
#include "rx/format.hpp"
#include "rx/print.hpp"
#include "thread/Process.hpp"
#include "vmem.hpp"
#include <algorithm>
@ -272,6 +273,13 @@ void orbis::blockpool::clear() {
}
orbis::ErrorCode orbis::blockpool::expand(rx::AddressRange dmemRange) {
rx::println(stderr, "blockpool::expand({:x}-{:x})", dmemRange.beginAddress(),
dmemRange.endAddress());
if (!dmemRange.isValid()) {
return ErrorCode::INVAL;
}
std::scoped_lock lock(*g_blockpool);
g_blockpool->expand(dmemRange);
return {};
@ -315,6 +323,9 @@ orbis::ErrorCode
orbis::blockpool::commit(Process *process, rx::AddressRange vmemRange,
MemoryType type,
rx::EnumBitSet<orbis::vmem::Protection> protection) {
rx::println(stderr, "blockpool::commit({:x}-{:x}, {}, {})",
vmemRange.beginAddress(), vmemRange.endAddress(), type,
protection);
auto pool = type == MemoryType::WbOnion ? g_cachedBlockpool : g_blockpool;
auto otherPool =
type == MemoryType::WbOnion ? g_blockpool : g_cachedBlockpool;

View file

@ -720,28 +720,29 @@ orbis::ErrorCode orbis::dmem::notifyUnmap(orbis::Process *process,
for (auto mapIt = it->mappings.begin(); mapIt != it->mappings.end();) {
if (mapIt->process == process && mapIt->vmRange.intersects(range)) {
if (mapIt->vmRange == range) {
auto blockRange = range.intersection(mapIt->vmRange);
if (mapIt->vmRange == blockRange) {
mapIt = it->mappings.erase(mapIt);
break;
}
if (mapIt->vmRange.beginAddress() == range.beginAddress()) {
if (mapIt->vmRange.beginAddress() == blockRange.beginAddress()) {
mapIt->vmRange = rx::AddressRange::fromBeginEnd(
range.endAddress(), mapIt->vmRange.endAddress());
blockRange.endAddress(), mapIt->vmRange.endAddress());
break;
}
if (mapIt->vmRange.endAddress() == range.endAddress()) {
if (mapIt->vmRange.endAddress() == blockRange.endAddress()) {
mapIt->vmRange = rx::AddressRange::fromBeginEnd(
mapIt->vmRange.beginAddress(), range.beginAddress());
mapIt->vmRange.beginAddress(), blockRange.beginAddress());
break;
}
auto leftAllocation = rx::AddressRange::fromBeginEnd(
mapIt->vmRange.beginAddress(), range.beginAddress());
mapIt->vmRange.beginAddress(), blockRange.beginAddress());
auto rightAllocation = rx::AddressRange::fromBeginEnd(
range.endAddress(), mapIt->vmRange.endAddress());
blockRange.endAddress(), mapIt->vmRange.endAddress());
mapIt->vmRange = leftAllocation;
it->mappings.push_back({.process = process, .vmRange = rightAllocation});