void media_track_info::fix_sample_table( trak & track )
{
	if( _heapchk() != _HEAPOK )
	{
		cout << "heap corrupted." << endl;
		assert( false );
	}

	// fix stts, decoding time to sample
	fix_stts(track);

	// fix ctts, composition time to sample box
	fix_ctts(track);

	// fix stsc, sample to chunk
	fix_stsc(track);

	// fix stss, sync sample box
	fix_stss(track);

	fix_stsz(track);

	//// FIX STSC, STCO
	//throw std::exception( "to fix stsz, stco" );


	if( _heapchk() != _HEAPOK )
	{
		cout << "heap corrupted." << endl;
		assert( false );
	}
}
Exemple #2
0
main()
{
	int i;
	dynatab_t *pt[NTABS];

	for (i=0;i<NTABS;i++) {
		pt[i] = dynatab_create(sizeof(int));
		if (!pt[i]) {
			printf("create: test failed\n");
			exit(1);
		}
		if (dynatab_subscript(pt[i], 1) != NULL) {
			printf("subcript1: test failed\n");
			exit(1);
		}
	}
	for (i=0;i<NTABS;i++) {
		int h;
		h = _heapchk();
		if (h != _HEAPOK) {
			printf("heapchk: test failed\n");
			exit(1);
		}
		test1(pt[i]);
	}
	for (i=0;i<NTABS;i++) 
		dynatab_destroy(pt[i]);
	printf("test okay\n");
	return 0;
}
Exemple #3
0
bool KeyValues::LoadFromFile(IFileSystem *filesystem, const char *resourceName, const char *pathID)
{
	assert(filesystem);
	assert(IsX360() || (IsPC() && _heapchk() == _HEAPOK));

	FileHandle_t f = filesystem->Open(resourceName, "rb", pathID);

	if (!f)
		return false;

	s_LastFileLoadingFrom = (char *)resourceName;

	int fileSize = filesystem->Size(f);
	char *buffer = (char *)MemAllocScratch(fileSize + 1);
	Assert(buffer);

	bool bRetOK = (filesystem->Read(buffer, fileSize, f) != 0);
	filesystem->Close(f);

	if (bRetOK)
	{
		buffer[fileSize] = 0;
		bRetOK = LoadFromBuffer(resourceName, buffer, filesystem);
	}

	MemFreeScratch();
	return bRetOK;
}
Exemple #4
0
HIDDEN void TSTRACEValidateHeaps()
{
#ifdef DEBUG_HEAP
	if ( _heapchk() != _HEAPOK )
	{
		CkmError("*****  HEAP DAMAGE DETECTED *****");
		LOG(CallTrace, "Error: *****  HEAP DAMAGE DETECTED *****");
		DebugBreak();
	}
#endif
#ifdef DEBUG_PROCESS_HEAP
	tsByteString buffer;
	DWORD heapCount;

	buffer.resize (sizeof(HANDLE));
	heapCount = GetProcessHeaps(1, (PHANDLE)buffer.rawData());
	if ( heapCount > 1 )
	{
		buffer.resize(sizeof(HANDLE) * heapCount);
		heapCount = GetProcessHeaps(heapCount, (PHANDLE)buffer.rawData());
	}
	for (int ii = 0; ii < heapCount; ii++)
	{
		if ( !HeapValidate(((PHANDLE)buffer.rawData())[ii], 0, NULL) )
		{
			CkmError("*****  PROCESS HEAP DAMAGE DETECTED *****");
			LOG(CallTrace, "Error: *****  PROCESS HEAP DAMAGE DETECTED *****");
			//            DebugBreak();
		}
	}
#endif // DEBUG_PROCESS_HEAP
}
Exemple #5
0
/*
 * @implemented
 */
int	_heapset(unsigned int unFill)
{
	if (_heapchk() == -1)
		return -1;
	return 0;

}
Exemple #6
0
int CDbgMemAlloc::heapchk()
{
#ifdef WIN32	
	return _heapchk();
#else
	printf("XXX: CDbgMemAlloc::heapchk() not portd to FreeBSD in file %s\n", __FILE__);
	return 0;
#endif	

}
Exemple #7
0
 bool heap_ok( const char *msg )
 {
   bool rc = true;
   int heap_status = _heapchk( );
   if( heap_status != _HEAPOK && heap_status != _HEAPEMPTY ) {
     std::cout << "!!! HEAP CONSISTENCY FAILURE: " << msg << "\n";
     rc = false;
   }
   return( rc );
 }
