Esempio n. 1
0
extern void DumpMem( void )
/*************************/
{
    unsigned int            curr_addr;
    unsigned int            total;
    unsigned int            start_size;
    int                     loc_size;
    int                     loc_count;
    int                     heap_status;
    char                    loc_mark;
    struct _heapinfo        h_info;

    if( !WalkMem() ) return;
    h_info._pentry = NULL;
    start_size = 0;
    total = 0;
    for( ;; ) {
        heap_status = _heapwalk( &h_info );
        if( heap_status != _HEAPOK ) break;
        if( start_size == 0 ) {
            start_size = (char __far *)h_info._pentry - (char __far *)0;
        }
        printf( "  %s block at %Fp of size %4.4X-%d\n",
                  (h_info._useflag == _USEDENTRY ? "USED" : "FREE"),
                  h_info._pentry, h_info._size, h_info._size );
        total += h_info._size;
    }
    loc_count = 60;
    h_info._pentry = NULL;
    for( ;; ) {
        heap_status = _heapwalk( &h_info );
        if( heap_status != _HEAPOK ) break;
        if( h_info._useflag == _USEDENTRY ) {
            loc_mark = 254;
        } else {
            loc_mark = 249;
        }
        curr_addr = (char __far *)h_info._pentry - (char __far *)0;
        loc_size = h_info._size;
        for( ;; ) {
            if( loc_count == 60 ) {
                printf( "\n%.4x: ", curr_addr );
                loc_count = 0;
            }
            printf( "%c", loc_mark );
            loc_count++;
            curr_addr += LOCSIZE;
            loc_size -= LOCSIZE;
            if( loc_size <= 0 ) break;
        }
    }
    printf( "\n\nStarting size   = %u\n", start_size );
    printf( "New allocations = %u\n", total );
    printf( "Ending address  = %u\n", start_size+total );
}
Esempio n. 2
0
void heap_dump()
{
    struct _heapinfo h_info;
    int heap_status;

    h_info._pentry = NULL;
    for(;;) {
      heap_status = _heapwalk( &h_info );
      if( heap_status != _HEAPOK ) break;
      printf( "  %s block at %Fp of size %4.4X\n",
        (h_info._useflag == _USEDENTRY ? "USED" : "FREE"),
        h_info._pentry, h_info._size );
    }

    switch( heap_status ) {
    case _HEAPEND:
      printf( "OK - end of heap\n" );
      break;
    case _HEAPEMPTY:
      printf( "OK - heap is empty\n" );
      break;
    case _HEAPBADBEGIN:
      printf( "ERROR - heap is damaged\n" );
      break;
    case _HEAPBADPTR:
      printf( "ERROR - bad pointer to heap\n" );
      break;
    case _HEAPBADNODE:
      printf( "ERROR - bad node in heap\n" );
    }
}
Esempio n. 3
0
void heapdump( void )
{
    _HEAPINFO hinfo;
    int heapstatus;
    hinfo._pentry = NULL;
    while( ( heapstatus = _heapwalk( &hinfo ) ) == _HEAPOK ) {
        printf( "%6s block at %Fp of size %4.4X\n",
                ( hinfo._useflag == _USEDENTRY ? "USED" : "FREE" ),
                hinfo._pentry, hinfo._size );
    }

    switch( heapstatus ) {
    case _HEAPEMPTY:
        printf( "OK - empty heap\n" );
        break;
    case _HEAPEND:
        printf( "OK - end of heap\n" );
        break;
    case _HEAPBADPTR:
        printf( "ERROR - bad pointer to heap\n" );
        break;
    case _HEAPBADBEGIN:
        printf( "ERROR - bad start of heap\n" );
        break;
    case _HEAPBADNODE:
        printf( "ERROR - bad node in heap\n" );
        break;
    }
}
Esempio n. 4
0
  int heap_count( )
  {
    int used_size = 0;
    struct _heapinfo info;

    info._pentry = NULL;
    if( _heapwalk( &info ) != _HEAPOK )
      return( 0 );
    info._pentry = NULL;
    while( _heapwalk( &info ) != _HEAPEND ) {
      if( info._useflag == _USEDENTRY ) {
        used_size += info._size;
      }
    }
    return( used_size );
  }
