Example #1
0
//===========================================================================
//
// Parameter:			-
// Returns:				-
// Changes Globals:		-
//===========================================================================
void Tree_FreePortals_r( node_t *node ) {
	portal_t    *p, *nextp;
	int s;

	// free children
	if ( node->planenum != PLANENUM_LEAF ) {
		Tree_FreePortals_r( node->children[0] );
		Tree_FreePortals_r( node->children[1] );
	}

	// free portals
	for ( p = node->portals; p; p = nextp )
	{
		s = ( p->nodes[1] == node );
		nextp = p->next[s];

		RemovePortalFromNode( p, p->nodes[!s] );
#ifdef ME
		if ( p->winding ) {
			freedtreemem += MemorySize( p->winding );
		}
		freedtreemem += MemorySize( p );
#endif //ME
		FreePortal( p );
	}
	node->portals = NULL;
} //end of the function Tree_FreePortals_r
Example #2
0
//===========================================================================
//
// Parameter:			-
// Returns:				-
// Changes Globals:		-
//===========================================================================
void Tree_Free_r( node_t *node ) {
//	face_t *f, *nextf;
	bspbrush_t *brush, *nextbrush;

	//free children
	if ( node->planenum != PLANENUM_LEAF ) {
		Tree_Free_r( node->children[0] );
		Tree_Free_r( node->children[1] );
	} //end if
	  //free bspbrushes
//	FreeBrushList (node->brushlist);
	for ( brush = node->brushlist; brush; brush = nextbrush )
	{
		nextbrush = brush->next;
#ifdef ME
		freedtreemem += MemorySize( brush );
#endif //ME
		FreeBrush( brush );
	} //end for
	node->brushlist = NULL;

	/*
	NOTE: only used when creating Q2 bsp
	// free faces
	for (f = node->faces; f; f = nextf)
	{
		nextf = f->next;
#ifdef ME
		if (f->w) freedtreemem += MemorySize(f->w);
		freedtreemem += sizeof(face_t);
#endif //ME
		FreeFace(f);
	} //end for
	*/

	// free the node
	if ( node->volume ) {
#ifdef ME
		freedtreemem += MemorySize( node->volume );
#endif //ME
		FreeBrush( node->volume );
	} //end if

	if ( numthreads == 1 ) {
		c_nodes--;
	}
#ifdef ME
	freedtreemem += MemorySize( node );
#endif //ME
	FreeMemory( node );
} //end of the function Tree_Free_r
Example #3
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
void *GetMemory(unsigned long size)
{
	void *ptr;
	ptr = malloc(size);
	if (!ptr) Error("out of memory");
	allocedmemory += MemorySize(ptr);
	return ptr;
} //end of the function GetMemory
Example #4
0
MOZ_WARN_UNUSED_RESULT nsresult
CacheFileChunk::EnsureBufSize(uint32_t aBufSize)
{
  mFile->AssertOwnsLock();

  // EnsureBufSize() is called only when we want to write some data to the chunk
  // and we never write data anymore once some error occurs.
  MOZ_ASSERT(NS_SUCCEEDED(mStatus));

  if (mBufSize >= aBufSize) {
    return NS_OK;
  }

  bool copy = false;
  if (!mBuf && mState == WRITING) {
    // We need to duplicate the data that is being written on the background
    // thread, so make sure that all the data fits into the new buffer.
    copy = true;

    if (mRWBufSize > aBufSize)
      aBufSize = mRWBufSize;
  }

  // find smallest power of 2 greater than or equal to aBufSize
  aBufSize--;
  aBufSize |= aBufSize >> 1;
  aBufSize |= aBufSize >> 2;
  aBufSize |= aBufSize >> 4;
  aBufSize |= aBufSize >> 8;
  aBufSize |= aBufSize >> 16;
  aBufSize++;

  const uint32_t minBufSize = kMinBufSize;
  const uint32_t maxBufSize = kChunkSize;
  aBufSize = clamped(aBufSize, minBufSize, maxBufSize);

  if (!CanAllocate(aBufSize - mBufSize)) {
    SetError(NS_ERROR_OUT_OF_MEMORY);
    return mStatus;
  }

  char *newBuf = static_cast<char *>(moz_realloc(mBuf, aBufSize));
  if (!newBuf) {
    SetError(NS_ERROR_OUT_OF_MEMORY);
    return mStatus;
  }

  mBuf = newBuf;
  mBufSize = aBufSize;
  ChunkAllocationChanged();

  if (copy)
    memcpy(mBuf, mRWBuf, mRWBufSize);

  DoMemoryReport(MemorySize());

  return NS_OK;
}
Example #5
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
void FreePortal( portal_t *p ) {
	if ( p->winding ) {
		FreeWinding( p->winding );
	}
	if ( numthreads == 1 ) {
		c_active_portals--;
		c_portalmemory -= MemorySize( p );
	} //end if
	FreeMemory( p );
} //end of the function FreePortal
Example #6
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
node_t *AllocNode( void ) {
	node_t  *node;

	node = GetMemory( sizeof( *node ) );
	memset( node, 0, sizeof( *node ) );
	if ( numthreads == 1 ) {
		c_nodememory += MemorySize( node );
	} //end if
	return node;
} //end of the function AllocNode
Example #7
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
void *GetClearedMemory(int size)
{
	void *ptr;

	ptr = (void *) malloc(size);
	if (!ptr) Error("out of memory");
	memset(ptr, 0, size);
	allocedmemory += MemorySize(ptr);
	return ptr;
} //end of the function GetClearedMemory
Example #8
0
void FiniDOSLoadFile( void )
/*********************************/
/* terminate writing of load file */
{
    unsigned_32         hdr_size;
    unsigned_32         mz_hdr_size;
    unsigned_32         temp;
    unsigned_32         min_size;
    unsigned_32         root_size;
    dos_exe_header      exe_head;

    if( FmtData.type & MK_COM ) {
        WriteCOMFile();
        return;
    }
    if( FmtData.u.dos.full_mz_hdr ) {
        mz_hdr_size = 0x40;
    } else {
        mz_hdr_size = sizeof( dos_exe_header ) + sizeof( unsigned_32 );
    }
    SeekLoad( mz_hdr_size );
    root_size = WriteDOSData( mz_hdr_size );
    if( FmtData.type & MK_OVERLAYS ) {
        PadOvlFiles();
    }
    // output debug info into root main output file
    CurrSect = Root;
    DBIWrite();
    hdr_size = MAKE_PARA( (unsigned long)Root->relocs * sizeof( dos_addr )
                                                                 + mz_hdr_size );
    DEBUG((DBG_LOADDOS, "root size %l, hdr size %l", root_size, hdr_size ));
    SeekLoad( 0 );
    _HostU16toTarg( DOS_SIGNATURE, exe_head.signature );
    temp = hdr_size / 16U;
    _HostU16toTarg( temp, exe_head.hdr_size );
    _HostU16toTarg( root_size % 512U, exe_head.mod_size );
    temp = ( root_size + 511U ) / 512U;
    _HostU16toTarg( temp, exe_head.file_size );
    _HostU16toTarg( Root->relocs, exe_head.num_relocs );

    min_size = MemorySize() - ( root_size - hdr_size ) + FmtData.SegMask;
    min_size >>= FmtData.SegShift;
    _HostU16toTarg( min_size, exe_head.min_16 );
    _HostU16toTarg( 0xffff, exe_head.max_16 );
    _HostU16toTarg( StartInfo.addr.off, exe_head.IP );
    _HostU16toTarg( StartInfo.addr.seg, exe_head.CS_offset );
    _HostU16toTarg( StackAddr.seg, exe_head.SS_offset );
    _HostU16toTarg( StackAddr.off, exe_head.SP );
    _HostU16toTarg( 0, exe_head.chk_sum );
    _HostU16toTarg( mz_hdr_size, exe_head.reloc_offset );
    _HostU16toTarg( 0, exe_head.overlay_num );
    WriteLoad( &exe_head, sizeof( dos_exe_header ) );
    WriteLoad( &OvlTabOffset, sizeof( unsigned_32 ) );
}
Example #9
0
void FreeWinding( winding_t *w ) {
	if ( *(unsigned *)w == 0xdeaddead ) {
		Error( "FreeWinding: freed a freed winding" );
	}

	if ( numthreads == 1 ) {
		c_active_windings--;
		c_windingmemory -= MemorySize( w );
	} //end if

	*(unsigned *)w = 0xdeaddead;

	FreeMemory( w );
} //end of the function FreeWinding
Example #10
0
static void WritePharSimple( unsigned_32 start )
/**********************************************/
{
    simple_header   header;
    unsigned_32     file_size;
    unsigned_32     header_size;
    unsigned_32     extra;
    unsigned_32     temp;

    if( FmtData.type & MK_PHAR_REX ) {
        SeekLoad( start + sizeof(simple_header) );
        extra = start + sizeof( simple_header ) + WritePharRelocs();
        header_size = MAKE_PARA( extra );
        PadLoad( header_size - extra );
    } else {
        SeekLoad( start + MAKE_PARA( sizeof(simple_header) ) );
        header_size = MAKE_PARA( sizeof(simple_header) );    // para align.
    }
    file_size = header_size + WritePharData( start + header_size );
    DBIWrite();
    if( FmtData.type & MK_PHAR_SIMPLE ) {
        _HostU16toTarg( SIMPLE_SIGNATURE, header.signature );
    } else {
        _HostU16toTarg( REX_SIGNATURE, header.signature );
    }
    _HostU16toTarg( file_size % 512U, header.mod_size );
    _HostU16toTarg( (file_size + 511U) / 512U, header.file_size );
    _HostU16toTarg( Root->relocs, header.num_relocs );
    _HostU16toTarg( header_size / 16, header.hdr_size );
    extra = MemorySize() - file_size + header_size + 0xfff;
    temp = FmtData.u.phar.mindata + extra;
    if( temp < FmtData.u.phar.mindata ) temp = 0xffffffff;
    _HostU16toTarg( temp >> 12, header.min_data );
    temp = FmtData.u.phar.maxdata + extra;
    if( temp < FmtData.u.phar.maxdata ) temp = 0xffffffff;
    _HostU16toTarg( temp >> 12, header.max_data );
    _HostU32toTarg( StackAddr.off, header.ESP );
    _HostU16toTarg( 0, header.checksum );
    _HostU32toTarg( StartInfo.addr.off, header.EIP );
    _HostU16toTarg( 0x1E, header.reloc_offset );
    _HostU16toTarg( 0, header.overlay_num );
    /* allow header size to exceed 1M */
    _HostU16toTarg( (header_size / (16*0x10000ul)) + 1, header.always_one );
    SeekLoad( start );
    WriteLoad( &header, sizeof( simple_header ) );
    if( FmtData.type & MK_PHAR_SIMPLE ) {
        PadLoad( 2 );                   // header occupies a full paragraph.
    }
}
Example #11
0
//===========================================================================
//
// Parameter:			-
// Returns:				-
// Changes Globals:		-
//===========================================================================
void FreeBrush (bspbrush_t *brushes)
{
	int			i;

	for (i=0 ; i<brushes->numsides ; i++)
		if (brushes->sides[i].winding)
			FreeWinding(brushes->sides[i].winding);
	if (numthreads == 1)
	{
		c_active_brushes--;
		c_brushmemory -= MemorySize(brushes);
		if (c_brushmemory < 0) c_brushmemory = 0;
	} //end if
	FreeMemory(brushes);
} //end of the function FreeBrush
Example #12
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
bspbrush_t *AllocBrush( int numsides ) {
	bspbrush_t  *bb;
	int c;

	c = (int)&( ( (bspbrush_t *)0 )->sides[numsides] );
	bb = GetMemory( c );
	memset( bb, 0, c );
	if ( numthreads == 1 ) {
		c_active_brushes++;
		c_brushmemory += MemorySize( bb );
		if ( c_brushmemory > c_peak_brushmemory ) {
			c_peak_brushmemory = c_brushmemory;
		}
	} //end if
	return bb;
} //end of the function AllocBrush
Example #13
0
nsresult
CacheFileChunk::OnDataWritten(CacheFileHandle *aHandle, const char *aBuf,
                              nsresult aResult)
{
  LOG(("CacheFileChunk::OnDataWritten() [this=%p, handle=%p, result=0x%08x]",
       this, aHandle, aResult));

  nsCOMPtr<CacheFileChunkListener> listener;

  {
    CacheFileAutoLock lock(mFile);

    MOZ_ASSERT(mState == WRITING);
    MOZ_ASSERT(mListener);

#if 0
    // TODO: properly handle error states
    if (NS_FAILED(aResult)) {
      mState = ERROR;
    }
    else {
#endif
      mState = READY;
      if (!mBuf) {
        mBuf = mRWBuf;
        mBufSize = mRWBufSize;
      }
      else {
        free(mRWBuf);
      }

      mRWBuf = nullptr;
      mRWBufSize = 0;

      DoMemoryReport(MemorySize());
#if 0
    }
#endif

    mListener.swap(listener);
  }

  listener->OnChunkWritten(aResult, this);

  return NS_OK;
}
Example #14
0
//===========================================================================
//
// Parameter:			-
// Returns:				-
// Changes Globals:		-
//===========================================================================
bspbrush_t *AllocBrush (int numsides)
{
	bspbrush_t	*bb;
	size_t		c;

	c = sizeof(*bb) + sizeof(*bb->sides) * numsides;
	bb = GetMemory(c);
	memset (bb, 0, c);
	if (numthreads == 1)
	{
		c_active_brushes++;
		c_brushmemory += MemorySize(bb);
		if (c_brushmemory > c_peak_brushmemory)
				c_peak_brushmemory = c_brushmemory;
	} //end if
	return bb;
} //end of the function AllocBrush
Example #15
0
void
CacheFileChunk::EnsureBufSize(uint32_t aBufSize)
{
  mFile->AssertOwnsLock();

  // EnsureBufSize() is called only when we want to write some data to the chunk
  // and we never write data anymore once some error occurs.
  MOZ_ASSERT(mState != ERROR);

  if (mBufSize >= aBufSize)
    return;

  bool copy = false;
  if (!mBuf && mState == WRITING) {
    // We need to duplicate the data that is being written on the background
    // thread, so make sure that all the data fits into the new buffer.
    copy = true;

    if (mRWBufSize > aBufSize)
      aBufSize = mRWBufSize;
  }

  // find smallest power of 2 greater than or equal to aBufSize
  aBufSize--;
  aBufSize |= aBufSize >> 1;
  aBufSize |= aBufSize >> 2;
  aBufSize |= aBufSize >> 4;
  aBufSize |= aBufSize >> 8;
  aBufSize |= aBufSize >> 16;
  aBufSize++;

  const uint32_t minBufSize = kMinBufSize;
  const uint32_t maxBufSize = kChunkSize;
  aBufSize = clamped(aBufSize, minBufSize, maxBufSize);

  mBuf = static_cast<char *>(moz_xrealloc(mBuf, aBufSize));
  mBufSize = aBufSize;

  if (copy)
    memcpy(mBuf, mRWBuf, mRWBufSize);

  DoMemoryReport(MemorySize());
}
Example #16
0
nsresult
CacheFileChunk::OnDataWritten(CacheFileHandle *aHandle, const char *aBuf,
                              nsresult aResult)
{
  LOG(("CacheFileChunk::OnDataWritten() [this=%p, handle=%p, result=0x%08x]",
       this, aHandle, aResult));

  nsCOMPtr<CacheFileChunkListener> listener;

  {
    CacheFileAutoLock lock(mFile);

    MOZ_ASSERT(mState == WRITING);
    MOZ_ASSERT(mListener);

    if (NS_WARN_IF(NS_FAILED(aResult))) {
      SetError(aResult);
    }

    mState = READY;

    if (!mBuf) {
      mBuf = mRWBuf;
      mBufSize = mRWBufSize;
      mRWBuf = nullptr;
      mRWBufSize = 0;
    } else {
      free(mRWBuf);
      mRWBuf = nullptr;
      mRWBufSize = 0;
      ChunkAllocationChanged();
    }


    DoMemoryReport(MemorySize());

    mListener.swap(listener);
  }

  listener->OnChunkWritten(aResult, this);

  return NS_OK;
}
Example #17
0
//portal_t *portallist = NULL;
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
portal_t *AllocPortal( void ) {
	portal_t    *p;

	p = GetMemory( sizeof( portal_t ) );
	memset( p, 0, sizeof( portal_t ) );

	if ( numthreads == 1 ) {
		c_active_portals++;
		if ( c_active_portals > c_peak_portals ) {
			c_peak_portals = c_active_portals;
		} //end if
		c_portalmemory += MemorySize( p );
	} //end if

//	p->nextportal = portallist;
//	portallist = p;

	return p;
} //end of the function AllocPortal
Example #18
0
//===========================================================================
//
// Parameter:			-
// Returns:				-
// Changes Globals:		-
//===========================================================================
void Tree_Free( tree_t *tree ) {
	//if no tree just return
	if ( !tree ) {
		return;
	}
	//
	freedtreemem = 0;
	//
	Tree_FreePortals_r( tree->headnode );
	Tree_Free_r( tree->headnode );
#ifdef ME
	freedtreemem += MemorySize( tree );
#endif //ME
	FreeMemory( tree );
#ifdef ME
	Log_Print( "freed " );
	PrintMemorySize( freedtreemem );
	Log_Print( " of tree memory\n" );
#endif //ME
} //end of the function Tree_Free
Example #19
0
/*
=============
AllocWinding
=============
*/
winding_t *AllocWinding( int points ) {
	winding_t   *w;
	int s;

	s = sizeof( vec_t ) * 3 * points + sizeof( int );
	w = GetMemory( s );
	memset( w, 0, s );

	if ( numthreads == 1 ) {
		c_winding_allocs++;
		c_winding_points += points;
		c_active_windings++;
		if ( c_active_windings > c_peak_windings ) {
			c_peak_windings = c_active_windings;
		}
		c_windingmemory += MemorySize( w );
		if ( c_windingmemory > c_peak_windingmemory ) {
			c_peak_windingmemory = c_windingmemory;
		}
	} //end if
	return w;
} //end of the function AllocWinding
Example #20
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
void FreeMemory(void *ptr)
{
	allocedmemory -= MemorySize(ptr);
	free(ptr);
} //end of the function FreeMemory
Example #21
0
nsresult
CacheFileChunk::OnDataRead(CacheFileHandle *aHandle, char *aBuf,
                           nsresult aResult)
{
  LOG(("CacheFileChunk::OnDataRead() [this=%p, handle=%p, result=0x%08x]",
       this, aHandle, aResult));

  nsCOMPtr<CacheFileChunkListener> listener;

  {
    CacheFileAutoLock lock(mFile);

    MOZ_ASSERT(mState == READING);
    MOZ_ASSERT(mListener);

    if (NS_SUCCEEDED(aResult)) {
      CacheHash::Hash16_t hash = CacheHash::Hash16(mRWBuf, mRWBufSize);
      if (hash != mReadHash) {
        LOG(("CacheFileChunk::OnDataRead() - Hash mismatch! Hash of the data is"
             " %hx, hash in metadata is %hx. [this=%p, idx=%d]",
             hash, mReadHash, this, mIndex));
        aResult = NS_ERROR_FILE_CORRUPTED;
      }
      else {
        if (!mBuf) {
          // Just swap the buffers if we don't have mBuf yet
          MOZ_ASSERT(mDataSize == mRWBufSize);
          mBuf = mRWBuf;
          mBufSize = mRWBufSize;
          mRWBuf = nullptr;
          mRWBufSize = 0;
        } else {
          LOG(("CacheFileChunk::OnDataRead() - Merging buffers. [this=%p]",
               this));

          // Merge data with write buffer
          if (mRWBufSize >= mBufSize) {
            // The new data will fit into the buffer that contains data read
            // from the disk. Simply copy the valid pieces.
            mValidityMap.Log();
            for (uint32_t i = 0; i < mValidityMap.Length(); i++) {
              if (mValidityMap[i].Offset() + mValidityMap[i].Len() > mBufSize) {
                MOZ_CRASH("Unexpected error in validity map!");
              }
              memcpy(mRWBuf + mValidityMap[i].Offset(),
                     mBuf + mValidityMap[i].Offset(), mValidityMap[i].Len());
            }
            mValidityMap.Clear();

            free(mBuf);
            mBuf = mRWBuf;
            mBufSize = mRWBufSize;
            mRWBuf = nullptr;
            mRWBufSize = 0;
            ChunkAllocationChanged();
          } else {
            // Buffer holding the new data is larger. Use it as the destination
            // buffer to avoid reallocating mRWBuf. We need to copy those pieces
            // from mRWBuf which are not valid in mBuf.
            uint32_t invalidOffset = 0;
            uint32_t invalidLength;
            mValidityMap.Log();
            for (uint32_t i = 0; i < mValidityMap.Length(); i++) {
              MOZ_ASSERT(invalidOffset <= mValidityMap[i].Offset());
              invalidLength = mValidityMap[i].Offset() - invalidOffset;
              if (invalidLength > 0) {
                if (invalidOffset + invalidLength > mRWBufSize) {
                  MOZ_CRASH("Unexpected error in validity map!");
                }
                memcpy(mBuf + invalidOffset, mRWBuf + invalidOffset,
                       invalidLength);
              }
              invalidOffset = mValidityMap[i].Offset() + mValidityMap[i].Len();
            }
            if (invalidOffset < mRWBufSize) {
              invalidLength = invalidOffset - mRWBufSize;
              memcpy(mBuf + invalidOffset, mRWBuf + invalidOffset,
                     invalidLength);
            }
            mValidityMap.Clear();

            free(mRWBuf);
            mRWBuf = nullptr;
            mRWBufSize = 0;
            ChunkAllocationChanged();
          }

          DoMemoryReport(MemorySize());
        }
      }
    }

    if (NS_FAILED(aResult)) {
      aResult = mIndex ? NS_ERROR_FILE_CORRUPTED : NS_ERROR_FILE_NOT_FOUND;
      SetError(aResult);
      mDataSize = 0;
    }

    mState = READY;
    mListener.swap(listener);
  }

  listener->OnChunkRead(aResult, this);

  return NS_OK;
}
Example #22
0
//======================================
// ScanXStuff: hw scan of StuffData
//--------------------------------------
void ScanXStuff::Scan (void) {
	MsgDetect display;
	unsigned VBEmem;
	ScanServer server(question,withx,card,cardopt);
	XF86ConfigFile srvmsg;
	map<int,ParseData>  parse;
	map<int,ServerData> graphics;
	map<int,StuffData>  stuff;
	str fbstring = "";
	int mapnr    = 0;
	int precard  = 0;
	int card     = 0;
 
	display = MonitorGetData();
	VBEmem  = MemorySize();

	srvmsg.SetFile(SERVER_STUFF_DATA);
	server.SetFile(SERVER_DATA);
	// ...
	// if no server scan data is present, scan it
	// -------------------------------------------
	if (server.Read() < 0) {
		server.Scan();
	}
	// ...
	// read the server scan data and save it
	// to graphics...
	// ---------------
	for (int i = server.Count(); i > 0; i--) {
		graphics[card] = server.Pop();
		card++;
	}
	precard = card;

	// ...
	// it is not sure to get any server message data
	// this depend on some items which you can see in the
	// server.c code. If no server message data is present
	// we had to run a server and parse the messages. If
	// there is only one card in the system we will obtain
	// the information from the libhd without starting an
	// X-Server...
	// ------------
	if ((graphics.size() == 1) && (graphics[0].module != "vmware")) {
		parse[0].dtype = display.displaytype;
		parse[0].model = display.model;
		parse[0].bus   = graphics[0].bus;
		parse[0].slot  = graphics[0].slot;
		parse[0].func  = graphics[0].func;
		parse[0].pbus  = graphics[0].bus;
		parse[0].pslot = graphics[0].slot;
		parse[0].pfunc = graphics[0].func;
		parse[0].ddc   = "<undefined>";
		if (VBEmem > 0) {
			parse[0].videoram = VBEmem;
		} else {
			parse[0].videoram = 4096;
		}
		// ...
		// the following values could not be detected via libhd
		// without starting an X-Server. Some defaults are set
		// now
		parse[0].dacspeed = 220;
		parse[0].hsmax    = 33;
		parse[0].vsmax    = 72;
		parse[0].chipset  = "<undefined>";
		parse[0].dpix     = 0;
		parse[0].dpiy     = 0;
		parse[0].vmdepth  = 0;

	} else {

		if (srvmsg.Read() < 0) {
			str config;
			sprintf(config,"%s-%d",TMP_CONFIG,getpid());
			map<int,string> section;
			ScanMouse mouse;
			ofstream handle(config);

			// open startup config...
			// -----------------------
			if (! handle) {
				cout << "ScanXStuff: could not create file: ";
				cout << TMP_CONFIG << endl;
				return;
			}
 
			// scan the mouse...
			// -------------------
			mouse.Scan(); MouseData mdata = mouse.Pop();
			srvmsg.SetMouseProperties(mdata.protocol,mdata.device);

			// create base sections...
			// ------------------------
			section[0] = srvmsg.DoFilesSection();
			section[1] = srvmsg.DoModuleSection();
			section[2] = srvmsg.DoInputDeviceSection();

			srvmsg.SetSectionID(card);
			section[3] = srvmsg.DoServerLayoutSection();

			// create dynamic sections...
			// ---------------------------
			for (int n=0;n<card;n++) {
			srvmsg.SetSectionID(n);
			if ((srvmsg.SetDriver(graphics[n].module)) == 1) {
				cout << "SaX: sorry could not open /dev/fb0... abort" << endl;
				exit(1);
			}
			srvmsg.SetBus (graphics[n].bus,graphics[n].slot,graphics[n].func);
			srvmsg.SetDeviceOption (graphics[n].option);

			section[4] = section[4] + "\n" + srvmsg.DoMonitorSection();
			section[5] = section[5] + "\n" + srvmsg.DoScreenSection();
			section[6] = section[6] + "\n" + srvmsg.DoDeviceSection();
			section[7] = section[7] + "\n" + srvmsg.DoServerFlagsSection();
			}

			// write sections to file...
			// ---------------------------
			handle << section[0] << endl;
			handle << section[1] << endl;
			handle << section[7] << endl;
			handle << section[2] << endl;
			handle << section[4] << endl;
			handle << section[5] << endl;
			handle << section[6] << endl;
			handle << section[3] << endl;

			handle.close();
			srvmsg.CallXF86Loader(config); 
			unlink(config);
		}
	}
	// ...
	// read the parse data from the XFree86 log
	// and save it to parse...
	// -------------------------
	if ((graphics.size() > 1) || (graphics[0].module == "vmware")) {
	card = 0;
	for (int i = srvmsg.Count(); i > 0; i--) {
		parse[card] = srvmsg.Pop();
		card++;
	}
	}
	if (precard > card) {
		cout << "SaX: ups lost card during probing... abort" << endl;
		exit(1);
	}
	// ...
	// lookup framebuffer timing for primary device
	// ---------------------------------------------
	ifstream handle(FB_DEV);
	FbData *fb = NULL;
	if (handle) {
		handle.close();
		fb = FbGetData();
		sprintf(fbstring,"\"%dx%d\" %.2f %s %s %s",
			fb->x,fb->y,fb->clock,fb->ht,fb->vt,fb->flags
		);
	}
	// ...
	// merge all the data. If only one card is detected
	// we will call the MonitorGetData() function to use
	// the VBE interface for getting more information 
	// via DDC[1/2]...
	// ----------------
	str current = "";
	str primary = "";
	for (int i=0;i<card;i++) {
		mapnr = FindParseData(parse,
			graphics[i].bus,graphics[i].slot,graphics[i].func
		); 
		sprintf(current,"%02d-%02d-%d",
		graphics[i].bus,graphics[i].slot,graphics[i].func);
		sprintf(primary,"%02d-%02d-%d",
		parse[mapnr].pbus,parse[mapnr].pslot,parse[mapnr].pfunc);  

		stuff[i].model = "<undefined>";
		if (parse[mapnr].model != "") {
			stuff[i].model = parse[mapnr].model;
		}
		stuff[i].vmdepth   = parse[mapnr].vmdepth;
		stuff[i].ddc       = parse[mapnr].ddc;
		stuff[i].dtype     = parse[mapnr].dtype;
		stuff[i].primary   = primary;
		stuff[i].chipset   = parse[mapnr].chipset;
		stuff[i].hsync     = parse[mapnr].hsmax; 
		stuff[i].vsync     = parse[mapnr].vsmax;
		stuff[i].dacspeed  = parse[mapnr].dacspeed;
		stuff[i].videoram  = parse[mapnr].videoram;
		stuff[i].current   = current; 
		stuff[i].raw       = graphics[i].raw;
		stuff[i].option    = graphics[i].option;
		stuff[i].extension = graphics[i].extension;
		if (TvSupport()) {
		if (stuff[i].extension == "") {
			stuff[i].extension = "v4l";
		} else {
			stuff[i].extension += ",v4l";
		}
		}
		stuff[i].driver    = graphics[i].module;
		stuff[i].dpix      = parse[mapnr].dpix;
		stuff[i].dpiy      = parse[mapnr].dpiy;

		if (
		(ddc == 1) && (
			(string(parse[i].ddc) != "<undefined>") || 
			(string(display.ddc)  != "00000000")
		)
		) {
			stuff[i].vesacount = parse[mapnr].modecount;
			stuff[i].vesa      = parse[mapnr].modes;
		} else {
			stuff[i].vesacount = -1;
			stuff[i].vesa[0].x = 640;
			stuff[i].vesa[0].y = 480;
			stuff[i].vesa[0].hsync = 25;
			stuff[i].vesa[0].vsync = 60;
		}

		// save fbtiming only for primary device...
		// -----------------------------------------
		if ((i==0) && (stuff[0].dtype == "CRT")) {
		if ((stuff[i].vesacount == -1) && (fb != NULL) && (ddc == 1)) {
			stuff[i].fbtiming  = fbstring;
			stuff[i].vesacount = 1;
			stuff[i].hsync     = (int)fb->hsync + 1;
			stuff[i].vsync     = (int)fb->vsync + 1;
			stuff[i].vesa[0].x = fb->x;
			stuff[i].vesa[0].y = fb->y;
			stuff[i].vesa[0].hsync = (int)fb->hsync;
			stuff[i].vesa[0].vsync = (int)fb->vsync;
			ddc = 0;
		} else if ((stuff[i].vesacount == -1) && (fb == NULL)) {
			stuff[i].vesacount = 1;
			stuff[i].vesa[0].x = 640;
			stuff[i].vesa[0].y = 480;
			stuff[i].vesa[0].hsync = 25;
			stuff[i].vesa[0].vsync = 60;
		}
		}
	}
	// ...
	// set the VBE DDC probed values if valid
	// --------------------------------------
	if (ddc == 1) {
	if (graphics.size() == 1) {
	if ((string(display.ddc) != "") && (string(display.ddc) != "00000000")) {
		stuff[0].ddc = display.ddc;
	}
	if (display.hsync_max > 0) { 
		stuff[0].hsync = display.hsync_max; 
	}
	if (display.vsync_max > 0) { 
		stuff[0].vsync = display.vsync_max; 
	}
	if ((display.dpix > 0) && (display.dpix < 100))     { 
		stuff[0].dpix  = display.dpix; 
	}
	if ((display.dpiy > 0) && (display.dpiy < 100))     { 
		stuff[0].dpiy  = display.dpiy; 
	}
	stuff[0].vesacount = display.vesacount;
	if (display.vesacount > 0) {
		int vesaCount = 0;
		for (int n=0;n<=display.vesacount;n++) {
		if (display.vmodes[n].x <= 1600) {
			XMode mode;
			mode.x = display.vmodes[n].x;
			mode.y = display.vmodes[n].y;
			// ...
			// check if the detected resolutions are part
			// of the following list
			// ---
			XMode vesaStandard[7];
			vesaStandard[0].x = 640;  vesaStandard[0].y = 480;
			vesaStandard[1].x = 800;  vesaStandard[1].y = 600;
			vesaStandard[2].x = 1024; vesaStandard[2].y = 768;
			vesaStandard[3].x = 1152; vesaStandard[3].y = 864;
			vesaStandard[4].x = 1280; vesaStandard[4].y = 1024;
			vesaStandard[5].x = 1400; vesaStandard[5].y = 1050;
			vesaStandard[6].x = 1600; vesaStandard[6].y = 1200;
	
			int isStandard = false;
			for (int i=0;i<7;i++) {
			if ((mode.x == vesaStandard[i].x)&&(mode.y == vesaStandard[i].y)) {
				isStandard = true;
				break;
			} 
			}
			if (! isStandard) {
				continue;
			}
			mode.hsync = display.vmodes[n].hsync;
			mode.vsync = display.vmodes[n].vsync;
			// ...
			// if mode has more than 100 Hz skip it
			// ---
			if (mode.vsync > 100) {
				continue;
			}
			// ...
			// if mode has no hsync specification, estimate it
			// from the vsync value
			// ---
			if (mode.hsync <= 0) {
				mode.hsync = (int)((mode.vsync * mode.x) / 1224);
			}
			// ...
			// if mode hsync or vsync is greater than currently
			// used max hsync/vsync, overwrite it
			// ---
			if (mode.hsync > stuff[0].hsync) {
				stuff[0].hsync = mode.hsync;
			}
			if (mode.vsync > stuff[0].vsync) {
				stuff[0].vsync = mode.vsync;
			}
			stuff[0].vesa[vesaCount] = mode;
			vesaCount++;
			stuff[0].vesacount = vesaCount;
		}
		}
	}
	}
	}
	// ...
	// save the stuff result...
	// -------------------------
	for (int i=0;i<card;i++) {
		Push(stuff[i]);
	}
}
Example #23
0
PPERFSYSTEM
GetComputer (
    HDLG hDlg,
    WORD wControlID,
    BOOL bWarn,
    PPERFDATA *ppPerfData,
    PPERFSYSTEM *ppSystemFirst
)
/*
   Effect:        Attempt to set the current computer to the one in the
                  hWndComputers dialog edit box. If this computer system
                  can be found, load the objects, etc. for the computer
                  and set pSystem and ppPerfdata to the values for this
                  system.
*/
{   // GetComputer
    TCHAR          szComputer [MAX_SYSTEM_NAME_LENGTH + 1] ;
    PPERFSYSTEM    pSystem;
    TCHAR          tempBuffer [LongTextLen] ;
    DWORD          dwBufferSize = 0;
    LPTSTR         pBuffer = NULL ;
    DWORD          dwLastError;

    DialogText (hDlg, wControlID, szComputer) ;

    // If necessary, add the system to the lists for this view.
    pSystem = SystemGet (*ppSystemFirst, szComputer) ;
    if (!pSystem) {
        pSystem = SystemAdd (ppSystemFirst, szComputer, hDlg) ;
    }

    if (!pSystem && bWarn) {
        dwLastError = GetLastError();

        EditSetModified (GetDlgItem(hDlg, wControlID), FALSE) ;

        // unable to get specified computer so set to:
        //  the first computer in the system list if present
        //      -- or --
        //  set he local machine if not.

        pSystem = *ppSystemFirst;   // set to first in list

        if (pSystem == NULL) {
            // this would mean the user can't access the local
            // system since normally that would be the first one
            // so the machine name will be restored to the
            // local machine (for lack of a better one) but the
            // system won't be added unless they want to explicitly

            DialogSetString (hDlg, wControlID, LocalComputerName) ;
        } else {
            // set to name in system structure
            DialogSetString (hDlg, wControlID, pSystem->sysName);
        }

        if (dwLastError != ERROR_ACCESS_DENIED) {
            DlgErrorBox (hDlg, ERR_COMPUTERNOTFOUND) ;
        } else {
            // the appropriate error message has already been displayed
        }

        SetFocus (DialogControl(hDlg, wControlID)) ;
    }

    if (pSystem) {
        if (PlayingBackLog ()) {
            *ppPerfData =
                LogDataFromPosition (pSystem, &(PlaybackLog.StartIndexPos)) ;
        } else {
            if (pSystem->lpszValue) {
                // save the previous lpszValue string before
                // SetSystemValueNameToGlobal screw it up
                dwBufferSize = MemorySize (pSystem->lpszValue) ;
                if (dwBufferSize <= sizeof(tempBuffer)) {
                    pBuffer = tempBuffer ;
                } else {
                    pBuffer = MemoryAllocate (dwBufferSize) ;
                }
                memcpy (pBuffer, pSystem->lpszValue, dwBufferSize) ;
            }

            SetSystemValueNameToGlobal (pSystem);
            UpdateSystemData (pSystem, ppPerfData) ;

            if (pSystem->lpszValue) {
                // retore the previous lpszValue string
                memcpy (pSystem->lpszValue, pBuffer, dwBufferSize) ;
                if (pBuffer != tempBuffer) {
                    MemoryFree (pBuffer) ;
                }
            }
        }
    }
    return (pSystem) ;

}  // GetComputer
Example #24
0
nsresult
CacheFileChunk::OnDataRead(CacheFileHandle *aHandle, char *aBuf,
                           nsresult aResult)
{
  LOG(("CacheFileChunk::OnDataRead() [this=%p, handle=%p, result=0x%08x]",
       this, aHandle, aResult));

  nsCOMPtr<CacheFileChunkListener> listener;

  {
    CacheFileAutoLock lock(mFile);

    MOZ_ASSERT(mState == READING);
    MOZ_ASSERT(mListener);

    if (NS_SUCCEEDED(aResult)) {
      CacheHash::Hash16_t hash = CacheHash::Hash16(mRWBuf, mRWBufSize);
      if (hash != mReadHash) {
        LOG(("CacheFileChunk::OnDataRead() - Hash mismatch! Hash of the data is"
             " %hx, hash in metadata is %hx. [this=%p, idx=%d]",
             hash, mReadHash, this, mIndex));
        aResult = NS_ERROR_FILE_CORRUPTED;
      }
      else {
        if (!mBuf) {
          // Just swap the buffers if we don't have mBuf yet
          MOZ_ASSERT(mDataSize == mRWBufSize);
          mBuf = mRWBuf;
          mBufSize = mRWBufSize;
          mRWBuf = nullptr;
          mRWBufSize = 0;
        } else {
          LOG(("CacheFileChunk::OnDataRead() - Merging buffers. [this=%p]",
               this));

          // Merge data with write buffer
          if (mRWBufSize < mBufSize) {
            mRWBuf = static_cast<char *>(moz_xrealloc(mRWBuf, mBufSize));
            mRWBufSize = mBufSize;
          }

          mValidityMap.Log();
          for (uint32_t i = 0 ; i < mValidityMap.Length() ; i++) {
            memcpy(mRWBuf + mValidityMap[i].Offset(),
                   mBuf + mValidityMap[i].Offset(), mValidityMap[i].Len());
          }
          mValidityMap.Clear();

          free(mBuf);
          mBuf = mRWBuf;
          mBufSize = mRWBufSize;
          mRWBuf = nullptr;
          mRWBufSize = 0;

          DoMemoryReport(MemorySize());
        }
      }
    }

    if (NS_FAILED(aResult)) {
      aResult = mIndex ? NS_ERROR_FILE_CORRUPTED : NS_ERROR_FILE_NOT_FOUND;
      SetError(aResult);
      mDataSize = 0;
    } else {
      mState = READY;
    }

    mListener.swap(listener);
  }

  listener->OnChunkRead(aResult, this);

  return NS_OK;
}
Example #25
0
    size += portals.Size();
    size += portalIndex.Size();
    size += clusters.Size();
    size += sizeof( idReachability_Walk ) * NumReachabilities();

    return size;
}

/*
================
idAASFileLocal::PrintInfo
================
*/
void idAASFileLocal::PrintInfo( void ) const
{
    common->Printf( "%6d KB file size\n", MemorySize() >> 10 );
    common->Printf( "%6d areas\n", areas.Num() );
    common->Printf( "%6d max tree depth\n", MaxTreeDepth() );
    ReportRoutingEfficiency();
}

/*
================
idAASFileLocal::NumReachabilities
================
*/
int idAASFileLocal::NumReachabilities( void ) const
{
    int i, num;
    idReachability *reach;