ReactOS 0.4.16-dev-983-g23ad936
verifier.c File Reference
#include <ntdll.h>
#include <reactos/verifier.h>
#include <debug.h>
Include dependency graph for verifier.c:

Go to the source code of this file.

Classes

struct  _VERIFIER_PROVIDER
 

Macros

#define NDEBUG
 
#define VERIFIER_DLL_FLAGS_RESOLVED   1
 

Typedefs

typedef struct _VERIFIER_PROVIDER VERIFIER_PROVIDER
 
typedef struct _VERIFIER_PROVIDERPVERIFIER_PROVIDER
 

Functions

HANDLE NTAPI RtlpPageHeapCreate (ULONG Flags, PVOID Addr, SIZE_T TotalSize, SIZE_T CommitSize, PVOID Lock, PRTL_HEAP_PARAMETERS Parameters)
 
PVOID NTAPI RtlpPageHeapDestroy (HANDLE HeapPtr)
 
VOID NTAPI AVrfReadIFEO (HANDLE KeyHandle)
 
NTSTATUS NTAPI LdrpInitializeApplicationVerifierPackage (HANDLE KeyHandle, PPEB Peb, BOOLEAN SystemWide, BOOLEAN ReadAdvancedOptions)
 
BOOLEAN AVrfpIsVerifierProviderDll (PVOID BaseAddress)
 
SIZE_T AVrfpCountThunks (PIMAGE_THUNK_DATA Thunk)
 
VOID AVrfpSnapDllImports (IN PLDR_DATA_TABLE_ENTRY LdrEntry)
 
VOID AvrfpResolveThunks (IN PLDR_DATA_TABLE_ENTRY LdrEntry)
 
VOID NTAPI AVrfDllLoadNotification (IN PLDR_DATA_TABLE_ENTRY LdrEntry)
 
VOID NTAPI AVrfDllUnloadNotification (IN PLDR_DATA_TABLE_ENTRY LdrEntry)
 
VOID NTAPI AVrfInternalHeapFreeNotification (PVOID AllocationBase, SIZE_T AllocationSize)
 
VOID NTAPI AVrfPageHeapDllNotification (IN PLDR_DATA_TABLE_ENTRY LdrEntry)
 
VOID NTAPI AVrfpResnapInitialModules (VOID)
 
PVOID NTAPI AvrfpFindDuplicateThunk (PLIST_ENTRY EndEntry, PWCHAR DllName, PCHAR ThunkName)
 
VOID NTAPI AVrfpChainDuplicateThunks (VOID)
 
static PVOID NTAPI AVrfpGetStackTraceAddress (ULONG Arg0)
 
static HANDLE NTAPI AVrfpDebugPageHeapCreate (ULONG Flags, PVOID Addr, SIZE_T TotalSize, SIZE_T CommitSize, PVOID Lock, PRTL_HEAP_PARAMETERS Parameters)
 
static PVOID AVrfpDebugPageHeapDestroy (HANDLE HeapPtr)
 
NTSTATUS NTAPI AVrfpLoadAndInitializeProvider (PVERIFIER_PROVIDER Provider)
 
NTSTATUS NTAPI AVrfInitializeVerifier (VOID)
 

Variables

PLDR_DATA_TABLE_ENTRY LdrpImageEntry
 
ULONG AVrfpVerifierFlags = 0
 
WCHAR AVrfpVerifierDllsString [256] = { 0 }
 
ULONG AVrfpDebug = 0
 
BOOL AVrfpInitialized = FALSE
 
RTL_CRITICAL_SECTION AVrfpVerifierLock
 
LIST_ENTRY AVrfpVerifierProvidersList
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file verifier.c.

◆ VERIFIER_DLL_FLAGS_RESOLVED

#define VERIFIER_DLL_FLAGS_RESOLVED   1

Definition at line 28 of file verifier.c.

Typedef Documentation

◆ PVERIFIER_PROVIDER

◆ VERIFIER_PROVIDER

Function Documentation

◆ AVrfDllLoadNotification()

VOID NTAPI AVrfDllLoadNotification ( IN PLDR_DATA_TABLE_ENTRY  LdrEntry)

Definition at line 298 of file verifier.c.

299{
301
303 return;
304
306 if (!AVrfpIsVerifierProviderDll(LdrEntry->DllBase))
307 {
308 AvrfpResolveThunks(LdrEntry);
309
311 {
313 RTL_VERIFIER_DLL_LOAD_CALLBACK ProviderDllLoadCallback;
314
316
317 ProviderDllLoadCallback = Provider->ProviderDllLoadCallback;
318 if (ProviderDllLoadCallback)
319 {
320 ProviderDllLoadCallback(LdrEntry->BaseDllName.Buffer,
321 LdrEntry->DllBase,
322 LdrEntry->SizeOfImage,
323 LdrEntry);
324 }
325 }
326 }
328}
#define NtCurrentPeb()
Definition: FLS.c:22
#define FLG_APPLICATION_VERIFIER
Definition: pstypes.h:64
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
LIST_ENTRY AVrfpVerifierProvidersList
Definition: verifier.c:26
RTL_CRITICAL_SECTION AVrfpVerifierLock
Definition: verifier.c:25
BOOLEAN AVrfpIsVerifierProviderDll(PVOID BaseAddress)
Definition: verifier.c:107
VOID AvrfpResolveThunks(IN PLDR_DATA_TABLE_ENTRY LdrEntry)
Definition: verifier.c:239
ULONG NtGlobalFlag
Definition: init.c:54
base of all file and directory entries
Definition: entries.h:83
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
VOID(NTAPI * RTL_VERIFIER_DLL_LOAD_CALLBACK)(PWSTR DllName, PVOID DllBase, SIZE_T DllSize, PVOID Reserved)
Definition: verifier.h:6

Referenced by LdrpWalkImportDescriptor().

◆ AVrfDllUnloadNotification()

VOID NTAPI AVrfDllUnloadNotification ( IN PLDR_DATA_TABLE_ENTRY  LdrEntry)

Definition at line 332 of file verifier.c.

333{
335
337 return;
338
340 if (!AVrfpIsVerifierProviderDll(LdrEntry->DllBase))
341 {
343 {
345 RTL_VERIFIER_DLL_UNLOAD_CALLBACK ProviderDllUnloadCallback;
346
348
349 ProviderDllUnloadCallback = Provider->ProviderDllUnloadCallback;
350 if (ProviderDllUnloadCallback)
351 {
352 ProviderDllUnloadCallback(LdrEntry->BaseDllName.Buffer,
353 LdrEntry->DllBase,
354 LdrEntry->SizeOfImage,
355 LdrEntry);
356 }
357 }
358 }
360}
BOOL AVrfpInitialized
Definition: verifier.c:24
VOID(NTAPI * RTL_VERIFIER_DLL_UNLOAD_CALLBACK)(PWSTR DllName, PVOID DllBase, SIZE_T DllSize, PVOID Reserved)
Definition: verifier.h:7

