Changeset 57


Ignore:
Timestamp:
Apr 9, 2001, 10:50:16 PM (24 years ago)
Author:
umoeller
Message:

Sources for V0.9.9, plus a couple of fixes.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/helpers/procstat.h

    r44 r57  
    233233     ********************************************************************/
    234234
     235    // #pragma pack(1)
     236    #pragma pack(4)         // V0.9.10 (2001-04-08) [umoeller]
     237
    235238    #define QS32_PROCESS      0x0001
    236239    #define QS32_SEMAPHORE    0x0002
     
    244247    #define QS32_MODVER       0x0200
    245248
    246     #define QS32_STANDARD    (QS32_PROCESS | QS32_SEMAPHORE | QS32_MTE | QS32_FILESYS | QS32_SHMEMORY)
    247 
    248     APIRET APIENTRY DosQuerySysState(ULONG flQueries,
    249                                      ULONG arg1,
    250                                      ULONG arg2,
    251                                      ULONG _res_,
    252                                      PVOID buf,
    253                                      ULONG bufsz);
     249    #define QS32_SUPPORTED    (QS32_PROCESS | QS32_SEMAPHORE | QS32_MTE | QS32_FILESYS \
     250                               | QS32_SHMEMORY | QS32_MODVER)
     251
     252    APIRET  APIENTRY DosQuerySysState(ULONG EntityList,
     253                                      ULONG EntityLevel,
     254                                      PID pid,
     255                                      TID tid,
     256                                      PVOID pDataBuf,
     257                                      ULONG cbBuf);
     258
     259    /**********************
     260     *
     261     *  global struct
     262     *
     263     **********************/
    254264
    255265    /*
     
    265275    } QGLOBAL32, *PQGLOBAL32;
    266276
     277    /**********************
     278     *
     279     *  thread struct
     280     *
     281     **********************/
     282
    267283    /*
    268284     *@@ QTHREAD32:
     
    272288    typedef struct _QTHREAD32
    273289    {
    274         ULONG   rectype;        // 256 for thread
     290        ULONG   ulRecType;        // 256 for thread
    275291        USHORT  usTID;          // thread ID, process-specific
    276         USHORT  usSlotID;       // slot ID, this identifies the thread to the kernel
    277         ULONG   ulSleepID;      // something the kernel uses for blocking threads
     292        USHORT  usSlotID;       // system-specific slot ID, this identifies the
     293                                // thread to the kernel
     294        ULONG   ulSleepID;      // sleep ID the kernel uses for blocking threads
    278295        ULONG   ulPriority;     // priority flags
    279296        ULONG   ulSystime;      // CPU time spent in system code
     
    287304        USHORT  _reserved2_;    /* padding to ULONG */
    288305    } QTHREAD32, *PQTHREAD32;
     306
     307    /**********************
     308     *
     309     *  open files
     310     *
     311     **********************/
    289312
    290313    // found the following in the "OS/2 Debugging handbook"
     
    319342    typedef struct _QFDS32
    320343    {
    321         USHORT  sfn;                // "system file number" of the file.
     344        USHORT  usSFN;              // "system file number" of the file.
    322345                                    // This is the same as in
    323346                                    // the QPROCESS32.pausFds array,
     
    350373
    351374        ULONG   ulFileSize;         // file size in bytes
    352         USHORT  hVolume;            // "volume handle"; apparently,
     375        USHORT  usHVolume;          // "volume handle"; apparently,
    353376                                    // this identifies some kernel
    354377                                    // structure, it's the same for
    355378                                    // files on the same disk
    356         USHORT  attrib;             // attributes:
     379        USHORT  fsAttribs;          // attributes:
    357380                                    // 0x20: 'A' (archived)
    358381                                    // 0x10: 'D' (directory)
     
    361384                                    // 0x02: 'H' (hidden)
    362385                                    // 0x01: 'R' (read-only)
    363         USHORT  _reserved_;
     386        USHORT  us_pad_;
    364387    } QFDS32, *PQFDS32;
    365388
     
    373396    typedef struct _QFILEDATA32
    374397    {
    375         ULONG           rectype;        // 8 for file
    376         struct _QFILEDATA32 *pNext;
    377         ULONG           ulOpenCount;
    378         PQFDS32         filedata;
    379         char            acFilename[1];
     398        ULONG           ulRecType;          // 8 for file
     399        struct _QFILEDATA32 *pNext;         // next record
     400        ULONG           ulCFiles;           // no. of SFT entries for this MFT entry
     401        PQFDS32         paFiles;            // first entry here
     402        char            szFilename[1];
    380403    } QFILEDATA32, *PQFILEDATA32;
     404
     405    /**********************
     406     *
     407     *  process struct
     408     *
     409     **********************/
    381410
    382411    /*
     
    393422    typedef struct _QPROCESS32
    394423    {
    395         ULONG       rectype;        // 1 for process
    396         PQTHREAD32  pThreads;       // thread data array; apperently with usThreadCount items
    397         USHORT      pid;            // process ID
    398         USHORT      ppid;           // parent process ID
     424        ULONG       ulRecType;      // 1 for process
     425        PQTHREAD32  pThreads;       // thread data array,
     426                                    // apperently with usThreadCount items
     427        USHORT      usPID;          // process ID
     428        USHORT      usPPID;         // parent process ID
    399429        ULONG       ulProgType;
    400430                // -- 0: Full screen protected mode.
     
    411441                // -- STAT_DYING    0x40
    412442                // -- STAT_EMBRYO   0x80
    413         ULONG       sessid;         // session ID
     443        ULONG       ulScreenGroupID; // screen group ID
    414444        USHORT      usHModule;      // module handle of main executable
    415         USHORT      usThreadCount;  // no. of threads
     445        USHORT      usThreadCount;  // no. of threads (TCB's in use)
    416446        ULONG       ulPrivSem32Count;  // count of 32-bit semaphores
    417         ULONG       ulPrivSem32s;   // should be ptr to 32-bit sems array; 0 always
     447        PVOID       pvPrivSem32s;   // ptr to 32-bit sems array
    418448        USHORT      usSem16Count;   // count of 16-bit semaphores in pausSem16 array
    419449        USHORT      usModuleCount;  // count of DLLs owned by this process
    420         USHORT      usShrMemCount;  // count of shared memory items
     450        USHORT      usShrMemCount;  // count of shared memory handles
    421451        USHORT      usFdsCount;     // count of open files; this is mostly way too large
    422452        PUSHORT     pausSem16;      // ptr to array of 16-bit semaphore handles;
     
    424454        PUSHORT     pausModules;    // ptr to array of modules (MTE);
    425455                                    // has usModuleCount items
    426         PUSHORT     pausShrMems;    // ptr to array of shared mem items;
     456        PUSHORT     pausShrMems;    // ptr to array of shared mem handles;
    427457                                    // has usShrMemCount items
    428458        PUSHORT     pausFds;        // ptr to array of file handles;
     
    432462    } QPROCESS32, *PQPROCESS32;
    433463
    434     /*
    435      *@@ QSEMA32:
    436      *      Member of QSEM16STRUC32.
    437      */
    438 
    439     typedef struct _QSEMA32
    440     {
    441         struct _QSEMA32 *pNext;
    442         USHORT      usRefCount;
    443         UCHAR       ucSysFlags;
    444         UCHAR       ucSysProcCount;
    445         ULONG       _reserved1_;
    446         USHORT      usIndex;
    447         CHAR        acName[1];
    448     } QSEMA32, *PQSEMA32;
    449 
    450     /*
    451      *@@ QSEM16STRUC32:
    452      *      Apparently 16-bit semaphores.
    453      *
    454      *      Pointed to by QTOPLEVEL32.
    455      */
    456 
    457     typedef struct _QSEM16STRUC32
    458     {
    459         ULONG   rectype;        /**/
    460         ULONG   _reserved1_;
    461         USHORT  _reserved2_;
    462         USHORT  usSysSemIndex;
    463         ULONG   ulIndex;
    464         QSEMA32   sema;
    465     } QSEM16STRUC32, *PQSEM16STRUC32;
    466 
    467     /*
    468      *@@ QSEM32OWNER32:
    469      *      Pointed to by QSEM16SMUX32, QSEM16EV32, QSEM16MUX32.
    470      */
    471 
    472     typedef struct _QSEM32OWNER32
    473     {
    474         USHORT  pid;
    475         USHORT  usOpenCount;        // or owner?!?
    476     } QSEM32OWNER32, *PQSEM32OWNER32;
    477 
    478     /*
    479      *@@ QSEM32SMUX32:
    480      *      member of QSEM32STRUC32.
    481      */
    482 
    483     typedef struct _QSEM32SMUX32
    484     {
    485         PQSEM32OWNER32  pOwner;
    486         PCHAR           pszName;
    487         PVOID           semrecs;        // array of associated sema's
    488         USHORT          flags;
    489         USHORT          semreccnt;
    490         USHORT          waitcnt;
    491         USHORT          _reserved_;     // padding to ULONG
    492     } QSEM32SMUX32, *PQSEM32SMUX32;
    493 
    494     /*
    495      *@@ QSEM32EV32:
    496      *      describes an event semaphore.
    497      *      Member of QSEM32STRUC32.
    498      */
    499 
    500     typedef struct _QSEM32EV32
    501     {
    502         PQSEM32OWNER32  pOwner;
    503         PCHAR           pacName;
    504         PQSEM32SMUX32   pMux;
    505         USHORT          flags;
    506         USHORT          postcnt;
    507     } QSEM32EV32, *PQSEM32EV32;
    508 
    509     /*
    510      *@@ QSEM32MUX32:
    511      *      member of QSEM32STRUC32.
    512      */
    513 
    514     typedef struct _QSEM32MUX32
    515     {
    516         PQSEM32OWNER32  pOwner;
    517         PCHAR           name;
    518         PQSEM32SMUX32   mux;
    519         USHORT          flags;
    520         USHORT          usRefCount;
    521         USHORT          thrdnum;
    522         USHORT          _reserved_;     /* padding to ULONG */
    523     } QSEM32MUX32, *PQSEM32MUX32;
    524 
    525     /*
    526      *@@ QSEM32STRUC32:
    527      *      apparently describes a 32-bit semaphore.
    528      *
    529      *      Pointed to by QTOPLEVEL32.
    530      */
    531 
    532     typedef struct _QSEM32STRUC32
    533     {
    534         struct _QSEM32STRUC32 *pNext;
    535         QSEM32EV32    EventSem;
    536         QSEM32MUX32   MuxSem;
    537         QSEM32SMUX32  SmuxSem;
    538     } QSEM32STRUC32, *PQSEM32STRUC32;
     464    /**********************
     465     *
     466     *  16-bit semaphores
     467     *
     468     **********************/
     469
     470    // SysSemFlag values
     471
     472    #define QS32_SYSSEM_WAITING 0x01               /* a thread is waiting on the sem */
     473    #define QS32_SYSSEM_MUXWAITING 0x02            /* a thread is muxwaiting on the sem */
     474    #define QS32_SYSSEM_OWNER_DIED 0x04            /* the process/thread owning the sem died */
     475    #define QS32_SYSSEM_EXCLUSIVE 0x08             /* indicates a exclusive system semaphore */
     476    #define QS32_SYSSEM_NAME_CLEANUP 0x10          /* name table entry needs to be removed */
     477    #define QS32_SYSSEM_THREAD_OWNER_DIED 0x20     /* the thread owning the sem died */
     478    #define QS32_SYSSEM_EXITLIST_OWNER 0x40        /* the exitlist thread owns the sem */
     479
     480    /*
     481     *@@ QS32SEM16:
     482     *      16-bit semaphore description.
     483     *
     484     *@@added V0.9.10 (2001-04-08) [umoeller]
     485     */
     486
     487    typedef struct _QS32SEM16
     488    {
     489        struct _QS32SEM16 *pNext;
     490        // ULONG         NextRec;        /* offset to next record in buffer */
     491                                      /* System Semaphore Table Structure */
     492        USHORT        usSysSemOwner;   /* thread owning this semaphore */
     493        UCHAR         fsSysSemFlags;    /* system semaphore flag bit field */
     494        UCHAR         usSysSemRefCnt ;  /* number of references to this sys sem */
     495        UCHAR         usSysSemProcCnt ; /* number of requests for this owner */
     496        UCHAR         usSysSemPad ;     /* pad byte to round structure up to word */
     497        USHORT        pad_sh;
     498        USHORT        SemPtr;         /* RMP SysSemPtr field */
     499        char          szName[1];      /* start of semaphore name string */
     500    } QS32SEM16, *PQS32SEM16;
     501
     502    /*
     503     *@@ QS32SEM16HEAD:
     504     *
     505     *@@added V0.9.10 (2001-04-08) [umoeller]
     506     */
     507
     508    typedef struct _QS32SEM16HEAD
     509    {
     510        ULONG         SRecType;       /* offset of SysSemDataTable */
     511        ULONG         SpNextRec;      /* overlays NextRec of 1st QS32SEM16 */
     512        ULONG         S32SemRec;
     513        ULONG         S16TblOff;
     514        // ULONG         pSem16Rec;
     515        QS32SEM16     Sem16Rec;       // first record, with subsequent following
     516    } QS32SEM16HEAD, *PQS32SEM16HEAD;
     517
     518    /**********************
     519     *
     520     *  shared memory
     521     *
     522     **********************/
    539523
    540524    /*
     
    548532    {
    549533        struct _QSHRMEM32 *pNext;
    550         USHORT      usHandle;
    551         USHORT      usSelector;
    552         USHORT      usRefCount;
    553         CHAR        acName[1];
     534        USHORT      usHandle;           // shared memory handle
     535        USHORT      usSelector;         // selector
     536        USHORT      usRefCount;         // reference count
     537        CHAR        acName[1];          // shared memory name
    554538    } QSHRMEM32, *PQSHRMEM32;
     539
     540    /**********************
     541     *
     542     *  32-bit semaphores
     543     *
     544     **********************/
     545
     546    #define QS32_DC_SEM_SHARED   0x0001   //  Shared Mutex, Event or MUX semaphore
     547    #define QS32_DCMW_WAIT_ANY   0x0002   //  Wait on any event/mutex to occur
     548    #define QS32_DCMW_WAIT_ALL   0x0004   //  Wait on all events/mutexs to occur
     549    #define QS32_DCM_MUTEX_SEM   0x0008   //  Mutex semaphore
     550    #define QS32_DCE_EVENT_SEM   0x0010   //  Event semaphore
     551    #define QS32_DCMW_MUX_SEM    0x0020   //  Muxwait semaphore
     552    // #define QS32_DC_SEM_PM       0x0040   //  PM Shared Event Semphore
     553    #define QS32_DE_POSTED       0x0040   //  event sem is in the posted state
     554    #define QS32_DM_OWNER_DIED   0x0080   //  The owning process died
     555    #define QS32_DMW_MTX_MUX     0x0100   //  MUX contains mutex sems
     556    #define QS32_DHO_SEM_OPEN    0x0200   //  Device drivers have opened this semaphore
     557    #define QS32_DE_16BIT_MW     0x0400   //  Part of a 16-bit MuxWait
     558    #define QS32_DCE_POSTONE     0x0800   //  Post one flag event semaphore
     559    #define QS32_DCE_AUTORESET   0x1000   //  Auto-reset event semaphore
     560
     561    /*
     562     *@@ QS32OPENQ:
     563     *
     564     *@@added V0.9.10 (2001-04-08) [umoeller]
     565     */
     566
     567    typedef struct _QS32OPENQ {    /* qsopenq */
     568            PID           pidOpener;      /* process id of opening process */
     569            USHORT        OpenCt;         /* number of opens for this process */
     570    } QS32OPENQ, *PQS32OPENQ;
     571
     572    /*
     573     *@@ QS32EVENT:
     574     *
     575     *@@added V [umoeller]
     576     */
     577
     578    typedef struct _QS32EVENT {    /* qsevent */
     579            QS32OPENQ     *pOpenQ;        /* pointer to open q entries */
     580            UCHAR         *pName;         /* pointer to semaphore name */
     581            ULONG         *pMuxQ;         /* pointer to the mux queue */
     582            USHORT        flags;
     583            USHORT        PostCt;         /* # of posts */
     584    } QS32EVENT, *PQS32EVENT;
     585
     586    /*
     587     *@@ QS32MUTEX:
     588     *
     589     *@@added V0.9.10 (2001-04-08) [umoeller]
     590     */
     591
     592    typedef struct _QS32MUTEX {    /* qsmutex */
     593            QS32OPENQ     *pOpenQ;        /* pointer to open q entries */
     594            UCHAR         *pName;         /* pointer to semaphore name */
     595            ULONG         *pMuxQ;         /* pointer to the mux queue */
     596            USHORT        flags;
     597            USHORT        ReqCt;          /* # of requests */
     598            USHORT        SlotNum;        /* slot # of owning thread */
     599            USHORT        pad_sh;
     600    } QS32MUTEX, *PQS32MUTEX;
     601
     602    /*
     603     *@@ QS32MUX:
     604     *
     605     *@@added V0.9.10 (2001-04-08) [umoeller]
     606     */
     607
     608    typedef struct _QS32MUX {   /* qsmux */
     609            QS32OPENQ       *pOpenQ;        /* pointer to open q entries */
     610            UCHAR           *pName;         /* pointer to semaphore name */
     611            void            *pSemRec;       /* array of semaphore record entries */
     612            USHORT          flags;
     613            USHORT          cSemRec;        /* count of semaphore records */
     614            USHORT          WaitCt;         /* # threads waiting on the mux */
     615            USHORT          pad_sh;
     616    } QS32MUX, *PQS32MUX;
     617
     618    /*
     619     *@@ QS32SHUN:
     620     *
     621     *@@added V0.9.10 (2001-04-08) [umoeller]
     622     */
     623
     624    typedef union _QS32SHUN {  /* qsshun */
     625            QS32EVENT       qsSEvt;         /* shared event sem */
     626            QS32MUTEX       qsSMtx;         /* shared mutex sem */
     627            QS32MUX         qsSMux;         /* shared mux sem */
     628    } QS32SHUN, *PQS32SHUN;
     629
     630    /*
     631     *@@ QS32SEM32:
     632     *
     633     *@@added V0.9.10 (2001-04-08) [umoeller]
     634     */
     635
     636    typedef struct _QS32SEM32 {   /* qsS32rec */
     637            void        *pNext;      /* pointer to next record in buffer */
     638            ULONG       fl;         // semaphore flags; THIS FIELD IS MISSING
     639                                    // IN THE ORIGINAL TOOLKIT DEFINITIONS...
     640                                    // only with this field we can determine
     641                                    // if this is a mutex, event, or muxwait
     642            PSZ         pszName;        // or NULL if unnamed
     643            ULONG       pvDeviceDriver; // ?!? points into kernel memory
     644            USHORT      usPostCount;
     645            USHORT      us_;
     646            ULONG       ulBlockID;
     647
     648            // can't make sense of the following fields... these
     649            // seem to be variable in size
     650            ULONG       ulHandle;
     651            /* USHORT      usAlways1;
     652            ULONG       ulElse;
     653            ULONG       ulElse2; */
     654    } QS32SEM32, *PQS32SEM32;           // qsS32rec_t;
     655
     656    /**********************
     657     *
     658     *  modules
     659     *
     660     **********************/
     661
     662    /*
     663     *@@ QS32OBJ:
     664     *      describes an object in a module.
     665     *      Pointed to by QSMODULE32, but only
     666     *      if QS32_MTE was set on query.
     667     *
     668     *@@added V0.9.10 (2001-04-08) [umoeller]
     669     */
     670
     671    typedef struct _QS32OBJ {
     672            ULONG   oaddr;  /* object address */
     673            ULONG   osize;  /* object size */
     674            ULONG   oflags; /* object flags */
     675    } QS32OBJ, *PQS32OBJ;
    555676
    556677    /*
     
    564685    {
    565686        struct _QMODULE32 *pNext;       // next module
    566         USHORT      usHModule;          // module handle
    567         USHORT      type;
    568         ULONG       ulRefCount;
    569         ULONG       ulSegmentCount;
    570         PVOID       _reserved_;
     687        USHORT      usHModule;          // module handle (HMTE)
     688        USHORT      fFlat;              // TRUE for 32-bit modules
     689        ULONG       ulRefCount;         // no. of imports
     690        ULONG       cObjects;           // no. of objects in module
     691        PQS32OBJ    paObjects;          // ptr to objects list, if QS32_MTE was queried
    571692        PCHAR       pcName;             // module name (fully qualified)
    572693        USHORT      ausModRef[1];       // array of module "references";
     
    575696    } QMODULE32, *PQMODULE32;
    576697
     698    /**********************
     699     *
     700     *  top-level struct
     701     *
     702     **********************/
     703
    577704    /*
    578705     *@@ QTOPLEVEL32:
     
    585712        PQGLOBAL32      pGlobalData;
    586713        PQPROCESS32     pProcessData;
    587         PQSEM16STRUC32  pSem16Data;
    588         PQSEM32STRUC32  pSem32Data;     // not always present!
     714        PQS32SEM16HEAD  pSem16Data;
     715        PQS32SEM32      pSem32Data;     // not always present!
    589716        PQSHRMEM32      pShrMemData;
    590717        PQMODULE32      pModuleData;
     
    636763    #pragma pack()
    637764
    638    /********************************************************************
    639     *
    640     *   DosQProcStat (16-bit) interface
    641     *
    642     ********************************************************************/
    643 
    644     PQPROCSTAT16 prc16GetInfo(APIRET *parc);
    645 
    646     VOID prc16FreeInfo(PQPROCSTAT16 pInfo);
     765    /********************************************************************
     766     *
     767     *   DosQProcStat (16-bit) interface
     768     *
     769     ********************************************************************/
     770
     771    APIRET prc16GetInfo(PQPROCSTAT16 *ppps);
     772
     773    APIRET prc16FreeInfo(PQPROCSTAT16 pInfo);
    647774
    648775    PQPROCESS16 prc16FindProcessFromName(PQPROCSTAT16 pInfo,
     
    681808                                         const char *pcszName);
    682809
    683     PQSEMA32 prc32FindSem16(PQTOPLEVEL32 pInfo,
     810    PQS32SEM16 prc32FindSem16(PQTOPLEVEL32 pInfo,
    684811                              USHORT usSemID);
    685812
    686     PQSEM32STRUC32 prc32FindSem32(PQTOPLEVEL32 pInfo,
    687                                   USHORT usSemID);
     813    PQS32SEM32 prc32FindSem32(PQTOPLEVEL32 pInfo,
     814                              USHORT usSemID);
    688815
    689816    PQSHRMEM32 prc32FindShrMem(PQTOPLEVEL32 pInfo,
  • trunk/src/helpers/dosh2.c

    r56 r57  
    810810 *@@changed V0.9.1 (2000-02-13) [umoeller]: fixed 32-bits flag
    811811 *@@changed V0.9.7 (2000-12-20) [lafaix]: fixed ulNewHeaderOfs
     812 *@@changed V0.9.10 (2001-04-08) [umoeller]: now setting ppExec only if NO_ERROR is returned
    812813 */
    813814
     
    819820    ULONG   ulAction = 0;
    820821    HFILE   hFile;
     822    PEXECUTABLE pExec = NULL;
    821823
    822824    if (!ppExec)
    823825        return (ERROR_INVALID_PARAMETER);
    824826
    825     *ppExec = (PEXECUTABLE)malloc(sizeof(EXECUTABLE));
    826     if (!(*ppExec))
     827    pExec = (PEXECUTABLE)malloc(sizeof(EXECUTABLE));
     828    if (!(pExec))
    827829        return (ERROR_NOT_ENOUGH_MEMORY);
    828830
    829     memset((*ppExec), 0, sizeof(EXECUTABLE));
     831    memset(pExec, 0, sizeof(EXECUTABLE));
    830832
    831833    if (!(arc = DosOpen((PSZ)pcszExecutable,
     
    850852
    851853        // read old DOS EXE header
    852         (*ppExec)->pDosExeHeader = (PDOSEXEHEADER)malloc(sizeof(DOSEXEHEADER));
    853         if (!((*ppExec)->pDosExeHeader))
     854        pExec->pDosExeHeader = (PDOSEXEHEADER)malloc(sizeof(DOSEXEHEADER));
     855        if (!(pExec->pDosExeHeader))
    854856            arc = ERROR_NOT_ENOUGH_MEMORY;
    855857        else
     
    862864                                           &ulLocal)))      // out: new offset
    863865                 && (!(arc = DosRead(hFile,
    864                                      (*ppExec)->pDosExeHeader,
     866                                     pExec->pDosExeHeader,
    865867                                     sizeof(DOSEXEHEADER),
    866                                      &((*ppExec)->cbDosExeHeader))))
     868                                     &(pExec->cbDosExeHeader))))
    867869               )
    868870            {
    869871                // now check if we really have a DOS header
    870                 if ((*ppExec)->pDosExeHeader->usDosExeID != 0x5a4d)
     872                if (pExec->pDosExeHeader->usDosExeID != 0x5a4d)
    871873                    arc = ERROR_INVALID_EXE_SIGNATURE;
    872874                else
    873875                {
    874876                    // we have a DOS header:
    875                     if ((*ppExec)->pDosExeHeader->usRelocTableOfs < 0x40)
     877                    if (pExec->pDosExeHeader->usRelocTableOfs < 0x40)
    876878                    {
    877879                        // neither LX nor PE nor NE:
    878                         (*ppExec)->ulOS = EXEOS_DOS3;
    879                         (*ppExec)->ulExeFormat = EXEFORMAT_OLDDOS;
     880                        pExec->ulOS = EXEOS_DOS3;
     881                        pExec->ulExeFormat = EXEFORMAT_OLDDOS;
    880882                    }
    881883                    else
     
    886888
    887889                        if (    (!(arc = DosSetFilePtr(hFile,
    888                                                        (*ppExec)->pDosExeHeader->ulNewHeaderOfs,
     890                                                       pExec->pDosExeHeader->ulNewHeaderOfs,
    889891                                                       FILE_BEGIN,
    890892                                                       &ulLocal)))
     
    900902                            // reset file ptr
    901903                            DosSetFilePtr(hFile,
    902                                           (*ppExec)->pDosExeHeader->ulNewHeaderOfs,
     904                                          pExec->pDosExeHeader->ulNewHeaderOfs,
    903905                                          FILE_BEGIN,
    904906                                          &ulLocal);
     
    907909                            {
    908910                                // New Executable:
    909                                 (*ppExec)->ulExeFormat = EXEFORMAT_NE;
     911                                pExec->ulExeFormat = EXEFORMAT_NE;
    910912                                // allocate NE header
    911                                 (*ppExec)->pNEHeader = (PNEHEADER)malloc(sizeof(NEHEADER));
    912                                 if (!((*ppExec)->pNEHeader))
     913                                pExec->pNEHeader = (PNEHEADER)malloc(sizeof(NEHEADER));
     914                                if (!(pExec->pNEHeader))
    913915                                    arc = ERROR_NOT_ENOUGH_MEMORY;
    914916                                else
    915917                                    // read in NE header
    916918                                    if (!(arc = DosRead(hFile,
    917                                                         (*ppExec)->pNEHeader,
     919                                                        pExec->pNEHeader,
    918920                                                        sizeof(NEHEADER),
    919                                                         &((*ppExec)->cbNEHeader))))
    920                                         if ((*ppExec)->cbNEHeader == sizeof(NEHEADER))
    921                                             pbCheckOS = &((*ppExec)->pNEHeader->bTargetOS);
     921                                                        &(pExec->cbNEHeader))))
     922                                        if (pExec->cbNEHeader == sizeof(NEHEADER))
     923                                            pbCheckOS = &(pExec->pNEHeader->bTargetOS);
    922924                            }
    923925                            else if (   (memcmp(achNewHeaderType, "LX", 2) == 0)
     
    927929                            {
    928930                                // OS/2 Linear Executable:
    929                                 (*ppExec)->ulExeFormat = EXEFORMAT_LX;
     931                                pExec->ulExeFormat = EXEFORMAT_LX;
    930932                                // allocate LX header
    931                                 (*ppExec)->pLXHeader = (PLXHEADER)malloc(sizeof(LXHEADER));
    932                                 if (!((*ppExec)->pLXHeader))
     933                                pExec->pLXHeader = (PLXHEADER)malloc(sizeof(LXHEADER));
     934                                if (!(pExec->pLXHeader))
    933935                                    arc = ERROR_NOT_ENOUGH_MEMORY;
    934936                                else
    935937                                    // read in LX header
    936938                                    if (!(arc = DosRead(hFile,
    937                                                         (*ppExec)->pLXHeader,
     939                                                        pExec->pLXHeader,
    938940                                                        sizeof(LXHEADER),
    939                                                         &((*ppExec)->cbLXHeader))))
    940                                         if ((*ppExec)->cbLXHeader == sizeof(LXHEADER))
    941                                             pbCheckOS = (PBYTE)(&((*ppExec)->pLXHeader->usTargetOS));
     941                                                        &(pExec->cbLXHeader))))
     942                                        if (pExec->cbLXHeader == sizeof(LXHEADER))
     943                                            pbCheckOS = (PBYTE)(&(pExec->pLXHeader->usTargetOS));
    942944                            }
    943945                            else if (memcmp(achNewHeaderType, "PE", 2) == 0)
    944946                            {
    945                                 (*ppExec)->ulExeFormat = EXEFORMAT_PE;
    946                                 (*ppExec)->ulOS = EXEOS_WIN32;
    947                                 (*ppExec)->f32Bits = TRUE;
     947                                pExec->ulExeFormat = EXEFORMAT_PE;
     948                                pExec->ulOS = EXEOS_WIN32;
     949                                pExec->f32Bits = TRUE;
    948950
    949951                                // can't parse this yet
     
    959961                                {
    960962                                    case NEOS_OS2:
    961                                         (*ppExec)->ulOS = EXEOS_OS2;
    962                                         if ((*ppExec)->ulExeFormat == EXEFORMAT_LX)
    963                                             (*ppExec)->f32Bits = TRUE;
     963                                        pExec->ulOS = EXEOS_OS2;
     964                                        if (pExec->ulExeFormat == EXEFORMAT_LX)
     965                                            pExec->f32Bits = TRUE;
    964966                                    break;
    965967
    966968                                    case NEOS_WIN16:
    967                                         (*ppExec)->ulOS = EXEOS_WIN16;
     969                                        pExec->ulOS = EXEOS_WIN16;
    968970                                    break;
    969971
    970972                                    case NEOS_DOS4:
    971                                         (*ppExec)->ulOS = EXEOS_DOS4;
     973                                        pExec->ulOS = EXEOS_DOS4;
    972974                                    break;
    973975
    974976                                    case NEOS_WIN386:
    975                                         (*ppExec)->ulOS = EXEOS_WIN386;
    976                                         (*ppExec)->f32Bits = TRUE;
     977                                        pExec->ulOS = EXEOS_WIN386;
     978                                        pExec->f32Bits = TRUE;
    977979                                    break;
    978980                                }
     
    981983                }
    982984            } // end if (!(arc = DosSetFilePtr(hFile,
    983         } // end if (*ppExec)->pDosExeHeader = (PDOSEXEHEADER)malloc(sizeof(DOSEXEHEADER));
     985        } // end if pExec->pDosExeHeader = (PDOSEXEHEADER)malloc(sizeof(DOSEXEHEADER));
    984986
    985987        // store exec's HFILE
    986         (*ppExec)->hfExe = hFile;
     988        pExec->hfExe = hFile;
    987989    } // end if (!(arc = DosOpen((PSZ)pcszExecutable,
    988990
    989991    if (arc != NO_ERROR)
    990992        // error: clean up
    991         doshExecClose(*ppExec);
     993        doshExecClose(pExec);
     994    else
     995        *ppExec = pExec;
    992996
    993997    return (arc);
     
    30053009 *@@added V0.9.0 [umoeller]
    30063010 *@@changed V0.9.9 (2001-04-07) [umoeller]: added transparent LVM support; changed prototype
    3007  *@@changed V0.9.9 (2001-04-07) [umoeller]: added memory leaks on errors
     3011 *@@changed V0.9.9 (2001-04-07) [umoeller]: fixed memory leaks on errors
    30083012 */
    30093013
  • trunk/src/helpers/procstat.c

    r44 r57  
    8484 *
    8585 *@@added V0.9.3 (2000-05-05) [umoeller]
    86  */
    87 
    88 PQPROCSTAT16 prc16GetInfo(APIRET *parc)     // out: error, ptr can be NULL
     86 *@@changed V0.9.10 (2001-04-08) [umoeller]: this returned != NULL even though item was freed, fixed
     87 *@@changed V0.9.10 (2001-04-08) [umoeller]: now using DosAllocMem, raised bufsize, changed prototype
     88 */
     89
     90APIRET prc16GetInfo(PQPROCSTAT16 *ppps)     // out: error, ptr can be NULL
    8991{
    9092    APIRET arc = NO_ERROR;
    91     PQPROCSTAT16 pps = (PQPROCSTAT16)malloc(0x8000);
     93    PQPROCSTAT16 pps = NULL;
     94
     95    /* PQPROCSTAT16 pps = (PQPROCSTAT16)malloc(0x8000);
    9296    if (!pps)
    9397        arc = ERROR_NOT_ENOUGH_MEMORY;
    94     else
    95     {
    96         arc = DosQProcStatus(pps, 0x8000);
    97         if (arc != NO_ERROR)
    98             free(pps);
    99     }
    100 
    101     if (parc)
    102         *parc = arc;
    103 
    104     return (pps);
     98    else */
     99
     100    if (!ppps)
     101        return (ERROR_INVALID_PARAMETER);
     102
     103    // changed allocation V0.9.10 (2001-04-08) [umoeller]:
     104    // malloc didn't guarantee that the object did not
     105    // cross a 64K boundary, which could cause DosQProcStat
     106    // to fail...
     107    #define BUF_SIZE        0xFFFF          // raised from 0x8000
     108
     109    if (!(arc = DosAllocMem((VOID**)&pps,
     110                            BUF_SIZE,
     111                            PAG_READ | PAG_WRITE | PAG_COMMIT
     112                                | OBJ_TILE          // 16-bit compatible, ignored really
     113                           )))
     114    {
     115        if (arc = DosQProcStatus(pps, BUF_SIZE))
     116        {
     117            // error:
     118            DosFreeMem(pps);        // V0.9.10 (2001-04-08) [umoeller]
     119
     120            // and even worse, I forgot to set the return ptr
     121            // to NULL, so this was freed twice... I guess
     122            // this produced the crashes in WarpIN with the
     123            // KILLPROCESS attribute... V0.9.10 (2001-04-08) [umoeller]
     124            pps = NULL;
     125        }
     126    }
     127
     128    *ppps = pps;
     129
     130    return (arc);
    105131}
    106132
     
    110136 *
    111137 *@@added V0.9.3 (2000-05-05) [umoeller]
    112  */
    113 
    114 VOID prc16FreeInfo(PQPROCSTAT16 pInfo)
    115 {
    116     if (pInfo)
    117         free(pInfo);
     138 *@@changed V0.9.10 (2001-04-08) [umoeller]: now using DosFreeMem
     139 */
     140
     141APIRET prc16FreeInfo(PQPROCSTAT16 pInfo)
     142{
     143    if (!pInfo)
     144        return ERROR_INVALID_PARAMETER;
     145
     146    return DosFreeMem(pInfo);
    118147}
    119148
     
    476505 *@@added V0.9.1 (2000-02-12) [umoeller]
    477506 *@@changed V0.9.3 (2000-05-01) [umoeller]: now using DosAllocMem
     507 *@@changed V0.9.10 (2001-04-08) [umoeller]: fixed second QuerySysState param
    478508 */
    479509
    480510PQTOPLEVEL32 prc32GetInfo(APIRET *parc)     // out: error, ptr can be NULL
    481511{
    482     #define BUFSIZE 128000l
     512    #define BUFSIZE (256 * 1024) // 128000l
    483513    PCHAR pBuf = NULL; // (PCHAR)malloc(BUFSIZE);
    484514
     
    489519        if (pBuf)
    490520        {
    491             APIRET arc = DosQuerySysState(0x1f,
    492                                           0, 0, 0,
     521            APIRET arc = DosQuerySysState(QS32_SUPPORTED,
     522                                          QS32_SUPPORTED,       // this was missing
     523                                                                // V0.9.10 (2001-04-08) [umoeller]
     524                                          0, 0,
    493525                                          (PCHAR)pBuf,
    494526                                          BUFSIZE);
     
    528560{
    529561    PQPROCESS32 pProcThis = pInfo->pProcessData;
    530     while (pProcThis && pProcThis->rectype == 1)
     562    while (pProcThis && pProcThis->ulRecType == 1)
    531563    {
    532564        int i;
     
    561593    }
    562594
    563     if (pProcThis->rectype == 1)
     595    if (pProcThis->ulRecType == 1)
    564596        return (pProcThis);
    565597    else
     
    578610 */
    579611
    580 PQSEMA32 prc32FindSem16(PQTOPLEVEL32 pInfo,     // in: as returned by prc32GetInfo
     612PQS32SEM16 prc32FindSem16(PQTOPLEVEL32 pInfo,     // in: as returned by prc32GetInfo
    581613                          USHORT usSemID)       // in: as in QPROCESS32.pausSem16
    582614{
    583     PQSEM16STRUC32  pSemData = pInfo->pSem16Data;
    584     PQSEMA32        pSemThis = &pSemData->sema;
    585     ULONG           i = 0;
     615    PQS32SEM16HEAD      pSemHead = pInfo->pSem16Data;
     616    PQS32SEM16          // pSemThis = &pSemData->sema;
     617                        pSemThis = &pSemHead->Sem16Rec;
     618    ULONG               i = 0;
    586619
    587620    while (pSemThis)
    588621    {
    589         _Pmpf(("prc32FindSem16: found usIndex 0x%lX", pSemThis->usIndex));
    590         if (/* pSemThis->usIndex */ i == usSemID)
     622        if (i == usSemID)
    591623            return (pSemThis);
    592624
     
    610642 */
    611643
    612 PQSEM32STRUC32 prc32FindSem32(PQTOPLEVEL32 pInfo,     // in: as returned by prc32GetInfo
    613                               USHORT usSemID)         // in: as in QPROCESS32.pausSem16
     644PQS32SEM32 prc32FindSem32(PQTOPLEVEL32 pInfo,     // in: as returned by prc32GetInfo
     645                          USHORT usSemID)         // in: as in QPROCESS32.pausSem16
    614646{
    615647    // PQSEM32STRUC32  pSemThis = pInfo->pSem32Data;
     
    687719    PQFILEDATA32 pFile = pInfo->pFileData;
    688720    while (     (pFile)
    689              && (pFile->rectype == 8)  // this is necessary, we'll crash otherwise!!
     721             && (pFile->ulRecType == 8)  // this is necessary, we'll crash otherwise!!
    690722          )
    691723    {
    692             if (pFile->filedata->sfn == usFileID)
     724        ULONG ul;
     725        // for some reason, there is an array in the file struct,
     726        // so search the array for the SFN
     727        for (ul = 0;
     728             ul < pFile->ulCFiles;
     729             ul++)
     730        {
     731            if (pFile->paFiles[ul].usSFN == usFileID)
    693732                return (pFile);
     733        }
    694734
    695735        pFile = pFile->pNext;
Note: See TracChangeset for help on using the changeset viewer.