
/*static char *SCCSID = "@(#)qsexport.h 6.2 90/12/10";*/
/*      SCCSID = "@(#)qsexport.h        6.2 90/12/10"       */

//
//         IBM/Microsoft Confidential
//
//         Copyright (c) IBM Corporation 1987, 1989
//         Copyright (c) Microsoft Corporation 1987, 1989
//
//         All Rights Reserved

/*
 *      QuerySystemState - Local Defines, Macros and Data Structures
 *
 *      This is an OS/2 2.x specific file
 *      (C) Copyright 1989 Microsoft Corp.
 *
 *      Created: July 1989
 *
 *                          MODIFICATIONS
 *---------------------------------------------------------------------
 * 12/14/95  ChangeTeam    Scott Garfinkle - Enabled QS_FILESYS for
 *                         QS_SUPPORTED - DosQueryProcStatus/DosQuerySysState
 *
 */


/* Constants */

/* Resource Type */
/*      These defines parallel the qsFunc[] array. Do not change the
 *      order without also changing qsFunc[] in qstate.c. For efficiency,
 *      the most commonly queried entities are placed first.
 */

/* XLATOFF */

#define QS_PROCESS      0x0001
#define QS_SEMAPHORE    0x0002
#define QS_MTE          0x0004
#define QS_FILESYS      0x0008
#define QS_SHMEMORY     0x0010
#define QS_DISK         0x0020
#define QS_HWCONFIG     0x0040
#define QS_NAMEDPIPE    0x0080
#define QS_THREAD       0x0100

/* Defect : 145345 Enabled QS_FILE processing */
/* #define QS_SUPPORTED    (QS_PROCESS|QS_SEMAPHORE|QS_MTE |QS_SHMEMORY) */
#define QS_SUPPORTED    (QS_PROCESS|QS_SEMAPHORE|QS_MTE |QS_FILESYS|QS_SHMEMORY)

/* All structures must be padded to dword boundaries if necessary */
#define PADSHORT        ushort_t        pad_sh;
#define PADCHAR         uchar_t         pad_ch;

/* XLATON */
#define QS_END          0L
#define REC_SEMAPHORE   3
/* XLATOFF */
#define CACHESIZE       4096    /** BUG BUG Increase to 16K + for release */

/* Function Declarations */

ulong_t qsCheckCache(ulong_t);
ulong_t qsReserveCache(uchar_t **, ulong_t);
ulong_t qsFlushCache(void);
void    qsFlushResCache(uchar_t *, uchar_t *, ulong_t);
void    qsUpdatePtrs(uchar_t *);

/* Global Record structure
 * Holds all global system information. Placed first in user buffer
 */
typedef struct qsGrec_s {
        ulong_t         cThrds;
        ulong_t         c32SSem;
        ulong_t         cMFTNodes;
}qsGrec_t;

/* Thread Record structure
 *      Holds all per thread information.
 */
typedef struct qsTrec_s {
        ulong_t         RecType;        /* Record Type */
        ushort_t        tid;            /* thread ID */
        ushort_t        slot;           /* "unique" thread slot number */
        ulong_t         sleepid;        /* sleep id thread is sleeping on */
        ulong_t         priority;       /* thread priority */
        ulong_t         systime;        /* thread system time */
        ulong_t         usertime;       /* thread user time */
        uchar_t         state;          /* thread state */
        PADCHAR
        PADSHORT
} qsTrec_t;

