Ejemplo n.º 1
0
ssize_t BufIo::PutFlush(SOCKET sk, char *buf, size_t len)
{
	if (_left_buffer_size < len && p) {
		if (FlushOut(sk) < 0)
			return -1;
	}

	for (; _left_buffer_size < len;)
		if (_realloc_buffer() < 0)
			return -3;

	memcpy(b + p, buf, len);
	p += len;
	return FlushOut(sk);
}
Ejemplo n.º 2
0
void Lz4::End()
{
	ASSERT(compress >= 0);
	if(compress)
		FlushOut();
	else
		if(pos)
			error = true;
}
Ejemplo n.º 3
0
void LZ4CompressStream::Close()
{
	ASSERT(compress >= 0);
	if(out) {
		FlushOut();
		out->Put32le(0);
		out->Put32le(xxh.Finish());
		out = NULL;
	}
}
Ejemplo n.º 4
0
ssize_t BufIo::Put(SOCKET sk, char *buf, size_t len)
{
	ssize_t r;
	if (_left_buffer_size < len) { //no enough space
		r = FlushOut(sk);
		if (r < 0)
			return r;
		for (; _left_buffer_size < len;) // still no enough space
			if (_realloc_buffer() < 0)
				return -3;
	}
	memcpy(b + p, buf, len);
	p += len;
	return 0;
}
Ejemplo n.º 5
0
ssize_t BufIo::PutFlush(SOCKET sk, const char *buf, size_t len)
{
  if( !m_valid ){
#ifdef ENOBUFS
    errno = ENOBUFS;
#else
    errno = EIO;
#endif
    return -1;
  }

  if( LeftSize() < len ){
    if( m_len && FlushOut(sk) < 0 ) return -1;
    while( LeftSize() < len ){
      if( _realloc_buffer() < 0 ){
        m_valid = 0;
        return -1;
      }
    }
  }
  memcpy(m_buf + m_len, buf, len);
  m_len += len;
  return FlushOut(sk);
}
Ejemplo n.º 6
0
LogFile::~LogFile()
{
	if (unwritten.size())
	{
		FILE * fp = fopen(fname,"a");
		for (int attempt=0; !fp && attempt<10; ++attempt)
		{
			/* Sleep(100); */
			fp = fopen(fname,"a");
		}
		if (fp)
		{
			FlushOut(fp);
			fclose(fp);
		}
	}
	if (fname) delete[] fname;
}
Ejemplo n.º 7
0
void LZ4CompressStream::_Put(const void *data, dword size)
{
	ASSERT(compress >= 0);
	
	const char *s = reinterpret_cast<const char *>(data);

	while(size > 0) {
		if(IsError() || out && out->IsError())
			return;
		dword n = dword(wrlim - ptr);
		if(size >= n) {
			memcpy(ptr, s, n);
			ptr = wrlim;
			FlushOut();
			size -= n;
			s += n;
		}
		else {
			memcpy(ptr, s, size);
			ptr += size;
			break;
		}
	}
}
Ejemplo n.º 8
0
void WDbgArkAnalyzeGDT::Analyze(const ExtRemoteTyped &gdt_entry,
                                const std::string &cpu_idx,
                                const uint32_t selector,
                                const std::string &additional_info) {
    try {
        uint64_t address = GetGDTBase(gdt_entry);
        uint32_t limit = GetGDTLimit(gdt_entry);

        std::stringstream expression;
        expression << std::hex << std::showbase <<  address;
        address = g_Ext->EvalExprU64(expression.str().c_str());

        std::stringstream addr_ext;

        if ( address ) {
            if ( g_Ext->IsCurMachine64() ) {
                if ( selector == KGDT64_SYS_TSS )
                    addr_ext << "<exec cmd=\"dt nt!_KTSS64 " << std::hex << std::showbase << address << "\">";
            } else {
                if ( selector == KGDT_TSS || selector == KGDT_DF_TSS || selector == KGDT_NMI_TSS )
                    addr_ext << "<exec cmd=\"dt nt!_KTSS " << std::hex << std::showbase << address << "\">";
                else if ( selector == KGDT_R0_PCR )
                    addr_ext << "<exec cmd=\"dt nt!_KPCR " << std::hex << std::showbase << address << "\">";
            }
        }

        addr_ext << std::internal << std::setw(18) << std::setfill('0') << std::hex << std::showbase << address;

        if ( address ) {
            if ( g_Ext->IsCurMachine64() ) {
                if ( selector == KGDT64_SYS_TSS )
                    addr_ext << "</exec>";
            } else {
                if ( selector == KGDT_TSS ||
                     selector == KGDT_DF_TSS ||
                     selector == KGDT_NMI_TSS ||
                     selector == KGDT_R0_PCR ) {
                     addr_ext << "</exec>";
                }
            }
        }

        std::stringstream selector_ext;
        selector_ext << std::hex << std::showbase << selector;

        std::stringstream limit_ext;
        limit_ext << std::internal << std::setw(10) << std::setfill('0') << std::hex << std::showbase << limit;

        std::stringstream dpl;
        dpl << std::dec << GetGDTDpl(gdt_entry);

        std::stringstream granularity;

        if ( IsGDTPageGranularity(gdt_entry) )
            granularity << "Page";
        else
            granularity << "Byte";

        std::stringstream present;

        if ( IsGDTFlagPresent(gdt_entry) )
            present << "P";
        else
            present << "NP";

        *this << addr_ext.str() << limit_ext.str() << cpu_idx << selector_ext.str();
        *this << GetGDTSelectorName(selector) << GetGDTTypeName(gdt_entry);
        *this << dpl.str() << granularity.str() << present.str() << additional_info;

        FlushOut();
    }
    catch( const ExtRemoteException &Ex ) {
        err << wa::showminus << __FUNCTION__ << ": " << Ex.GetMessage() << endlerr;
    }
}
Ejemplo n.º 9
0
void LZ4CompressStream::Co(bool b)
{
	FlushOut();
	concurrent = b;
	Alloc();
}
Ejemplo n.º 10
0
void LZ4CompressStream::_Put(int w)
{
	FlushOut();
	*ptr++ = w;
}
Ejemplo n.º 11
0
void Lz4::Put(const void *ptr_, int size)
{
	LLOG("Put " << size);

	ASSERT(compress >= 0);
	
	if(error)
		return;
	
	const char *ptr = reinterpret_cast<const char *>(ptr_);

	if(compress) {
		while(size > 0) {
			if(error)
				return;
			int n = BLOCK_BYTES - pos;
			if(size >= n) {
				memcpy(block[cbi] + pos, ptr, n); // TODO: Avoid unnecessary memcpy
				pos = BLOCK_BYTES;
				FlushOut();
				size -= n;
				ptr += n;
			}
			else {
				memcpy(block[cbi] + pos, ptr, size);
				pos += size;
				break;
			}
		}
	}
	else {
		while(size > 0) { // TODO might try to avoid memcpy
			if(pos < 4) { // Get length first
				int n = min(size, 4 - pos);
				memcpy(~buffer + pos, ptr, n);
				pos += n;
				ptr += n;
				size -= n;
			}
			if(pos < 4)
				return;
			int count = Peek32le(~buffer);
			int need = count - (pos - 4);
			if(size >= need) { // we have enough data to finish the block
				memcpy(~buffer + pos, ptr, need);
				int out_count = LZ4_decompress_safe_continue(lz4StreamDecode, ~buffer + 4, block[cbi], count, BLOCK_BYTES);
				if(out_count <= 0) {
					error = true;
					return;
				}
				WhenOut(block[cbi], out_count);
				cbi = !cbi;
				ptr += need;
				size -= need;
				pos = 0;
			}
			else {
				memcpy(~buffer + pos, ptr, size);
				pos += size;
				break;
			}
		}
	}
}