Referenced by LdrUnloadDll().

◆ AVrfInitializeVerifier()

NTSTATUS NTAPI AVrfInitializeVerifier ( VOID  )

Definition at line 672 of file verifier.c.

673{
677 WCHAR* Ptr, *Next;
678
681
682 if (!NT_SUCCESS(Status))
683 return Status;
684
685 DbgPrint("AVRF: %wZ: pid 0x%X: flags 0x%X: application verifier enabled\n",
687
688 Provider = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(VERIFIER_PROVIDER));
689 if (!Provider)
690 return STATUS_NO_MEMORY;
691
692 RtlInitUnicodeString(&Provider->DllName, L"verifier.dll");
694
696
697 do
698 {
699 while (*Next == L' ' || *Next == L'\t')
700 Next++;
701
702 Ptr = Next;
703
704 while (*Next != ' ' && *Next != '\t' && *Next)
705 Next++;
706
707 if (*Next)
708 *(Next++) = '\0';
709 else
710 Next = NULL;
711
712 if (*Ptr)
713 {
714 Provider = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(VERIFIER_PROVIDER));
715 if (!Provider)
716 return STATUS_NO_MEMORY;
719 }
720 } while (Next);
721
724 {
726 Entry = Entry->Flink;
727
729 if (!NT_SUCCESS(Status))
730 {
731 RemoveEntryList(&Provider->ListEntry);
732 RtlFreeHeap(RtlGetProcessHeap(), 0, Provider);
733 }
734 }
735
736 if (!NT_SUCCESS(Status))
737 {
738 DbgPrint("AVRF: %wZ: pid 0x%X: application verifier will be disabled due to an initialization error.\n",
740 NtCurrentPeb()->NtGlobalFlag &= ~FLG_APPLICATION_VERIFIER;
741 }
742
743 return Status;
744}
LONG NTSTATUS
Definition: precomp.h:26
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:616
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:634
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define InsertTailList(ListHead, Entry)
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
Status
Definition: gdiplustypes.h:25
#define DbgPrint
Definition: hal.h:12
#define NtCurrentTeb
NTSYSAPI NTSTATUS NTAPI RtlInitializeCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
ULONG AVrfpVerifierFlags
Definition: verifier.c:21
PLDR_DATA_TABLE_ENTRY LdrpImageEntry
Definition: ldrinit.c:39
WCHAR AVrfpVerifierDllsString[256]
Definition: verifier.c:22
NTSTATUS NTAPI AVrfpLoadAndInitializeProvider(PVERIFIER_PROVIDER Provider)
Definition: verifier.c:549
#define L(x)
Definition: ntvdm.h:50
STDMETHOD() Next(THIS_ ULONG celt, IAssociationElement *pElement, ULONG *pceltFetched) PURE
HANDLE UniqueProcess
Definition: compat.h:825
UNICODE_STRING BaseDllName
Definition: ldrtypes.h:149
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1151
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by LdrpInitializeProcess().

◆ AVrfInternalHeapFreeNotification()

VOID NTAPI AVrfInternalHeapFreeNotification ( PVOID  AllocationBase,
SIZE_T  AllocationSize 
)

Definition at line 364 of file verifier.c.

365{
367
369 return;
370
373 {
375 RTL_VERIFIER_NTDLLHEAPFREE_CALLBACK ProviderHeapFreeCallback;
376
378
379 ProviderHeapFreeCallback = Provider->ProviderNtdllHeapFreeCallback;
380 if (ProviderHeapFreeCallback)
381 {
382 ProviderHeapFreeCallback(AllocationBase, AllocationSize);
383 }
384 }
386}
IN PFCB IN PFILE_OBJECT FileObject IN ULONG AllocationSize
Definition: fatprocs.h:323
VOID(NTAPI * RTL_VERIFIER_NTDLLHEAPFREE_CALLBACK)(PVOID AllocationBase, SIZE_T AllocationSize)
Definition: verifier.h:8

◆ AVrfPageHeapDllNotification()

VOID NTAPI AVrfPageHeapDllNotification ( IN PLDR_DATA_TABLE_ENTRY  LdrEntry)

Definition at line 390 of file verifier.c.

391{
392 /* Check if page heap dll notification is turned on */
394 return;
395
396 /* We don't support this flag currently */
398}
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
ULONG RtlpDphGlobalFlags
Definition: heappage.c:108
#define DPH_FLAG_DLL_NOTIFY
Definition: ntdllp.h:24

Referenced by LdrpWalkImportDescriptor().

◆ AVrfpChainDuplicateThunks()

VOID NTAPI AVrfpChainDuplicateThunks ( VOID  )

Definition at line 477 of file verifier.c.

478{
481
483 {
484 PRTL_VERIFIER_DLL_DESCRIPTOR DllDescriptor;
485 PRTL_VERIFIER_THUNK_DESCRIPTOR ThunkDescriptor;
486
488
489 for (DllDescriptor = Provider->ProviderDlls; DllDescriptor && DllDescriptor->DllName; ++DllDescriptor)
490 {
491 for (ThunkDescriptor = DllDescriptor->DllThunks; ThunkDescriptor && ThunkDescriptor->ThunkName; ++ThunkDescriptor)
492 {
493 PVOID Ptr;
494
496 DbgPrint("AVRF: Checking %wZ for duplicate (%ws: %s)\n",
497 &Provider->DllName, DllDescriptor->DllName, ThunkDescriptor->ThunkName);
498
499 Ptr = AvrfpFindDuplicateThunk(Entry, DllDescriptor->DllName, ThunkDescriptor->ThunkName);
500 if (Ptr)
501 {
503 DbgPrint("AVRF: Chaining (%ws: %s) to %wZ\n", DllDescriptor->DllName, ThunkDescriptor->ThunkName, &Provider->DllName);
504
505 ThunkDescriptor->ThunkOldAddress = Ptr;
506 }
507 }
508 }
509 }
510}
ULONG AVrfpDebug
Definition: verifier.c:23
PVOID NTAPI AvrfpFindDuplicateThunk(PLIST_ENTRY EndEntry, PWCHAR DllName, PCHAR ThunkName)
Definition: verifier.c:431
PRTL_VERIFIER_THUNK_DESCRIPTOR DllThunks
Definition: verifier.h:20
#define RTL_VRF_DBG_SHOWCHAINING
Definition: verifier.h:73
#define RTL_VRF_DBG_SHOWCHAINING_DEBUG
Definition: verifier.h:74

Referenced by AVrfpLoadAndInitializeProvider().

◆ AVrfpCountThunks()

SIZE_T AVrfpCountThunks ( PIMAGE_THUNK_DATA  Thunk)

Definition at line 124 of file verifier.c.