/* Process Record structure
 *      Holds all per process information.
 *      ________________________________
 *      |       RecType                 |
 *      |-------------------------------|
 *      |       pThrdRec                |----|
 *      |-------------------------------|    |
 *      |       pid                     |    |
 *      |-------------------------------|    |
 *      |       ppid                    |    |
 *      |-------------------------------|    |
 *      |       type                    |    |
 *      |-------------------------------|    |
 *      |       stat                    |    |
 *      |-------------------------------|    |
 *      |       sgid                    |    |
 *      |-------------------------------|    |
 *      |       hMte                    |    |
 *      |-------------------------------|    |
 *      |       cTCB                    |    |
 *      |-------------------------------|    |
 *      |       c32PSem                 |    |
 *      |-------------------------------|    |
 *      |       p32SemRec               |----|---|
 *      |-------------------------------|    |   |
 *      |       c16Sem                  |    |   |
 *      |-------------------------------|    |   |
 *      |       cLib                    |    |   |
 *      |-------------------------------|    |   |
 *      |       cShrMem                 |    |   |
 *      |-------------------------------|    |   |
 *      |       cFS                     |    |   |
 *      |-------------------------------|    |   |
 *      |       p16SemRec               |----|---|----|
 *      |-------------------------------|    |   |    |
 *      |       pLibRec                 |----|---|----|------|
 *      |-------------------------------|    |   |    |      |
 *      |       pShrMemRec              |----|---|----|------|----|
 *      |-------------------------------|    |   |    |      |    |
 *      |       pFSRec                  |----|---|----|------|----|-----|
 *      |-------------------------------|    |   |    |      |    |     |
 *      |       32SemPPRUN[0]           |<---|---|    |      |    |     |
 *      |          .                    |    |        |      |    |     |
 *      |          .                    |    |        |      |    |     |
 *      |          .                    |    |        |      |    |     |
 *      |       32SemPPRUN[c32PSem-1]   |    |        |      |    |     |
 *      |-------------------------------|    |        |      |    |     |
 *      |       16SemIndx[0]            |<---|--------|      |    |     |
 *      |          .                    |    |               |    |     |
 *      |          .                    |    |               |    |     |
 *      |          .                    |    |               |    |     |
 *      |       16SemIndx[c16Sem-1]     |    |               |    |     |
 *      |-------------------------------|    |               |    |     |
 *      |       hmte[0] (or "name str") |<---|---------------|    |     |
 *      |          .                    |    |                    |     |
 *      |          .                    |    |                    |     |
 *      |          .                    |    |                    |     |
 *      |       hmte[cLib-1]            |    |                    |     |
 *      |-------------------------------|    |                    |     |
 *      |       hshmem[0]               |<---|--------------------|     |
 *      |          .                    |    |                          |
 *      |          .                    |    |                          |
 *      |          .                    |    |                          |
 *      |       hshmem[cShrMem-1]       |    |                          |
 *      |-------------------------------|    |                          |
 *      |       fsinfo[0]               |<---|--------------------------|
 *      |          .                    |    |
 *      |          .                    |    |
 *      |          .                    |    |
 *      |       fsinfo[cFS-1]           |    |
 *      |-------------------------------|    |
 *                                      <-----
 *      NOTE that the process name string will be stored in place of hmtes
 *              if MTE information is NOT being requested.
 *      NOTE that following this structure in the user buffer is
 *              an array c32Sems long of PRUN structures for 32 bit sems
 *              an array c16Sems long of indices for 16 bit sems
 *              the process name string
 */
typedef struct qsPrec_s {
        ulong_t         RecType;        /* type of record being processed */
        qsTrec_t  FAR      *pThrdRec;      /* ptr to thread recs for this proc */
        ushort_t        pid;            /* process ID */
        ushort_t        ppid;           /* parent process ID */
        ulong_t         type;           /* process type */
        ulong_t         stat;           /* process status */
        ulong_t         sgid;           /* process screen group */
        ushort_t        hMte;           /* program module handle for process */
        ushort_t        cTCB;           /* # of TCBs in use */
        ulong_t         c32PSem;        /* # of private 32-bit sems in use */
        void      FAR      *p32SemRec;     /* pointer to head of 32bit sem info */
        ushort_t        c16Sem;         /* # of 16 bit system sems in use */
        ushort_t        cLib;           /* number of runtime linked libraries */
        ushort_t        cShrMem;        /* number of shared memory handles */
        ushort_t        cFH;           /* number of open files */
        ushort_t   FAR     *p16SemRec;     /* pointer to head of 16 bit sem info */
        ushort_t   FAR     *pLibRec;       /* ptr to list of runtime libraries */
        ushort_t   FAR     *pShrMemRec;    /* ptr to list of shared mem handles */
        ushort_t   FAR     *pFSRec;        /* pointer to list of file handles */
} qsPrec_t;

/*
 *      16 bit system semaphore structure
 *      ________________________________
 *      |       pNextRec                |----|
 *      |-------------------------------|    |
 *      |SysSemData     :               |    |
 *      |       SysSemOwner             |    |
 *      |       SysSemFlag              |    |
 *      |       SysSemRecCnt            |    |
 *      |       SysSemProcCnt           |    |
 *      |-------------------------------|    |
 *      |-------------------------------|    |
 *      |-------------------------------|    |
 *      |       SysSemPtr               |    |
 *      |-------------------------------|    |
 *      |SysSemName:                    |    |
 *      |       "pathname"              |    |
 *      |-------------------------------|    |
 *                                      <-----
 */
/* XLATON */
typedef struct qsS16rec_s {
        ulong_t         NextRec;        /* offset to next record in buffer */
        SysSemTblStruc  SysSemData;     /* global semaphore info (sem.h) */
        ushort_t        pad_sh;
        ushort_t        SemPtr;         /* RMP SysSemPtr field */
        char            SemName;        /* start of semaphore name string */
} qsS16rec_t;

