home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / xwphescr.zip / XWPH0208.ZIP / include / helpers / procstat.h < prev    next >
C/C++ Source or Header  |  2002-04-17  |  32KB  |  836 lines

  1.  
  2. /*
  3.  *@@sourcefile procstat.h:
  4.  *      header file for procstat.c (querying process information).
  5.  *      See remarks there.
  6.  *
  7.  *      Note: Version numbering in this file relates to XWorkplace version
  8.  *            numbering.
  9.  *
  10.  *@@include #include <os2.h>
  11.  *@@include #include "helpers\procstat.h"
  12.  */
  13.  
  14. /*
  15.  *      This file Copyright (C) 1992-99 Ulrich Möller,
  16.  *                                      Kai Uwe Rommel.
  17.  *      This file is part of the "XWorkplace helpers" source package.
  18.  *      This is free software; you can redistribute it and/or modify
  19.  *      it under the terms of the GNU General Public License as published
  20.  *      by the Free Software Foundation, in version 2 as it comes in the
  21.  *      "COPYING" file of the XWorkplace main distribution.
  22.  *      This program is distributed in the hope that it will be useful,
  23.  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
  24.  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  25.  *      GNU General Public License for more details.
  26.  */
  27.  
  28. #if __cplusplus
  29. extern "C" {
  30. #endif
  31.  
  32. #ifndef PROCSTAT_HEADER_INCLUDED
  33.     #define PROCSTAT_HEADER_INCLUDED
  34.  
  35.     #pragma pack(1)
  36.  
  37.     /********************************************************************
  38.      *
  39.      *   DosQProcStatus declarations (16-bit)
  40.      *
  41.      ********************************************************************/
  42.  
  43.     #define PTR(ptr, ofs)  ((void *) ((char *) (ptr) + (ofs)))
  44.  
  45.     /* DosQProcStatus() = DOSCALLS.154 */
  46.     USHORT APIENTRY16 DosQProcStatus(PVOID pBuf, USHORT cbBuf);
  47.     /* DosGetPrty = DOSCALLS.9 */
  48.     USHORT APIENTRY16 DosGetPrty(USHORT usScope, PUSHORT pusPriority, USHORT pid);
  49.  
  50.     /*
  51.      *@@ QPROCSTAT16:
  52.      *      "header" structure returned by DosQProcStat,
  53.      *      containing the offsets to the other data
  54.      */
  55.  
  56.     typedef struct _QPROCSTAT16
  57.     {
  58.         ULONG  ulGlobal;        // offset to global data section (QGLOBAL16)
  59.         ULONG  ulProcesses;     // offset to process data section (QPROCESS16)
  60.         ULONG  ulSemaphores;    // offset to semaphore data section
  61.         ULONG  ulUnknown1;
  62.         ULONG  ulSharedMem;     // offset to shared mem data section
  63.         ULONG  ulModules;       // offset to DLL data section (QMODULE16)
  64.         ULONG  ulUnknown2;
  65.         ULONG  ulUnknown3;
  66.     } QPROCSTAT16, *PQPROCSTAT16;
  67.  
  68.     /*
  69.      *@@ QGLOBAL16:
  70.      *      at offset QPROCSTAT.ulGlobal, contains
  71.      *      global system information (no. of threads)
  72.      */
  73.  
  74.     typedef struct _QGLOBAL16
  75.     {
  76.         ULONG  ulThreads;       // total number of threads;
  77.         ULONG  ulReserved1,
  78.                ulReserved2;
  79.     } QGLOBAL16, *PQGLOBAL16;
  80.  
  81.     /*
  82.      *@@ QPROCESS16:
  83.      *      DosQProcStat structure for process info
  84.      */
  85.  
  86.     typedef struct _QPROCESS16
  87.     {
  88.         ULONG  ulType;          // 1 for processes
  89.         ULONG  ulThreadList;    // ofs to array of QTHREAD16 structs
  90.         USHORT usPID;
  91.         USHORT usParentPID;
  92.         ULONG  ulSessionType;
  93.                 // according to bsedos.h, the PROG_* types are identical
  94.                 // to the SSF_TYPE_* types, so we have:
  95.                 // -- PROG_DEFAULT              0
  96.                 // -- PROG_FULLSCREEN           1
  97.                 // -- PROG_WINDOWABLEVIO        2
  98.                 // -- PROG_PM                   3
  99.                 // -- PROG_GROUP                5
  100.                 // -- PROG_REAL                 4
  101.                 // -- PROG_VDM                  4
  102.                 // -- PROG_WINDOWEDVDM          7
  103.                 // -- PROG_DLL                  6
  104.                 // -- PROG_PDD                  8
  105.                 // -- PROG_VDD                  9
  106.                 // -- PROG_WINDOW_REAL          10
  107.                 // -- PROG_WINDOW_PROT          11
  108.                 // -- PROG_30_STD               11
  109.                 // -- PROG_WINDOW_AUTO          12
  110.                 // -- PROG_SEAMLESSVDM          13
  111.                 // -- PROG_30_STDSEAMLESSVDM    13
  112.                 // -- PROG_SEAMLESSCOMMON       14
  113.                 // -- PROG_30_STDSEAMLESSCOMMON 14
  114.                 // -- PROG_31_STDSEAMLESSVDM    15
  115.                 // -- PROG_31_STDSEAMLESSCOMMON 16
  116.                 // -- PROG_31_ENHSEAMLESSVDM    17
  117.                 // -- PROG_31_ENHSEAMLESSCOMMON 18
  118.                 // -- PROG_31_ENH               19
  119.                 // -- PROG_31_STD               20
  120.                 // -- PROG_RESERVED             255
  121.         ULONG  ulStatus;        // see status #define's below
  122.         ULONG  ulSID;           // session (screen group) ID
  123.         USHORT usHModule;       // program module handle for process
  124.         USHORT usThreads;       // # of TCBs in use in process
  125.         ULONG  ulReserved1;
  126.         ULONG  ulReserved2;
  127.         USHORT usSemaphores;    // # of 16-bit semaphores
  128.         USHORT usDLLs;          // # of linked DLLs
  129.         USHORT usSharedMems;
  130.         USHORT usReserved3;
  131.         ULONG  ulSemList;       // offset to semaphore list
  132.         ULONG  ulDLLList;       // offset to DLL list
  133.         ULONG  ulSharedMemList; // offset to shared mem list
  134.         ULONG  ulReserved4;
  135.     } QPROCESS16, *PQPROCESS16;
  136.  
  137.     // process status flags
  138.     #define STAT_EXITLIST 0x01  // processing exit list
  139.     #define STAT_EXIT1    0x02  // exiting thread 1
  140.     #define STAT_EXITALL  0x04  // whole process is exiting
  141.     #define STAT_PARSTAT  0x10  // parent cares about termination
  142.     #define STAT_SYNCH    0x20  // parent did exec-and-wait
  143.     #define STAT_DYING    0x40  // process is dying
  144.     #define STAT_EMBRYO   0x80  // process is in emryonic state
  145.  
  146.     /*
  147.      *@@ QTHREAD16:
  148.      *      DosQProcStat structure for thread info
  149.      */
  150.  
  151.     typedef struct _QTHREAD16
  152.     {
  153.         ULONG  ulType;          // 0x100 for thread records
  154.         USHORT usTID;           // thread ID
  155.         USHORT usThreadSlotID;  // ???
  156.         ULONG  ulBlockID;       // sleep id thread is sleeping on
  157.         ULONG  ulPriority;
  158.         ULONG  ulSysTime;
  159.         ULONG  ulUserTime;
  160.         UCHAR  ucStatus;        // TSTAT_* flags
  161.         UCHAR  ucReserved1;
  162.         USHORT usReserved2;
  163.     } QTHREAD16, *PQTHREAD16;
  164.  
  165.     // thread status flags
  166.     #define TSTAT_VOID          0   // uninitialized
  167.     #define TSTAT_READY         1   // ready to run (waiting for CPU time)
  168.     #define TSTAT_BLOCKED       2   // blocked on a block ID
  169.     #define TSTAT_SUSPENDED     3   // DosSuspendThread
  170.     #define TSTAT_CRITSEC       4   // blocked by another thread in a critical section
  171.     #define TSTAT_RUNNING       5   // currently running
  172.     #define TSTAT_READYBOOST    6   // ready, but apply I/O boost
  173.     #define TSTAT_TSD           7   // thead waiting for thread swappable data (TSD)
  174.     #define TSTAT_DELAYED       8   // delayed TKWakeup (almost ready)
  175.     #define TSTAT_FROZEN        9   // frozen (FF_ICE)
  176.     #define TSTAT_GETSTACK     10   // incoming thread swappable data (TSD)
  177.     #define TSTAT_BADSTACK     11   // TSD failed to swap in
  178.  
  179.     /*
  180.      *@@ QMODULE16:
  181.      *      DosQProcStat structure for module info
  182.      */
  183.  
  184.     typedef struct _QMODULE16
  185.     {
  186.         ULONG  nextmodule;
  187.         USHORT modhandle;
  188.         USHORT modtype;
  189.         ULONG  submodules;
  190.         ULONG  segments;
  191.         ULONG  reserved;
  192.         ULONG  namepointer;
  193.         USHORT submodule[1];      // varying, see member submodules */
  194.     } QMODULE16, *PQMODULE16;
  195.  
  196.     /*
  197.      *@@ QSEMAPHORE16:
  198.      *      DosQProcStat structure for semaphore info (16-bit only, I guess)
  199.      */
  200.  
  201.     typedef struct _QSEMAPHORE16
  202.     {
  203.         ULONG  nextsem;
  204.         USHORT owner;
  205.         UCHAR  flag;
  206.         UCHAR  refs;
  207.         UCHAR  requests;
  208.         UCHAR  reserved1;
  209.         USHORT reserved2;
  210.         USHORT index;
  211.         USHORT dummy;
  212.         UCHAR  name[1];       /* varying */
  213.     } QSEMAPHORE16, *PQSEMAPHORE16;
  214.  
  215.     /*
  216.      *@@ QSHAREDMEM16:
  217.      *      DosQProcStat structure for shared memory info
  218.      */
  219.  
  220.     typedef struct _QSHAREDMEM16
  221.     {
  222.         ULONG  nextseg;
  223.         USHORT handle;            // handle for shared memory
  224.         USHORT selector;          // shared memory selector
  225.         USHORT refs;              // reference count
  226.         UCHAR  name[1];           // varying
  227.     } QSHAREDMEM16, *PQSHAREDMEM16;
  228.  
  229.     /********************************************************************
  230.      *
  231.      *   DosQuerySysState declarations (32-bit)
  232.      *
  233.      ********************************************************************/
  234.  
  235.     // #pragma pack(1)
  236.     #pragma pack(4)         // V0.9.10 (2001-04-08) [umoeller]
  237.  
  238.     #define QS32_PROCESS      0x0001
  239.     #define QS32_SEMAPHORE    0x0002
  240.     #define QS32_MTE          0x0004
  241.     #define QS32_FILESYS      0x0008
  242.     #define QS32_SHMEMORY     0x0010
  243.     #define QS32_DISK         0x0020
  244.     #define QS32_HWCONFIG     0x0040
  245.     #define QS32_NAMEDPIPE    0x0080
  246.     #define QS32_THREAD       0x0100
  247.     #define QS32_MODVER       0x0200
  248.  
  249. /*
  250.     #define QS32_SUPPORTED    (QS32_PROCESS | QS32_SEMAPHORE | QS32_MTE | QS32_FILESYS \
  251.                                | QS32_SHMEMORY | QS32_MODVER)
  252.     QS32_SEMAPHORE is broken V0.9.19 (2002-04-14) [pr]
  253. */
  254.     #define QS32_SUPPORTED    (QS32_PROCESS | QS32_MTE | QS32_FILESYS \
  255.                                | QS32_SHMEMORY | QS32_MODVER)
  256.  
  257.     APIRET  APIENTRY DosQuerySysState(ULONG EntityList,
  258.                                       ULONG EntityLevel,
  259.                                       PID pid,
  260.                                       TID tid,
  261.                                       PVOID pDataBuf,
  262.                                       ULONG cbBuf);
  263.  
  264.     /**********************
  265.      *
  266.      *  global struct
  267.      *
  268.      **********************/
  269.  
  270.     /*
  271.      *@@ QGLOBAL32:
  272.      *      Pointed to by QTOPLEVEL32.
  273.      */
  274.  
  275.     typedef struct _QGLOBAL32
  276.     {
  277.         ULONG   ulThreadCount;  // thread count
  278.         ULONG   ulProcCount;    // process count
  279.         ULONG   ulModuleCount;  // module count
  280.     } QGLOBAL32, *PQGLOBAL32;
  281.  
  282.     /**********************
  283.      *
  284.      *  thread struct
  285.      *
  286.      **********************/
  287.  
  288.     /*
  289.      *@@ QTHREAD32:
  290.      *      Pointed to by QPROCESS32.
  291.      */
  292.  
  293.     typedef struct _QTHREAD32
  294.     {
  295.         ULONG   ulRecType;        // 256 for thread
  296.         USHORT  usTID;          // thread ID, process-specific
  297.         USHORT  usSlotID;       // system-specific slot ID, this identifies the
  298.                                 // thread to the kernel
  299.         ULONG   ulSleepID;      // sleep ID the kernel uses for blocking threads
  300.         ULONG   ulPriority;     // priority flags
  301.         ULONG   ulSystime;      // CPU time spent in system code
  302.         ULONG   ulUsertime;     // CPU time spent in user code
  303.         UCHAR   ucState;        // one of the following:
  304.                     // -- TSTAT_READY   1
  305.                     // -- TSTAT_BLOCKED 2
  306.                     // -- TSTAT_RUNNING 5
  307.                     // -- TSTAT_LOADED  9
  308.         UCHAR   _reserved1_;    /* padding to ULONG */
  309.         USHORT  _reserved2_;    /* padding to ULONG */
  310.     } QTHREAD32, *PQTHREAD32;
  311.  
  312.     /**********************
  313.      *
  314.      *  open files
  315.      *
  316.      **********************/
  317.  
  318.     // found the following in the "OS/2 Debugging handbook"
  319.     // (the identifiers are not official, but invented by
  320.     // me; V0.9.1 (2000-02-12) [umoeller]):
  321.     // these are the flags for QFDS32.flFlags
  322.     #define FSF_CONSOLEINPUT            0x0001      // bit 0
  323.     #define FSF_CONSOLEOUTPUT           0x0002      // bit 1
  324.     #define FSF_NULLDEVICE              0x0004      // bit 2
  325.     #define FSF_CLOCKDEVICE             0x0008      // bit 3
  326.     // #define FSF_UNUSED1                 0x0010      // bit 4
  327.     #define FSF_RAWMODE                 0x0020      // bit 5
  328.     #define FSF_DEVICEIDNOTDIRTY        0x0040      // bit 6
  329.     #define FSF_LOCALDEVICE             0x0080      // bit 7
  330.     #define FSF_NO_SFT_HANDLE_ALLOCTD   0x0100      // bit 8
  331.     #define FSF_THREAD_BLOCKED_ON_SF    0x0200      // bit 9
  332.     #define FSF_THREAD_BUSY_ON_SF       0x0400      // bit 10
  333.     #define FSF_NAMED_PIPE              0x0800      // bit 11
  334.     #define FSF_SFT_USES_FCB            0x1000      // bit 12
  335.     #define FSF_IS_PIPE                 0x2000      // bit 13;
  336.                 // then bit 11 determines whether this pipe is named or unnamed
  337.     // #define FSF_UNUSED2                 0x4000      // bit 14
  338.     #define FSF_REMOTE_FILE             0x8000      // bit 15
  339.                 // otherwise local file or device
  340.  
  341.     /*
  342.      *@@ QFDS32:
  343.      *      open file entry.
  344.      *      Pointed to by QFILEDATA32.
  345.      */
  346.  
  347.     typedef struct _QFDS32
  348.     {
  349.         USHORT  usSFN;              // "system file number" of the file.
  350.                                     // This is the same as in
  351.                                     // the QPROCESS32.pausFds array,
  352.                                     // so we can identify files opened
  353.                                     // by a process. File handles returned
  354.                                     // by DosOpen ("job file numbers", JFN's)
  355.                                     // are mapped to SFN's for each process
  356.                                     // individually.
  357.         USHORT  usRefCount;
  358.         ULONG   flFlags;            // FSF_* flags above
  359.         ULONG   flAccess;           // fsOpenMode flags of DosOpen:
  360.               /* #define OPEN_ACCESS_READONLY               0x0000
  361.                  #define OPEN_ACCESS_WRITEONLY              0x0001
  362.                  #define OPEN_ACCESS_READWRITE              0x0002
  363.                  #define OPEN_SHARE_DENYREADWRITE           0x0010
  364.                  #define OPEN_SHARE_DENYWRITE               0x0020
  365.                  #define OPEN_SHARE_DENYREAD                0x0030
  366.                  #define OPEN_SHARE_DENYNONE                0x0040
  367.                  #define OPEN_FLAGS_NOINHERIT               0x0080
  368.                  #define OPEN_FLAGS_NO_LOCALITY             0x0000
  369.                  #define OPEN_FLAGS_SEQUENTIAL              0x0100
  370.                  #define OPEN_FLAGS_RANDOM                  0x0200
  371.                  #define OPEN_FLAGS_RANDOMSEQUENTIAL        0x0300
  372.                  #define OPEN_FLAGS_NO_CACHE                0x1000
  373.                  #define OPEN_FLAGS_FAIL_ON_ERROR           0x2000
  374.                  #define OPEN_FLAGS_WRITE_THROUGH           0x4000
  375.                  #define OPEN_FLAGS_DASD                    0x8000
  376.                  #define OPEN_FLAGS_NONSPOOLED          0x00040000
  377.                  #define OPEN_FLAGS_PROTECTED_HANDLE    0x40000000 */
  378.  
  379.         ULONG   ulFileSize;         // file size in bytes
  380.         USHORT  usHVolume;          // "volume handle"; apparently,
  381.                                     // this identifies some kernel
  382.                                     // structure, it's the same for
  383.                                     // files on the same disk
  384.         USHORT  fsAttribs;          // attributes:
  385.                                     // 0x20: 'A' (archived)
  386.                                     // 0x10: 'D' (directory)
  387.                                     // 0x08: 'L' (?!?)
  388.                                     // 0x04: 'S' (system)
  389.                                     // 0x02: 'H' (hidden)
  390.                                     // 0x01: 'R' (read-only)
  391.         USHORT  us_pad_;
  392.     } QFDS32, *PQFDS32;
  393.  
  394.     /*
  395.      *@@ QFILEDATA32:
  396.      *      open files linked-list item.
  397.      *
  398.      *      First item is pointed to by QTOPLEVEL32.
  399.      */
  400.  
  401.     typedef struct _QFILEDATA32
  402.     {
  403.         ULONG           ulRecType;          // 8 for file
  404.         struct _QFILEDATA32 *pNext;         // next record
  405.         ULONG           ulCFiles;           // no. of SFT entries for this MFT entry
  406.         PQFDS32         paFiles;            // first entry here
  407.         char            szFilename[1];
  408.     } QFILEDATA32, *PQFILEDATA32;
  409.  
  410.     /**********************
  411.      *
  412.      *  process struct
  413.      *
  414.      **********************/
  415.  
  416.     /*
  417.      *@@ QPROCESS32:
  418.      *      process description structure.
  419.      *
  420.      *      Pointed to by QTOPLEVEL32.
  421.      *
  422.      *      Following this structure is an array
  423.      *      of ulPrivSem32Count 32-bit semaphore
  424.      *      descriptions.
  425.      */
  426.  
  427.     typedef struct _QPROCESS32
  428.     {
  429.         ULONG       ulRecType;      // 1 for process
  430.         PQTHREAD32  pThreads;       // thread data array,
  431.                                     // apperently with usThreadCount items
  432.         USHORT      usPID;          // process ID
  433.         USHORT      usPPID;         // parent process ID
  434.         ULONG       ulProgType;
  435.                 // -- 0: Full screen protected mode.
  436.                 // -- 1: Real mode (probably DOS or Windoze).
  437.                 // -- 2: VIO windowable protected mode.
  438.                 // -- 3: Presentation manager protected mode.
  439.                 // -- 4: Detached protected mode.
  440.         ULONG       ulState;    // one of the following:
  441.                 // -- STAT_EXITLIST 0x01
  442.                 // -- STAT_EXIT1    0x02
  443.                 // -- STAT_EXITALL  0x04
  444.                 // -- STAT_PARSTAT  0x10
  445.                 // -- STAT_SYNCH    0x20
  446.                 // -- STAT_DYING    0x40
  447.                 // -- STAT_EMBRYO   0x80
  448.         ULONG       ulScreenGroupID; // screen group ID
  449.         USHORT      usHModule;      // module handle of main executable
  450.         USHORT      usThreadCount;  // no. of threads (TCB's in use)
  451.         ULONG       ulPrivSem32Count;  // count of 32-bit semaphores
  452.         PVOID       pvPrivSem32s;   // ptr to 32-bit sems array
  453.         USHORT      usSem16Count;   // count of 16-bit semaphores in pausSem16 array
  454.         USHORT      usModuleCount;  // count of DLLs owned by this process
  455.         USHORT      usShrMemCount;  // count of shared memory handles
  456.         USHORT      usFdsCount;     // count of open files; this is mostly way too large
  457.         PUSHORT     pausSem16;      // ptr to array of 16-bit semaphore handles;
  458.                                     // has usSem16Count items
  459.         PUSHORT     pausModules;    // ptr to array of modules (MTE);
  460.                                     // has usModuleCount items
  461.         PUSHORT     pausShrMems;    // ptr to array of shared mem handles;
  462.                                     // has usShrMemCount items
  463.         PUSHORT     pausFds;        // ptr to array of file handles;
  464.                                     // many of these are pseudo-file handles, but
  465.                                     // will be the same as the QFDS32.sfn field,
  466.                                     // so open files can be identified.
  467.     } QPROCESS32, *PQPROCESS32;
  468.  
  469.     /**********************
  470.      *
  471.      *  16-bit semaphores
  472.      *
  473.      **********************/
  474.  
  475.     // SysSemFlag values
  476.  
  477.     #define QS32_SYSSEM_WAITING 0x01               /* a thread is waiting on the sem */
  478.     #define QS32_SYSSEM_MUXWAITING 0x02            /* a thread is muxwaiting on the sem */
  479.     #define QS32_SYSSEM_OWNER_DIED 0x04            /* the process/thread owning the sem died */
  480.     #define QS32_SYSSEM_EXCLUSIVE 0x08             /* indicates a exclusive system semaphore */
  481.     #define QS32_SYSSEM_NAME_CLEANUP 0x10          /* name table entry needs to be removed */
  482.     #define QS32_SYSSEM_THREAD_OWNER_DIED 0x20     /* the thread owning the sem died */
  483.     #define QS32_SYSSEM_EXITLIST_OWNER 0x40        /* the exitlist thread owns the sem */
  484.  
  485.     /*
  486.      *@@ QS32SEM16:
  487.      *      16-bit semaphore description.
  488.      *
  489.      *@@added V0.9.10 (2001-04-08) [umoeller]
  490.      */
  491.  
  492.     typedef struct _QS32SEM16
  493.     {
  494.         struct _QS32SEM16 *pNext;
  495.         // ULONG         NextRec;        /* offset to next record in buffer */
  496.                                       /* System Semaphore Table Structure */
  497.         USHORT        usSysSemOwner;   /* thread owning this semaphore */
  498.         UCHAR         fsSysSemFlags;    /* system semaphore flag bit field */
  499.         UCHAR         usSysSemRefCnt ;  /* number of references to this sys sem */
  500.         UCHAR         usSysSemProcCnt ; /* number of requests for this owner */
  501.         UCHAR         usSysSemPad ;     /* pad byte to round structure up to word */
  502.         USHORT        pad_sh;
  503.         USHORT        SemPtr;         /* RMP SysSemPtr field */
  504.         char          szName[1];      /* start of semaphore name string */
  505.     } QS32SEM16, *PQS32SEM16;
  506.  
  507.     /*
  508.      *@@ QS32SEM16HEAD:
  509.      *
  510.      *@@added V0.9.10 (2001-04-08) [umoeller]
  511.      */
  512.  
  513.     typedef struct _QS32SEM16HEAD
  514.     {
  515.         ULONG         SRecType;       /* offset of SysSemDataTable */
  516.         ULONG         SpNextRec;      /* overlays NextRec of 1st QS32SEM16 */
  517.         ULONG         S32SemRec;
  518.         ULONG         S16TblOff;
  519.         // ULONG         pSem16Rec;
  520.         QS32SEM16     Sem16Rec;       // first record, with subsequent following
  521.     } QS32SEM16HEAD, *PQS32SEM16HEAD;
  522.  
  523.     /**********************
  524.      *
  525.      *  shared memory
  526.      *
  527.      **********************/
  528.  
  529.     /*
  530.      *@@ QSHRMEM32:
  531.      *      describes a shared memory block.
  532.      *
  533.      *      Pointed to by QTOPLEVEL32.
  534.      */
  535.  
  536.     typedef struct _QSHRMEM32
  537.     {
  538.         struct _QSHRMEM32 *pNext;
  539.         USHORT      usHandle;           // shared memory handle
  540.         USHORT      usSelector;         // selector
  541.         USHORT      usRefCount;         // reference count
  542.         CHAR        acName[1];          // shared memory name
  543.     } QSHRMEM32, *PQSHRMEM32;
  544.  
  545.     /**********************
  546.      *
  547.      *  32-bit semaphores
  548.      *
  549.      **********************/
  550.  
  551.     #define QS32_DC_SEM_SHARED   0x0001   //  Shared Mutex, Event or MUX semaphore
  552.     #define QS32_DCMW_WAIT_ANY   0x0002   //  Wait on any event/mutex to occur
  553.     #define QS32_DCMW_WAIT_ALL   0x0004   //  Wait on all events/mutexs to occur
  554.     #define QS32_DCM_MUTEX_SEM   0x0008   //  Mutex semaphore
  555.     #define QS32_DCE_EVENT_SEM   0x0010   //  Event semaphore
  556.     #define QS32_DCMW_MUX_SEM    0x0020   //  Muxwait semaphore
  557.     // #define QS32_DC_SEM_PM       0x0040   //  PM Shared Event Semphore
  558.     #define QS32_DE_POSTED       0x0040   //  event sem is in the posted state
  559.     #define QS32_DM_OWNER_DIED   0x0080   //  The owning process died
  560.     #define QS32_DMW_MTX_MUX     0x0100   //  MUX contains mutex sems
  561.     #define QS32_DHO_SEM_OPEN    0x0200   //  Device drivers have opened this semaphore
  562.     #define QS32_DE_16BIT_MW     0x0400   //  Part of a 16-bit MuxWait
  563.     #define QS32_DCE_POSTONE     0x0800   //  Post one flag event semaphore
  564.     #define QS32_DCE_AUTORESET   0x1000   //  Auto-reset event semaphore
  565.  
  566.     /*
  567.      *@@ QS32OPENQ:
  568.      *
  569.      *@@added V0.9.10 (2001-04-08) [umoeller]
  570.      */
  571.  
  572.     typedef struct _QS32OPENQ {    /* qsopenq */
  573.             PID           pidOpener;      /* process id of opening process */
  574.             USHORT        OpenCt;         /* number of opens for this process */
  575.     } QS32OPENQ, *PQS32OPENQ;
  576.  
  577.     /*
  578.      *@@ QS32EVENT:
  579.      *
  580.      *@@added V0.9.10 (2001-04-08) [umoeller]
  581.      */
  582.  
  583.     typedef struct _QS32EVENT {    /* qsevent */
  584.             QS32OPENQ     *pOpenQ;        /* pointer to open q entries */
  585.             UCHAR         *pName;         /* pointer to semaphore name */
  586.             ULONG         *pMuxQ;         /* pointer to the mux queue */
  587.             USHORT        flags;
  588.             USHORT        PostCt;         /* # of posts */
  589.     } QS32EVENT, *PQS32EVENT;
  590.  
  591.     /*
  592.      *@@ QS32MUTEX:
  593.      *
  594.      *@@added V0.9.10 (2001-04-08) [umoeller]
  595.      */
  596.  
  597.     typedef struct _QS32MUTEX {    /* qsmutex */
  598.             QS32OPENQ     *pOpenQ;        /* pointer to open q entries */
  599.             UCHAR         *pName;         /* pointer to semaphore name */
  600.             ULONG         *pMuxQ;         /* pointer to the mux queue */
  601.             USHORT        flags;
  602.             USHORT        ReqCt;          /* # of requests */
  603.             USHORT        SlotNum;        /* slot # of owning thread */
  604.             USHORT        pad_sh;
  605.     } QS32MUTEX, *PQS32MUTEX;
  606.  
  607.     /*
  608.      *@@ QS32MUX:
  609.      *
  610.      *@@added V0.9.10 (2001-04-08) [umoeller]
  611.      */
  612.  
  613.     typedef struct _QS32MUX {   /* qsmux */
  614.             QS32OPENQ       *pOpenQ;        /* pointer to open q entries */
  615.             UCHAR           *pName;         /* pointer to semaphore name */
  616.             void            *pSemRec;       /* array of semaphore record entries */
  617.             USHORT          flags;
  618.             USHORT          cSemRec;        /* count of semaphore records */
  619.             USHORT          WaitCt;         /* # threads waiting on the mux */
  620.             USHORT          pad_sh;
  621.     } QS32MUX, *PQS32MUX;
  622.  
  623.     /*
  624.      *@@ QS32SHUN:
  625.      *
  626.      *@@added V0.9.10 (2001-04-08) [umoeller]
  627.      */
  628.  
  629.     typedef union _QS32SHUN {  /* qsshun */
  630.             QS32EVENT       qsSEvt;         /* shared event sem */
  631.             QS32MUTEX       qsSMtx;         /* shared mutex sem */
  632.             QS32MUX         qsSMux;         /* shared mux sem */
  633.     } QS32SHUN, *PQS32SHUN;
  634.  
  635.     /*
  636.      *@@ QS32SEM32:
  637.      *
  638.      *@@added V0.9.10 (2001-04-08) [umoeller]
  639.      */
  640.  
  641.     typedef struct _QS32SEM32 {   /* qsS32rec */
  642.             void        *pNext;      /* pointer to next record in buffer */
  643.             ULONG       fl;         // semaphore flags; THIS FIELD IS MISSING
  644.                                     // IN THE ORIGINAL TOOLKIT DEFINITIONS...
  645.                                     // only with this field we can determine
  646.                                     // if this is a mutex, event, or muxwait
  647.             PSZ         pszName;        // or NULL if unnamed
  648.             ULONG       pvDeviceDriver; // ?!? points into kernel memory
  649.             USHORT      usPostCount;
  650.             USHORT      us_;
  651.             ULONG       ulBlockID;
  652.  
  653.             // can't make sense of the following fields... these
  654.             // seem to be variable in size
  655.             ULONG       ulHandle;
  656.             /* USHORT      usAlways1;
  657.             ULONG       ulElse;
  658.             ULONG       ulElse2; */
  659.     } QS32SEM32, *PQS32SEM32;           // qsS32rec_t;
  660.  
  661.     /**********************
  662.      *
  663.      *  modules
  664.      *
  665.      **********************/
  666.  
  667.     /*
  668.      *@@ QS32OBJ:
  669.      *      describes an object in a module.
  670.      *      Pointed to by QSMODULE32, but only
  671.      *      if QS32_MTE was set on query.
  672.      *
  673.      *@@added V0.9.10 (2001-04-08) [umoeller]
  674.      */
  675.  
  676.     typedef struct _QS32OBJ {
  677.             ULONG   oaddr;  /* object address */
  678.             ULONG   osize;  /* object size */
  679.             ULONG   oflags; /* object flags */
  680.     } QS32OBJ, *PQS32OBJ;
  681.  
  682.     /*
  683.      *@@ QMODULE32:
  684.      *      describes an executable module.
  685.      *
  686.      *      Pointed to by QTOPLEVEL32.
  687.      */
  688.  
  689.     typedef struct _QMODULE32
  690.     {
  691.         struct _QMODULE32 *pNext;       // next module
  692.         USHORT      usHModule;          // module handle (HMTE)
  693.         USHORT      fFlat;              // TRUE for 32-bit modules
  694.         ULONG       ulRefCount;         // no. of imports
  695.         ULONG       cObjects;           // no. of objects in module
  696.         PQS32OBJ    paObjects;          // ptr to objects list, if QS32_MTE was queried
  697.         PCHAR       pcName;             // module name (fully qualified)
  698.         USHORT      ausModRef[1];       // array of module "references";
  699.                                         // this has usRefCount items
  700.                                         // and holds other modules (imports)
  701.     } QMODULE32, *PQMODULE32;
  702.  
  703.     /**********************
  704.      *
  705.      *  top-level struct
  706.      *
  707.      **********************/
  708.  
  709.     /*
  710.      *@@ QTOPLEVEL32:
  711.      *      head of the buffer returned by
  712.      *      DosQuerySysState.
  713.      */
  714.  
  715.     typedef struct _QTOPLEVEL32
  716.     {
  717.         PQGLOBAL32      pGlobalData;
  718.         PQPROCESS32     pProcessData;
  719.         PQS32SEM16HEAD  pSem16Data;
  720.         PQS32SEM32      pSem32Data;     // not always present!
  721.         PQSHRMEM32      pShrMemData;
  722.         PQMODULE32      pModuleData;
  723.         PVOID           _reserved2_;
  724.         PQFILEDATA32    pFileData;      // only present in FP19 or later or W4
  725.     } QTOPLEVEL32, *PQTOPLEVEL32;
  726.  
  727.     /********************************************************************
  728.      *
  729.      *   New procstat.c declarations
  730.      *
  731.      ********************************************************************/
  732.  
  733.     /*
  734.      *@@ PRCPROCESS:
  735.      *      additional, more lucid structure
  736.      *      filled by prc16QueryProcessInfo.
  737.      */
  738.  
  739.     typedef struct _PRCPROCESS
  740.     {
  741.         CHAR   szModuleName[CCHMAXPATH];    // module name
  742.         USHORT usPID,                       // process ID
  743.                usParentPID,                 // parent process ID
  744.                usThreads;                   // thread count
  745.         ULONG  ulSID;                       // session ID
  746.         ULONG  ulSessionType;
  747.         ULONG  ulStatus;
  748.         ULONG  ulCPU;                       // CPU usage (sum of thread data)
  749.     } PRCPROCESS, *PPRCPROCESS;
  750.  
  751.     /*
  752.      *@@ PRCTHREAD:
  753.      *      additional, more lucid structure
  754.      *      filled by prc16QueryThreadInfo.
  755.      */
  756.  
  757.     typedef struct _PRCTHREAD
  758.     {
  759.         USHORT usTID;           // thread ID
  760.         USHORT usThreadSlotID;  // kernel thread slot ID
  761.         ULONG  ulBlockID;       // sleep id thread is sleeping on
  762.         ULONG  ulPriority;
  763.         ULONG  ulSysTime;
  764.         ULONG  ulUserTime;
  765.         UCHAR  ucStatus;        // see status #define's below
  766.     } PRCTHREAD, *PPRCTHREAD;
  767.  
  768.     #pragma pack()
  769.  
  770.     /********************************************************************
  771.      *
  772.      *   DosQProcStat (16-bit) interface
  773.      *
  774.      ********************************************************************/
  775.  
  776.     APIRET prc16GetInfo(PQPROCSTAT16 *ppps);
  777.  
  778.     APIRET prc16FreeInfo(PQPROCSTAT16 pInfo);
  779.  
  780.     PQPROCESS16 prc16FindProcessFromName(PQPROCSTAT16 pInfo,
  781.                                          const char *pcszName);
  782.  
  783.     PQPROCESS16 prc16FindProcessFromPID(PQPROCSTAT16 pInfo,
  784.                                         ULONG ulPID);
  785.  
  786.     /********************************************************************
  787.      *
  788.      *   DosQProcStat (16-bit) helpers
  789.      *
  790.      ********************************************************************/
  791.  
  792.     BOOL prc16QueryProcessInfo(PQPROCSTAT16 pps, USHORT usPID, PPRCPROCESS pprcp);
  793.  
  794.     ULONG prc16ForEachProcess(PFNWP pfnwpCallback, HWND hwnd, ULONG ulMsg, MPARAM mp1);
  795.  
  796.     ULONG prc16QueryThreadCount(PQPROCSTAT16 pps, USHORT usPID);
  797.  
  798.     BOOL prc16QueryThreadInfo(PQPROCSTAT16 pps, USHORT usPID, USHORT usTID, PPRCTHREAD pprct);
  799.  
  800.     ULONG prc16QueryThreadPriority(PQPROCSTAT16 pps, USHORT usPID, USHORT usTID);
  801.  
  802.     /********************************************************************
  803.      *
  804.      *   DosQuerySysState (32-bit) interface
  805.      *
  806.      ********************************************************************/
  807.  
  808.     PQTOPLEVEL32 prc32GetInfo(APIRET *parc);
  809.  
  810.     VOID prc32FreeInfo(PQTOPLEVEL32 pInfo);
  811.  
  812.     PQPROCESS32 prc32FindProcessFromName(PQTOPLEVEL32 pInfo,
  813.                                          const char *pcszName);
  814.  
  815.     PQS32SEM16 prc32FindSem16(PQTOPLEVEL32 pInfo,
  816.                               USHORT usSemID);
  817.  
  818.     PQS32SEM32 prc32FindSem32(PQTOPLEVEL32 pInfo,
  819.                               USHORT usSemID);
  820.  
  821.     PQSHRMEM32 prc32FindShrMem(PQTOPLEVEL32 pInfo,
  822.                                USHORT usShrMemID);
  823.  
  824.     PQMODULE32 prc32FindModule(PQTOPLEVEL32 pInfo,
  825.                                USHORT usHModule);
  826.  
  827.     PQFILEDATA32 prc32FindFileData(PQTOPLEVEL32 pInfo,
  828.                                    USHORT usFileID);
  829.  
  830. #endif
  831.  
  832. #if __cplusplus
  833. }
  834. #endif
  835.  
  836.