Esempio n. 5
0
  void heap_dump()
  {
    struct _heapinfo h_info;
    int heap_status;

    h_info._pentry = NULL;
    for(;;) {
        heap_status = _heapwalk( &h_info );
        if( heap_status != _HEAPOK ) break;
        std::cout << (h_info._useflag == _USEDENTRY ? "USED" : "FREE")<<
            " block at " << reinterpret_cast<int>(h_info._pentry) <<
            " of size " << h_info._size << "\n" ;
    }

    switch( heap_status ) {
    case _HEAPEND:
      std::cout << "OK - end of heap\n" ;
      break;
    case _HEAPEMPTY:
      std::cout << "OK - heap is empty\n" ;
      break;
    case _HEAPBADBEGIN:
      std::cout << "ERROR - heap is damaged\n" ;
      break;
    case _HEAPBADPTR:
      std::cout << "ERROR - bad pointer to heap\n" ;
      break;
    case _HEAPBADNODE:
      std::cout << "ERROR - bad node in heap\n" ;
      break;
    default:
      std::cout << "unexpected!\n";
    }
  }
Esempio n. 6
0
void dumpheap( void )
{
#if 0
    struct _heapinfo h;
    int         status;

    h._pentry = NULL;
    for( ;; ) {
        status = _heapwalk( &h );
        if( status != _HEAPOK )
            break;
        printf( "%s block at %Fp of size %4.4X\r\n",
                (h._useflag == _USEDENTRY ? "USED": "FREE"),
                h._pentry, h._size );
    }
    switch( status ) {
    case _HEAPEND:
        printf( "OK - end of heap\r\n" );
        break;
    case _HEAPEMPTY:
        printf( "OK - heap is empty\r\n" );
        break;
    case _HEAPBADBEGIN:
        printf( "ERROR - heap is damaged\r\n" );
        break;
    case _HEAPBADPTR:
        printf( "ERROR - bad pointer to heap\r\n" );
        break;
    case _HEAPBADNODE:
        printf( "ERROR - bad node in heap\r\n" );
        break;
    }
#endif
}
Esempio n. 7
0
size_t xrMemory::mem_usage()
{
    _HEAPINFO hinfo = {};
    int status;
    size_t bytesUsed = 0;
    while ((status = _heapwalk(&hinfo)) == _HEAPOK)
    {
        if (hinfo._useflag == _USEDENTRY)
            bytesUsed += hinfo._size;
    }
    switch (status)
    {
    case _HEAPEMPTY:
        break;
    case _HEAPEND:
        break;
    case _HEAPBADPTR:
        FATAL("bad pointer to heap");
        break;
    case _HEAPBADBEGIN:
        FATAL("bad start of heap");
        break;
    case _HEAPBADNODE:
        FATAL("bad node in heap");
        break;
    }
    return bytesUsed;
}
Esempio n. 8
0
static void heap_dump( void ){
    struct _heapinfo h_info;
    int heap_status;
    h_info._pentry = NULL;
    for(;;){
        heap_status = _heapwalk( &h_info );
        if( heap_status != _HEAPOK )break;
        printf( " %s block at %Fp of size %4.4X\n",
        (h_info._useflag == _USEDENTRY ? "USED" : "FREE" ),
        h_info._pentry, h_info._size );
    }
    switch( heap_status ){
    case _HEAPEND:
        printf( "end of heap\n" );
        break;
    case _HEAPEMPTY:
        printf( "heap empty\n" );
        break;
    case _HEAPBADBEGIN:
        printf( "heap hurt\n" );
        break;
    case _HEAPBADPTR:
        printf( "bad heap ptr\n" );
        break;
    case _HEAPBADNODE:
        printf( "bad heap node\n" );
        break;
    }
}
Esempio n. 9
0
extern int WalkMem( void ) 
/************************/
{
    char                    * str;
    int                     heap_status;
    struct _heapinfo        h_info;

    h_info._pentry = NULL;
    for( ;; ) {
        heap_status = _heapwalk( &h_info );
        if( heap_status != _HEAPOK ) {
            if( heap_status == _HEAPBADBEGIN ) {
                str = "ERROR - heap is damaged";
            } else if( heap_status == _HEAPBADPTR ) {
                str = "ERROR - bad pointer to heap";
            } else if( heap_status == _HEAPBADNODE ) {
                str = "ERROR - bad node in heap";
            } else {
                break;
            }
            printf( "%s\n\n", str );
            return( FALSE );
        }
    }
    return( TRUE );
}
Esempio n. 10
0
void DbgHeapFini                // COMPLETION
    ( void )
{
#if 0
    unsigned count;             // - # of entries
    _HEAPINFO hi;               // - heap information
    ALLOCED* ae;                // - allocated entry

    hi._pentry = NULL;
    count = 0;
    for( ; ; ) {
        switch( _heapwalk( &hi ) ) {
          case _HEAPEND :
          case _HEAPEMPTY :
            break;
          case _HEAPOK :
            if( hi._useflag ) {
                unsigned dec;
                for( ae = entries, dec = entry_count; ; --dec, ++ae ) {
                    if( dec == 0 ) {
                        printf( "DbgHeapFini -- unfreed entry %p size %x\n"
                              , hi._pentry
                              , hi._size );
                        break;
                    }
                    if( hi._pentry == ae->_pentry ) {
                        ++ count;
                        break;
                    }
                }
            }
            continue;
          case _HEAPBADBEGIN :
            puts( "DbgHeapFini -- BAD BEGIN" );
            abort();
          case _HEAPBADPTR :
            puts( "DbgHeapFini -- BAD PTR" );
            abort();
          case _HEAPBADNODE :
            puts( "DbgHeapFini -- BAD NODE" );
            abort();
        }
        break;
    }
    if( count != entry_count ) {
        puts( "DbgHeapFini -- freed entries since DbgHeapInit" );
    }
    if( NULL != entries ) {
        free( entries );
    }
#endif
}
Esempio n. 11
0
void PrintAllocationData()
{
#ifdef _WIN32
  _HEAPINFO hinfo;
  int heapstatus;
  hinfo._pentry = NULL;
  size_t blocks_used = 0, bytes_used = 0, blocks_free = 0, bytes_free = 0;
  while ( ( heapstatus = _heapwalk( &hinfo ) ) == _HEAPOK )
  {
    if ( hinfo._useflag == _USEDENTRY )
    {
      ++blocks_used;
      bytes_used += hinfo._size;
    }
    else
    {
      ++blocks_free;
      bytes_free += hinfo._size;
    }
  }
  fmt::Writer _tmp;
  _tmp.Format( "Heap:  Used {} blocks, {} bytes, Free {} blocks, {} bytes\n" )
      << blocks_used << bytes_used << blocks_free << bytes_free;
  _tmp.Format( "Delta: Used {} blocks, {} bytes, Free {} blocks, {} bytes\n" )
      << ( blocks_used - last_blocks_used ) << ( bytes_used - last_bytes_used )
      << ( blocks_free - last_blocks_free ) << ( bytes_free - last_bytes_free );
  last_blocks_used = blocks_used;
  last_bytes_used = bytes_used;
  last_blocks_free = blocks_free;
  last_bytes_free = bytes_free;

  switch ( heapstatus )
  {
  case _HEAPEMPTY:
    _tmp << "OK - empty heap\n";
    break;
  case _HEAPEND:
    _tmp << "OK - end of heap\n";
    break;
  case _HEAPBADPTR:
    _tmp << "ERROR - bad pointer to heap\n";
    break;
  case _HEAPBADBEGIN:
    _tmp << "ERROR - bad start of heap\n";
    break;
  case _HEAPBADNODE:
    _tmp << "ERROR - bad node in heap\n";
    break;
  }
  INFO_PRINT << _tmp.str();
#endif
}
Esempio n. 12
0
/*********************************************************************
 *		_heapset (MSVCRT.@)
 */
