Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

A Resource Monitor for NT 4.0


February 1999/A Resource Monitor for NT 4.0/Listing 2

Listing 2: getstats.c — Implementation of object statistics functions

// getstats.c -- wrappers for win32k.sys services

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "getstats.h"

#define STATUS_INVALID_PARAMETER         (0xC000000DL)

static int      gUserServiceNumber;
static int      gGdiServiceNumber;

void _NtUserGetStats(DWORD pid, DWORD flags, void *objCount,
                int maxEntries);
void _NtGdiGetStats(DWORD pid, DWORD reserved, DWORD flags,
                void *objCount, int sizeInBytes);


BOOL UserGetStats(DWORD pid, DWORD flags, DWORD objCount[],
                int maxEntries)
{
    HMODULE hModule;
    BYTE    *address;
    DWORD   ntStatus;
    int     number;

    //
    // Find the service number for kernel-mode NtUserGetStats()
    // by adding 1 to service number for GetProcessWindowStation().
    //
    if (gUserServiceNumber == 0) {
        gUserServiceNumber = -1;
        hModule = GetModuleHandle("USER32");
        if (IsNT4() && hModule != NULL) {
            address = (BYTE *) GetProcAddress(hModule, \
                                    "GetProcessWindowStation");
            if (address != NULL) {
                address += 1;   /* skip 'mov' opcode */
                number = *((DWORD *) address) + 1;
                if (number >= 0x1000 && number < 0x1500)
                    gUserServiceNumber = number;
            }
        }
    }

    ntStatus = 0;
    if (gUserServiceNumber > 0) {
        memset(objCount, 0, sizeof(DWORD) * maxEntries);
        _NtUserGetStats(pid, flags, objCount, maxEntries);
        __asm mov ntStatus, eax
    } else
        ntStatus = STATUS_INVALID_PARAMETER;

    return((ntStatus == 0) ? TRUE : FALSE);
}

void __declspec(naked) _NtUserGetStats(DWORD pid, DWORD flags,
                void *objCount, int maxEntries)
{
    __asm   mov eax, gUserServiceNumber
    __asm   lea edx, [esp+4]
    __asm   int 0x2e
    __asm   ret
}

BOOL GdiGetStats(DWORD pid, DWORD flags, DWORD objCount[],
                int maxEntries)
{
    HMODULE hModule;
    BYTE    *address;
    DWORD   ntStatus;
    int     number;

    //
    // Find the service number for kernel-mode NtGdiGetStats()
    // by adding 1 to service number for GdiGetSpoolMessage().
    //
    if (gGdiServiceNumber == 0) {
        gGdiServiceNumber = -1;
        hModule = GetModuleHandle("GDI32");
        if (IsNT4() && hModule != NULL) {
            address = (BYTE *) GetProcAddress(hModule, \
                                    "GdiGetSpoolMessage");
            if (address != NULL) {
                address += 1;   /* skip 'mov' opcode */
                number = *((DWORD *) address) + 1;
                if (number >= 0x1000 && number < 0x1500)
                    gGdiServiceNumber = number;
            }
        }
    }

    ntStatus = 0;
    if (gGdiServiceNumber > 0) {
        memset(objCount, 0, sizeof(DWORD) * maxEntries);
        _NtGdiGetStats(pid, 0L, flags, objCount, \
                        sizeof(DWORD) * maxEntries);
        __asm mov ntStatus, eax
    } else
        ntStatus = STATUS_INVALID_PARAMETER;

    return((ntStatus == 0) ? TRUE : FALSE);
}

void __declspec(naked) _NtGdiGetStats(DWORD pid, DWORD reserved,
                DWORD flags, void *objCount, int sizeInBytes)
{
    __asm   mov eax, gGdiServiceNumber
    __asm   lea edx, [esp+4]
    __asm   int 0x2e
    __asm   ret
}

BOOL IsNT4(void)
{
    OSVERSIONINFO   osvi;

    osvi.dwOSVersionInfoSize = sizeof(osvi);
    if (GetVersionEx(&osvi)) {
        if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
            if (osvi.dwMajorVersion == 4)
                return(TRUE);
    }

    return(FALSE);
}
//End of File

Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.