| 1 | /* $Id: QueryMemStat.c 1276 2004-02-20 22:08:31Z bird $ */
|
|---|
| 2 | /** @file
|
|---|
| 3 | * DosQueryMemState() exploration.
|
|---|
| 4 | * Based on toolkit example (addendum.inf).
|
|---|
| 5 | */
|
|---|
| 6 |
|
|---|
| 7 | /*******************************************************************************
|
|---|
| 8 | * Header Files *
|
|---|
| 9 | *******************************************************************************/
|
|---|
| 10 | #include <os2.h>
|
|---|
| 11 | #include <stdio.h>
|
|---|
| 12 | #include <string.h>
|
|---|
| 13 | #include <stdlib.h>
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 | int main(int argc, char *argv[], char *envp[])
|
|---|
| 17 | {
|
|---|
| 18 | APIRET rc=0;
|
|---|
| 19 | PVOID pvMem;
|
|---|
| 20 | ULONG onepage = 0x1000;
|
|---|
| 21 |
|
|---|
| 22 | if (argc < 3)
|
|---|
| 23 | {
|
|---|
| 24 | printf("Syntax MEMSTATE <address> <cbMem>\n");
|
|---|
| 25 | return 0;
|
|---|
| 26 | }
|
|---|
| 27 | else
|
|---|
| 28 | {
|
|---|
| 29 | PVOID pvMem = (PVOID) strtoul(argv[1], NULL, 0);
|
|---|
| 30 | ULONG cbMem = strtoul(argv[2], NULL, 0);
|
|---|
| 31 | ULONG cPages = (cbMem+0x0fff) >> 12;
|
|---|
| 32 |
|
|---|
| 33 | printf(" address state\n");
|
|---|
| 34 | while (cPages > 0)
|
|---|
| 35 | {
|
|---|
| 36 | ULONG cbQuery = argc == 4 ? 0x1000 : cPages * 0x1000;
|
|---|
| 37 | ULONG fulFlags = 0xffffffff;
|
|---|
| 38 | rc = DosQueryMemState(pvMem, &cbQuery, &fulFlags);
|
|---|
| 39 | if (rc)
|
|---|
| 40 | printf("*0x%08x DosQueryMemState returned %lu\n", pvMem, rc);
|
|---|
| 41 | else
|
|---|
| 42 | {
|
|---|
| 43 | ULONG i;
|
|---|
| 44 | for (i = 0; i < cbQuery; i += 0x1000)
|
|---|
| 45 | {
|
|---|
| 46 | const char *psz1, *psz2;
|
|---|
| 47 | switch (fulFlags & PAG_PRESMASK)
|
|---|
| 48 | {
|
|---|
| 49 | case PAG_NPOUT: psz1 = "not present, not in-core,"; break;
|
|---|
| 50 | case PAG_NPIN: psz1 = "not present, in-core,"; break;
|
|---|
| 51 | case PAG_PRESENT: psz1 = "present, in-core,"; break;
|
|---|
| 52 | default: psz1 = "huh?"; break;
|
|---|
| 53 | }
|
|---|
| 54 | switch (fulFlags & PAG_TYPEMASK)
|
|---|
| 55 | {
|
|---|
| 56 | case PAG_INVALID: psz2 = "invalid"; break;
|
|---|
| 57 | case PAG_RESIDENT: psz2 = "resident"; break;
|
|---|
| 58 | case PAG_SWAPPABLE: psz2 = "swappable"; break;
|
|---|
| 59 | case PAG_DISCARDABLE: psz2 = "discardable"; break;
|
|---|
| 60 | }
|
|---|
| 61 | printf("%s0x%08x 0x%08x %s %s\n", i ? " " : "*", pvMem + i, fulFlags, psz1, psz2);
|
|---|
| 62 | }
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | cPages -= cbQuery / 0x1000;
|
|---|
| 66 | pvMem = (PVOID)((ULONG)pvMem + 0x1000);
|
|---|
| 67 | }
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | return rc;
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|