125{
126 SIZE_T Count = 0;
127 while (Thunk[Count].u1.Function)
128 Count++;
129 return Count;
130}
GLdouble u1
Definition: glext.h:8308
int Count
Definition: noreturn.cpp:7
ULONG_PTR SIZE_T
Definition: typedefs.h:80

Referenced by AVrfpSnapDllImports().

◆ AVrfpDebugPageHeapCreate()

static HANDLE NTAPI AVrfpDebugPageHeapCreate ( ULONG  Flags,
PVOID  Addr,
SIZE_T  TotalSize,
SIZE_T  CommitSize,
PVOID  Lock,
PRTL_HEAP_PARAMETERS  Parameters 
)
static

Definition at line 525 of file verifier.c.

531{
532 HANDLE hHeap;
533 hHeap = RtlpPageHeapCreate(Flags, Addr, TotalSize, CommitSize, Lock, Parameters);
534 DbgPrint("AVRF: DebugPageHeapCreate(Flags=%x, Addr=%p, TotalSize=%u, CommitSize=%u, Lock=%p, Parameters=%p) = %p\n",
535 Flags, Addr, TotalSize, CommitSize, Lock, Parameters, hHeap);
536 return hHeap;
537}
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T CommitSize
Definition: mmfuncs.h:406
HANDLE NTAPI RtlpPageHeapCreate(ULONG Flags, PVOID Addr, SIZE_T TotalSize, SIZE_T CommitSize, PVOID Lock, PRTL_HEAP_PARAMETERS Parameters)
Definition: heappage.c:1537
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:869
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:127
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Referenced by AVrfpLoadAndInitializeProvider().

◆ AVrfpDebugPageHeapDestroy()

static PVOID AVrfpDebugPageHeapDestroy ( HANDLE  HeapPtr)
static

Definition at line 541 of file verifier.c.

542{
543 DbgPrint("AVRF: DebugPageHeapDestroy(HeapPtr=%p)\n", HeapPtr);
544 return RtlpPageHeapDestroy(HeapPtr);
545}
PVOID NTAPI RtlpPageHeapDestroy(HANDLE HeapPtr)
Definition: heappage.c:1678

Referenced by AVrfpLoadAndInitializeProvider().

◆ AvrfpFindDuplicateThunk()

PVOID NTAPI AvrfpFindDuplicateThunk ( PLIST_ENTRY  EndEntry,
PWCHAR  DllName,
PCHAR  ThunkName 
)

Definition at line 431 of file verifier.c.

432{
434
435 for (Entry = AVrfpVerifierProvidersList.Flink; Entry != EndEntry; Entry = Entry->Flink)
436 {
438 PRTL_VERIFIER_DLL_DESCRIPTOR DllDescriptor;
439
441
443 DbgPrint("AVRF: chain: searching in %wZ\n", &Provider->DllName);
444
445 for (DllDescriptor = Provider->ProviderDlls; DllDescriptor && DllDescriptor->DllName; ++DllDescriptor)
446 {
447 PRTL_VERIFIER_THUNK_DESCRIPTOR ThunkDescriptor;
448
450 DbgPrint("AVRF: chain: dll: %ws\n", DllDescriptor->DllName);
451
452 if (_wcsicmp(DllDescriptor->DllName, DllName))
453 continue;
454
455 for (ThunkDescriptor = DllDescriptor->DllThunks; ThunkDescriptor && ThunkDescriptor->ThunkName; ++ThunkDescriptor)
456 {
458 DbgPrint("AVRF: chain: thunk: %s == %s ?\n", ThunkDescriptor->ThunkName, ThunkName);
459
460 if (!_stricmp(ThunkDescriptor->ThunkName, ThunkName))
461 {
463 DbgPrint("AVRF: Found duplicate for (%ws: %s) in %wZ\n",
464 DllDescriptor->DllName, ThunkDescriptor->ThunkName, &Provider->DllName);
465
466 return ThunkDescriptor->ThunkNewAddress;
467 }
468 }
469 }
470 }
471 return NULL;
472}
#define _stricmp
Definition: cat.c:22
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)

Referenced by AVrfpChainDuplicateThunks().

◆ AVrfpGetStackTraceAddress()

static PVOID NTAPI AVrfpGetStackTraceAddress ( ULONG  Arg0)
static

Definition at line 515 of file verifier.c.

516{
519 return NULL;
520}
NTSYSAPI void WINAPI DbgBreakPoint(void)

Referenced by AVrfpLoadAndInitializeProvider().

◆ AVrfpIsVerifierProviderDll()

BOOLEAN AVrfpIsVerifierProviderDll ( PVOID  BaseAddress)

Definition at line 107 of file verifier.c.

108{
111
113 {
115
116 if (BaseAddress == Provider->BaseAddress)
117 return TRUE;
118 }
119
120 return FALSE;
121}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404

Referenced by AVrfDllLoadNotification(), AVrfDllUnloadNotification(), and AVrfpResnapInitialModules().

◆ AVrfpLoadAndInitializeProvider()

NTSTATUS NTAPI AVrfpLoadAndInitializeProvider ( PVERIFIER_PROVIDER  Provider)

Definition at line 549 of file verifier.c.

