I'm reading https://github.com/erynian/virtdbg sources and have trouble understanding this code:
Code: Select all
for (i = 0; i < KeNumberProcessors; i++)
{
OldAffinity = KeSetSystemAffinityThreadEx((KAFFINITY) (1 << i));
OldIrql = KeRaiseIrqlToDpcLevel();
_StartVirtualization();
KeLowerIrql(OldIrql);
KeRevertToUserAffinityThreadEx(OldAffinity);
}
Code: Select all
Inside StartVirtualization, there is some VMX setup code and then a call to Virtualize:_StartVirtualization PROC
;int 3
push rax
push rcx
push rdx
push rbx
push rbp
push rsi
push rdi
push r8
push r9
push r10
push r11
push r12
push r13
push r14
push r15
sub rsp, 28h
mov rcx, rsp
call StartVirtualization
_StartVirtualization ENDP
Code: Select all
So we have a call tree that ends in vmlaunch that starts exexuting guest code if successful and doesn't return! How is the topmost loop going to terminate then, or proceed to virtualize more than 1 processors?NTSTATUS Virtualize(PVIRT_CPU pCpu)
{
/* ULONG64 rsp;*/
ULONG32 i;
i = KeGetCurrentProcessorNumber();
DbgLog(("CPU: 0x%p \n", pCpu));
DbgLog(("rsp: 0x%llx \n", _Rsp()));
_VmLaunch();
/* never returns if successful */