typedef struct qsS16Headrec_s {
        ulong_t         SRecType;      /* offset of SysSemDataTable */
        ulong_t         SpNextRec;      /* overlays NextRec of 1st qsS16rec_t*/
        ulong_t         S32SemRec;
        ulong_t         S16TblOff;
        ulong_t         pSem16Rec;
} qsS16Headrec_t;

/*
 *      System wide Shared Mem information
 *      ________________________________
 *      |       NextRec                 |
 *      |-------------------------------|
 *      |       hmem                    |
 *      |-------------------------------|
 *      |       sel                     |
 *      |-------------------------------|
 *      |       refcnt                  |
 *      |-------------------------------|
 *      |       name                    |
 *      |_______________________________|
 *
 */
typedef struct qsMrec_s {
        ulong_t         MemNextRec;       /* offset to next record in buffer */
        ushort_t        hmem;        /* handle for shared memory */
        ushort_t        sel;            /* selector */
        ushort_t        refcnt;           /* reference count */
        char            Memname;         /* start of shared memory name string */
} qsMrec_t;

/* XLATOFF */
#ifndef DOSQPROCSTATUS
/*
 *      32 bit system semaphore structure
 *      ________________________________
 *      |       pNextRec                |----|
 *      |-------------------------------|    |
 *      |       QSHUN[0]                |    |
 *      |-------------------------------|    |
 *      |         MuxQ                  |    |
 *      |-------------------------------|    |
 *      |         OpenQ                 |    |
 *      |-------------------------------|    |
 *      |         SemName               |    |
 *      |-------------------------------|<---|
 *      |          .                    |
 *      |          .                    |
 *      |-------------------------------|<---|
 *      |       pNextRec                |----|
 *      |-------------------------------|    |
 *      |       QSHUN[c32SSem-1]        |    |
 *      |-------------------------------|    |
 *      |         MuxQ                  |    |
 *      |-------------------------------|    |
 *      |         OpenQ                 |    |
 *      |-------------------------------|    |
 *      |         SemName               |    |
 *      |-------------------------------|<---|
 */
typedef struct qsopenq_s {
        PID             pidOpener;      /* process id of opening process */
        ushort_t        OpenCt;         /* number of opens for this process */
} QSOPENQ;
typedef struct qsevent_s {
        QSOPENQ         *pOpenQ;        /* pointer to open q entries */
        uchar_t         *pName;         /* pointer to semaphore name */
        ulong_t         *pMuxQ;         /* pointer to the mux queue */
        ushort_t        flags;
        ushort_t        PostCt;         /* # of posts */
} QSEVENT;
typedef struct qsmutex_s {
        QSOPENQ         *pOpenQ;        /* pointer to open q entries */
        uchar_t         *pName;         /* pointer to semaphore name */
        ulong_t         *pMuxQ;         /* pointer to the mux queue */
        ushort_t        flags;
        ushort_t        ReqCt;          /* # of requests */
        ushort_t        SlotNum;        /* slot # of owning thread */
        PADSHORT
} QSMUTEX;
typedef struct qsmux_s {
        QSOPENQ         *pOpenQ;        /* pointer to open q entries */
        uchar_t         *pName;         /* pointer to semaphore name */
        void            *pSemRec;       /* array of semaphore record entries */
        ushort_t        flags;
        ushort_t        cSemRec;        /* count of semaphore records */
        ushort_t        WaitCt;         /* # threads waiting on the mux */
        PADSHORT
} QSMUX;
typedef struct qsshun_s {
        QSEVENT         qsSEvt;         /* shared event sem */
        QSMUTEX         qsSMtx;         /* shared mutex sem */
        QSMUX           qsSMux;         /* shared mux sem */
} QSHUN;
typedef struct qsS32rec_s {
        void            *pNextRec;      /* pointer to next record in buffer */
        QSHUN           qsh;            /* qstate version of SHUN record */
} qsS32rec_t;
#endif /* NOT DOSQPROCSTATUS */

/*
 *      System wide MTE information
 *      ________________________________
 *      |       pNextRec                |----|
 *      |-------------------------------|    |
 *      |       hmte                    |    |
 *      |-------------------------------|    |
 *      |       ctImpMod                |    |
 *      |-------------------------------|    |
 *      |       ctObj                   |    |
 *      |-------------------------------|    |
 *      |       pObjInfo                |----|----------|
 *      |-------------------------------|    |          |
 *      |       pName                   |----|----|     |
 *      |-------------------------------|    |    |     |
 *      |       imported module handles |    |    |     |
 *      |          .                    |    |    |     |
 *      |          .                    |    |    |     |
 *      |          .                    |    |    |     |
 *      |-------------------------------| <--|----|     |
 *      |       "pathname"              |    |          |
 *      |-------------------------------| <--|----------|
 *      |       Object records          |    |
 *      |       (if requested)          |    |
 *      |_______________________________|    |
 *                                      <-----
 *      NOTE that if the level bit is set, the base Lib record will be followed
 *      by a series of object records (qsLObj_t); one for each object of the
 *      module.
 */