550{
556
557 RtlInitEmptyUnicodeString(&DllPath, StringBuffer, sizeof(StringBuffer));
559 RtlAppendUnicodeToString(&DllPath, L"\\System32\\");
560
562 DbgPrint("AVRF: verifier dll `%wZ'\n", &Provider->DllName);
563
564 Status = LdrLoadDll(DllPath.Buffer, NULL, &Provider->DllName, &Provider->BaseAddress);
565 if (!NT_SUCCESS(Status))
566 {
567 DbgPrint("AVRF: %wZ: failed to load provider `%wZ' (status %08X) from %wZ\n",
569 &Provider->DllName,
570 Status,
571 &DllPath);
572 return Status;
573 }
574
575 /* Prevent someone funny from specifying his own application as provider */
577 if (!ImageNtHeader ||
579 {
580 DbgPrint("AVRF: provider %wZ is not a DLL image\n", &Provider->DllName);
582 }
583
584 Provider->EntryPoint = LdrpFetchAddressOfEntryPoint(Provider->BaseAddress);
585 if (!Provider->EntryPoint)
586 {
587 DbgPrint("AVRF: cannot find an entry point for provider %wZ\n", &Provider->DllName);
589 }
590
592 {
593 if (LdrpCallInitRoutine(Provider->EntryPoint,
594 Provider->BaseAddress,
596 &Descriptor))
597 {
599 {
600 /* Copy the data */
601 Provider->ProviderDlls = Descriptor->ProviderDlls;
602 Provider->ProviderDllLoadCallback = Descriptor->ProviderDllLoadCallback;
603 Provider->ProviderDllUnloadCallback = Descriptor->ProviderDllUnloadCallback;
604 Provider->ProviderNtdllHeapFreeCallback = Descriptor->ProviderNtdllHeapFreeCallback;
605
606 /* Update some info for the provider */
608 Descriptor->VerifierFlags = AVrfpVerifierFlags;
609 Descriptor->VerifierDebug = AVrfpDebug;
610
611 Descriptor->RtlpGetStackTraceAddress = AVrfpGetStackTraceAddress;
612 Descriptor->RtlpDebugPageHeapCreate = AVrfpDebugPageHeapCreate;
613 Descriptor->RtlpDebugPageHeapDestroy = AVrfpDebugPageHeapDestroy;
615 }
616 else
617 {
618 DbgPrint("AVRF: provider %wZ passed an invalid descriptor @ %p\n", &Provider->DllName, Descriptor);
620 }
621 }
622 else
623 {
624 DbgPrint("AVRF: provider %wZ did not initialize correctly\n", &Provider->DllName);
626 }
627 }
629 {
631 }
632 _SEH2_END;
633
634 if (!NT_SUCCESS(Status))
635 return Status;
636
637
639 DbgPrint("AVRF: initialized provider %wZ (descriptor @ %p)\n", &Provider->DllName, Descriptor);
640
641 /* Done loading providers, allow dll notifications */
643
646
647 /* Manually call with DLL_PROCESS_ATTACH, since the process is not done initializing */
649 {
650 if (!LdrpCallInitRoutine(Provider->EntryPoint,
651 Provider->BaseAddress,
653 NULL))
654 {
655 DbgPrint("AVRF: provider %wZ did not initialize correctly\n", &Provider->DllName);
657 }
658
659 }
661 {
663 }
664 _SEH2_END;
665
666 return Status;
667}
PIMAGE_NT_HEADERS WINAPI ImageNtHeader(_In_ PVOID)
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define RtlImageNtHeader
Definition: compat.h:806
#define MAX_PATH
Definition: compat.h:34
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
WCHAR StringBuffer[156]
Definition: ldrinit.c:41
NTSTATUS NTAPI DECLSPEC_HOTPATCH LdrLoadDll(_In_opt_ PWSTR SearchPath, _In_opt_ PULONG DllCharacteristics, _In_ PUNICODE_STRING DllName, _Out_ PVOID *BaseAddress)
Definition: ldrapi.c:312
static const char const char * DllPath
Definition: image.c:34
static PVOID AVrfpDebugPageHeapDestroy(HANDLE HeapPtr)
Definition: verifier.c:541
static PVOID NTAPI AVrfpGetStackTraceAddress(ULONG Arg0)
Definition: verifier.c:515
VOID NTAPI AVrfpResnapInitialModules(VOID)
Definition: verifier.c:403
static HANDLE NTAPI AVrfpDebugPageHeapCreate(ULONG Flags, PVOID Addr, SIZE_T TotalSize, SIZE_T CommitSize, PVOID Lock, PRTL_HEAP_PARAMETERS Parameters)
Definition: verifier.c:525
VOID NTAPI AVrfpChainDuplicateThunks(VOID)
Definition: verifier.c:477
BOOLEAN NTAPI LdrpCallInitRoutine(IN PDLL_INIT_ROUTINE EntryPoint, IN PVOID BaseAddress, IN ULONG Reason, IN PVOID Context)
Definition: ldrutils.c:100
PVOID NTAPI LdrpFetchAddressOfEntryPoint(PVOID ImageBase)
#define STATUS_INVALID_PARAMETER_4
Definition: ntstatus.h:478
#define STATUS_PROCEDURE_NOT_FOUND
Definition: ntstatus.h:358
#define STATUS_DLL_INIT_FAILED
Definition: ntstatus.h:558
#define IMAGE_FILE_DLL
Definition: pedump.c:169
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:181
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:82
#define _SEH2_END
Definition: pseh2_64.h:171
#define _SEH2_TRY
Definition: pseh2_64.h:71
#define SharedUserData
#define STATUS_SUCCESS
Definition: shellext.h:65
IMAGE_FILE_HEADER FileHeader
Definition: ntddk_ex.h:183
#define RTL_VRF_DBG_LISTPROVIDERS
Definition: verifier.h:72
#define RTL_VRF_DBG_SHOWSNAPS
Definition: verifier.h:69
#define DLL_PROCESS_VERIFIER
Definition: verifier.h:4
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:342

Referenced by AVrfInitializeVerifier().

◆ AVrfpResnapInitialModules()

VOID NTAPI AVrfpResnapInitialModules ( VOID  )

Definition at line 403 of file verifier.c.

404{
405 PLIST_ENTRY ListHead, ListEntry;
406
407 ListHead = &NtCurrentPeb()->Ldr->InLoadOrderModuleList;
408 for (ListEntry = ListHead->Flink; ListHead != ListEntry; ListEntry = ListEntry->Flink)
409 {
410 PLDR_DATA_TABLE_ENTRY LdrEntry;
411
412 LdrEntry = CONTAINING_RECORD(ListEntry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
413
414 if (AVrfpIsVerifierProviderDll(LdrEntry->DllBase))
415 {
417 DbgPrint("AVRF: skipped resnapping provider %wZ ...\n", &LdrEntry->BaseDllName);
418 }
419 else
420 {
422 DbgPrint("AVRF: resnapping %wZ ...\n", &LdrEntry->BaseDllName);
423
424 AvrfpResolveThunks(LdrEntry);
425 }
426 }
427}
Definition: btrfs_drv.h:1876
PVOID DllBase
Definition: btrfs_drv.h:1880

Referenced by AVrfpLoadAndInitializeProvider().

◆ AvrfpResolveThunks()

VOID AvrfpResolveThunks ( IN PLDR_DATA_TABLE_ENTRY  LdrEntry)

Definition at line 239 of file verifier.c.

240{
243
244 if (!AVrfpInitialized)
245 return;
246
248 {
249 PRTL_VERIFIER_DLL_DESCRIPTOR DllDescriptor;
250
252
253 for (DllDescriptor = Provider->ProviderDlls; DllDescriptor && DllDescriptor->DllName; ++DllDescriptor)
254 {
255 PRTL_VERIFIER_THUNK_DESCRIPTOR ThunkDescriptor;
256
257 if ((DllDescriptor->DllFlags & VERIFIER_DLL_FLAGS_RESOLVED) ||
258 _wcsicmp(DllDescriptor->DllName, LdrEntry->BaseDllName.Buffer))
259 continue;
260
262 DbgPrint("AVRF: pid 0x%X: found dll descriptor for `%wZ' with verified exports\n",
264 &LdrEntry->BaseDllName);
265
266 for (ThunkDescriptor = DllDescriptor->DllThunks; ThunkDescriptor && ThunkDescriptor->ThunkName; ++ThunkDescriptor)
267 {
268 if (!ThunkDescriptor->ThunkOldAddress)
269 {
270 ANSI_STRING ThunkName;
271
272 RtlInitAnsiString(&ThunkName, ThunkDescriptor->ThunkName);
273 /* We cannot call the public api, because that would run init routines! */
274 if (NT_SUCCESS(LdrpGetProcedureAddress(LdrEntry->DllBase, &ThunkName, 0, &ThunkDescriptor->ThunkOldAddress, FALSE)))
275 {
277 DbgPrint("AVRF: (%wZ) %Z export found.\n", &LdrEntry->BaseDllName, &ThunkName);
278 }
279 else
280 {
282 DbgPrint("AVRF: warning: did not find `%Z' export in %wZ.\n", &ThunkName, &LdrEntry->BaseDllName);
283 }
284 }
285 }
286
287 DllDescriptor->DllFlags |= VERIFIER_DLL_FLAGS_RESOLVED;
288 }
289 }
290
291 AVrfpSnapDllImports(LdrEntry);
292}
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
#define VERIFIER_DLL_FLAGS_RESOLVED
Definition: verifier.c:28
VOID AVrfpSnapDllImports(IN PLDR_DATA_TABLE_ENTRY LdrEntry)
Definition: verifier.c:133
NTSTATUS NTAPI LdrpGetProcedureAddress(_In_ PVOID BaseAddress, _In_opt_ _When_(Ordinal==0, _Notnull_) PANSI_STRING Name, _In_opt_ _When_(Name==NULL, _In_range_(>, 0)) ULONG Ordinal, _Out_ PVOID *ProcedureAddress, _In_ BOOLEAN ExecuteInit)
Definition: ldrutils.c:2231
#define RTL_VRF_DBG_SHOWFOUNDEXPORTS
Definition: verifier.h:70
#define RTL_VRF_DBG_SHOWVERIFIEDEXPORTS
Definition: verifier.h:71

Referenced by AVrfDllLoadNotification(), and AVrfpResnapInitialModules().

◆ AVrfpSnapDllImports()

VOID AVrfpSnapDllImports ( IN PLDR_DATA_TABLE_ENTRY  LdrEntry)

Definition at line 133 of file verifier.c.

134{
135 ULONG Size;
136 PIMAGE_IMPORT_DESCRIPTOR ImportDescriptor;
137 PBYTE DllBase = LdrEntry->DllBase;
138
140 if (!ImportDescriptor)
141 {
142 //SHIMENG_INFO("Skipping module 0x%p \"%wZ\" due to no iat found\n", LdrEntry->DllBase, &LdrEntry->BaseDllName);
143 return;
144 }
145
146 for (; ImportDescriptor->Name && ImportDescriptor->OriginalFirstThunk; ImportDescriptor++)
147 {
148 PIMAGE_THUNK_DATA FirstThunk;
149 PVOID UnprotectedPtr = NULL;
150 SIZE_T UnprotectedSize = 0;
151 ULONG OldProtection = 0;
152 FirstThunk = (PIMAGE_THUNK_DATA)(DllBase + ImportDescriptor->FirstThunk);
153
154 /* Walk all imports */
155 for (;FirstThunk->u1.Function; FirstThunk++)
156 {
159
161 {
162 PRTL_VERIFIER_DLL_DESCRIPTOR DllDescriptor;
163
165 for (DllDescriptor = Provider->ProviderDlls; DllDescriptor && DllDescriptor->DllName; ++DllDescriptor)
166 {
167 PRTL_VERIFIER_THUNK_DESCRIPTOR ThunkDescriptor;
168
169 for (ThunkDescriptor = DllDescriptor->DllThunks; ThunkDescriptor && ThunkDescriptor->ThunkName; ++ThunkDescriptor)
170 {
171 /* Just compare function addresses, the loader will have handled forwarders and ordinals for us */
172 if ((PVOID)FirstThunk->u1.Function != ThunkDescriptor->ThunkOldAddress)
173 continue;
174
175 if (!UnprotectedPtr)
176 {
177 PVOID Ptr = &FirstThunk->u1.Function;
178 SIZE_T Size = sizeof(FirstThunk->u1.Function) * AVrfpCountThunks(FirstThunk);
180
181 UnprotectedPtr = Ptr;
182 UnprotectedSize = Size;
183
185 &Ptr,
186 &Size,
188 &OldProtection);
189
190 if (!NT_SUCCESS(Status))
191 {
192 DbgPrint("AVRF: Unable to unprotect IAT to modify thunks (status %08X).\n", Status);
193 UnprotectedPtr = NULL;
194 continue;
195 }
196 }
197
198 if (ThunkDescriptor->ThunkNewAddress == NULL)
199 {
200 DbgPrint("AVRF: internal error: New thunk for %s is null.\n", ThunkDescriptor->ThunkName);
201 continue;
202 }
203 FirstThunk->u1.Function = (SIZE_T)ThunkDescriptor->ThunkNewAddress;
205 DbgPrint("AVRF: Snapped (%wZ: %s) with (%wZ: %p).\n",
206 &LdrEntry->BaseDllName,
207 ThunkDescriptor->ThunkName,
208 &Provider->DllName,
209 ThunkDescriptor->ThunkNewAddress);
210 }
211 }
212 }
213 }
214
215 if (UnprotectedPtr)
216 {
217 PVOID Ptr = UnprotectedPtr;
218 SIZE_T Size = UnprotectedSize;
220
221 UnprotectedPtr = Ptr;
222 UnprotectedSize = Size;
223
225 &Ptr,
226 &Size,
227 OldProtection,
228 &OldProtection);
229 if (!NT_SUCCESS(Status))
230 {
231 DbgPrint("AVRF: Unable to reprotect IAT to modify thunks (status %08X).\n", Status);
232 }
233 }
234 }
235}
#define RtlImageDirectoryEntryToData
Definition: compat.h:809
if(dx< 0)
Definition: linetemp.h:194
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1308
SIZE_T AVrfpCountThunks(PIMAGE_THUNK_DATA Thunk)
Definition: verifier.c:124
PIMAGE_THUNK_DATA32 PIMAGE_THUNK_DATA
Definition: ntimage.h:566
NTSTATUS NTAPI NtProtectVirtualMemory(IN HANDLE ProcessHandle, IN OUT PVOID *UnsafeBaseAddress, IN OUT SIZE_T *UnsafeNumberOfBytesToProtect, IN ULONG NewAccessProtection, OUT PULONG UnsafeOldAccessProtection)
Definition: virtual.c:3111
#define IMAGE_DIRECTORY_ENTRY_IMPORT
Definition: pedump.c:260
BYTE * PBYTE
Definition: pedump.c:66
union _IMAGE_THUNK_DATA32::@2218 u1
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533

