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

@@ -0,0 +1,137 @@
// Win32 condition-variable smoke test for Bink worker synchronization.
#include <stdint.h>
#include <stddef.h>
#include <ntlite/syscall.h>
typedef void* HANDLE;
typedef unsigned long DWORD;
typedef int BOOL;
typedef struct { uintptr_t _opaque[5]; } CRITICAL_SECTION;
typedef struct { void* _ptr; } CONDITION_VARIABLE;
typedef DWORD (__stdcall *THREAD_START_ROUTINE)(void* parameter);
#define FALSE 0
#define TRUE 1
#define INFINITE 0xFFFFFFFFu
#define WAIT_OBJECT_0 0u
#define INVALID_HANDLE_VALUE ((HANDLE)(intptr_t)-1)
#define ERROR_TIMEOUT 1460u
__declspec(dllimport) void InitializeCriticalSection(CRITICAL_SECTION* criticalSection);
__declspec(dllimport) void DeleteCriticalSection(CRITICAL_SECTION* criticalSection);
__declspec(dllimport) void EnterCriticalSection(CRITICAL_SECTION* criticalSection);
__declspec(dllimport) void LeaveCriticalSection(CRITICAL_SECTION* criticalSection);
__declspec(dllimport) void InitializeConditionVariable(CONDITION_VARIABLE* conditionVariable);
__declspec(dllimport) BOOL SleepConditionVariableCS(CONDITION_VARIABLE* conditionVariable,
CRITICAL_SECTION* criticalSection,
DWORD milliseconds);
__declspec(dllimport) void WakeConditionVariable(CONDITION_VARIABLE* conditionVariable);
__declspec(dllimport) void WakeAllConditionVariable(CONDITION_VARIABLE* conditionVariable);
__declspec(dllimport) HANDLE CreateThread(void* attributes,
size_t stackSize,
THREAD_START_ROUTINE startRoutine,
void* parameter,
DWORD creationFlags,
DWORD* threadId);
__declspec(dllimport) DWORD WaitForSingleObject(HANDLE handle, DWORD milliseconds);
__declspec(dllimport) BOOL CloseHandle(HANDLE handle);
__declspec(dllimport) DWORD GetLastError(void);
static CRITICAL_SECTION gLock;
static CONDITION_VARIABLE gCondition;
static uint32_t gReady;
static uint32_t gRelease;
static uint32_t gWoke;
static uint32_t gWorkerFailure;
// Writes one test message to the native console.
static void print(const char* text) {
SYS_WRITE_CONSOLE_REQUEST request = { SysSvFromCstr(text) };
(void)SysWriteConsole(&request);
}
// Terminates the smoke test after one failure.
static void fail(const char* message) {
print("win32_condition_variable_smoke: ");
print(message);
print("\n");
while (true) (void)SysExitProcess(1);
}
// Waits until the main thread releases all condition-variable workers.
static DWORD __stdcall worker_main(void* parameter) {
(void)parameter;
EnterCriticalSection(&gLock);
gReady++;
while (!gRelease) {
if (!SleepConditionVariableCS(&gCondition, &gLock, INFINITE)) {
gWorkerFailure = 1;
LeaveCriticalSection(&gLock);
return 1;
}
}
gWoke++;
LeaveCriticalSection(&gLock);
return 0;
}
// Waits for both workers to enter their condition wait.
static void wait_for_workers(void) {
for (uint32_t attempt = 0; attempt < 5000u; attempt++) {
EnterCriticalSection(&gLock);
uint32_t ready = gReady;
LeaveCriticalSection(&gLock);
if (ready == 2u)
return;
(void)SysSleep(1);
}
fail("workers did not reach condition wait");
}
// Runs wake-all and finite-timeout condition-variable checks.
int main(void) {
print("win32_condition_variable_smoke: begin\n");
InitializeCriticalSection(&gLock);
InitializeConditionVariable(&gCondition);
HANDLE workers[2];
workers[0] = CreateThread(NULL, 0, worker_main, NULL, 0, NULL);
workers[1] = CreateThread(NULL, 0, worker_main, NULL, 0, NULL);
if (!workers[0] || workers[0] == INVALID_HANDLE_VALUE ||
!workers[1] || workers[1] == INVALID_HANDLE_VALUE)
fail("CreateThread failed");
wait_for_workers();
print("win32_condition_variable_smoke: workers waiting\n");
EnterCriticalSection(&gLock);
gRelease = 1;
WakeAllConditionVariable(&gCondition);
LeaveCriticalSection(&gLock);
print("win32_condition_variable_smoke: wake-all sent\n");
for (uint32_t index = 0; index < 2u; index++) {
if (WaitForSingleObject(workers[index], 5000u) != WAIT_OBJECT_0)
fail("worker did not exit after WakeAllConditionVariable");
if (!CloseHandle(workers[index]))
fail("CloseHandle failed");
}
if (gWorkerFailure || gWoke != 2u)
fail("wake-all result mismatch");
print("win32_condition_variable_smoke: workers joined\n");
EnterCriticalSection(&gLock);
BOOL signaled = SleepConditionVariableCS(&gCondition, &gLock, 25u);
DWORD error = GetLastError();
gRelease = 2;
LeaveCriticalSection(&gLock);
if (signaled || error != ERROR_TIMEOUT || gRelease != 2u)
fail("finite timeout or critical-section reacquire failed");
print("win32_condition_variable_smoke: timeout complete\n");
// A wake with no waiter is intentionally not retained.
WakeConditionVariable(&gCondition);
DeleteCriticalSection(&gLock);
print("win32_condition_variable_smoke: PASS\n");
while (true) (void)SysExitProcess(0);
}