void circular_char_buffer::squeeze() {
  // squeeze to a minimum of 4 bytes
  if (bufsize <= 4) return;
  // 2 cases
  // case 1: no loop around
  // case 2: loop around. Easiest solution is to allocate a new buffer
  if (tail >= head) {
    if (head > 0) memmove(buffer, buffer+head, len);
    std::streamsize efflen = std::max(len + 1, std::streamsize(4));
    buffer = (char*)realloc((void*)buffer, efflen);
    head = 0;
    tail = len;
    bufsize = efflen;
  }
  else {
    // allocate a new buffer
    std::streamsize efflen = std::max(len + 1, std::streamsize(4));
    char *newbuf = (char*)malloc(efflen);
    // read into this buffer
    peek(newbuf, len);
    // free the old buffer
    free(buffer);
    buffer = newbuf;
    head = 0;
    tail = len;
    bufsize = efflen;
  }
  consistency_check();
}
示例#2
0
void
vex_adx_server::process_d_sub(int conn_idx, const d_sub &req)
{
    // Update auction context
    auction_context *ctx = &(auctions_ctx_.at(req.id));
    assert(ctx);

    ctx->vds.insert(std::pair<int, vex_decommitment>(conn_idx, req.vd));

    // When full, check consistency, compute auction, and report_outcome(ctx)
    if (ctx->vds.size() == conn_.size() - 1) {


#ifndef NOCC
        // currently NOT using optimized approach
        // To switch: replaces with consistency_and_proof(ctx);
        // and put compute_auction before.
        if (!consistency_check(ctx)) {
//    ctx->outcome = compute_auction(ctx);
            fatal << "Consistency check failed...\n";
        }
#endif
        ctx->outcome = compute_auction(ctx);
        report_outcome(ctx);
    }
}
示例#3
0
    void doSendEndpoints (IP::Endpoint const& remote_endpoint,
        Endpoints const& endpoints)
    {
        Links::iterator const iter1 (std::find_if (
            links().begin (), links().end(),
                is_remote_endpoint (remote_endpoint)));
        if (iter1 != links().end())
        {
            // Drop the message if they closed their end
            if (iter1->closed ())
                return;
            Node& remote_node (iter1->remote_node());
            // Find their link to us
            Links::iterator const iter2 (std::find_if (
                remote_node.links().begin(), remote_node.links().end(),
                    is_remote_endpoint (iter1->local_endpoint ())));
            consistency_check (iter2 != remote_node.links().end());

            //
            // VFALCO NOTE This looks wrong! Shouldn't it call receive()
            //             on the link and not the Peer?
            //
            Message const m (endpoints);
            iter2->local_node().receive (*iter2, m);
            //iter2->post (m);
        }
    }