Referenced by AvrfpResolveThunks().

◆ AVrfReadIFEO()

VOID NTAPI AVrfReadIFEO ( HANDLE  KeyHandle)

Definition at line 50 of file verifier.c.

51{
53
55 L"VerifierDlls",
56 REG_SZ,
58 sizeof(AVrfpVerifierDllsString) - sizeof(WCHAR),
59 NULL);
60
61 if (!NT_SUCCESS(Status))
63
65 L"VerifierFlags",
68 sizeof(AVrfpVerifierFlags),
69 NULL);
70 if (!NT_SUCCESS(Status))
72
74 L"VerifierDebug",
77 sizeof(AVrfpDebug),
78 NULL);
79 if (!NT_SUCCESS(Status))
80 AVrfpDebug = 0;
81}
#define REG_SZ
Definition: layer.c:22
NTSTATUS NTAPI LdrQueryImageFileKeyOption(_In_ HANDLE KeyHandle, _In_ PCWSTR ValueName, _In_ ULONG Type, _Out_ PVOID Buffer, _In_ ULONG BufferSize, _Out_opt_ PULONG ReturnedLength)
Definition: ldrinit.c:184
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
#define UNICODE_NULL
#define REG_DWORD
Definition: sdbapi.c:596
#define RTL_VRF_FLG_HANDLE_CHECKS
Definition: verifier.h:47
#define RTL_VRF_FLG_LOCK_CHECKS
Definition: verifier.h:64
#define RTL_VRF_FLG_FAST_FILL_HEAP
Definition: verifier.h:60

