add a realtime scheduler class and priority-inheritance mutexes with timeouts and abandonment, add an HDA audio driver and a SYS_AUDIO_* syscall family, flesh out kernel32 with Win32 threads, events, mutexes, critical sections, and condition variables, add SYS_RESUME_THREAD for suspended thread creation, add KeInitializeMemoryTypes to reprogram MTRRs and install a canonical PAT for WB/WC/UC control, rework the display pipeline with a pitched present path and console output flush, bring back disk.vhd with mtools since vvfat fucking sucks, harden AHCI with serialized cache flush, USB mass storage with SCSI sense-data decoding, and xHCI with cleaner DMA teardown, fix the last stray for(;;) in HalStopProcessor to while(true), pile on smoke tests for audio, win32 sync primitives, and thread suspend, implement AHCI timeout, kill readahead since it was desperetaly trying to murder me, fix doom sound x2.

This commit is contained in:
maksw committed 2026-08-11 18:38:36 +02:00
1 parent 8b254f84f4
commit 4add6789ba
177 files changed
+22565 -3070

No files matched your search

+85 -18
View File
@@ -472,8 +472,13 @@ __declspec(dllexport) PHYSICAL_ADDRESS MmPfnAllocateInRange(PHYSICAL_ADDRESS min
return (PHYSICAL_ADDRESS)0;
}
// Allocates a physically contiguous run for DMA or hardware structures.
__declspec(dllexport) PHYSICAL_ADDRESS MmPfnAllocateContiguous(size_t count, MM_PFN_USAGE usage) {
// Allocates a physically contiguous run inside an address and alignment window.
PHYSICAL_ADDRESS MmPfnAllocateContiguousInRange(size_t count,
PHYSICAL_ADDRESS minInclusive,
PHYSICAL_ADDRESS maxExclusive,
size_t alignment,
size_t boundary,
MM_PFN_USAGE usage) {
if (!count || count > gMaxPfn) {
uintptr_t flags = KeAcquireSpinlock(&gPfnLock);
gPfnFailedContiguousAllocations++;
@@ -482,6 +487,50 @@ __declspec(dllexport) PHYSICAL_ADDRESS MmPfnAllocateContiguous(size_t count, MM_
return (PHYSICAL_ADDRESS)0;
}
if (!alignment)
alignment = PAGE_SIZE;
if (alignment < PAGE_SIZE)
alignment = PAGE_SIZE;
if ((alignment & (alignment - 1)) != 0 ||
(boundary && (boundary & (boundary - 1)) != 0)) {
uintptr_t flags = KeAcquireSpinlock(&gPfnLock);
gPfnFailedContiguousAllocations++;
gPfnFailedContiguousInvalidRequest++;
KeReleaseSpinlock(&gPfnLock, flags);
return (PHYSICAL_ADDRESS)0;
}
if (count > ((size_t)-1) / PAGE_SIZE) {
uintptr_t flags = KeAcquireSpinlock(&gPfnLock);
gPfnFailedContiguousAllocations++;
gPfnFailedContiguousInvalidRequest++;
KeReleaseSpinlock(&gPfnLock, flags);
return (PHYSICAL_ADDRESS)0;
}
size_t byteCount = count * PAGE_SIZE;
if (boundary && byteCount > boundary) {
uintptr_t flags = KeAcquireSpinlock(&gPfnLock);
gPfnFailedContiguousAllocations++;
gPfnFailedContiguousInvalidRequest++;
KeReleaseSpinlock(&gPfnLock, flags);
return (PHYSICAL_ADDRESS)0;
}
minInclusive = KiAlignUp(minInclusive);
maxExclusive = KiAlignDown(maxExclusive);
PHYSICAL_ADDRESS managedLimit = (PHYSICAL_ADDRESS)gMaxPfn * PAGE_SIZE;
if (maxExclusive > managedLimit)
maxExclusive = managedLimit;
if (maxExclusive <= minInclusive ||
(PHYSICAL_ADDRESS)byteCount > maxExclusive - minInclusive) {
uintptr_t flags = KeAcquireSpinlock(&gPfnLock);
gPfnFailedContiguousAllocations++;
gPfnFailedContiguousInvalidRequest++;
KeReleaseSpinlock(&gPfnLock, flags);
return (PHYSICAL_ADDRESS)0;
}
if (!KiPfnUsageMayUseReserve(usage))
KiPfnReclaimForPressure();
@@ -493,23 +542,31 @@ __declspec(dllexport) PHYSICAL_ADDRESS MmPfnAllocateContiguous(size_t count, MM_
return (PHYSICAL_ADDRESS)0;
}
size_t runStart = 0;
size_t runLength = 0;
for (size_t pfn = 1; pfn < gMaxPfn; pfn++) {
if (KiPfnAvailableLocked(pfn)) {
if (!runLength)
runStart = pfn;
runLength++;
if (runLength == count) {
for (size_t i = 0; i < count; i++)
KiClaimPfnLocked(runStart + i, usage);
KeReleaseSpinlock(&gPfnLock, flags);
return MmPfnAddress(runStart);
}
} else {
runLength = 0;
size_t firstPfn = (size_t)(minInclusive / PAGE_SIZE);
size_t limitPfn = (size_t)(maxExclusive / PAGE_SIZE);
for (size_t runStart = firstPfn; runStart + count <= limitPfn; ++runStart) {
PHYSICAL_ADDRESS runAddress = MmPfnAddress(runStart);
if ((runAddress & (alignment - 1)) != 0)
continue;
if (boundary) {
PHYSICAL_ADDRESS runEnd = runAddress + (PHYSICAL_ADDRESS)byteCount - 1;
if ((runAddress & ~((PHYSICAL_ADDRESS)boundary - 1)) !=
(runEnd & ~((PHYSICAL_ADDRESS)boundary - 1)))
continue;
}
size_t available = 0;
while (available < count && KiPfnAvailableLocked(runStart + available))
available++;
if (available != count) {
runStart += available;
continue;
}
for (size_t i = 0; i < count; ++i)
KiClaimPfnLocked(runStart + i, usage);
KeReleaseSpinlock(&gPfnLock, flags);
return runAddress;
}
gPfnFailedContiguousAllocations++;
@@ -518,6 +575,16 @@ __declspec(dllexport) PHYSICAL_ADDRESS MmPfnAllocateContiguous(size_t count, MM_
return (PHYSICAL_ADDRESS)0;
}
// Allocates a physically contiguous run for DMA or hardware structures.
__declspec(dllexport) PHYSICAL_ADDRESS MmPfnAllocateContiguous(size_t count, MM_PFN_USAGE usage) {
return MmPfnAllocateContiguousInRange(count,
PAGE_SIZE,
(PHYSICAL_ADDRESS)gMaxPfn * PAGE_SIZE,
PAGE_SIZE,
0,
usage);
}
// Increments the reference count on an allocated frame.
__declspec(dllexport) KSTATUS MmPfnRetain(PHYSICAL_ADDRESS frame) {
size_t pfn = MmPfnIndex(frame);