/*----------------------------------------------------------------------------
 * HeapCheck()
 *----------------------------------------------------------------------------
 * Check heap status
 *----------------------------------------------------------------------------
*/
void HeapCheck (void)
{
    int heapStatus;

    /* Check heap status */
    heapStatus = _heapchk();
    if ((heapStatus == _HEAPOK) || (heapStatus == _HEAPEMPTY))
        return;

    EAS_ReportX(_EAS_SEVERITY_FATAL, "Heap corrupt\n" );
}
Exemple #9
0
void checkHeap()
{
#ifdef _MSC_VER
    static a_int32_t count( 0 );
    if( ( ++count % 10000 ) == 0 && _heapchk() != _HEAPOK )
    {
        LBERROR << disableFlush << "Abort: heap corruption detected"<< std::endl
                << "    Set breakpoint in " << __FILE__ << ':' << __LINE__ + 1 
                << " to debug" << std::endl << enableFlush;
    }
#else
#endif
}
Exemple #10
0
FLAC__StreamDecoderWriteStatus mwrite
    (const FLAC__SeekableStreamDecoder *decoder, 
    const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
{
   Mdata *mdata = client_data;
   unsigned i,j;
   size_t newend;

   if (!mdata) { return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;} 

   newend = frame->header.blocksize*frame->header.channels*(frame->header.bits_per_sample/8);
   if (mdata->bufend < newend) {
        if (mdata->buffer) {
            free(mdata->buffer);
            mdata->buffer = 0;
        } /* endif */
        mdata->bufend=newend;
   } /* endif */

   if (!mdata->buffer) {
        mdata->buffer = malloc(mdata->bufend);
        if (!mdata->buffer) { return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;} 
   } /* endif */

#ifdef DEBUG
			fprintf(file,"callback write %ld\n",newend);
			fprintf(file,"size_t: %ld\n",sizeof(size_t));
     fprintf(file,"heap: %d\n",_heapchk());
#endif
   mdata->bufsize=0;
   for(i=0;i<frame->header.blocksize;i++) {
       for(j=0;j<frame->header.channels;j++) {
           mdata->buffer[mdata->bufsize] = (buffer[j][i] & 0xFF);
           if (mdata->bits_per_sample <= 8) {
              mdata->buffer[mdata->bufsize]+=1<<(mdata->bits_per_sample-1);
           }
           mdata->bufsize++;
           if (mdata->bits_per_sample > 8) {
               mdata->buffer[mdata->bufsize] = ((buffer[j][i] & 0xFF00) >> 8);
               mdata->bufsize++;
           } /* endif */
           if (mdata->bits_per_sample > 16) {
               mdata->buffer[mdata->bufsize] = ((buffer[j][i] & 0xFF0000) >> 8);
               mdata->bufsize++;
           } /* endif */
           if (mdata->bits_per_sample > 24) {
               mdata->buffer[mdata->bufsize] = ((buffer[j][i] & 0xFF000000) >> 8);
               mdata->bufsize++;
           } /* endif */
Exemple #11
0
void SampleScene01::Render(Dx11Context* context, Dx11Camera* camera, Dx11Lens* lens)
{
	wchar_t buf[32]; 
	wsprintf(buf, L"カウント: %d", left); 
	float w = text->SetText(context, buf); 

	EffectGUIStandardInfo info = {0, 0, 0.125f * w, 0.125f, 
		1.0f, 0.5f, 0, 0}; // 完全不透明(1.0f), 色半反転(0,5f)

	effect->Update(context, text, &info); 
	if(_heapchk()!=_HEAPOK) {
		DebugBreak();
	}
	osd_fps->Render(context, camera, lens); 
}
Exemple #12
0
void TestHeap(void)
{
	WORD msgId;
	char *outStr;
	
	switch (_heapchk())
	{
		case _HEAPBADBEGIN: outStr= "HEAPBADBEGIN";	msgId= MSG_HEAP_BADBEGIN;	break;										
		case _HEAPBADNODE	: outStr= "HEAPBADNODE"; msgId= MSG_HEAP_BADNODE;	break;										
		case _HEAPBADPTR		: outStr= "HEAPBADPTR";	msgId= MSG_HEAP_BADPTR; break;										
		case _HEAPEMPTY			: outStr= "HEAPEMPTY";	msgId= MSG_HEAP_EMPTY;	break;										
		case _HEAPOK						: outStr= "HEAPOK"; msgId= MSG_HEAP_OK;	break;										
		case _HEAPEND					: outStr= "HEAPEND";	msgId= MSG_HEAP_END;	break;										
		default											:	outStr= "UNKNOWNMESSAGE";	msgId= MSG_HEAP_UNKNOWN;
	}
	if (heapMsg)
		WriteMessageToPow(msgId, NULL, NULL);
}	
 void ObjMeshGPUDeformer::heap_check_()
 {
   int heapstatus = _heapchk();
   switch( heapstatus )
   {
     case _HEAPOK:
       printf(" OK - heap is fine\n" );
     break;
     case _HEAPEMPTY:
       printf(" OK - heap is empty\n" );
     break;
     case _HEAPBADBEGIN:
       printf( "ERROR - bad start of heap\n" );
     break;
     case _HEAPBADNODE:
       printf( "ERROR - bad node in heap\n" );
     break;
   }
 }
Exemple #14
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;
}
//! Runs consistency checks on the heap. 
//! This is enabled in release builds, unlike _CrtCheckMemory.
Value* heapcheck_cf(Value**, int count)
{
	check_arg_count(heapcheck, 0, count);
	int heap_status = _heapchk();
	/* I'll use these later
	switch (heap_status)
	{
	case _HEAPOK:
		break;
	case _HEAPEMPTY:
		break;
	case _HEAPBADPTR:
		break;
	case _HEAPBADNODE:
		break;
	case _HEAPBADBEGIN:
		break;
	}
	*/
	return (heap_status == _HEAPOK) ? &true_value : &false_value;
}
bool CHalfLife2::KVLoadFromFile(KeyValues *kv, IBaseFileSystem *filesystem, const char *resourceName, const char *pathID)
{
#if defined METAMOD_PLAPI_VERSION
	if (g_SMAPI->GetSourceEngineBuild() == SOURCE_ENGINE_ORIGINAL)
#else
	if (strcasecmp(g_SourceMod.GetGameFolderName(), "ship") == 0)
#endif
	{
		Assert(filesystem);
#ifdef _MSC_VER
		Assert(_heapchk() == _HEAPOK);
#endif

		FileHandle_t f = filesystem->Open(resourceName, "rb", pathID);
		if (!f)
			return false;

		// load file into a null-terminated buffer
		int fileSize = filesystem->Size(f);
		char *buffer = (char *)MemAllocScratch(fileSize + 1);

		Assert(buffer);

		filesystem->Read(buffer, fileSize, f); // read into local buffer

		buffer[fileSize] = 0; // null terminate file as EOF

		filesystem->Close( f );	// close file after reading

		bool retOK = kv->LoadFromBuffer( resourceName, buffer, filesystem );

		MemFreeScratch();

		return retOK;
	}
	else
	{
		return kv->LoadFromFile(filesystem, resourceName, pathID);
	}
}
Exemple #17
0
/* Returns non-zero value if heap is corrupted. Declare in the main program,
permit any other module to use it. Todo- place in a "general" functions 
source file and include only front end header. */
int check_heap() {
  int rc = 0;
  
  #ifdef __DOS__
  switch(_heapchk()) {
  case _HEAPOK:
    printf("OK - heap is good\n");
    break;
  case _HEAPEMPTY:
    printf("OK - heap is empty\n");
    break;
  case _HEAPBADBEGIN:
    printf("ERROR - heap is damaged\n");
    rc = -1;
    break;
  case _HEAPBADNODE:
    printf("ERROR - bad node in heap\n");
    rc = -1;
    break;
  }
  #endif
  return rc;
}
Exemple #18
0
// ================================================================================================
// FUNCTION  : wiMemory_Check()
// ------------------------------------------------------------------------------------------------
// ================================================================================================
wiStatus wiMemory_Check(char *Filename, int Line)
{
    STATUS( wiProcess_WaitForMutex(&TraceMemoryMutex) );
    {
        wiMemory_traceMem_t *item = traceMemList;
        unsigned long total = 0;

        wiUtil_WriteLogFile("wiMemory_Check() called from %s line %d in thread %d\n",
            Filename, Line, wiProcess_ThreadIndex() );

        if (traceMemList)
        {
            while (item)
            {
                XSTATUS( wiMemory_CheckTraceBlock(item) )
                total += item->size;
                item = item->next;
            }
            wiUtil_WriteLogFile("    Total Allocated Memory: %d bytes\n",total);
        }
        #ifdef WIN32
        {
            int heapstatus = _heapchk();
            switch (heapstatus)
            {
                case _HEAPOK      : wiUtil_WriteLogFile("    HEAP CHECK: OK - heap is okay\n"); break;
                case _HEAPEMPTY   : wiUtil_WriteLogFile("    HEAP CHECK: OK - heap is empty\n"); break;
                case _HEAPBADBEGIN: wiUtil_WriteLogFile("    HEAP CHECK: ERROR - bad start of heap\n"); break;
                case _HEAPBADNODE : wiUtil_WriteLogFile("    HEAP CHECK: ERROR - bad node in heap\n"); break;
                default           : wiUtil_WriteLogFile("    HEAP CHECK: UNKNOWN STATUS %d\n",heapstatus);
            }
        }
        #endif
    }
    STATUS( wiProcess_ReleaseMutex(&TraceMemoryMutex) );
    return WI_SUCCESS;
}
Exemple #19
0
//=================================================================================================
void eve::mem::check_heap(void)
{
#if defined(EVE_MEMORY_CHECK)

#if defined(EVE_OS_WIN)
	int32_t	heapstatus = _heapchk();
	switch (heapstatus)
	{
	case _HEAPEMPTY:	
		break;
	case _HEAPOK:		
		break;

	case _HEAPBADBEGIN:
		eve::mess::log_error(__FUNCTION__, "Memory Heap Error: Bad Begin.");
		eve::core::failure();
		break;
	
	case _HEAPBADNODE:
		eve::mess::log_error(__FUNCTION__, "Memory Heap Error: Bad Node.");
		eve::core::failure();
		break;

	default:
		eve::mess::log_error(__FUNCTION__, "Memory Heap Unknown Error.");
		eve::core::failure();
		break;
	}

#else
	
	// Do nothing.
#endif

#endif
}
Exemple #20
0
static void my_heapchk()
{
	int heapstatus = _heapchk();
	assert(_HEAPOK == heapstatus);
}
Exemple #21
0
int __cdecl _heapset (
        unsigned int _fill
        )
{
        return _heapchk();
}
Exemple #22
0
FxBool txConvert( Gu3dfInfo *info, GrTextureFormat_t srcFormat,
                  int srcWidth, int srcHeight,
                  const void *srcImage, FxU32 flags,
                  const void *palNcc )
{
  TxMip srcMip;
  TxMip trueColorMip;
  TxMip outputMip;
  TxMip tmpMip;

  /*
   * Make a txMip out of the passed data.
   */
  memset( &srcMip, 0, sizeof( srcMip ) );
  srcMip.format         = srcFormat;
  srcMip.width          = srcWidth;
  srcMip.height         = srcHeight;
  srcMip.depth          = 1;

  if( palNcc )
    {
      switch( srcFormat )
        {
        case GR_TEXFMT_YIQ_422:
        case GR_TEXFMT_AYIQ_8422:
         txNccToPal( srcMip.pal, palNcc);
          break;
        case GR_TEXFMT_P_8:
          memcpy( srcMip.pal, palNcc, sizeof( FxU32 ) * 256 );
          break;
        }
    }
  srcMip.data[0]        = ( void * )srcImage;

  /*
   * Set up a txMip to put a true color version of the texture in.
   */
  memset( &trueColorMip, 0, sizeof( trueColorMip ) );
  trueColorMip.format         = GR_TEXFMT_ARGB_8888;
  trueColorMip.width          = srcWidth;
  trueColorMip.height         = srcHeight;
  /*
   * Set the depth to the mipmapped depth to allocate the image.
   */
#ifdef GLIDE3
  trueColorMip.depth          = info->header.large_lod - info->header.small_lod + 1;
#else
  trueColorMip.depth          = info->header.small_lod - info->header.large_lod + 1;
#endif
  if( !txMipAlloc( &trueColorMip ) )
    return FXFALSE;

  /*
   * Set to one level only since we only want to dequant the first 
   * level.
   */
  trueColorMip.depth          = 1;

  /*
   * Convert from the input format to truecolor.
   */
  txMipDequantize( &trueColorMip, &srcMip );

  /*
   * We realy have more than one level, so. . . 
   */
#ifdef GLIDE3
  trueColorMip.depth          = info->header.large_lod - info->header.small_lod + 1;
#else
  trueColorMip.depth          = info->header.small_lod - info->header.large_lod + 1;
#endif

  /*
   * WARNING!  I do not free srcMip.data[0] since it is passed in by the users.
   */

  /*
   * Resample the true color version of the input image to 
   * the passed in size. . . . this should be a valid
   * size for the hardware to handle.
   */
  tmpMip = trueColorMip;
  tmpMip.width = info->header.width;
  tmpMip.height = info->header.height;
  txMipAlloc( &tmpMip );

  if( ( flags & TX_CLAMP_MASK ) == TX_CLAMP_DISABLE )
    {
      txMipResample( &tmpMip, &trueColorMip );
    }
  else
    {
      txMipClamp( &tmpMip, &trueColorMip );
#if 0
      txMipView( &tmpMip, "blah", FXTRUE, 0 );
#endif
    }
    
  
#if 0
  if( _heapchk() != _HEAPOK )
    txPanic( "_heapchk failed" );
#endif
  txFree( trueColorMip.data[0] );

  trueColorMip = tmpMip;

  /*
   * Generate mipmap levels.
   */
#ifdef GLIDE3
  trueColorMip.depth          = info->header.large_lod - info->header.small_lod + 1;
#else
  trueColorMip.depth          = info->header.small_lod - info->header.large_lod + 1;
#endif
  txMipMipmap( &trueColorMip );

#if 0
  txMipView( &trueColorMip, "blah", FXTRUE, 0 );
#endif

  /*
   * Convert from true color to the output color format.
   */
  memset( &outputMip, 0, sizeof( outputMip ) );
  outputMip.format         = info->header.format;
  outputMip.width          = info->header.width;
  outputMip.height         = info->header.height;
  outputMip.depth          = trueColorMip.depth;
  outputMip.data[0]        = info->data;
#if 0
  txMipAlloc( &outputMip );
#else
  txMipSetMipPointers( &outputMip );
#endif
  
  if( ( flags & TX_TARGET_PALNCC_MASK ) == TX_TARGET_PALNCC_SOURCE )
    {
      txMipTrueToFixedPal( &outputMip, &trueColorMip, palNcc, 
                           flags & TX_FIXED_PAL_QUANT_MASK );
    }
  else
    {
      txMipQuantize( &outputMip, &trueColorMip, outputMip.format, 
                     flags & TX_DITHER_MASK, flags & TX_COMPRESSION_MASK );
    }

  info->data = outputMip.data[0];

  if( ( info->header.format == GR_TEXFMT_YIQ_422 ) ||
      ( info->header.format == GR_TEXFMT_AYIQ_8422 ) )
    {
      txPalToNcc( &info->table.nccTable, outputMip.pal );
    }
  
  if( info->header.format == GR_TEXFMT_P_8 || info->header.format == GR_TEXFMT_AP_88 )
    {
      memcpy( info->table.palette.data, outputMip.pal, sizeof( FxU32 ) * 256 );
    }

  txFree( trueColorMip.data[0] );

  return FXTRUE;
}
Exemple #23
0
void SaveHeapLog()
{
  FILE *f;
  _HEAPINFO hi;
  char block[129],*ad;
  block[128]=0;
  int code;
  HANDLE heaps[200];
  DWORD n;
  PROCESS_HEAP_ENTRY phe;

  f=fopen(WriteDir+SLASH+"heap.log","wb");

  SetLastError(0);
  n=GetProcessHeaps(200,heaps);
  heaps[n]=GetProcessHeap();n++;
  fprintf(f,"There are %i heaps for Steem\r\n",n);
  for (DWORD i=0;i<n;i++){
    code=HeapValidate(heaps[i],0,NULL);
    if (code){
      fprintf(f,"Heap %u okay\r\n",i);
    }else{
      fprintf(f,"Heap %u has an error in it!\r\n",i);
    }
    HeapLock(heaps[i]);
    phe.lpData=NULL;
    while (HeapWalk(heaps[i],&phe)){
      fprintf(f,"%s%X\r\n","Bad node, address=",(unsigned long)(phe.lpData));
      ad=((char*)phe.lpData)-64;
      for (int n=0;n<128;n++){
        block[n]=*(ad++);
        if (block[n]==0) block[n]='\\';
        if (block[n]==10) block[n]='\\';
        if (block[n]==13) block[n]='\\';
      }
      fprintf(f,"%s\r\n",block);
    }
    HeapUnlock(heaps[i]);
    if (phe.lpData==NULL) DisplayLastError();
  }

  fprintf(f,"\r\n\r\n");
  code=_heapchk();
  if (code==_HEAPOK){
    fprintf(f,"%s\r\n","Heap okay, walking:");
  }else if (code==_HEAPBADNODE){
    fprintf(f,"%s\r\n","Heap has bad node! Walking anyway:");
  }
  hi._pentry=NULL;
  for(;;){
    code=_rtl_heapwalk(&hi);
    if (code==_HEAPEND) break;
    if (code==_HEAPBADNODE){
      fprintf(f,"%s%X\r\n","Bad node, address=",(unsigned long)(hi.__pentry));
      ad=((char*)hi._pentry)-64;
      for (int n=0;n<128;n++){
        block[n]=*(ad++);
        if (block[n]==0) block[n]='\\';
        if (block[n]==10) block[n]='\\';
        if (block[n]==13) block[n]='\\';
      }
      fprintf(f,"%s\r\n",block);
    }else if (code==_HEAPOK){
      fprintf(f,"%s%X\r\n","Good node, address=",(unsigned long)(hi.__pentry));
    }
  }
  fclose(f);
}
Exemple #24
0
int
readSyms(void)
{
	int i;
	int count = 0;
	int	firstSym = 0;			/* First symbol this module */
	byte b, c, type;
	word w, len;

	codeLNAMES = NONE;			/* Invalidate indexes for code segment */
	codeSEGDEF = NONE;			/* Else won't be assigned */

    offset = 0;                 /* For diagnostics, really */

	if ((keys = (HASHENTRY *)malloc(SYMALLOC * sizeof(HASHENTRY))) == 0)
	{
		printf("Could not malloc the initial %d entries for keys[]\n");
		exit(10);
	}

	if ((leData = (byte *)malloc(0xFF80)) == 0)
	{
		printf("Could not malloc 64k bytes for LEDATA\n"); 
		exit(10);
	}
#if 0
	switch(_heapchk())
	{
		case _HEAPBADBEGIN:
			printf("Bad begin\n");
			break;
		case _HEAPBADNODE:
			printf("Bad node\n");
			break;
		case _HEAPEMPTY:
			printf("Bad empty\n");
			break;
		case _HEAPOK:
			printf("Heap OK\n");
			break;
	}
#endif

	while (!feof(f))
	{
		type = readByte();
		len = readWord();
/* Note: uncommenting the following generates a *lot* of output */
/*printf("Offset %05lX: type %02X len %d\n", offset-3, type, len);/**/
		switch (type)
		{

			case 0x96:				/* LNAMES */
				while (len > 1)
				{
				 	readString();
					++lnum;
					if (strcmp(buf, "CODE") == 0)
					{
						/* This is the class name we're looking for */
						codeLNAMES= lnum;
					}
					len -= strlen(buf)+1;
				}
				b = readByte();		/* Checksum */
				break;

			case 0x98:				/* Segment definition */
				b = readByte();		/* Segment attributes */
				if ((b & 0xE0) == 0)
				{
					/* Alignment field is zero. Frame and offset follow */
					readWord();
					readByte();
				}

				w = readWord();		/* Segment length */

				b = readByte();		/* Segment name index */
				++segnum;

				b = readByte();		/* Class name index */
				if ((b == codeLNAMES) && (codeSEGDEF == NONE))
				{
					/* This is the segment defining the code class */
					codeSEGDEF = segnum;
				}

				b = readByte();		/* Overlay index */
				b = readByte();		/* Checksum */
				break;

			case 0x90:				/* PUBDEF: public symbols */
				b = readByte();		/* Base group */
				c = readByte();		/* Base segment */
				len -= 2;
				if (c == 0)
				{
					w = readWord();
					len -= 2;
				}
				while (len > 1)
				{
					readString();
					w = readWord();		/* Offset */
					b = readByte();		/* Type index */
					if (c == codeSEGDEF)
					{
						byte *p;

						allocSym(count);
						p = buf;
						if (buf[0] == '_')	/* Leading underscore? */
						{
							p++; 			/* Yes, remove it*/
						}
						i = MIN(SYMLEN-1, strlen(p));
						memcpy(keys[count].name, p, i);
						keys[count].name[i] = '\0';
						keys[count].offset = w;
/*printf("%04X: %s is sym #%d\n", w, keys[count].name, count);/**/
						count++;
					}
					len -= strlen(buf) + 1 + 2 + 1;
				}
				b = readByte();		/* Checksum */
				break;


			case 0xA0:				/* LEDATA */
			{
				b = readByte();		/* Segment index */
				w = readWord();		/* Offset */
				len -= 3;
/*printf("LEDATA seg %d off %02X len %Xh, looking for %d\n", b, w, len-1, codeSEGDEF);/**/

				if (b != codeSEGDEF)
				{
					readNN(len);	/* Skip the data */
					break;			/* Next record */
				}


				if (fread(&leData[w], 1, len-1, f) != len-1)
				{
					printf("Could not read LEDATA length %d\n", len-1);
					exit(2);
				}
				offset += len-1;
				maxLeData = MAX(maxLeData, w+len-1);

			 	readByte();				/* Checksum */
				break;
			}

			default:
				readNN(len);			/* Just skip the lot */

				if (type == 0x8A)	/* Mod end */
				{
				/* Now find all the patterns for public code symbols that
					we have found */
					for (i=firstSym; i < count; i++)
					{
						word off = keys[i].offset;
						if (off == (word)-1)
						{
							continue;			/* Ignore if already done */
						}
						if (keys[i].offset > maxLeData)
						{
							printf(
							"Warning: no LEDATA for symbol #%d %s "
							"(offset %04X, max %04X)\n",
							i, keys[i].name, off, maxLeData);
							/* To make things consistant, we set the pattern for
								this symbol to nulls */
							memset(&keys[i].pat, 0, PATLEN);
							continue;
						}
						/* Copy to temp buffer so don't overrun later patterns.
							(e.g. when chopping a short pattern).
							Beware of short patterns! */
						if (off+PATLEN <= maxLeData)
						{
							/* Available pattern is >= PATLEN */
							memcpy(buf, &leData[off], PATLEN);
						}
						else
						{
							/* Short! Only copy what is available (and malloced!) */
							memcpy(buf, &leData[off], maxLeData-off);
							/* Set rest to zeroes */
							memset(&buf[maxLeData-off], 0, PATLEN-(maxLeData-off));
						}
						fixWildCards(buf);
						/* Save into the hash entry. */
						memcpy(keys[i].pat, buf, PATLEN);
						keys[i].offset = (word)-1;	/* Flag it as done */
/*printf("Saved pattern for %s\n", keys[i].name);/**/
					}


					while (readByte() == 0);
					readNN(-1);			/* Unget the last byte (= type) */
					lnum = 0;			/* Reset index into lnames */
					segnum = 0;			/* Reset index into snames */
					firstSym = count;	/* Remember index of first sym this mod */
					codeLNAMES = NONE;	/* Invalidate indexes for code segment */
					codeSEGDEF = NONE;
					memset(leData, 0, maxLeData);	/* Clear out old junk */
					maxLeData = 0;		/* No data read this module */
				}

				else if (type == 0xF1)
				{
					/* Library end record */
					return count;
				}

		}
	}


	free(leData);
	free(keys);

	return count;
}
Exemple #25
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;
}