Referenced by LdrpInitializeApplicationVerifierPackage().

◆ LdrpInitializeApplicationVerifierPackage()

NTSTATUS NTAPI LdrpInitializeApplicationVerifierPackage ( HANDLE  KeyHandle,
PPEB  Peb,
BOOLEAN  SystemWide,
BOOLEAN  ReadAdvancedOptions 
)

Definition at line 86 of file verifier.c.

87{
88 /* If global flags request DPH, perform some additional actions */
90 {
91 // TODO: Read advanced DPH flags from the registry if requested
92 if (ReadAdvancedOptions)
93 {
95 }
96
97 /* Enable page heap */
99 }
100
102
103 return STATUS_SUCCESS;
104}
PPEB Peb
Definition: dllmain.c:27
#define FLG_HEAP_PAGE_ALLOCS
Definition: pstypes.h:84
VOID NTAPI AVrfReadIFEO(HANDLE KeyHandle)
Definition: verifier.c:50
BOOLEAN RtlpPageHeapEnabled
Definition: heappage.c:107
ULONG NtGlobalFlag
Definition: ntddk_ex.h:270

◆ RtlpPageHeapCreate()

HANDLE NTAPI RtlpPageHeapCreate ( ULONG  Flags,
PVOID  Addr,
SIZE_T  TotalSize,
SIZE_T  CommitSize,
PVOID  Lock,
PRTL_HEAP_PARAMETERS  Parameters 
)

Definition at line 1537 of file heappage.c.