int CDECL _heapset(unsigned int value)
{
  int retval;
  _HEAPINFO heap;

  memset( &heap, 0, sizeof(heap) );
  LOCK_HEAP;
  while ((retval = _heapwalk(&heap)) == _HEAPOK)
  {
    if (heap._useflag == _FREEENTRY)
      memset(heap._pentry, value, heap._size);
  }
  UNLOCK_HEAP;
  return retval == _HEAPEND? _HEAPOK : retval;
}
Esempio n. 13
0
/*********************************************************************
 *		_heapset (MSVCRT.@)
 */
int CDECL _heapset(unsigned int value)
{
  int retval;
  struct MSVCRT__heapinfo heap;

  memset( &heap, 0, sizeof(heap) );
  LOCK_HEAP;
  while ((retval = _heapwalk(&heap)) == MSVCRT__HEAPOK)
  {
    if (heap._useflag == MSVCRT__FREEENTRY)
      memset(heap._pentry, value, heap._size);
  }
  UNLOCK_HEAP;
  return retval == MSVCRT__HEAPEND? MSVCRT__HEAPOK : retval;
}
Esempio n. 14
0
static int heap_size( struct heap_stat *stat ) {
    struct _heapinfo h_info;
    int heap_status;
    h_info._pentry = NULL;
    stat->free = 0;
    stat->used = 0;
    for( ; (heap_status = _heapwalk( &h_info )) == _HEAPOK; ) {
        if( h_info._useflag == _USEDENTRY ) {
            stat->used += h_info._size;
        } else {
            stat->free += h_info._size;
        }
    }
    return( heap_status );
}
Esempio n. 15
0
static int heap_size( struct heap_stat *stat ){
    struct _heapinfo h_info;
    int heap_status;
    h_info._pentry = NULL;
    stat->free = 0;
    stat->used = 0;
    for(;;){
        heap_status = _heapwalk( &h_info );
        if( heap_status != _HEAPOK )break;
        if( h_info._useflag ){
            stat->used += h_info._size;
        }else{
            stat->free += h_info._size;
        }
    }
    return( heap_status );
}
Esempio n. 16
0
void MemFini( void )
{
#ifdef TRMEM
    MemTrackFini();
#elif defined( __WATCOMC__ )

    struct _heapinfo    h_info;
    int                 status;
    char                buf[50];
    char                *end;

    if( getenv( "TRMEMFILE" ) == NULL )
        return;
    h_info._pentry = NULL;
    for( ;; ) {
        status = _heapwalk( &h_info );
        if( status != _HEAPOK )
            break;
#ifndef NDEBUG
        if( h_info._useflag == _USEDENTRY ) {
            end = Format( buf, "%s block",
                h_info._useflag == _USEDENTRY ? "Used" : "Free" );
            WriteText( STD_OUT, buf, end - buf );
        }
#endif
    }
    switch( status ) {
    case _HEAPBADBEGIN:
        end = Format( buf, Heap_Corupt, "bad header info" );
        WriteText( STD_OUT, buf, end - buf );
        break;
    case _HEAPBADPTR:
        end = Format( buf, Heap_Corupt, "bad pointer" );
        WriteText( STD_OUT, buf, end - buf );
        break;
    case _HEAPBADNODE:
        end = Format( buf, Heap_Corupt, "bad node" );
        WriteText( STD_OUT, buf, end - buf );
        break;
    default:
        break;
    }
#endif
}
Esempio n. 17
0
void *HeapWalker( void )
{
    struct _heapinfo    info;
    int                 status;
    char                buffer[80];

    info._pentry = NULL;
    status = _HEAPOK;
    while( status != _HEAPEND ) {
        status = _heapwalk( &info );
        sprintf( buffer, "%s black at %Fp of size %4.4X\n",
                (info._useflag == _USEDENTRY) ? "USED" : "FREE",
                info._pentry, info._size );
        if( status != _HEAPOK ) {
            return( info._pentry );
        }
    }
    return( NULL );
}
Esempio n. 18
0
static void heapdump()
{
   _HEAPINFO   hinfo;
   int         heapstatus;
   DWORD       used  = 0;
   DWORD       avail = 0;
   char        report[256];

   hinfo._pentry = NULL;
   while ((heapstatus = _heapwalk( &hinfo )) == _HEAPOK) { 
      sprintf_s(report, "%6s block at %Fp of size %4.4X\n",
               ( hinfo._useflag == _USEDENTRY ? "USED" : "FREE" ),
                 hinfo._pentry, hinfo._size);

      _RPT0(_CRT_WARN, report);

      if (hinfo._useflag == _USEDENTRY)
         used  += hinfo._size;
      else
         avail += hinfo._size;
   }

   sprintf_s(report, "------\nUsed Blocks:  %d\nAvail Blocks: %d\nTotal Blocks: %d\n", used, avail, used+avail);
   _RPT0(_CRT_WARN, report);

   switch (heapstatus) {
   case _HEAPEMPTY:
      _RPT0(_CRT_WARN,  "OK - empty heap\n" );
      break;
   case _HEAPEND:
      _RPT0(_CRT_WARN,  "OK - end of heap\n" );
      break;
   case _HEAPBADPTR:
      _RPT0(_CRT_WARN,  "ERROR - bad pointer to heap\n" );
      break;
   case _HEAPBADBEGIN:
      _RPT0(_CRT_WARN,  "ERROR - bad start of heap\n" );
      break;
   case _HEAPBADNODE:
      _RPT0(_CRT_WARN,  "ERROR - bad node in heap\n" );
      break;
   }
}
Esempio n. 19
0
// ================================================================================================
// FUNCTION  : wiMemory_RecordHeap()
// ------------------------------------------------------------------------------------------------
// ================================================================================================
wiStatus wiMemory_RecordHeap(void)
{
#ifdef WIN32

    char filename[256]; FILE *F;
	int heapstatus, numLoops = 0;
	_HEAPINFO hinfo;

    STATUS(wiProcess_WaitForMutex(&TraceMemoryMutex));
    
	sprintf(filename, "HeapImage%u.txt",wiProcess_ThreadIndex());
	printf("filename = %s\n",filename);

    F = fopen(filename, "wt");
	if (!F) return STATUS(WI_ERROR);

	heapstatus = _heapchk();
	fprintf(F,"wiMemory_RecordHeap()\n");
	fprintf(F,"_HEAP_MAXREQ = %u\n",_HEAP_MAXREQ);
	fprintf(F,"heapstatus = %d (OK=%d, EMPTY=%d, BAD START=%d, BAD NODE = %d)\n",heapstatus, _HEAPOK, _HEAPEMPTY, _HEAPBADBEGIN, _HEAPBADNODE);

	hinfo._pentry = NULL;
	while((heapstatus = _heapwalk(&hinfo)) == _HEAPOK)
	{
		fprintf(F,"%6s block at %Fp of size %4.4X\n",
				(hinfo._useflag == _USEDENTRY ? "USED" : "FREE"), hinfo._pentry, hinfo._size);
		numLoops++;
	}
	switch(heapstatus)
	{
	    case _HEAPEMPTY   : fprintf(F,"OK - empty heap\n");             break;
	    case _HEAPEND     : fprintf(F,"OK - end of heap\n");            break;
	    case _HEAPBADPTR  : fprintf(F,"ERROR - bad pointer to heap\n"); break;
	    case _HEAPBADBEGIN: fprintf(F,"ERROR - bad start of heap\n");   break;
	    case _HEAPBADNODE : fprintf(F,"ERROR - bad node in heap\n");    break;
	}
	fclose(F);

    STATUS(wiProcess_ReleaseMutex(&TraceMemoryMutex));
#endif
    return WI_SUCCESS;
}
Esempio n. 20
0
jlib_decl void PrintMemoryStatusLog()
{
#ifdef _WIN32
    MEMORYSTATUS mS;
    GlobalMemoryStatus(&mS);
    LOG(MCdebugInfo, unknownJob, "Available Physical Memory = %dK", (unsigned)(mS.dwAvailPhys/1024));
#ifdef FRAGMENTATION_CHECK
    // see if fragmented
    size32_t sz = MAX_TRY_SIZE;
    while (sz) {
        if (sz<mS.dwAvailPhys/4) {
            void *p=malloc(sz);
            if (p) {
                free(p);
                break;
            }
        }
        sz /= 2;
    }
    sz *= 2;
    if ((sz<MAX_TRY_SIZE)&&(sz<mS.dwAvailPhys/4)) {
        LOG(MCdebugInfo, unknownJob, "WARNING: Could not allocate block size %d", sz);
       _HEAPINFO hinfo;
       int heapstatus;
       hinfo._pentry = NULL;
       size32_t max=0;
       unsigned fragments=0;
       while( ( heapstatus = _heapwalk( &hinfo ) ) == _HEAPOK ) { 
           if (hinfo._useflag != _USEDENTRY) {
                if (hinfo._size>max)
                    max = hinfo._size;
                fragments++;
           }
       }
       LOG(MCdebugInfo, unknownJob, "Largest unused fragment = %d", max);
       LOG(MCdebugInfo, unknownJob, "Number of fragments = %d", fragments);
    }
#endif
#endif
}
Esempio n. 21
0
void __CommonTerm( void )
{
    struct _heapinfo    hinfo;
    void _WCNEAR        *moffs;

    /* Run the normal termination first. */
    (*__int23_exit)();
    __FiniRtns( FINI_PRIORITY_EXIT, 255 );
    (*__int23_exit)();
    __FiniRtns( 0, FINI_PRIORITY_EXIT-1 );
    /* Now try to free "forgotten" memory. */
    hinfo._pentry = NULL;
    for( ;; ) {
        if( _heapwalk( &hinfo ) != _HEAPOK )
            break;
        if( hinfo._useflag ) {
            moffs = (void _WCNEAR *)FP_OFF( hinfo._pentry );
            free( (char *)moffs + sizeof( void * ) );
        }
    }
    /* Return freed memory back to the OS. */
    _heapshrink();
}
Esempio n. 22
0
void NEAR
heapdump(char *file, int line)
{
    struct _heapinfo h, prev;
    int status;

    h._pentry = NULL;
    prev = h;

    printf("heapdump at %s(%d): ", file, line);

    while((status = _heapwalk(&h)) == _HEAPOK) {
	if (fDebug)
	    printf("%6s block at %p of size %4.4X\n",
		   (h._useflag == _USEDENTRY) ? "USED" : "FREE",
		   h._pentry,
		   h._size);
	if (!h._size)
	    if (h._useflag == _USEDENTRY)
		printf("**** Error, Block of size 0 in use at %p ***\n",
		       h._pentry);
	    else if (fDebug)
		printf("** Plausible error, free block of size 0 at %p **\n",
		       h._pentry);
	prev = h;
    }
    switch (status) {
	case _HEAPEMPTY:  printf("OK - empty heap\n\n");     break;
	case _HEAPEND:		    printf("OK - end of heap\n\n");	break;
	case _HEAPBADBEGIN: printf("ERROR - bad pointer to heap at %p\n\n",
				   h._pentry);	break;
	case _HEAPBADNODE:  printf("ERROR - bad node in heap at %p\n\n",
				   h._pentry);	break;
    }
    fflush(stdout);
}
Esempio n. 23
0
    unsigned cdecl coreleft(void)
    {
      #ifdef __WATCOMC__

        struct _heapinfo entry;
        unsigned left;

        left=0;
        entry._pentry=NULL;

        while (1)
        {
          if (_heapwalk(&entry) != _HEAPOK)
            break;

          if (entry._useflag==_FREEENTRY)
            left += entry._size;
        }

        return (left);
      #else
        return (_memavl());
      #endif
    }
