mirror of
https://github.com/par274/sharpemu.git
synced 2026-08-01 07:29:43 +08:00
[Kernel] Return largest available direct-memory span (#334)
This commit is contained in:
@@ -2459,7 +2459,20 @@ public static partial class KernelMemoryCompatExports
|
||||
return (int)OrbisGen2Result.ORBIS_GEN2_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
if (!TryFindAvailableDirectMemorySpanLocked(searchStart, searchEnd, alignment, out var candidate, out var rangeAvailable))
|
||||
bool foundSpan;
|
||||
ulong candidate;
|
||||
ulong rangeAvailable;
|
||||
lock (_memoryGate)
|
||||
{
|
||||
foundSpan = TryFindAvailableDirectMemorySpanLocked(
|
||||
searchStart,
|
||||
searchEnd,
|
||||
alignment,
|
||||
out candidate,
|
||||
out rangeAvailable);
|
||||
}
|
||||
|
||||
if (!foundSpan)
|
||||
{
|
||||
return (int)OrbisGen2Result.ORBIS_GEN2_ERROR_NOT_FOUND;
|
||||
}
|
||||
@@ -5909,9 +5922,12 @@ public static partial class KernelMemoryCompatExports
|
||||
var gapEnd = Math.Min(allocation.Start, effectiveEnd);
|
||||
if (candidate < gapEnd)
|
||||
{
|
||||
spanStart = candidate;
|
||||
spanLength = gapEnd - candidate;
|
||||
return true;
|
||||
var candidateLength = gapEnd - candidate;
|
||||
if (candidateLength > spanLength)
|
||||
{
|
||||
spanStart = candidate;
|
||||
spanLength = candidateLength;
|
||||
}
|
||||
}
|
||||
|
||||
if (allocation.Start >= effectiveEnd)
|
||||
@@ -5922,12 +5938,20 @@ public static partial class KernelMemoryCompatExports
|
||||
candidate = AlignUp(Math.Max(candidate, allocationEnd), alignment);
|
||||
if (candidate >= effectiveEnd)
|
||||
{
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (candidate < effectiveEnd)
|
||||
{
|
||||
var candidateLength = effectiveEnd - candidate;
|
||||
if (candidateLength > spanLength)
|
||||
{
|
||||
spanStart = candidate;
|
||||
spanLength = candidateLength;
|
||||
}
|
||||
}
|
||||
|
||||
spanStart = candidate;
|
||||
spanLength = effectiveEnd - candidate;
|
||||
return spanLength != 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user