1543{
1544 PVOID Base = NULL;
1545 PHEAP HeapPtr;
1546 PDPH_HEAP_ROOT DphRoot;
1547 PDPH_HEAP_BLOCK DphNode;
1548 ULONG MemSize;
1550 LARGE_INTEGER PerfCounter;
1551
1552 /* Check for a DPH bypass flag */
1553 if ((ULONG_PTR)Parameters == -1) return NULL;
1554
1555 /* Make sure no user-allocated stuff was provided */
1556 if (Addr || Lock) return NULL;
1557
1558 /* Allocate minimum amount of virtual memory */
1559 MemSize = DPH_RESERVE_SIZE;
1561 if (!NT_SUCCESS(Status))
1562 {
1563 ASSERT(FALSE);
1564 return NULL;
1565 }
1566
1567 /* Set protection */
1569 if (!NT_SUCCESS(Status))
1570 {
1571 //RtlpDphFreeVm(Base, 0, 0, 0);
1572 ASSERT(FALSE);
1573 return NULL;
1574 }
1575
1576 /* Start preparing the 1st page. Fill it with the default filler */
1578
1579 /* Set flags in the "HEAP" structure */
1580 HeapPtr = (PHEAP)Base;
1581 HeapPtr->Flags = Flags | HEAP_FLAG_PAGE_ALLOCS;
1583
1584 /* Set 1st page to read only now */
1586 if (!NT_SUCCESS(Status))
1587 {
1588 ASSERT(FALSE);
1589 return NULL;
1590 }
1591
1592 /* 2nd page is the real DPH root block */
1593 DphRoot = (PDPH_HEAP_ROOT)((PCHAR)Base + PAGE_SIZE);
1594
1595 /* Initialize the DPH root */
1596 DphRoot->Signature = DPH_SIGNATURE;
1597 DphRoot->HeapFlags = Flags;
1598 DphRoot->HeapCritSect = (PHEAP_LOCK)((PCHAR)DphRoot + DPH_POOL_SIZE);
1599 DphRoot->ExtraFlags = RtlpDphGlobalFlags;
1600
1601 ZwQueryPerformanceCounter(&PerfCounter, NULL);
1602 DphRoot->Seed = PerfCounter.LowPart;
1603
1606
1607 /* Create a normal heap for this paged heap */
1608 DphRoot->NormalHeap = RtlCreateHeap(Flags, NULL, TotalSize, CommitSize, NULL, (PRTL_HEAP_PARAMETERS)-1);
1609 if (!DphRoot->NormalHeap)
1610 {
1611 ASSERT(FALSE);
1612 return NULL;
1613 }
1614
1615 /* 3rd page: a pool for DPH allocations */
1616 RtlpDphAddNewPool(DphRoot, NULL, DphRoot + 1, DPH_POOL_SIZE - sizeof(DPH_HEAP_ROOT), FALSE);
1617
1618 /* Allocate internal heap blocks. For the root */
1619 DphNode = RtlpDphAllocateNode(DphRoot);
1620 ASSERT(DphNode != NULL);
1621 DphNode->pVirtualBlock = (PUCHAR)DphRoot;
1623 RtlpDphPlaceOnPoolList(DphRoot, DphNode);
1624
1625 /* For the memory we allocated as a whole */
1626 DphNode = RtlpDphAllocateNode(DphRoot);
1627 ASSERT(DphNode != NULL);
1628 DphNode->pVirtualBlock = Base;
1629 DphNode->nVirtualBlockSize = MemSize;
1630 RtlpDphPlaceOnVirtualList(DphRoot, DphNode);
1631
1632 /* For the remaining part */
1633 DphNode = RtlpDphAllocateNode(DphRoot);
1634 ASSERT(DphNode != NULL);
1636 DphNode->nVirtualBlockSize = MemSize - (2*PAGE_SIZE + DPH_POOL_SIZE);
1637 RtlpDphCoalesceNodeIntoAvailable(DphRoot, DphNode);
1638
1639 //DphRoot->CreateStackTrace = RtlpDphLogStackTrace(1);
1640
1641 /* Initialize AVL-based busy nodes table */
1646 NULL);
1647
1648 /* Initialize per-process startup info */
1650
1651 /* Acquire the heap list lock */
1653
1654 /* Insert this heap to the tail of the global list */
1656
1657 /* Note we increased the size of the list */
1659
1660 /* Release the heap list lock */
1662
1664 {
1665 DPRINT1("Page heap: process 0x%p created heap @ %p (%p, flags 0x%X)\n",
1667 DphRoot->NormalHeap, DphRoot->ExtraFlags);
1668 }
1669
1670 /* Perform internal validation if required */
1673
1674 return (PUCHAR)DphRoot - PAGE_SIZE;
1675}
VOID NTAPI RtlInitializeGenericTableAvl(IN OUT PRTL_AVL_TABLE Table, IN PRTL_AVL_COMPARE_ROUTINE CompareRoutine, IN PRTL_AVL_ALLOCATE_ROUTINE AllocateRoutine, IN PRTL_AVL_FREE_ROUTINE FreeRoutine, IN PVOID TableContext)
Definition: avltable.c:26
#define DPRINT1
Definition: precomp.h:8
struct _HEAP * PHEAP
NTSTATUS NTAPI RtlInitializeHeapLock(IN OUT PHEAP_LOCK *Lock)
Definition: libsupp.c:128
NTSTATUS NTAPI RtlEnterHeapLock(IN OUT PHEAP_LOCK Lock, IN BOOLEAN Exclusive)
Definition: libsupp.c:110
NTSTATUS NTAPI RtlLeaveHeapLock(IN OUT PHEAP_LOCK Lock)
Definition: libsupp.c:135
#define PAGE_READONLY
Definition: compat.h:138
#define PAGE_SIZE
Definition: env_spec_w32.h:49
VOID NTAPI RtlpDphPlaceOnPoolList(PDPH_HEAP_ROOT DphRoot, PDPH_HEAP_BLOCK Node)
Definition: heappage.c:515
PHEAP_LOCK RtlpDphPageHeapListLock
Definition: heappage.c:116
ULONG RtlpDphGlobalFlags
Definition: heappage.c:108
LIST_ENTRY RtlpDphPageHeapList
Definition: heappage.c:113
VOID NTAPI RtlpDphFreeNodeForTable(IN PRTL_AVL_TABLE Table, IN PVOID Buffer)
Definition: heappage.c:1227
NTSTATUS NTAPI RtlpDphProtectVm(PVOID Base, SIZE_T Size, ULONG Protection)
Definition: heappage.c:421
BOOLEAN RtlpDphPageHeapListInitialized
Definition: heappage.c:114
PDPH_HEAP_BLOCK NTAPI RtlpDphAllocateNode(PDPH_HEAP_ROOT DphRoot)
Definition: heappage.c:1018
#define DPH_RESERVE_SIZE
Definition: heappage.c:134
VOID NTAPI RtlpDphInternalValidatePageHeap(PDPH_HEAP_ROOT DphRoot, PVOID Address, ULONG Value)
Definition: heappage.c:1318
VOID NTAPI RtlpDphAddNewPool(PDPH_HEAP_ROOT DphRoot, PDPH_HEAP_BLOCK NodeBlock, PVOID Virtual, SIZE_T Size, BOOLEAN PlaceOnPool)
Definition: heappage.c:829
VOID NTAPI RtlpDphCoalesceNodeIntoAvailable(PDPH_HEAP_ROOT DphRoot, PDPH_HEAP_BLOCK Node)
Definition: heappage.c:684
#define DPH_FILL
Definition: heappage.c:155
ULONG RtlpDphPageHeapListLength
Definition: heappage.c:117
PVOID NTAPI RtlpDphAllocateNodeForTable(IN PRTL_AVL_TABLE Table, IN CLONG ByteSize)
Definition: heappage.c:1206
#define DPH_DEBUG_INTERNAL_VALIDATE
Definition: heappage.c:147
NTSTATUS NTAPI RtlpDphProcessStartupInitialization(VOID)
Definition: heappage.c:1496
#define DPH_DEBUG_VERBOSE
Definition: heappage.c:148
struct _DPH_HEAP_ROOT * PDPH_HEAP_ROOT
RTL_GENERIC_COMPARE_RESULTS NTAPI RtlpDphCompareNodeForTable(IN PRTL_AVL_TABLE Table, IN PVOID FirstStruct, IN PVOID SecondStruct)
Definition: heappage.c:1187
#define DPH_POOL_SIZE
Definition: heappage.c:135
#define DPH_SIGNATURE
Definition: heappage.c:176
ULONG RtlpDphDebugOptions
Definition: heappage.c:185
NTSTATUS NTAPI RtlpDphAllocateVm(PVOID *Base, SIZE_T Size, ULONG Type, ULONG Protection)
Definition: heappage.c:346
VOID NTAPI RtlpDphPlaceOnVirtualList(PDPH_HEAP_ROOT DphRoot, PDPH_HEAP_BLOCK Node)
Definition: heappage.c:535
#define RtlFillMemoryUlong(dst, len, val)
Definition: mkhive.h:55
#define ASSERT(a)
Definition: mode.c:44
NTSYSAPI NTSTATUS NTAPI ZwQueryPerformanceCounter(_Out_ PLARGE_INTEGER Counter, _Out_opt_ PLARGE_INTEGER Frequency)
_In_opt_ ULONG Base
Definition: rtlfuncs.h:2478
struct _HEAP_LOCK * PHEAP_LOCK
#define HEAP_FLAG_PAGE_ALLOCS
Definition: rtltypes.h:160
#define PAGE_READWRITE
Definition: nt_native.h:1304
NTSYSAPI PVOID NTAPI RtlCreateHeap(IN ULONG Flags, IN PVOID HeapBase OPTIONAL, IN ULONG ReserveSize OPTIONAL, IN ULONG CommitSize OPTIONAL, IN PVOID Lock OPTIONAL, IN PRTL_HEAP_PARAMETERS Parameters OPTIONAL)
#define MEM_COMMIT
Definition: nt_native.h:1313
#define PAGE_NOACCESS
Definition: nt_native.h:1302
PUCHAR pVirtualBlock
Definition: heappage.c:50
SIZE_T nVirtualBlockSize
Definition: heappage.c:51
PHEAP_LOCK HeapCritSect
Definition: heappage.c:66
ULONG Seed
Definition: heappage.c:99
LIST_ENTRY NextHeap
Definition: heappage.c:97
LIST_ENTRY AvailableAllocationHead
Definition: heappage.c:84
ULONG ExtraFlags
Definition: heappage.c:98
ULONG Signature
Definition: heappage.c:64
ULONG HeapFlags
Definition: heappage.c:65
PVOID NormalHeap
Definition: heappage.c:100
RTL_AVL_TABLE BusyNodesTable
Definition: heappage.c:74
Definition: heap.c:52
ULONG Flags
Definition: heap.h:226
ULONG ForceFlags
Definition: heap.h:227
uint32_t ULONG_PTR
Definition: typedefs.h:65
unsigned char * PUCHAR
Definition: typedefs.h:53
char * PCHAR
Definition: typedefs.h:51
ULONG LowPart
Definition: typedefs.h:106

