I have a question about kernl run-time functions. There are many Rlt**
functions for kernel such as RtlCchPrintf/RtlCchCat/RtlCopyString and so
on. I’m very confused about their declaration of IRQL level that most of
them can only be called in PASSIVE_LEVEL. See below:
- RtlCopyString: Any Level (if both source and destination are resident)
- RtlAppendStringToString: <= APC_LEVEL
- RtlCchPrintf/RtlCchCat: Passive_level
I can understand about any level and <=APC_LEVEL. If both source and
destination buffers are resident, such functions can be called in any level
else lower than DISPATCH_LEVEL. But why PASSIVE_LEVEL(3)? If such functions
will allocate memory from paged pool, this won’t prevent them being called
in APC_LEVE, right?
By de-assembling RtlCchPrintf, it will at last call into nt!_vsnwprintf. Is
vsnwprintf the reason for PASSIVE_LEVEL? Anyone can show me some light?
Thanks.
lkd> uf nt!RtlStringCchPrintfW
nt!RtlStringCchPrintfW:
82267453 8bff mov edi,edi
82267455 55 push ebp
82267456 8bec mov ebp,esp
82267458 33c0 xor eax,eax
8226745a 85c9 test ecx,ecx
8226745c 7408 je nt!RtlStringCchPrintfW+0x13 (82267466)
nt!RtlStringCchPrintfW+0xb:
8226745e 81f9ffffff7f cmp ecx,7FFFFFFFh
82267464 7605 jbe nt!RtlStringCchPrintfW+0x18 (8226746b)
nt!RtlStringCchPrintfW+0x13:
82267466 b80d0000c0 mov eax,0C000000Dh
nt!RtlStringCchPrintfW+0x18:
8226746b 85c0 test eax,eax
8226746d 7c35 jl nt!RtlStringCchPrintfW+0x4f (822674a4)
nt!RtlStringCchPrintfW+0x1c:
8226746f 53 push ebx
82267470 56 push esi
82267471 8d450c lea eax,[ebp+0Ch]
82267474 50 push eax
82267475 ff7508 push dword ptr [ebp+8]
82267478 8d71ff lea esi,[ecx-1]
8226747b 56 push esi
8226747c 57 push edi
8226747d 33db xor ebx,ebx
8226747f e8c6c80800 call nt!_vsnwprintf (822f3d4a)
82267484 83c410 add esp,10h
82267487 85c0 test eax,eax
82267489 7c0a jl nt!RtlStringCchPrintfW+0x40 (82267495)
nt!RtlStringCchPrintfW+0x38:
8226748b 3bc6 cmp eax,esi
8226748d 7706 ja nt!RtlStringCchPrintfW+0x40 (82267495)
nt!RtlStringCchPrintfW+0x3c:
8226748f 7409 je nt!RtlStringCchPrintfW+0x45 (8226749a)
nt!RtlStringCchPrintfW+0x3e:
82267491 eb0d jmp nt!RtlStringCchPrintfW+0x4b (822674a0)
nt!RtlStringCchPrintfW+0x40:
82267495 bb05000080 mov ebx,80000005h
nt!RtlStringCchPrintfW+0x45:
8226749a 33c0 xor eax,eax
8226749c 66890477 mov word ptr [edi+esi*2],ax
nt!RtlStringCchPrintfW+0x4b:
822674a0 5e pop esi
822674a1 8bc3 mov eax,ebx
822674a3 5b pop ebx
nt!RtlStringCchPrintfW+0x4f:
822674a4 5d pop ebp
822674a5 c3 ret
=================================
Best Regards!
Moore.Zhang (Zhang Pei)