Esempio n. 24
0
int
_cdecl
main()
{
    struct _heapinfo info;
    PROCESS_HEAP_ENTRY Entry;
    size_t i;
    LPBYTE s;

    info._pentry = NULL;
    setvbuf( stdout, MyBuffer, _IOFBF, sizeof( MyBuffer ) );
    _heapset( 0xAE );
    while (_heapwalk( &info ) == _HEAPOK) {
        printf( "%08x: %05x - %s", info._pentry, info._size, info._useflag ? "busy" : "free" );
        if (info._useflag == _FREEENTRY) {
            s = (LPBYTE)info._pentry;
            for (i=0; i<info._size; i++) {
                if (s[i] != 0xAE) {
                    printf( " *** free block invalid at offset %x [%x]", i, s[i] );
                    break;
                    }
                }
            }

        printf( "\n" );
        fflush( stdout );
        }
    printf( "*** end of heap ***\n\n" );
    fflush( stdout );

    NumberOfHeaps = GetProcessHeaps( 64, ProcessHeaps );
    Entry.lpData = NULL;
    for (i=0; i<NumberOfHeaps; i++) {
        printf( "Heap[ %u ]: %x  HeapCompact result: %lx\n",
                i,
                ProcessHeaps[ i ],
                HeapCompact( ProcessHeaps[ i ], 0 )
              );
        while (HeapWalk( ProcessHeaps[ i ], &Entry )) {
            if (Entry.wFlags & PROCESS_HEAP_REGION) {
                printf( "    %08x: %08x - Region(First: %08x  Last: %08x  Committed: %x  Uncommitted: %08x)\n",
                        Entry.lpData, Entry.cbData,
                        Entry.Region.lpFirstBlock,
                        Entry.Region.lpLastBlock,
                        Entry.Region.dwCommittedSize,
                        Entry.Region.dwUnCommittedSize
                      );
                }
            else
            if (Entry.wFlags & PROCESS_HEAP_UNCOMMITTED_RANGE) {
                printf( "    %08x: %08x - Uncommitted\n",
                        Entry.lpData, Entry.cbData
                      );
                }
            else
            if (Entry.wFlags & PROCESS_HEAP_ENTRY_BUSY) {
                printf( "    %08x: %08x - Busy", Entry.lpData, Entry.cbData );
                if (Entry.wFlags & PROCESS_HEAP_ENTRY_MOVEABLE) {
                    printf( "  hMem: %08x", Entry.Block.hMem );
                    }

                if (Entry.wFlags & PROCESS_HEAP_ENTRY_DDESHARE) {
                    printf( "  DDE" );
                    }

                printf( "\n" );
                }
            else {
                printf( "    %08x: %08x - Free\n", Entry.lpData, Entry.cbData );
                }

            fflush( stdout );
            }

        printf( "*** end of heap ***\n\n" );
        fflush( stdout );
        }

    return 0;
}
Esempio n. 25
0
void DbgHeapInit                // INITIALIZATION
    ( void )
{
#if 0
    unsigned count;             // - # of entries
    _HEAPINFO hi;               // - heap information
    ALLOCED* ae;                // - allocated entry

    hi._pentry = NULL;
    count = 0;
    for( ; ; ) {
        switch( _heapwalk( &hi ) ) {
          case _HEAPEND :
          case _HEAPEMPTY :
            break;
          case _HEAPOK :
            if( hi._useflag ) {
                ++ count;
            }
            continue;
          case _HEAPBADBEGIN :
            puts( "DbgHeapInit -- BAD BEGIN" );
            abort();
          case _HEAPBADPTR :
            puts( "DbgHeapInit -- BAD PTR" );
            abort();
          case _HEAPBADNODE :
            puts( "DbgHeapInit -- BAD NODE" );
            abort();
        }
        break;
    }
    if( count == 0 ) {
        entries = NULL;
        entry_count = 0;
    } else {
        ++ count;
        entry_count = count;
        ae = malloc( sizeof( ALLOCED ) * count );
        if( ae == NULL ) {
            puts( "DbgHeapInit -- cannot initialize" );
            abort();
        }
        entries = ae;
        hi._pentry = NULL;
        count = 0;
        for( ; ; ) {
            switch( _heapwalk( &hi ) ) {
              case _HEAPEND :
              case _HEAPEMPTY :
                break;
              case _HEAPOK :
                if( hi._useflag ) {
                    ++ count;
                    ae->_pentry = hi._pentry;
                    ae->_size = hi._size;
                    ++ae;
                }
                continue;
              case _HEAPBADBEGIN :
                puts( "DbgHeapInit -- BAD BEGIN" );
                abort();
              case _HEAPBADPTR :
                puts( "DbgHeapInit -- BAD PTR" );
                abort();
              case _HEAPBADNODE :
                puts( "DbgHeapInit -- BAD NODE" );
                abort();
            }
            break;
        }
        if( count != entry_count ) {
            puts( "DbgHeapInit -- count mismatch" );
            abort();
        }
    }
#endif
}
Esempio n. 26
0
/**
 *  MemDumpDiscarded is for debugging purposes only (and only will
 *  be compiled in debug mode).  It will output a list of blocks to the
 *  file "debugmem.txt".
 *
 *  NOTE: 
 *  None really.
 *
 *<!-----------------------------------------------------------------------*/