Referenced by AVrfpDebugPageHeapCreate(), and RtlCreateHeap().

◆ RtlpPageHeapDestroy()

PVOID NTAPI RtlpPageHeapDestroy ( HANDLE  HeapPtr)

Definition at line 1678 of file heappage.c.

1679{
1680 PDPH_HEAP_ROOT DphRoot;
1681 PVOID Ptr;
1683 PHEAP NormalHeap;
1684 ULONG Value;
1685
1686 /* Check if it's not a process heap */
1687 if (HeapPtr == RtlGetProcessHeap())
1688 {
1690 "attempt to destroy process heap",
1691 HeapPtr, "Heap handle",
1692 0, "",
1693 0, "",
1694 0, "");
1695 return NULL;
1696 }
1697
1698 /* Get pointer to the heap root */
1699 DphRoot = RtlpDphPointerFromHandle(HeapPtr);
1700 if (!DphRoot) return NULL;
1701
1702 RtlpDphPreProcessing(DphRoot, DphRoot->HeapFlags);
1703
1704 /* Get the pointer to the normal heap */
1705 NormalHeap = DphRoot->NormalHeap;
1706
1707 /* Free the delayed-free blocks */
1708 RtlpDphFreeDelayedBlocksFromHeap(DphRoot, NormalHeap);
1709
1710 /* Go through the busy blocks */
1712
1713 while (Ptr)
1714 {
1715 Node = CONTAINING_RECORD(Ptr, DPH_HEAP_BLOCK, pUserAllocation);
1716 if (!(DphRoot->ExtraFlags & DPH_EXTRA_CHECK_UNDERRUN))
1717 {
1718 if (!RtlpDphIsPageHeapBlock(DphRoot, Node->pUserAllocation, &Value, TRUE))
1719 {
1720 RtlpDphReportCorruptedBlock(DphRoot, 3, Node->pUserAllocation, Value);
1721 }
1722 }
1723
1724 AVrfInternalHeapFreeNotification(Node->pUserAllocation, Node->nUserRequestedSize);
1725
1726 /* Go to the next node */
1728 }
1729
1730 /* Acquire the global heap list lock */
1732
1733 /* Remove the entry and decrement the global counter */
1734 RemoveEntryList(&DphRoot->NextHeap);
1736
1737 /* Release the global heap list lock */
1739
1740 /* Leave and delete this heap's critical section */
1743
1744 /* Now go through all virtual list nodes and release the VM */
1745 Node = DphRoot->pVirtualStorageListHead;
1746 while (Node)
1747 {
1748 Next = Node->pNextAlloc;
1749 /* Release the memory without checking result */
1750 RtlpDphFreeVm(Node->pVirtualBlock, 0, MEM_RELEASE);
1751 Node = Next;
1752 }
1753
1754 /* Destroy the normal heap */
1755 RtlDestroyHeap(NormalHeap);
1756
1757 /* Report success */
1759 DPRINT1("Page heap: process 0x%p destroyed heap @ %p (%p)\n",
1760 NtCurrentTeb()->ClientId.UniqueProcess, HeapPtr, NormalHeap);
1761
1762 return NULL;
1763}
NTSTATUS NTAPI RtlDeleteHeapLock(IN OUT PHEAP_LOCK Lock)
Definition: libsupp.c:103
union node Node
Definition: types.h:1255
NTSTATUS NTAPI RtlpDphFreeVm(PVOID Base, SIZE_T Size, ULONG Type)
Definition: heappage.c:385
VOID NTAPI RtlpDphPreProcessing(PDPH_HEAP_ROOT DphRoot, ULONG Flags)
Definition: heappage.c:301
VOID NTAPI AVrfInternalHeapFreeNotification(PVOID AllocationBase, SIZE_T AllocationSize)
Definition: verifier.c:364
#define DPH_EXTRA_CHECK_UNDERRUN
Definition: heappage.c:152
PVOID NTAPI RtlpDphPointerFromHandle(PVOID Handle)
Definition: heappage.c:227
BOOLEAN NTAPI RtlpDphIsPageHeapBlock(PDPH_HEAP_ROOT DphRoot, PVOID Block, PULONG ValidationInformation, BOOLEAN CheckFillers)
Definition: heappage.c:1421
VOID NTAPI RtlpDphFreeDelayedBlocksFromHeap(PDPH_HEAP_ROOT DphRoot, PHEAP NormalHeap)
Definition: heappage.c:1258
VOID NTAPI RtlpDphReportCorruptedBlock(_In_ PDPH_HEAP_ROOT DphRoot, _In_ ULONG Reserved, _In_ PVOID Block, _In_ ULONG ValidationInfo)
Definition: heappage.c:1330
NTSYSAPI PVOID NTAPI RtlDestroyHeap(IN PVOID HeapHandle)
#define MEM_RELEASE
Definition: nt_native.h:1316
PDPH_HEAP_BLOCK pVirtualStorageListHead
Definition: heappage.c:69
Definition: dlist.c:348
#define VERIFIER_STOP(Code, Msg, Val1, Desc1, Val2, Desc2, Val3, Desc3, Val4, Desc4)
Definition: verifier.h:171
#define APPLICATION_VERIFIER_DESTROY_PROCESS_HEAP
Definition: verifier.h:102
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
_Must_inspect_result_ NTSYSAPI PVOID NTAPI RtlEnumerateGenericTableAvl(_In_ PRTL_AVL_TABLE Table, _In_ BOOLEAN Restart)

Referenced by AVrfpDebugPageHeapDestroy(), and RtlDestroyHeap().

Variable Documentation

◆ AVrfpDebug

◆ AVrfpInitialized

◆ AVrfpVerifierDllsString

WCHAR AVrfpVerifierDllsString[256] = { 0 }

Definition at line 22 of file verifier.c.

Referenced by AVrfInitializeVerifier(), and AVrfReadIFEO().

◆ AVrfpVerifierFlags

ULONG AVrfpVerifierFlags = 0

Definition at line 21 of file verifier.c.

Referenced by AVrfInitializeVerifier(), AVrfpLoadAndInitializeProvider(), and AVrfReadIFEO().

◆ AVrfpVerifierLock

◆ AVrfpVerifierProvidersList

◆ LdrpImageEntry