Exemple #1
0
/**
* @attention 本注释得到了"核高基"科技重大专项2012年课题“开源操作系统内核分析和安全性评估
*(课题编号:2012ZX01039-004)”的资助。
*
* @copyright 注释添加单位:清华大学——03任务(Linux内核相关通用基础软件包分析)承担单位
*
* @author 注释添加人员:谢文学
*
* @date 注释添加日期:2013年5月10日
*
* @note 注释详细内容:
* 
* 本函数实现使用gunzip的解压缩读入的功能。
*/
int
gunzip_read (char *buf, int len)
{
  int ret = 0;

  compressed_file = 0;
  gunzip_swap_values ();
  /*
   *  Now "gzip_*" values refer to the uncompressed data.
   */

  /* do we reset decompression to the beginning of the file? */
  if (saved_filepos > gzip_filepos + WSIZE)
    initialize_tables ();

  /*
   *  This loop operates upon uncompressed data only.  The only
   *  special thing it does is to make sure the decompression
   *  window is within the range of data it needs.
   */

  while (len > 0 && !errnum)
    {
      register int size;
      register char *srcaddr;

      while (gzip_filepos >= saved_filepos)
	inflate_window ();

      srcaddr = (char *) ((gzip_filepos & (WSIZE - 1)) + slide);
      size = saved_filepos - gzip_filepos;
      if (size > len)
	size = len;

      memmove (buf, srcaddr, size);

      buf += size;
      len -= size;
      gzip_filepos += size;
      ret += size;
    }

  compressed_file = 1;
  gunzip_swap_values ();
  /*
   *  Now "gzip_*" values refer to the compressed data.
   */

  if (errnum)
    ret = 0;

  return ret;
}
Exemple #2
0
static grub_ssize_t
grub_gzio_read (grub_file_t file, char *buf, grub_size_t len)
{
  grub_ssize_t ret = 0;
  grub_gzio_t gzio = file->data;
  grub_off_t offset;

  /* Do we reset decompression to the beginning of the file?  */
  if (gzio->saved_offset > file->offset + WSIZE)
    initialize_tables (file);

  /*
   *  This loop operates upon uncompressed data only.  The only
   *  special thing it does is to make sure the decompression
   *  window is within the range of data it needs.
   */

  offset = file->offset;

  while (len > 0 && grub_errno == GRUB_ERR_NONE)
    {
      register grub_size_t size;
      register char *srcaddr;

      while (offset >= gzio->saved_offset)
	inflate_window (file);

      srcaddr = (char *) ((offset & (WSIZE - 1)) + gzio->slide);
      size = gzio->saved_offset - offset;
      if (size > len)
	size = len;

      grub_memmove (buf, srcaddr, size);

      buf += size;
      len -= size;
      ret += size;
      offset += size;
    }

  if (grub_errno != GRUB_ERR_NONE)
    ret = -1;

  return ret;
}
Exemple #3
0
void
TcpSrc::receivePacket(Packet& pkt)
{
    TcpAck *p = (TcpAck*)(&pkt);
    TcpAck::seq_t seqno = p->ackno();
    pkt.flow().logTraffic(pkt,*this,TrafficLogger::PKT_RCVDESTROY);
    p->free();
    assert(seqno >= _last_acked);  // no dups or reordering allowed in this simple simulator
    if (seqno > _last_acked) { // a brand new ack
        if (!_in_fast_recovery) { // best behaviour: proper ack of a new packet, when we were expecting it
            _last_acked = seqno;
            _dupacks = 0;
            inflate_window();
            _unacked = _cwnd;
            _effcwnd = _cwnd;
            if (_logger) _logger->logTcp(*this, TcpLogger::TCP_RCV);
            send_packets();
            return;
        }
        // We're in fast recovery, i.e. one packet has been
        // dropped but we're pretending it's not serious
        if (seqno >= _recoverq) {
            // got ACKs for all the "recovery window": resume
            // normal service
            uint32_t flightsize = _highest_sent - seqno;
            _cwnd = min(_ssthresh, flightsize + _mss);
            _unacked = _cwnd;
            _effcwnd = _cwnd;
            _last_acked = seqno;
            _dupacks = 0;
            _in_fast_recovery = false;
            if (_logger) _logger->logTcp(*this, TcpLogger::TCP_RCV_FR_END);
            send_packets();
            return;
        }
        // In fast recovery, and still getting ACKs for the
        // "recovery window"

        // This is dangerous. It means that several packets
        // got lost, not just the one that triggered FR.
        uint32_t new_data = seqno - _last_acked;
        _last_acked = seqno;
        if (new_data < _cwnd) _cwnd -= new_data;
        else _cwnd=0;
        _cwnd += _mss;
        if (_logger) _logger->logTcp(*this, TcpLogger::TCP_RCV_FR);
        retransmit_packet();
        send_packets();
        return;
    }
    // It's a dup ack
    if (_in_fast_recovery) { // still in fast recovery; hopefully the prodigal ACK is on it's way
        _cwnd += _mss;
        if (_cwnd>_maxcwnd) _cwnd = _maxcwnd;
        // When we restart, the window will be set to
        // min(_ssthresh, flightsize+_mss), so keep track of
        // this
        _unacked = min(_ssthresh, _highest_sent-_recoverq+_mss);
        if (_last_acked+_cwnd >= _highest_sent+_mss) _effcwnd=_unacked; // starting to send packets again
        if (_logger) _logger->logTcp(*this, TcpLogger::TCP_RCV_DUP_FR);
        send_packets();
        return;
    }
    // Not yet in fast recovery. What should we do instead?
    _dupacks++;
    if (_dupacks!=3) { // not yet serious worry
        if (_logger) _logger->logTcp(*this, TcpLogger::TCP_RCV_DUP);
        send_packets();
        return;
    }
    // _dupacks==3
    if (_last_acked < _recoverq) {  //See RFC 3782: if we haven't
        //recovered from timeouts
        //etc. don't do fast recovery
        if (_logger) _logger->logTcp(*this, TcpLogger::TCP_RCV_3DUPNOFR);
        return;
    }
    // begin fast recovery
    _ssthresh = max(_cwnd/2, (uint32_t)(2 * _mss));
    retransmit_packet();
    _cwnd = _ssthresh + 3 * _mss;
    _unacked = _ssthresh;
    _effcwnd = 0;
    _in_fast_recovery = true;
    _recoverq = _highest_sent; // _recoverq is the value of the
    // first ACK that tells us things
    // are back on track
    if (_logger) _logger->logTcp(*this, TcpLogger::TCP_RCV_DUP_FASTXMIT);
}
Exemple #4
0
int
gunzip_read (char *buf, int len)
{
  int ret = 0;
  int check_crc;
  ulg crc_value = 0xffffffffUL;

  compressed_file = 0;
  gunzip_swap_values ();
  /*
   *  Now "gzip_*" values refer to the uncompressed data.
   */

  /* do we reset decompression to the beginning of the file? */
  if (saved_filepos > gzip_filepos + WSIZE)
    initialize_tables ();

  /* perform CRC check only if reading the entire file */
  check_crc = (saved_filepos == 0 && len == MAXINT);

  /*
   *  This loop operates upon uncompressed data only.  The only
   *  special thing it does is to make sure the decompression
   *  window is within the range of data it needs.
   */

  while (len > 0 && !errnum)
    {
      register int size;
      register char *srcaddr;

      while (gzip_filepos >= saved_filepos && !errnum)
	inflate_window ();

      if (errnum)
	break;

      /* We could have started with an unknown gzip_filemax (MAXINT)
       * which has been updated in get_byte(). If so, update len
       * to avoid reading beyond the end.
       */
      if (len > (gzip_filemax - gzip_filepos)) {
        len = gzip_filemax - gzip_filepos;
	if (len < 0) {
	  errnum = ERR_BAD_GZIP_DATA;
	  break;
	}
      }

      srcaddr = (char *) ((gzip_filepos & (WSIZE - 1)) + slide);
      size = saved_filepos - gzip_filepos;
      if (size > len)
	size = len;

      memmove (buf, srcaddr, size);

      /* do CRC calculation here! */
      crc_value = updcrc(buf, (unsigned)size);

      buf += size;
      len -= size;
      gzip_filepos += size;
      ret += size;
    }

  /* check for CRC error if reading entire file */
  if (!errnum && check_crc && gzip_crc != crc_value) {
#if 0
    printf ("gunzip: crc value 0x%x, expected 0x%x\n", crc_value, gzip_crc);
#endif
    errnum = ERR_BAD_GZIP_CRC;
  }

  compressed_file = 1;
  gunzip_swap_values ();
  /*
   *  Now "gzip_*" values refer to the compressed data.
   */

  if (errnum)
    ret = 0;

  return ret;
}