T_void MemDumpDiscarded(T_void)
{
#ifndef REAL_MODE
    FILE *fp ;
    T_memBlockHeader *p_header ;
//extern T_word32 G_packetsAlloc ;
//extern T_word32 G_packetsFree ;
struct _heapinfo h_info ;
int heap_status ;
    T_word32 totalUsed = 0 ;
    T_word32 totalFree = 0 ;

    DebugRoutine("MemDumpDiscarded") ;

printf("Dumping discard info!\n") ;
fflush(stdout) ;
MemCheck(991) ;
    fp = fopen("debugmem.txt", "w") ;
//fp = stdout ;
    DebugCheck(fp != NULL) ;

    fprintf(fp, "\n\nList of discarded memory:\n") ;
    fprintf(fp,     "-------------------------\n") ;
    p_header = P_startOfDiscardList ;
    fprintf(fp, "##### tag next: prev: callback?\n") ;
    fflush(fp) ;
    fprintf(fp, "start: %p  end: %p\n", P_startOfDiscardList, P_endOfDiscardList) ;
    fprintf(fp, "Start: %5d\n",
        (P_startOfDiscardList == NULL)?0:
            P_startOfDiscardList->blockId) ;
    fflush(fp) ;
    fprintf(fp, "  End: %5d\n",
        (P_endOfDiscardList == NULL)?0:
            P_endOfDiscardList->blockId) ;
    fprintf(fp, "\n\n") ;
    fflush(fp) ;

    while (p_header != NULL)  {
        fprintf(fp, "p_header = %p\n", p_header) ;
        fflush(fp) ;
        fprintf(fp, "%5d %s %5d %5d %c %s\n",
            p_header->blockId,
            p_header->blockTag,
            (p_header->p_nextBlock==NULL)?0:
                p_header->p_nextBlock->blockId,
            (p_header->p_prevBlock==NULL)?0:
                p_header->p_prevBlock->blockId,
            (p_header->p_callback == NULL)?'N':'Y',
#ifdef _MEM_RECORD_ROUTINES_
                p_header->routine) ;
#else
                "") ; //            p_header->routine) ;
#endif
        p_header = p_header->p_nextBlock ;
        fflush(fp) ;
    }
    fprintf(fp, "%d blocks allocated\n", G_allocCount-1) ;
    fprintf(fp, "%d blocks freed\n\n", G_deallocCount) ;
    fprintf(fp, "%d free memory\n", FreeMemory()) ;
    fflush(fp) ;
