orbis: do not touch budget for not commited memory

This commit is contained in:
DH 2025-11-30 20:50:52 +03:00
parent c650ac482b
commit 4685e4fecc

View file

@ -444,13 +444,13 @@ std::pair<rx::AddressRange, orbis::ErrorCode> orbis::vmem::mapFile(
}
if (blockFlags & BlockFlags::FlexibleMemory) {
if (prot) {
if (!budget->acquire(BudgetResource::Fmem, size)) {
rx::println(stderr, "map: fmem budget: failed to allocate {:#x} bytes",
size);
return {{}, ErrorCode::INVAL};
}
if (prot) {
blockFlags |= BlockFlags::Commited;
}
}
@ -458,13 +458,13 @@ std::pair<rx::AddressRange, orbis::ErrorCode> orbis::vmem::mapFile(
allocFlags = AllocationFlags::Fixed | (allocFlags & AllocationFlags::NoMerge);
if (blockFlags & BlockFlags::DirectMemory) {
if (prot) {
if (!budget->acquire(BudgetResource::Dmem, size)) {
rx::println(stderr, "map: dmem budget: failed to allocate {:#x} bytes",
size);
return {{}, ErrorCode::INVAL};
}
if (prot) {
blockFlags |= BlockFlags::Commited;
}
}
@ -479,6 +479,7 @@ std::pair<rx::AddressRange, orbis::ErrorCode> orbis::vmem::mapFile(
if (auto error = file->device->map(range, fileOffset, prot, file, process);
error != ErrorCode{}) {
if (prot) {
if (blockFlags & BlockFlags::FlexibleMemory) {
budget->release(BudgetResource::Fmem, size);
}
@ -486,6 +487,7 @@ std::pair<rx::AddressRange, orbis::ErrorCode> orbis::vmem::mapFile(
if (blockFlags & BlockFlags::DirectMemory) {
budget->release(BudgetResource::Dmem, size);
}
}
if (blockFlags & BlockFlags::PooledMemory) {
blockpool::releaseControlBlock();
@ -539,8 +541,12 @@ std::pair<rx::AddressRange, orbis::ErrorCode> orbis::vmem::mapDirect(
Process *process, std::uint64_t addressHint, rx::AddressRange directRange,
rx::EnumBitSet<Protection> prot, rx::EnumBitSet<AllocationFlags> allocFlags,
std::string_view name, std::uint64_t alignment, MemoryType type) {
ScopedBudgetAcquire dmemResource(process->getBudget(), BudgetResource::Dmem,
directRange.size());
ScopedBudgetAcquire dmemResource;
if (prot) {
dmemResource = ScopedBudgetAcquire(
process->getBudget(), BudgetResource::Dmem, directRange.size());
if (!dmemResource) {
rx::println(stderr,
"mapDirect: dmem budget: failed to allocate {:#x} bytes",
@ -548,6 +554,7 @@ std::pair<rx::AddressRange, orbis::ErrorCode> orbis::vmem::mapDirect(
return {{}, ErrorCode::INVAL};
}
}
VirtualMemoryAllocation allocationInfo;
allocationInfo.flags = orbis::vmem::BlockFlags::DirectMemory;
@ -635,15 +642,22 @@ orbis::vmem::mapFlex(Process *process, std::uint64_t size,
rx::EnumBitSet<AllocationFlags> allocFlags,
rx::EnumBitSet<BlockFlags> blockFlags,
std::string_view name, std::uint64_t alignment) {
ScopedBudgetAcquire fmemResource(process->getBudget(), BudgetResource::Fmem,
size);
ScopedBudgetAcquire fmemResource;
if (prot) {
fmemResource =
ScopedBudgetAcquire(process->getBudget(), BudgetResource::Fmem, size);
if (!fmemResource) {
rx::println(stderr, "mapFlex: fmem budget: failed to allocate {:#x} bytes",
size);
rx::println(stderr,
"mapFlex: fmem budget: failed to allocate {:#x} bytes", size);
return {{}, ErrorCode::INVAL};
}
blockFlags |= orbis::vmem::BlockFlags::Commited;
}
bool canOverwrite = (allocFlags & AllocationFlags::Fixed) &&
!(allocFlags & AllocationFlags::NoOverwrite);
@ -654,10 +668,6 @@ orbis::vmem::mapFlex(Process *process, std::uint64_t size,
allocationInfo.type = MemoryType::WbOnion;
allocationInfo.setName(process, name);
if (prot) {
allocationInfo.flags |= orbis::vmem::BlockFlags::Commited;
}
auto vmem = process->get(g_vmInstance);
std::lock_guard lock(*vmem);