std::streamsize circular_char_buffer::skip(std::streamsize clen) {
  std::streamsize readlen = std::min(clen, len);
  head += readlen;
  if (head >= bufsize) head -= bufsize;
  len -= readlen;
  consistency_check(); 
  return readlen;
}
示例#5
0
static void
major_finish_nursery_collection (void)
{
#ifdef MARKSWEEP_CONSISTENCY_CHECK
	consistency_check ();
#endif
	mono_sgen_register_major_sections_alloced (num_major_sections - old_num_major_sections);
}
std::streamsize circular_char_buffer::read(char* c, 
                                           std::streamsize clen) {
  if (len == 0) return -1;
  std::streamsize readlen = peek(c, clen);
  skip(readlen);
  consistency_check(); 

  return readlen;
}
示例#7
0
static void
major_start_nursery_collection (void)
{
#ifdef MARKSWEEP_CONSISTENCY_CHECK
	consistency_check ();
#endif

	old_num_major_sections = num_major_sections;
}
void BetterYao2::start()
{
	oblivious_transfer();
	cut_and_choose();
	cut_and_choose2();
	circuit_evaluate();
	consistency_check();
	final_report();
}
std::streamsize circular_char_buffer::write(const char* c, 
                                            std::streamsize clen) {
  // if we do not have enough capacity.
  // make sure we have enough capacity
  reserve(clen + len + 1);
  len += clen;
  
  std::streamsize firstcopy = std::min(clen, bufsize - tail);
  memcpy(buffer + tail, c, firstcopy);
  tail += firstcopy;
  if (tail == bufsize) tail = 0;
  if (firstcopy == clen) {
    consistency_check(); 
    return clen;
  }
  
  std::streamsize secondcopy = clen - firstcopy;
  memcpy(buffer, c + firstcopy, secondcopy);
  tail += secondcopy;
  consistency_check(); 
  return clen;
}
std::streamsize circular_char_buffer::peek(char* c, 
                                           std::streamsize clen) const {
  std::streamsize readlen = std::min(clen, len);
  // eliminate the case where head == tail, but buffer is empty
  if (readlen == 0) return 0;
  
  // first copy from head to end of buffer
  std::streamsize firstcopy = std::min(bufsize - head, readlen);
  memcpy(c, buffer+head, firstcopy);
  if (firstcopy == readlen) return readlen;
  // second copy from beginning of buffer to tail
  std::streamsize secondcopy = std::min(tail, readlen - firstcopy);
  memcpy(c+firstcopy, buffer, secondcopy);
  consistency_check();

  return readlen;

}
void circular_char_buffer::reserve(std::streamsize s) {
  // minimum of 4 bytes. disallow reserve of 0
  if (s <= 4) s = 4;
  // do nothing if s is smaller than the current buffer size
  if (s <= bufsize) return;
  
  // do a reallocation
  buffer = (char*)realloc((void*)buffer, s);

  // now, we need to be careful to reposition the head and tail
  // there are 2 cases
  
  // case 1:  no loop around,
  //         Easiest case. do nothing. just update bufsize
  // case 2:  we have a loop around,
  //         copy the left side of the loop around to the end. 
  if (tail >= head) {
    bufsize = s;
  }
  else {
    // how much excess space do we have now?
    size_t excess = (size_t)s - bufsize;
    // move up to excess bytes to the end 
    size_t movebytes = std::min<size_t>(tail, excess);
    memcpy(buffer + bufsize, buffer, movebytes); 
    // move the remaining bytes to the start of the buffer
    memmove(buffer, buffer+movebytes, tail - movebytes);
    // update buftail
    // if movebytes == tail, then tail has been wiped out
    // and it is no longer a looparound
    bufsize = s;    
    tail = (head + len) % bufsize;

  }
  consistency_check();
}
示例#12
0
文件: internals.c 项目: aosm/xinetd
static void periodic_check(void)
{
   consistency_check( PERIODIC ) ;
}
示例#13
0
文件: internals.c 项目: aosm/xinetd
void user_requested_check(void)
{
   consistency_check( USER_REQUESTED ) ;
} 
void circular_char_buffer::advance_write(std::streamsize bytes) {
  tail += bytes;
  if (tail >= bufsize) tail -= bufsize;
  len += bytes;
  consistency_check();
}
示例#15
0
    bool ktx_texture::write_to_stream(data_stream_serializer &serializer, bool no_keyvalue_data) const
    {
        if (!consistency_check())
        {
            VOGL_ASSERT_ALWAYS;
            return false;
        }

        memcpy(m_header.m_identifier, s_ktx_file_id, sizeof(m_header.m_identifier));
        m_header.m_endianness = m_opposite_endianness ? KTX_OPPOSITE_ENDIAN : KTX_ENDIAN;

        if (m_block_dim == 1)
        {
            m_header.m_glTypeSize = ktx_get_ogl_type_size(m_header.m_glType);
            m_header.m_glBaseInternalFormat = m_header.m_glFormat;
        }
        else
        {
            m_header.m_glBaseInternalFormat = ktx_get_ogl_compressed_base_internal_fmt(m_header.m_glInternalFormat);
        }

        m_header.m_bytesOfKeyValueData = 0;
        if (!no_keyvalue_data)
        {
            for (uint32_t i = 0; i < m_key_values.size(); i++)
                m_header.m_bytesOfKeyValueData += sizeof(uint32_t) + ((m_key_values[i].size() + 3) & ~3);
        }

        if (m_opposite_endianness)
            m_header.endian_swap();

        bool success = (serializer.write(&m_header, sizeof(m_header), 1) == 1);

        if (m_opposite_endianness)
            m_header.endian_swap();

        if (!success)
            return success;

        uint32_t total_key_value_bytes = 0;
        const uint8_t padding[3] = { 0, 0, 0 };

        if (!no_keyvalue_data)
        {
            for (uint32_t i = 0; i < m_key_values.size(); i++)
            {
                uint32_t key_value_size = m_key_values[i].size();

                if (m_opposite_endianness)
                    key_value_size = utils::swap32(key_value_size);

                success = (serializer.write(&key_value_size, sizeof(key_value_size), 1) == 1);
                total_key_value_bytes += sizeof(key_value_size);

                if (m_opposite_endianness)
                    key_value_size = utils::swap32(key_value_size);

                if (!success)
                    return false;

                if (key_value_size)
                {
                    if (serializer.write(&m_key_values[i][0], key_value_size, 1) != 1)
                        return false;
                    total_key_value_bytes += key_value_size;

                    uint32_t num_padding = 3 - ((key_value_size + 3) % 4);
                    if ((num_padding) && (serializer.write(padding, num_padding, 1) != 1))
                        return false;
                    total_key_value_bytes += num_padding;
                }
            }
            (void)total_key_value_bytes;
        }

        VOGL_ASSERT(total_key_value_bytes == m_header.m_bytesOfKeyValueData);

        for (uint32_t mip_level = 0; mip_level < get_num_mips(); mip_level++)
        {
            uint32_t mip_width, mip_height, mip_depth;
            get_mip_dim(mip_level, mip_width, mip_height, mip_depth);

            const uint32_t mip_row_blocks = (mip_width + m_block_dim - 1) / m_block_dim;
            const uint32_t mip_col_blocks = (mip_height + m_block_dim - 1) / m_block_dim;
            if ((!mip_row_blocks) || (!mip_col_blocks))
                return false;

            uint32_t image_size = mip_row_blocks * mip_col_blocks * m_bytes_per_block;
            if ((m_header.m_numberOfArrayElements) || (get_num_faces() == 1))
                image_size *= (get_array_size() * get_num_faces() * mip_depth);

            if (!image_size)
            {
                VOGL_ASSERT_ALWAYS;
                return false;
            }

            if (m_opposite_endianness)
                image_size = utils::swap32(image_size);

            success = (serializer.write(&image_size, sizeof(image_size), 1) == 1);

            if (m_opposite_endianness)
                image_size = utils::swap32(image_size);

            if (!success)
                return false;

            uint32_t total_mip_size = 0;
            uint32_t total_image_data_size = 0;

            if ((!m_header.m_numberOfArrayElements) && (get_num_faces() == 6))
            {
                // plain non-array cubemap
                for (uint32_t face = 0; face < get_num_faces(); face++)
                {
                    const uint8_vec &image_data = get_image_data(get_image_index(mip_level, 0, face, 0));
                    if ((!image_data.size()) || (image_data.size() != image_size))
                        return false;

                    if (m_opposite_endianness)
                    {
                        uint8_vec tmp_image_data(image_data);
                        utils::endian_swap_mem(&tmp_image_data[0], tmp_image_data.size(), m_header.m_glTypeSize);
                        if (serializer.write(&tmp_image_data[0], tmp_image_data.size(), 1) != 1)
                            return false;
                    }
                    else if (serializer.write(&image_data[0], image_data.size(), 1) != 1)
                        return false;

                    // Not +=, but =, because of the silly image_size plain cubemap exception in the KTX file format
                    total_image_data_size = image_data.size();

                    uint32_t num_cube_pad_bytes = 3 - ((image_data.size() + 3) % 4);
                    if ((num_cube_pad_bytes) && (serializer.write(padding, num_cube_pad_bytes, 1) != 1))
                        return false;

                    total_mip_size += image_size + num_cube_pad_bytes;
                }
            }
            else
            {
                // 1D, 2D, 3D (normal or array texture), or array cubemap
                for (uint32_t array_element = 0; array_element < get_array_size(); array_element++)
                {
                    for (uint32_t face = 0; face < get_num_faces(); face++)
                    {
                        for (uint32_t zslice = 0; zslice < mip_depth; zslice++)
                        {
                            const uint8_vec &image_data = get_image_data(get_image_index(mip_level, array_element, face, zslice));
                            if (!image_data.size())
                                return false;

                            if (m_opposite_endianness)
                            {
                                uint8_vec tmp_image_data(image_data);
                                utils::endian_swap_mem(&tmp_image_data[0], tmp_image_data.size(), m_header.m_glTypeSize);
                                if (serializer.write(&tmp_image_data[0], tmp_image_data.size(), 1) != 1)
                                    return false;
                            }
                            else if (serializer.write(&image_data[0], image_data.size(), 1) != 1)
                                return false;

                            total_image_data_size += image_data.size();

                            total_mip_size += image_data.size();
                        }
                    }
                }

                uint32_t num_mip_pad_bytes = 3 - ((total_mip_size + 3) % 4);
                if ((num_mip_pad_bytes) && (serializer.write(padding, num_mip_pad_bytes, 1) != 1))
                    return false;
                total_mip_size += num_mip_pad_bytes;
            }

            VOGL_ASSERT((total_mip_size & 3) == 0);
            VOGL_ASSERT(total_image_data_size == image_size);
        }

        return true;
    }