typedef struct qsLObjrec_s {
        ulong_t         oaddr;  /* object address */
        ulong_t         osize;  /* object size */
        ulong_t         oflags; /* object flags */
} qsLObjrec_t;

typedef struct qsLrec_s {
        void  FAR          *pNextRec;      /* pointer to next record in buffer */
        ushort_t        hmte;           /* handle for this mte */
        ushort_t        fFlat;          /* true if 32 bit module */
      /*  ulong_t         mflags; */       /* module flags (mte_mflags) */
        ulong_t         ctImpMod;       /* # of imported modules in table */
        ulong_t         ctObj;          /* # of objects in module (mte_objcnt)*/
        qsLObjrec_t FAR    *pObjInfo;      /* pointer to per object info if any */
        uchar_t     FAR    *pName;         /* -> name string following struc */
} qsLrec_t;
#ifndef DOSQPROCSTATUS
/*
 *      System wide FILE information
 *      ________________________________
 *      |       RecType                 |
 *      |-------------------------------|
 *      |       pNextRec                |-------|
 *      |-------------------------------|       |
 *      |       ctSft                   |       |
 *      |-------------------------------|       |
 *      |       pSft                    |---|   |
 *      |-------------------------------|   |   |
 *      |       name                    |   |   |
 *      |-------------------------------|<--|   |
 *      |       qsSft[0]                |       |
 *      |-------------------------------|       |
 *      |       ...                     |       |
 *      |-------------------------------|       |
 *      |       qsSft[ctSft -1]         |       |
 *      |_______________________________|       |
 *      |       name                    |
 *      |_______________________________|
 *                                      <-------|
 */
typedef struct qsSft_s {
        ushort_t        sfn;            /* SFN sf_fsi.sfi_selfSFN */
        ushort_t        refcnt;         /* sf_ref_count */
        ushort_t        flags;          /* sf_flags */
        ushort_t        flags2;         /* sf_flags2 */
        ushort_t        mode;           /* sf_fsi.sfi_mode - mode of access */
        ushort_t        mode2;          /* sf_fsi.sfi_mode2 - mode of access */
        ulong_t         size;           /* sf_fsi.sfi_size */
        ushort_t        hVPB;           /* sf_fsi.sfi_hVPB handle of volume */
        ushort_t        attr;           /* sf_attr */
/*        ushort_t        pid; */           /* sf_fsi.sfi_PID */
        PADSHORT
} qsSft_t;

typedef struct qsFrec_s {
        ulong_t         RecType;        /* Record Type */
        void            *pNextRec;      /* pointer to next record in buffer */
        ulong_t         ctSft;          /* # sft entries for this MFT entry */
        qsSft_t         *pSft;          /* -> start of sft entries in buf */
} qsFrec_t;
#endif /* NOT DOSQPROCSTATUS


/* Pointer Record Structure
 *      This structure is the first in the user buffer.
 *      It contains pointers to heads of record types that are loaded
 *      into the buffer.
 */
#ifndef DOSQPROCSTATUS
/* XLATON */
typedef struct qsPtrRec_s {
        qsGrec_t        *pGlobalRec;
        qsPrec_t        *pProcRec;      /* ptr to head of process records */
        qsS16Headrec_t  *p16SemRec;     /* ptr to head of 16 bit sem recds */
        qsS32rec_t      *p32SemRec;     /* ptr to head of 32 bit sem recds */
        qsMrec_t        *pMemRec;       /* ptr to head of shared mem recs */
        qsLrec_t        *pLibRec;       /* ptr to head of mte records */
        qsMrec_t        *pShrMemRec;    /* ptr to head of shared mem records */
        qsFrec_t        *pFSRec;        /* ptr to head of file sys records */
} qsPtrRec_t;
/* XLATOFF */
#else
typedef struct qsPtrRec_s {
        qsGrec_t FAR     *pGlobalRec;
        qsPrec_t FAR     *pProcRec;
        qsS16Headrec_t FAR  *p16SemRec;
        void FAR         *p32SemRec;
        qsMrec_t FAR     *pMemRec;
        qsLrec_t FAR     *pLibRec;
        qsMrec_t FAR     *pShrMemRec;
        qsFrec_t FAR     *pFSRec;
} qsPtrRec_t;
#endif
