parallel compile, SMP, swapgs, cleanup, remove useless Reserved fields
This commit is contained in:
1 parent
b17c9ac854
commit
bfe2b55142
42 files changed
+2131
-426
No files matched your search
@@ -1,10 +1,11 @@
|
||||
// ke_selftest.c - temporary kernel bring-up self-tests for execution/I/O model.
|
||||
// ke_selftest.c - kernel bring-up and regression self-tests.
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <ntlite/ddi/hal_api.h>
|
||||
#include <kernel/ke_apc.h>
|
||||
#include <kernel/ke_cpu.h>
|
||||
#include <kernel/ke_debug.h>
|
||||
#include <kernel/ke_event.h>
|
||||
#include <kernel/ke_irp.h>
|
||||
@@ -17,6 +18,7 @@
|
||||
#include <kernel/ke_trap.h>
|
||||
#include <kernel/mm_virt.h>
|
||||
#include <kernel/ob_object.h>
|
||||
#include <kernel/ke_smp.h>
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Kernel APC self-test
|
||||
@@ -747,6 +749,86 @@ static void KiRunTrapFrameSelfTest(void) {
|
||||
DbgPrint("TRAP selftest: PASS\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void KiRunCoreHardeningSelfTests(void) {
|
||||
DbgPrint("CORE selftest: begin\n");
|
||||
|
||||
if (gCpuCount == 0 || gCpuCount > KE_MAX_CPUS)
|
||||
KePanic(KE_PANIC_CODE_SELFTEST, "CORE selftest: invalid CPU count %u\n", gCpuCount);
|
||||
|
||||
KCPU* cpu = KeGetCurrentCpu();
|
||||
if (cpu != &gCpus[0])
|
||||
KePanic(KE_PANIC_CODE_SELFTEST, "CORE selftest: current CPU mismatch cpu=0x%llX cpu0=0x%llX\n",
|
||||
(uint64_t)cpu, (uint64_t)&gCpus[0]);
|
||||
if (cpu->Self != cpu)
|
||||
KePanic(KE_PANIC_CODE_SELFTEST, "CORE selftest: GS/KCPU self pointer mismatch self=0x%llX cpu=0x%llX\n",
|
||||
(uint64_t)cpu->Self, (uint64_t)cpu);
|
||||
if (KeGetCurrentCpuIndex() != 0)
|
||||
KePanic(KE_PANIC_CODE_SELFTEST, "CORE selftest: current CPU index is not BSP/0\n");
|
||||
if (!cpu->Present || !cpu->Started || !cpu->Online || !cpu->IsBsp)
|
||||
KePanic(KE_PANIC_CODE_SELFTEST, "CORE selftest: BSP lifecycle flags invalid P/S/O/B=%u/%u/%u/%u\n",
|
||||
cpu->Present, cpu->Started, cpu->Online, cpu->IsBsp);
|
||||
if (cpu->Parked)
|
||||
KePanic(KE_PANIC_CODE_SELFTEST, "CORE selftest: BSP is marked parked\n");
|
||||
if (KeGetCurrentIrql() != PASSIVE_LEVEL)
|
||||
KePanic(KE_PANIC_CODE_SELFTEST, "CORE selftest: expected PASSIVE_LEVEL, got %u\n", KeGetCurrentIrql());
|
||||
if (KeGetCurrentTss() != &cpu->Tss)
|
||||
KePanic(KE_PANIC_CODE_SELFTEST, "CORE selftest: current TSS is not CPU-local\n");
|
||||
if (!cpu->Tss.RSP0 || cpu->Tss.IoMapBase != sizeof(TSS64))
|
||||
KePanic(KE_PANIC_CODE_SELFTEST, "CORE selftest: invalid BSP TSS rsp0=0x%llX iomap=%u\n",
|
||||
cpu->Tss.RSP0, cpu->Tss.IoMapBase);
|
||||
if (!cpu->Gdtr.Base || cpu->Gdtr.Base != (uint64_t)cpu->Gdt)
|
||||
KePanic(KE_PANIC_CODE_SELFTEST, "CORE selftest: GDT is not CPU-local base=0x%llX gdt=0x%llX\n",
|
||||
cpu->Gdtr.Base, (uint64_t)cpu->Gdt);
|
||||
|
||||
for (uint32_t i = 1; i < gCpuCount; i++) {
|
||||
KCPU* ap = &gCpus[i];
|
||||
if (!ap->Present || !ap->Started || ap->Parked || !ap->Online || ap->IsBsp)
|
||||
KePanic(KE_PANIC_CODE_SELFTEST,
|
||||
"CORE selftest: AP%u lifecycle invalid P/S/Park/O/B=%u/%u/%u/%u/%u\n",
|
||||
i, ap->Present, ap->Started, ap->Parked, ap->Online, ap->IsBsp);
|
||||
if (!ap->SchedulerCommand || !ap->SchedulerActive)
|
||||
KePanic(KE_PANIC_CODE_SELFTEST,
|
||||
"CORE selftest: AP%u scheduler admission invalid command=%ld active=%ld\n",
|
||||
i, ap->SchedulerCommand, ap->SchedulerActive);
|
||||
if (!ap->KernelStack || !ap->KernelStackTop)
|
||||
KePanic(KE_PANIC_CODE_SELFTEST, "CORE selftest: AP%u missing kernel stack\n", i);
|
||||
if (!ap->Tss.RSP0 || ap->Tss.IoMapBase != sizeof(TSS64))
|
||||
KePanic(KE_PANIC_CODE_SELFTEST, "CORE selftest: AP%u invalid TSS rsp0=0x%llX iomap=%u\n",
|
||||
i, ap->Tss.RSP0, ap->Tss.IoMapBase);
|
||||
if (!ap->Gdtr.Base || ap->Gdtr.Base != (uint64_t)ap->Gdt)
|
||||
KePanic(KE_PANIC_CODE_SELFTEST, "CORE selftest: AP%u GDT not CPU-local\n", i);
|
||||
if (!ap->IdleThread || !ap->CurrentThread || ap->CurrentThread != ap->IdleThread)
|
||||
KePanic(KE_PANIC_CODE_SELFTEST, "CORE selftest: AP%u idle/current thread missing\n", i);
|
||||
if (!ap->IdleThread->IsIdleThread || ap->IdleThread->Queued || ap->IdleThread->RunningCpu != i)
|
||||
KePanic(KE_PANIC_CODE_SELFTEST,
|
||||
"CORE selftest: AP%u idle invariant failed queued=%u idle=%u runningCpu=%u\n",
|
||||
i, ap->IdleThread->Queued, ap->IdleThread->IsIdleThread, ap->IdleThread->RunningCpu);
|
||||
}
|
||||
|
||||
THREAD* cur = KeGetCurrentThread();
|
||||
if (!cur || cur != cpu->CurrentThread)
|
||||
KePanic(KE_PANIC_CODE_SELFTEST, "CORE selftest: current thread mismatch\n");
|
||||
if (!cpu->IdleThread || cur != cpu->IdleThread)
|
||||
KePanic(KE_PANIC_CODE_SELFTEST, "CORE selftest: scheduler did not start on CPU0 idle thread\n");
|
||||
if (!cur->IsIdleThread || cur->Queued || cur->RunningCpu != cpu->CpuIndex)
|
||||
KePanic(KE_PANIC_CODE_SELFTEST, "CORE selftest: idle invariant failed queued=%u idle=%u runningCpu=%u\n",
|
||||
cur->Queued, cur->IsIdleThread, cur->RunningCpu);
|
||||
|
||||
DbgPrint("CORE selftest: PASS\n");
|
||||
}
|
||||
|
||||
|
||||
void KiRunEarlyKernelSelfTests(void) {
|
||||
KSTATUS s = KeRunApplicationProcessorSchedulerSelfTests();
|
||||
if (!KSUCCESS(s)) {
|
||||
KePanic(KE_PANIC_CODE_SELFTEST,
|
||||
"SMP scheduler selftest failed status=0x%x\n",
|
||||
s);
|
||||
}
|
||||
}
|
||||
|
||||
void KiRunKernelSelfTests(const HAL_API* hal) {
|
||||
DbgPrint("Kernel selftests: begin\n");
|
||||
KiRunKernelApcSelfTest();
|
||||
|
||||
Reference in new issue
Block a user