Changeset 193 for trunk/nom/src/nomgc.c


Ignore:
Timestamp:
Jan 16, 2007, 8:31:25 PM (19 years ago)
Author:
cinc
Message:

Improvements to the GC interface and some more stuff

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/nom/src/nomgc.c

    r160 r193  
    5454#include <gc.h>
    5555
    56 gboolean bUseGC=FALSE; /* MArk if we use the garbage collector */
     56gboolean bUseGC=FALSE; /* Mark if we use the garbage collector */
    5757
    5858static gpointer  gcMalloc(gulong ulBytes)
     
    9494
    9595 g_mem_set_vtable(&vtbl);
    96  fprintf(stderr, "   GC memory functions set for GLIB. (%s: %d)\n", __FILE__, __LINE__);
     96 /* fprintf(stderr, "   GC memory functions set for GLIB. (%s: %d)\n", __FILE__, __LINE__); */
    9797
    9898 bUseGC=TRUE;
     
    104104}
    105105
     106static void qsAddDLLToList(HREGDLL hReg, qsLrec_t* rec)
     107{
     108  if(NULLHANDLE==g_slist_find(hReg->dllList, rec))
     109    hReg->dllList=g_slist_append(hReg->dllList, rec);
     110}
     111
     112#if 0
     113static void qsPrintDLLList(HREGDLL hReg)
     114{
     115  GSList* lTemp;
     116  int a=0;
     117 
     118  lTemp=hReg->dllList;
     119  while(lTemp)
     120    {
     121      qsLrec_t* rec;
     122      rec=(qsLrec_t*)lTemp->data;
     123      a++;
     124      g_message("  %d: %s", a, rec->pName);
     125      lTemp=g_slist_next(lTemp);
     126    }
     127}
     128#endif
    106129
    107130/*
    108131  Find a library record in the buffer filled by DosQuerySysState().
    109132 */
    110 static qsLrec_t* qsFindModuleRec(const HREGDLL hRegisterDLL,  USHORT hMod){
     133static qsLrec_t* qsFindModuleRec(const qsPtrRec_t * hRegisterDLL,  USHORT hMod){
    111134  qsLrec_t *       pModRec;
    112135  int a=0;
     
    116139    {
    117140      a++;
    118       //            printf("%d Checking: %x -> %04X (%s)\n", a, pModRec, pModRec->hmte, pModRec->pName);
     141      /* printf("%d Checking: %x -> %04X (%s)\n", a, pModRec, pModRec->hmte, pModRec->pName); */
    119142
    120143      if (NULLHANDLE==pModRec->pObjInfo   && pModRec->ctObj > 0)
     
    133156      pModRec=(qsLrec_t *)pModRec->pNextRec;
    134157    }
     158
    135159  return pModRec;
    136160}
    137161
    138 
     162#define BUFSIZE 1024*1024
     163NOMEXTERN HREGDLL NOMLINK nomBeginRegisterDLLWithGC(void)
     164{
     165  ULONG rc;
     166  HREGDLL hReg=NULLHANDLE;
     167  PTIB     ptib;
     168  PPIB     ppib;
     169  char *  buf;
     170  HREGDLL  pRegDLL=NULLHANDLE;
     171
     172  rc = DosGetInfoBlocks(&ptib, &ppib);
     173  if (rc!=NO_ERROR)
     174    return NULLHANDLE;
     175
     176  buf = malloc(BUFSIZE);
     177  if(!buf)
     178    return NULLHANDLE;
     179
     180  pRegDLL =(HREGDLL) malloc(sizeof(REGDLL));
     181  if(!pRegDLL){
     182    free(buf);
     183    return NULLHANDLE;
     184  }
     185  pRegDLL->dllList=NULLHANDLE;
     186
     187  memset(buf,0,BUFSIZE);
     188
     189  rc = DosQuerySysState(QS_PROCESS | QS_SEMAPHORE | QS_MTE | QS_FILESYS | QS_SHMEMORY ,
     190                        QS_MTE, /*0x96*/ ppib->pib_ulpid , 1UL, (PCHAR)buf, BUFSIZE);
     191  if (rc==NO_ERROR) {
     192    qsPrec_t * p;
     193    GSList* lTemp;
     194
     195    pRegDLL->pMainAnchor=(qsPtrRec_t*) buf;
     196
     197    p=pRegDLL->pMainAnchor->pProcRec;
     198
     199    while(p && p->RecType == 1)
     200      {
     201
     202        if (p->cLib) {
     203          int i;
     204
     205          for (i=0; i<p->cLib; i++){
     206            qsLrec_t * pModRec;
     207
     208            pModRec=qsFindModuleRec(pRegDLL->pMainAnchor,  p->pLibRec[i]);
     209
     210            if(pModRec){
     211              //if(pModRec->pName)
     212              //g_message("%s", pModRec->pName);
     213              qsAddDLLToList(pRegDLL, pModRec);
     214            }
     215          }/* for() */
     216        }/* if(p->clib) */
     217        break;
     218      };/* while() */
     219
     220    /* Ok, got directly imported DLLs. Now go over these and check them for additional imports.
     221       Every import is added to the end of the list (except duplicates). So while going over
     222       the list we touch every DLL and check every import. Import cycles are no problem, because
     223       later duplicates are ignored. */
     224    lTemp=pRegDLL->dllList;
     225    while(lTemp)
     226      {
     227        qsLrec_t* rec;
     228
     229        rec=(qsLrec_t*)lTemp->data;
     230
     231        /* Check the imports of this DLL if any */
     232        if(rec->ctImpMod >0)
     233          {
     234            int iImps;
     235            PUSHORT   pImpHmte;
     236
     237            pImpHmte=(PUSHORT)((void*)rec + sizeof(qsLrec_t));
     238            for(iImps=0; iImps < rec->ctImpMod; iImps++)
     239              {
     240                qsLrec_t * pModImp;
     241               
     242                pModImp=qsFindModuleRec(pRegDLL->pMainAnchor,  pImpHmte[iImps]);
     243                if(pModImp)
     244                  qsAddDLLToList(pRegDLL, pModImp);
     245              }/* for()*/
     246          }/* if() */
     247        lTemp=g_slist_next(lTemp);
     248      };/* while() */
     249    //qsPrintDLLList();
     250    hReg=pRegDLL;
     251  }
     252  else{
     253    free(pRegDLL);
     254    free(buf);
     255  }
     256  return hReg;
     257}
     258
     259NOMEXTERN void NOMLINK nomEndRegisterDLLWithGC(const HREGDLL hRegisterDLL )
     260{
     261  g_slist_free(hRegisterDLL->dllList);
     262  free((char*)hRegisterDLL->pMainAnchor);
     263  free((char*)hRegisterDLL);
     264}
     265
     266#define OBJREAD         0x0001L
     267#define OBJWRITE        0x0002L
     268#define OBJINVALID      0x0080L
     269NOMEXTERN BOOL NOMLINK nomRegisterDLLByName(const HREGDLL hRegisterDLL, const char* chrDLLName)
     270{
     271  GSList* lTemp;
     272
     273  //printf("Trying to register DLL %s\n", chrDLLName);
     274  lTemp=hRegisterDLL->dllList;
     275  while(lTemp)
     276    {
     277      qsLrec_t* pModRec;
     278     
     279      pModRec=(qsLrec_t*)lTemp->data;
     280      if(pModRec){
     281            //  printf("DLL name: %s\n", pModRec->pName);
     282        if(pModRec->pName && (NULLHANDLE!=strstr( pModRec->pName, chrDLLName)))
     283          {
     284            qsLObjrec_t  *pObjInfo;
     285            //g_message("    --> Found DLL %s", pModRec->pName);
     286            pObjInfo=pModRec->pObjInfo;
     287            if(NULLHANDLE!=pObjInfo)
     288              {
     289                int iObj;
     290                for(iObj=0; iObj<pModRec->ctObj ;iObj++)
     291                  {
     292                    if (!(pObjInfo[iObj].oflags & OBJWRITE)) continue;
     293                    if (!(pObjInfo[iObj].oflags & OBJREAD)) continue;
     294                    if ((pObjInfo[iObj].oflags & OBJINVALID)) continue;
     295                    //g_message("    #%d: %04lX, size: %04lX %04lX",
     296                    //        iObj, pObjInfo[iObj].oaddr, pObjInfo[iObj].osize, pObjInfo[iObj].oflags);
     297                    nomRegisterDataAreaForGC((char*)pObjInfo[iObj].oaddr,
     298                                             (char*)(pObjInfo[iObj].oaddr+pObjInfo[iObj].osize));
     299                  }
     300              }
     301            return TRUE;
     302          }
     303      }         
     304      lTemp=g_slist_next(lTemp);
     305    };/* while() */
     306    return FALSE;
     307}
     308
     309#if 0
    139310#define BUFSIZE 1024*1024
    140311NOMEXTERN HREGDLL NOMLINK nomBeginRegisterDLLWithGC(void)
     
    166337  return hReg;
    167338}
    168 
    169 NOMEXTERN void NOMLINK nomEndRegisterDLLWithGC(const HREGDLL hRegisterDLL )
    170 {
    171   free((char*)hRegisterDLL);
    172 }
    173 
    174 
    175339/*
    176340  FIXME:
     
    194358  int a=0;
    195359
    196   printf("Trying to register DLL %s\n", chrDLLName);
     360  //printf("Trying to register DLL %s\n", chrDLLName);
    197361
    198362  p=hRegisterDLL->pProcRec;
     
    214378              {
    215379                qsLObjrec_t  *pObjInfo;
    216                 printf("    --> Found DLL %s\n", pModRec->pName);
     380                //printf("    --> Found DLL %s\n", pModRec->pName);
    217381                pObjInfo=pModRec->pObjInfo;
    218382                if(NULLHANDLE!=pObjInfo)
     
    224388                        if (!(pObjInfo[iObj].oflags & OBJREAD)) continue;
    225389                        if ((pObjInfo[iObj].oflags & OBJINVALID)) continue;
    226                         printf("    #%d: %04lX, size: %04lX %04lX\n",
     390                        printf("    #%d: %04lX, size: %04lX %04lX",
    227391                               iObj, pObjInfo[iObj].oaddr, pObjInfo[iObj].osize, pObjInfo[iObj].oflags);
    228392                        nomRegisterDataAreaForGC((char*)pObjInfo[iObj].oaddr,
    229393                                                 (char*)(pObjInfo[iObj].oaddr+pObjInfo[iObj].osize));
    230 
    231394                      }
    232395                  }
     
    251414                        {
    252415                          qsLObjrec_t  *pObjInfo;
    253                           printf("    --> Found DLL %s\n", pModImp->pName);
     416                          //printf("    --> Found DLL %s\n", pModImp->pName);
    254417                          pObjInfo=pModImp->pObjInfo;
    255418                          if(NULLHANDLE!=pObjInfo)
     
    262425                                  if ((pObjInfo[iObj].oflags & OBJINVALID)) continue;
    263426                                 
    264                                   printf("    #%d: %04lX, size: %04lX %04lX\n",
    265                                          iObj, pObjInfo[iObj].oaddr, pObjInfo[iObj].osize, pObjInfo[iObj].oflags);
     427                                  //printf("    #%d: %04lX, size: %04lX %04lX\n",
     428                                  //     iObj, pObjInfo[iObj].oaddr, pObjInfo[iObj].osize, pObjInfo[iObj].oflags);
    266429                                  nomRegisterDataAreaForGC((char*)pObjInfo[iObj].oaddr,
    267430                                                           (char*)(pObjInfo[iObj].oaddr+pObjInfo[iObj].osize));
     
    280443  return FALSE;
    281444}
     445#endif
Note: See TracChangeset for help on using the changeset viewer.