test: heaptag.c File Reference

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# heaptag.c File Reference

`#include <ntos.h>`
`#include "ldrp.h"`
`#include <stktrace.h>`
`#include <heap.h>`
`#include <stdio.h>`

Go to the source code of this file.

## Defines

#define | LDRP_MAXIMUM_DLL_TAGS 64
#define | DEFINE_HEAPTAG_ENTRY(n) PVOID LdrpTagAllocateHeap##n( PVOID h, ULONG f, ULONG s ) {return LdrpTagAllocateHeap( h, f, s, n ); }

## Typedefs

typedef PVOID(* | PLDRP_DLL_TAG_PROCEDURE )(PVOID HeapHandle, ULONG Flags, ULONG Size)

## Functions

PVOID | LdrpTagAllocateHeap (IN PVOID HeapHandle, IN ULONG Flags, IN ULONG Size, IN ULONG n)
| DEFINE_HEAPTAG_ENTRY (0)
| DEFINE_HEAPTAG_ENTRY (1)
| DEFINE_HEAPTAG_ENTRY (2)
| DEFINE_HEAPTAG_ENTRY (3)
| DEFINE_HEAPTAG_ENTRY (4)
| DEFINE_HEAPTAG_ENTRY (5)
| DEFINE_HEAPTAG_ENTRY (6)
| DEFINE_HEAPTAG_ENTRY (7)
| DEFINE_HEAPTAG_ENTRY (8)
| DEFINE_HEAPTAG_ENTRY (9)
PVOID | LdrpDefineDllTag (PWSTR TagName, PUSHORT TagIndex)

## Variables

BOOLEAN | LdrpDllTagsInitialized
ULONG | LdrpNumberOfDllTags
ULONG | LdrpBaseDllTag
ULONG | LdrpDllTags [LDRP_MAXIMUM_DLL_TAGS]
const PLDRP_DLL_TAG_PROCEDURE | LdrpDllTagProcedures [LDRP_MAXIMUM_DLL_TAGS]

## Define Documentation

#define DEFINE_HEAPTAG_ENTRY | ( | n |  | ) | PVOID LdrpTagAllocateHeap##n( PVOID h, ULONG f, ULONG s ) {return LdrpTagAllocateHeap( h, f, s, n ); }

| Definition at line 34 of file heaptag.c.

#define LDRP_MAXIMUM_DLL_TAGS 64

| Definition at line 27 of file heaptag.c. Referenced by LdrpDefineDllTag().

## Typedef Documentation

typedef PVOID(* PLDRP_DLL_TAG_PROCEDURE)(PVOID HeapHandle, ULONG Flags, ULONG Size)

| Definition at line 117 of file heaptag.c.

## Function Documentation

DEFINE_HEAPTAG_ENTRY | ( | 9 |  | ) |

DEFINE_HEAPTAG_ENTRY | ( | 8 |  | ) |

DEFINE_HEAPTAG_ENTRY | ( | 7 |  | ) |

DEFINE_HEAPTAG_ENTRY | ( | 6 |  | ) |

DEFINE_HEAPTAG_ENTRY | ( | 5 |  | ) |

DEFINE_HEAPTAG_ENTRY | ( | 4 |  | ) |

DEFINE_HEAPTAG_ENTRY | ( | 3 |  | ) |

DEFINE_HEAPTAG_ENTRY | ( | 2 |  | ) |

DEFINE_HEAPTAG_ENTRY | ( | 1 |  | ) |

DEFINE_HEAPTAG_ENTRY | ( | 0 |  | ) |

PVOID LdrpDefineDllTag | ( | PWSTR | TagName,
|  | PUSHORT | TagIndex
| ) |

Definition at line 191 of file heaptag.c.

References LDRP_MAXIMUM_DLL_TAGS, LdrpDllTagProcedures, LdrpDllTags, LdrpDllTagsInitialized, LdrpNumberOfDllTags, NULL, RtlAllocateHeap, RtlCreateTagHeap(), RtlpGlobalTagHeap, TRUE, USHORT, and _HEAP::VirtualAllocdBlocks.

Referenced by LdrpWalkImportDescriptor().

    00195 {
    00196     PVOID Result;
    00197     WCHAR TagNameBuffer[ 260 ];
    00198
    00199     if (RtlpGlobalTagHeap == NULL) {
    00200         RtlpGlobalTagHeap = RtlAllocateHeap( RtlProcessHeap( ), HEAP_ZERO_MEMORY, sizeof( HEAP ));
    00201         if (RtlpGlobalTagHeap == NULL) {
    00202             return NULL;
    00203         }
    00204     }
    00205
    00206     if (!LdrpDllTagsInitialized) {
    00207         //
    00208         // Keep QUERY.C happy
    00209         //
    00210         InitializeListHead( &RtlpGlobalTagHeap->VirtualAllocdBlocks );
    00211         LdrpDllTagsInitialized = TRUE;
    00212         }
    00213
    00214     Result = NULL;
    00215     if (LdrpNumberOfDllTags < LDRP_MAXIMUM_DLL_TAGS) {
    00216         memset( TagNameBuffer, 0, sizeof( TagNameBuffer ) );
    00217         wcscpy( TagNameBuffer, TagName );
    00218         LdrpDllTags[ LdrpNumberOfDllTags ] =
    00219             RtlCreateTagHeap( NULL,
    00220                               0,
    00221                               NULL,
    00222                               TagNameBuffer
    00223                             );
    00224
    00225         if (LdrpDllTags[ LdrpNumberOfDllTags ] != 0) {
    00226             Result = LdrpDllTagProcedures[ LdrpNumberOfDllTags ];
    00227             }
    00228
    00229         if (Result != NULL) {
    00230             *TagIndex = (USHORT)(LdrpDllTags[ LdrpNumberOfDllTags ] >> HEAP_TAG_SHIFT);
    00231             LdrpNumberOfDllTags += 1;
    00232             }
    00233         }
    00234
    00235     return Result;
    00236 }

PVOID LdrpTagAllocateHeap | ( | IN PVOID | HeapHandle,
|  | IN ULONG | Flags,
|  | IN ULONG | Size,
|  | IN ULONG | n
| ) |

Definition at line 38 of file heaptag.c.

References HeapHandle, LdrpDllTags, n, RtlAllocateHeap, and Size.

    00044 {
    00045     if ((Flags & HEAP_TAG_MASK) == 0) {
    00046         Flags |= LdrpDllTags[ n ];
    00047         }
    00048
    00049     return RtlAllocateHeap( HeapHandle, Flags, Size );
    00050 }

## Variable Documentation

ULONG LdrpBaseDllTag

| Definition at line 31 of file heaptag.c.

const PLDRP_DLL_TAG_PROCEDURE LdrpDllTagProcedures[LDRP_MAXIMUM_DLL_TAGS]

| Definition at line 123 of file heaptag.c. Referenced by LdrpDefineDllTag().

ULONG LdrpDllTags[LDRP_MAXIMUM_DLL_TAGS]

| Definition at line 32 of file heaptag.c. Referenced by LdrpDefineDllTag(), and LdrpTagAllocateHeap().

BOOLEAN LdrpDllTagsInitialized

| Definition at line 29 of file heaptag.c. Referenced by LdrpDefineDllTag().

ULONG LdrpNumberOfDllTags

| Definition at line 30 of file heaptag.c. Referenced by LdrpDefineDllTag().