replace ad hoc driver loading with a proper driver manager, new DDK, new PnP manager with device matching, asynchronous startup, resource ownership and removal, add shared PCI capability helpers, replace typed, rigid services with a proper service manager, implement proper system shutdown and restart, shutting down unloads drivers and shuts down services, add simple power button, remove heavyweight boot self-tests and SMP stress runs, add monotonic timestamps to kernel debug output, fruitless USB and PS/2 fixes, make test builds opt in.

This commit is contained in:
maksw committed 2026-10-26 10:08:03 +01:00
1 parent c0ad63c27f
commit d36f19509c
160 files changed
+6563 -7366

No files matched your search

@@ -464,77 +464,21 @@ static int run_local_transport_test(void) {
return 0;
}
// Verifies that registration privilege alone cannot publish a claimed well-known service.
static int run_claimless_client(void) {
SYS_SECURITY_CONTEXT_INFO contextInfo;
memset(&contextInfo, 0, sizeof(contextInfo));
contextInfo.Size = sizeof(contextInfo);
KSTATUS status = SysQuerySecurityContext(SYS_SECURITY_CONTEXT_CURRENT, &contextInfo);
if (!KSUCCESS(status)) return 10;
if (contextInfo.EffectivePrivileges != SYS_PRIV_SYSTEM_SERVICE_REGISTER ||
contextInfo.ServiceClaims != 0)
return 11;
SYS_HANDLE listener = SYS_HANDLE_INVALID;
status = create_listener(1, &listener);
if (!KSUCCESS(status)) return 12;
status = SysRegisterSystemService(SYS_SERVICE_RESOURCE, listener);
(void)SysCloseHandle(listener);
return status == NTLSTATUS_ACCESS_DENIED ? 0 : 13;
}
// Verifies that the live resource service owns its well-known registry slot and remains connectable.
// Verifies that unrelated handles cannot authorize numeric service publication.
static int run_service_test(void) {
SYS_HANDLE listener = SYS_HANDLE_INVALID;
KSTATUS status = create_listener(1, &listener);
if (!KSUCCESS(status)) return fail("create service probe listener", status);
status = SysRegisterSystemService(SYS_SERVICE_MAX + 1u, listener);
if (status != NTLSTATUS_INVALID_PARAMETER)
return fail("invalid service id", status);
status = SysRegisterSystemService(SYS_HANDLE_INVALID, listener);
if (status != NTLSTATUS_INVALID_HANDLE)
return fail("missing registration capability", status);
status = SysRegisterSystemService(SYS_SERVICE_RESOURCE, listener);
if (status != NTLSTATUS_ALREADY_EXISTS)
return fail("resource service must already be registered", status);
status = SysRegisterSystemService(listener, listener);
if (KSUCCESS(status)) return fail("listener cannot impersonate registry authority", status);
SYS_HANDLE claimlessContext = SYS_HANDLE_INVALID;
SYS_DERIVE_SECURITY_CONTEXT_REQUEST deriveContext;
memset(&deriveContext, 0, sizeof(deriveContext));
deriveContext.Size = sizeof(deriveContext);
deriveContext.SourceContext = SYS_SECURITY_CONTEXT_CURRENT;
deriveContext.EffectivePrivileges = SYS_PRIV_SYSTEM_SERVICE_REGISTER;
deriveContext.ContextHandleOut = &claimlessContext;
status = SysDeriveSecurityContext(&deriveContext);
if (!KSUCCESS(status)) return fail("derive claimless service context", status);
SYS_PEB* peb = SysGetPeb();
if (!peb || !peb->ImagePath.Data || peb->ImagePath.Length == 0)
return fail("missing image path", NTLSTATUS_FAILURE);
SYS_HANDLE claimlessChild = SYS_HANDLE_INVALID;
NTL_CREATE_SYSTEM_PROCESS_REQUEST claimlessCreate;
memset(&claimlessCreate, 0, sizeof(claimlessCreate));
claimlessCreate.Size = sizeof(claimlessCreate);
claimlessCreate.Flags = NTL_PROCESS_LOAD_FLAG_NONE;
claimlessCreate.Path = peb->ImagePath;
claimlessCreate.CommandLine = SysSvFromCstr("claimless");
claimlessCreate.SecurityContext = claimlessContext;
claimlessCreate.ResolveModuleName = NtlResolveSystemModuleName;
claimlessCreate.ProcessHandleOut = &claimlessChild;
status = NtlCreateSystemProcess(&claimlessCreate);
(void)SysCloseHandle(claimlessContext);
if (!KSUCCESS(status)) return fail("create claimless service client", status);
status = SysWait(claimlessChild, SYS_WAIT_FLAG_NONE);
if (!KSUCCESS(status)) return fail("wait claimless service client", status);
int32_t claimlessExit = -1;
status = SysGetProcessExitCode(claimlessChild, &claimlessExit);
(void)SysCloseHandle(claimlessChild);
if (!KSUCCESS(status)) return fail("query claimless service client", status);
if (claimlessExit != 0) return fail("service claim enforcement", (KSTATUS)claimlessExit);
status = SysUnregisterSystemService(SYS_SERVICE_RESOURCE, listener);
if (status != NTLSTATUS_ACCESS_DENIED)
return fail("foreign listener cannot unregister service", status);
status = SysUnregisterSystemService(listener, listener);
if (KSUCCESS(status)) return fail("listener cannot revoke registry authority", status);
SYS_HANDLE endpoint = SYS_HANDLE_INVALID;
SYS_CONNECT_SYSTEM_SERVICE_REQUEST connect;
@@ -550,14 +494,8 @@ static int run_service_test(void) {
return 0;
}
// Runs either the privileged parent or claimless child half.
// Runs the capability-scoped port and registry smoke tests.
int main(void) {
SYS_PEB* peb = SysGetPeb();
if (!peb) return 2;
if (peb->CommandLine.Length == 9 &&
memcmp(peb->CommandLine.Data, "claimless", 9) == 0)
return run_claimless_client();
print("port_ipc_smoke: start\n");
if (run_connection_lifetime_test() != 0) return 1;
if (run_peer_process_test() != 0) return 1;