示例#16
0
static void
validate_resources(const struct subtest_t st, GLuint prog, bool *pass)
{
	GLsizei max_size = 0, size, i;
	char * name;

	/* Do not run the test for GL_ATOMIC_COUNTER_BUFFER.
	 * From the GL_ARB_program_interface_query extension:
	 *
	 * "The error INVALID_OPERATION is generated if <programInterface>
	 * is ATOMIC_COUNTER_BUFFER, since active atomic counter buffer
	 * resources are not assigned name strings."
	 */
	if (st.programInterface == GL_ATOMIC_COUNTER_BUFFER)
		return;

	name = (char *) malloc(st.max_length_name);
	for (i = 0; i < st.active_resources; i++) {
		GLuint index;

		glGetProgramResourceName(prog, st.programInterface,
					 i, st.max_length_name,
					 &size, name);
		piglit_check_gl_error(GL_NO_ERROR);

		/* keep track of the maximum size */
		if (size > max_size) {
			max_size = size;
		}

		/* Check the names. Transform feedback requires the order to be
		 * the same as the one given in glTransformFeedbackVaryings.
		 * From the GL_ARB_program_interface_query extension:
		 *
		 * "The order of the active resource list is
		 * implementation-dependent for all interfaces except for
		 * TRANSFORM_FEEDBACK_VARYING. For TRANSFORM_FEEDBACK_VARYING,
		 * the active resource list will use the variable order
		 * specified in the the most recent call to
		 * TransformFeedbackVaryings before the last call to
		 * LinkProgram.
		 */
		if (st.resources && !is_resource_in_list(st.resources, name, i,
			st.programInterface == GL_TRANSFORM_FEEDBACK_VARYING)) {
			fprintf(stderr, "Resource '%s' not found in '%s' "
					"resource list or found at the wrong "
					"index\n", name,
				st.programInterface_str);
			*pass = false;
		}

		/* Check the position of the arguments and see if it matches
		 * with the current position we are in.
		 */
		index = glGetProgramResourceIndex(prog, st.programInterface,
						  name);
		if (index != i) {
			fprintf(stderr, "%s: Resource '%s' is not at the "
					"position reported by "
					"glGetProgramResourceIndex (%i instead "
					"of %i)\n",
				st.programInterface_str, name, index, i);
			*pass = false;
		}

		/* check the equivalence with the old API */
		if (!consistency_check(prog, st.programInterface, name,
				       index)) {
			*pass = false;
		}
	}
	free(name);

	/* glGetProgramResourceName does not count the NULL terminator as part
	 * of the size contrarily to glGetProgramInterfaceiv.
	 * From the GL_ARB_program_interface_query extension:
	 *
	 * "void GetProgramInterfaceiv(uint program, enum programInterface,
	 *                             enum pname, int *params);
	 * [...]
	 * If <pname> is MAX_NAME_LENGTH, the value returned is the length of
	 * the longest active name string for an active resource in
	 * <programInterface>. This length includes an extra character for the
	 * null terminator."
	 *
	 * "void GetProgramResourceName(uint program, enum programInterface,
	 *                              uint index, sizei bufSize,
	 *                              sizei *length, char *name);
	 * [...]
	 * The actual number of characters written into <name>, excluding the
	 * null terminator, is returned in <length>."
	 */
	if (max_size != MAX2(0, st.max_length_name - 1)) {
		fprintf(stderr, "'%s actual max length' expected %i but got "
				"%i\n", st.programInterface_str,
			st.max_length_name - 1,	max_size);
		*pass = false;
	}
}