//    fprintf(fp, "%d packets alloc\n", G_packetsAlloc) ;
//    fprintf(fp, "%d packets free\n", G_packetsFree) ;

fprintf(fp, "\n\nHeap walk:\n\n") ;
h_info._pentry = NULL ;
for(;;)  {
  heap_status = _heapwalk(&h_info) ;
  if (heap_status != _HEAPOK)
    break ;
  fprintf(fp, "  %s %Fp %8.8X\n",
    (h_info._useflag == _USEDENTRY?"USED":"FREE"),
    h_info._pentry, h_info._size) ;
  if (h_info._useflag == _USEDENTRY)
      totalUsed += h_info._size ;
  else
      totalFree += h_info._size ;
}
fprintf(fp, "  heap status: %d\n", heap_status) ;
fprintf(fp, "  Total used: %ld bytes\n", totalUsed) ;
fprintf(fp, "  Total free: %ld bytes\n", totalFree) ;

    fflush(fp) ;
    fclose(fp) ;

    DebugEnd() ;
#endif
}
Esempio n. 27
0
int EBuffer::ShowPosition() {
    int CLine, NLines;
    int CAct, NAct;
    int CColumn, NColumns;
    int CCharPos, NChars;
#ifdef HEAPWALK
    unsigned long MemUsed = 0, MemFree = 0, BlkUsed = 0, BlkFree = 0, BigFree = 0, BigUsed = 0;
#endif

    if (!View)
        return 0;

    CLine = CP.Row + 1;
    NLines = VCount;
    CAct = VToR(CP.Row) + 1;
    NAct = RCount;
    CColumn = CP.Col + 1;
    NColumns = LineLen(CP.Row);
    CCharPos = CharOffset(VLine(CP.Row), CP.Col) + 1;
    NChars = VLine(CP.Row)->Count;

#ifdef HEAPWALK
    if (_heapchk() != _HEAPOK) {
        MemUsed = -1;
    } else {
        _HEAPINFO hi;

        hi._pentry = NULL;
        while (_heapwalk(&hi) == _HEAPOK) {
            if (hi._useflag == _USEDENTRY) {
                BlkUsed++;
                MemUsed += hi._size;
                if (hi._size > BigUsed)
                    BigUsed = hi._size;
                //fprintf(stderr, "USED %d\n", hi._size);
            } else {
                BlkFree++;
                MemFree += hi._size;
                if (hi._size > BigFree)
                    BigFree = hi._size;
                //fprintf(stderr, "FREE %d\n", hi._size);
            }
        }
    }
#endif

    int NN = -1;
    if (US.UndoPtr > 0)
        NN = US.Top[US.UndoPtr - 1];
    Msg(S_INFO,
#ifdef HEAPWALK
        "M%ld,%ld B%ld,%ld S%ld,%ld"
#endif
        "L%d/%d G%d/%d/%d A%d/%d C%d/%d P%d/%d "
        "U%d/%d/%d "
        "H%d/%d/%d",
#ifdef HEAPWALK
        MemUsed, MemFree, BlkUsed, BlkFree, BigUsed, BigFree,
#endif
        CLine, NLines,
        RGap, RCount, RAllocated,
        CAct, NAct,
        CColumn, NColumns,
        CCharPos, NChars,
        US.UndoPtr, US.Num, NN,
        StartHilit, MinRedraw, MaxRedraw);
    return 1;
}
Esempio n. 28
0
static void _dump_heaps( void )
{
    unsigned row, col, siz;
    unsigned prev_seg;
    int heap_status;
    unsigned long free_size;
    unsigned long used_size;
    unsigned largest_free_size;
    size_t old_size;
    struct _heapinfo hinfo;

    used_size = 0;
    free_size = 0;
    old_size = 0;
    largest_free_size = 0;
    hinfo._pentry = NULL;
    heap_status = _heapwalk( &hinfo );
    if( heap_status == _HEAPOK ) {
        prev_seg = FP_SEG( hinfo._pentry );
    }
    while( heap_status == _HEAPOK ) {
        if( prev_seg != FP_SEG( hinfo._pentry )) {
            printf("segment: %x\n", prev_seg );
            memset( &usage[last_row][last_col], ' ',
                    &usage[ROWS][0] - &usage[last_row][last_col] );
            last_row = 0;
            last_col = 0;
            _dump_heap( free_size, used_size, largest_free_size );
            used_size = 0;
            free_size = 0;
            old_size = 0;
            largest_free_size = 0;
            prev_seg = FP_SEG( hinfo._pentry );
        }
        /* we don't want to count the last free block */
        free_size += old_size;
        if( largest_free_size < old_size ) {
            largest_free_size = old_size;
        }
        if( hinfo._useflag == _USEDENTRY ) {
            used_size += hinfo._size;
            old_size = 0;
        } else {
            row = (unsigned) hinfo._pentry;
            row /= ( COLS * UNIT );
            col = (unsigned) hinfo._pentry;
            col %= ( COLS * UNIT );
            col /= UNIT/2;
            siz = hinfo._size / (UNIT/2);
            if( col & 1 ) {
                if( siz == 0 ) {
                    col >>= 1;
                } else {
                    usage[row][col>>1] = 'Ý';
                    last_row = row;
                    last_col = col>>1;
                    --siz;
                    col >>= 1;
                    ++col;
                    if( col == COLS ) {
                        ++row;
                        col = 0;
                    }
                }
            } else {