Ignore:
Timestamp:
Apr 19, 2000, 10:19:13 PM (25 years ago)
Author:
bird
Message:

Corrected flaw in FP13 DosQuerySysState.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/winimagepe2lx.cpp

    r2802 r3430  
    1 /* $Id: winimagepe2lx.cpp,v 1.8 2000-02-16 14:22:12 sandervl Exp $ */
     1/* $Id: winimagepe2lx.cpp,v 1.9 2000-04-19 20:19:13 bird Exp $ */
    22
    33/*
     
    2929#include <process.h>
    3030#include <stdlib.h>
     31#include <string.h>
    3132
    3233#include <win32type.h>
     
    3536#include <winimagepe2lx.h>
    3637
    37 #define DBG_LOCALLOG    DBG_winimagepe2lx
     38#define DBG_LOCALLOG    DBG_winimagepe2lx
    3839#include "dbglocal.h"
    3940
     
    100101   } qsLrec_t;
    101102
     103
     104
     105   /* Pointer Record Structure
     106    *      This structure is the first in the user buffer.
     107    *      It contains pointers to heads of record types that are loaded
     108    *      into the buffer.
     109    */
     110
     111   typedef struct qsPtrRec_s {   /* qsPRec */
     112           qsGrec_t        *pGlobalRec;
     113           void            *pProcRec;      /* ptr to head of process records */
     114           void            *p16SemRec;     /* ptr to head of 16 bit sem recds */
     115           void            *p32SemRec;     /* ptr to head of 32 bit sem recds */
     116           void            *pMemRec;       /* ptr to head of shared mem recs */
     117           qsLrec_t        *pLibRec;       /* ptr to head of mte records */
     118           void            *pShrMemRec;    /* ptr to head of shared mem records */
     119           void            *pFSRec;        /* ptr to head of file sys records */
     120   } qsPtrRec_t;
     121
    102122#endif
    103123
     
    310330{
    311331    APIRET rc = NO_ERROR;
    312     qsGrec_t ** pBuf;
    313     ULONG       cbBuf = 65536;
    314 
    315     pBuf = (qsGrec_t **)malloc(cbBuf);
    316     if (pBuf != NULL)
    317     {
    318         rc = DosQuerySysState(QS_MTE, QS_MTE, getpid(), 0L, pBuf, cbBuf);
     332    qsPtrRec_t *    pPtrRec;
     333    ULONG           cbBuf = 65536;
     334
     335    pPtrRec = (qsPtrRec_t *)malloc(cbBuf);
     336    if (pPtrRec != NULL)
     337    {
     338        rc = DosQuerySysState(QS_MTE, QS_MTE, getpid(), 0L, pPtrRec, cbBuf);
    319339        while (cbBuf < 1024*1024 && rc == ERROR_BUFFER_OVERFLOW)
    320340        {
    321             PVOID pv = pBuf;
     341            PVOID pv = pPtrRec;
    322342            cbBuf +=  65536;
    323             pBuf = (qsGrec_t **)realloc(pv, cbBuf);
    324             if (pBuf != NULL)
    325                 rc = DosQuerySysState(QS_MTE, QS_MTE, getpid(), 0L, pBuf, cbBuf);
     343            pPtrRec = (qsPtrRec_t *)realloc(pv, cbBuf);
     344            if (pPtrRec != NULL)
     345                rc = DosQuerySysState(QS_MTE, QS_MTE, getpid(), 0L, pPtrRec, cbBuf);
    326346            else
    327347            {
     
    333353        if (rc == NO_ERROR)
    334354        {
    335             qsGrec_t *  pGrec = *pBuf;
    336             qsLrec_t *  pLrec = (qsLrec_t * )((ULONG)pGrec + sizeof(qsGrec_t));
    337             while (pLrec != NULL && pLrec->hmte != hinstance)
     355            qsLrec_t *  pLrec = pPtrRec->pLibRec;
     356            while (pLrec != NULL)
     357            {
     358                /*
     359                 * Bug detected in OS/2 FP13. Probably a problem which occurs
     360                 * in _LDRSysMteInfo when qsCheckCache is calle before writing
     361                 * object info. The result is that the cache flushed and the
     362                 * attempt of updating the qsLrec_t next and object pointer is
     363                 * not done. This used to work earlier and on Aurora AFAIK.
     364                 *
     365                 * The fix for this problem is to check if the pObjInfo is NULL
     366                 * while the number of objects isn't 0 and correct this. pNextRec
     367                 * will also be NULL at this time. This will be have to corrected
     368                 * before we exit the loop or moves to the next record.
     369                 * There is also a nasty alignment of the object info... Hope
     370                 * I got it right. (This aligment seems new to FP13.)
     371                 */
     372                if (pLrec->pObjInfo == NULL /*&& pLrec->pNextRec == NULL*/ && pLrec->ctObj > 0)
     373                    {
     374                    pLrec->pObjInfo = (qsLObjrec_t*)(
     375                        (char*)pLrec
     376                        + ((sizeof(qsLrec_t)                     /* size of the lib record */
     377                           + pLrec->ctImpMod * sizeof(short)    /* size of the array of imported modules */
     378                           + strlen((char*)pLrec->pName) + 1    /* size of the filename */
     379                           + 3) & ~3));                          /* the size is align on 4 bytes boundrary */
     380                    pLrec->pNextRec = (qsLrec_t*)((char*)pLrec->pObjInfo
     381                                                   + sizeof(qsLObjrec_t) * pLrec->ctObj);
     382                    }
     383                if (pLrec->hmte == hinstance)
     384                    break;
     385
     386                /*
     387                 * Next record
     388                 */
    338389                pLrec = (qsLrec_t*)pLrec->pNextRec;
     390            }
     391
    339392
    340393            if (pLrec)
     
    370423            dprintf(("DosQuerySysState - failed with rc=%d (cbBuf=%d)\n", rc, cbBuf));
    371424
    372         if (pBuf != NULL)
    373             free(pBuf);
     425        if (pPtrRec != NULL)
     426            free(pPtrRec);
    374427    }
    375428    else
Note: See TracChangeset for help on using the changeset viewer.