예제 #1
0
static
void tag_buf_add(struct tag *t, char **buf, size_t *size)
{
	*buf = xrealloc(*buf, (*size) + byte_size(t));
	memcpy((*buf) + (*size), t, byte_size(t));
	*size += byte_size(t);
}
예제 #2
0
파일: BufferBase.cpp 프로젝트: gan74/Yave
vk::DescriptorBufferInfo BufferBase::descriptor_info() const {
	return vk::DescriptorBufferInfo()
			.setBuffer(_buffer)
			.setOffset(0)
			.setRange(byte_size())
		;
}
예제 #3
0
static
uint32_t *tag_buf_find_initrd_start(struct tag *buf)
{
	for(; byte_size(buf); buf = tag_next(buf))
		if(buf->hdr.tag == ATAG_INITRD2)
			return &buf->u.initrd.start;
	return NULL;
}
예제 #4
0
	GeometryID Renderer_GL44::geometry_create(GeometryBufferType buffer_type, uint32 index_count, uint32 vertex_count,
		GeometryConfigID geometry_config_id)
	{
		ARC_ASSERT(m_geometry_config_data.valid(geometry_config_id.value()), "Invalid GeometryConfigID");

		auto& buffer = m_geom_buffer_data[(uint32)buffer_type];
		auto& config = *m_geometry_config_data.data(geometry_config_id.value());
		auto& vertex_layout = *config.layout;

		// check wheter the buffer has enough free memory
		uint32 vertex_stride = vertex_layout.stride();
		uint32 aligned_begin = memory::util::forward_align(buffer.front, vertex_stride);
		uint32 vertex_size = vertex_count * vertex_stride;
		uint32 index_size = index_count * byte_size(config.index_type);
		uint32 block_end = aligned_begin + vertex_size + index_size;
		if (block_end > buffer.size) return INVALID_GEOMETRY_ID; // not enough memory

		uint32 index = m_geometry_indices.create();
		auto& mesh = m_geometry_data[index];

		mesh.buffer_type = buffer_type;

		mesh.vertex_begin = aligned_begin;
		mesh.vertex_begin_count = aligned_begin / vertex_layout.stride();
		mesh.vertex_count = vertex_count;
		mesh.vertex_size = vertex_size;

		mesh.index_begin = aligned_begin + vertex_size;
		mesh.index_begin_count = mesh.index_begin / byte_size(config.index_type);
		mesh.index_count = index_count;
		mesh.index_size = index_size;

		mesh.block_begin = buffer.front;
		mesh.block_size = block_end - buffer.front;

		mesh.gl_id = buffer.gl_id;
		mesh.geometry_config_id = geometry_config_id;

		buffer.front = block_end;

		return GeometryID{ index };
	}
예제 #5
0
    self& operator()(const std::vector<char>& val)
    {
        if (val.size() > 65535)
            throw std::runtime_error("array too long");

        uint16_t byte_size(val.size());
        write(htons(byte_size));
        write_.insert(write_.end(), val.begin(), val.end());

        return *this;
    }
예제 #6
0
 void encoding(T state, Encoding* obj) {
   if(obj->nil_p() || (!CBOOL(ascii_only()) && obj->ascii_compatible())) {
     ascii_only(cNil);
     num_chars(nil<Fixnum>());
     valid_encoding(cNil);
   }
   if(byte_size() == 0 && !obj->nil_p() && obj->ascii_compatible()) {
     ascii_only(cTrue);
     num_chars(Fixnum::from(0));
     valid_encoding(cTrue);
   }
   encoding(obj);
   state->memory()->write_barrier(this, obj);
 }
예제 #7
0
    self& operator()(const std::basic_string<char>& val)
    {
        if (val.size() * sizeof(char) > 65535)
            throw std::runtime_error("string too long");

        uint16_t byte_size(val.size() * sizeof(char));
        write(htons(byte_size));
        if (byte_size > 0) {
            size_type pos(write_.size());
            write_.resize(pos + byte_size);
            const char* ptr(reinterpret_cast<const char*>(&*val.begin()));
            std::copy(ptr, ptr + byte_size, write_.begin() + pos);
        }
        return *this;
    }
예제 #8
0
output_t& decompress (const compressed_data& in, output_t& out)
{
    uint16_t byte_size (in.unpacked_len);

    // Make room for the unpacked data
    out.resize(byte_size / sizeof(typename output_t::value_type));
    std::fill(out.begin(), out.end(), 0);
    if (byte_size > 0)
    {
        auto out_ptr (reinterpret_cast<char*>(&*out.begin()));
        int output_length (LZ4_uncompress(in.ptr(), out_ptr, byte_size));
        if (output_length < 0)
            throw std::runtime_error("lz4 decompression failed");

        assert((size_t)output_length == in.size());
    }

    return out;
}
예제 #9
0
compressed_data compress (const input_t& in)
{
    size_t byte_size (in.size() * sizeof(typename input_t::value_type));
    if (byte_size > 0xffff)
        throw std::runtime_error("too much data for compression");

    auto in_ptr (reinterpret_cast<const char*>(&*in.begin()));
    compressed_data out;
    if (byte_size > 0)
    {
        out.resize(byte_size + 16);
        std::fill(out.begin(), out.end(), 0);
        out.unpacked_len = byte_size;

        int compressed_length (LZ4_compress(in_ptr, out.ptr(), byte_size));
        if (compressed_length <= 0)
            throw std::runtime_error("lz4 compression failed");

        out.resize(compressed_length);
    }

    return out;
}
예제 #10
0
파일: main.c 프로젝트: evilaliv3/lz78
int main(int argc, char* argv[]) {
    char* name_in = NULL;
    char* name_out = NULL;
    char* w_argv = NULL;
    wrapper* w;
    int bsize = B_SIZE_DEFAULT;
    int opt, ret;
    uint8_t w_mode = WRAPPER_MODE_COMPRESS;
    uint8_t w_type = LZ78_ALGORITHM;

    while ((opt = getopt(argc, argv, "i:o:dt:b:a:h")) != -1) {
        switch (opt) {
            case 'i': /* Input */
                name_in = optarg;
                break;

            case 'o': /* Output */
                name_out = optarg;
                break;

            case 'd': /* Decompress */
                w_mode = WRAPPER_MODE_DECOMPRESS;
                break;

            case 't': /* Type */
                if (!(w_type = get_algorithm(optarg))) {
                    fprintf(stderr, "Invalid algorithm type: %s\n", optarg);
                    exit(EXIT_FAILURE);
                }
                break;

            case 'b': /* Buffer size */
                bsize = byte_size(optarg);
                break;

            case 'a': /* Additional parameter */
                w_argv = optarg;
                break;

            case 'h': /* Compressor help */
            default:
                help(argv);
                exit(EXIT_FAILURE);
        }
    }

    if (bsize <= 0) {
        help(argv);
        exit(EXIT_FAILURE);
    }

    /* Creates a wrapper instance */
    w = wrapper_new(w_mode, w_type, w_argv);
    if (w == NULL) {
        fprintf(stderr, "Unable to create wrapper\n");
        exit(EXIT_FAILURE);
    }

    /* Executes the wrapper function */
    ret = wrapper_exec(w, name_in, name_out);
    
    if (ret != WRAPPER_SUCCESS)
        wrapper_perror();

    /* Destroyes the wrapper instance */
    wrapper_destroy(w);

    return ret;
}
예제 #11
0
 /**
  * Returns the number of NodeRefs in the collection.
  *
  * Complexity: Constant.
  */
 size_type size() const noexcept {
     const auto size_node_refs = byte_size() - sizeof(NodeRefList);
     assert(size_node_refs % sizeof(NodeRef) == 0);
     return size_node_refs / sizeof(NodeRef);
 }
예제 #12
0
static
int atag_arm_load(struct kexec_info *info, unsigned long base,
	const char *command_line, off_t command_line_len,
	const char *initrd, off_t initrd_len, off_t initrd_off)
{
	struct tag *saved_tags = atag_read_tags();
	char *buf = NULL;
	size_t buf_size = 0;
	struct tag *params, *tag;
	uint32_t *initrd_start = NULL;

	params = xmalloc(getpagesize());
	if (!params) {
		fprintf(stderr, "Compiling ATAGs: out of memory\n");
		free(saved_tags);
		return -1;
	}
	memset(params, 0xff, getpagesize());

	if (saved_tags) {
		// Copy tags
		tag = saved_tags;
		while(byte_size(tag)) {
			switch (tag->hdr.tag) {
			case ATAG_INITRD:
			case ATAG_INITRD2:
			case ATAG_CMDLINE:
			case ATAG_NONE:
				// skip these tags
				break;
			default:
				// copy all other tags
				tag_buf_add(tag, &buf, &buf_size);
				break;
			}
			tag = tag_next(tag);
		}
		free(saved_tags);
	} else {
		params->hdr.size = 2;
		params->hdr.tag = ATAG_CORE;
		tag_buf_add(params, &buf, &buf_size);
		memset(params, 0xff, byte_size(params));
	}

	if (initrd) {
		params->hdr.size = tag_size(tag_initrd);
		params->hdr.tag = ATAG_INITRD2;
		params->u.initrd.size = initrd_len;

		tag_buf_add(params, &buf, &buf_size);
		memset(params, 0xff, byte_size(params));
	}

	if (command_line) {
		params->hdr.size = (sizeof(struct tag_header) + command_line_len + 3) >> 2;
		params->hdr.tag = ATAG_CMDLINE;
		memcpy(params->u.cmdline.cmdline, command_line,
			command_line_len);
		params->u.cmdline.cmdline[command_line_len - 1] = '\0';

		tag_buf_add(params, &buf, &buf_size);
		memset(params, 0xff, byte_size(params));
	}

	params->hdr.size = 0;
	params->hdr.tag = ATAG_NONE;
	tag_buf_add(params, &buf, &buf_size);

	free(params);

	add_segment(info, buf, buf_size, base, buf_size);

	if (initrd) {
		initrd_start = tag_buf_find_initrd_start((struct tag *)buf);
		if(!initrd_start)
		{
			fprintf(stderr, "Failed to find initrd start!\n");
			return -1;
		}

		*initrd_start = locate_hole(info, initrd_len, getpagesize(),
				initrd_off, ULONG_MAX, INT_MAX);
		if (*initrd_start == ULONG_MAX)
			return -1;
		add_segment(info, initrd, initrd_len, *initrd_start, initrd_len);
	}

	return 0;
}
예제 #13
0
 const_iterator cend() const {
     return const_iterator(data() + byte_size());
 }
예제 #14
0
 //--------------------------------------------------------------------------
 uword size() const   { return byte_size() / entry_byte_size(); }
예제 #15
0
 bool empty() const {
     return sizeof(Collection<TMember, TCollectionItemType>) == byte_size();
 }
예제 #16
0
 iterator end() {
     return iterator(data() + byte_size());
 }
예제 #17
0
 void dump_as_list(const int fd) final {
     osmium::io::detail::reliable_write(fd, reinterpret_cast<const char*>(m_vector.data()), byte_size());
 }
예제 #18
0
static
int atag_arm_load(struct kexec_info *info, unsigned long base,
	const char *command_line, off_t command_line_len,
	const char *initrd, off_t initrd_len)
{
	struct tag *saved_tags = atag_read_tags();
	char *buf, *cmdline_buf;
	off_t len, cmdline_len = 0;
	struct tag *params;
	uint32_t *initrd_start;
	int i;

	buf = xmalloc(getpagesize());
	if (!buf) {
		fprintf(stderr, "Compiling ATAGs: out of memory\n");
		return -1;
	}

	cmdline_buf = xmalloc(COMMAND_LINE_SIZE);
	if (!cmdline_buf) {
		fprintf(stderr, "Compiling Command line: out of memory\n");
		return -1;
	}

	memset(buf, 0xff, getpagesize());
        memset((void *)cmdline_buf, 0, COMMAND_LINE_SIZE);
	params = (struct tag *)buf;
	if (saved_tags) {
		// Copy tags
		saved_tags = (struct tag *) saved_tags;
		while(byte_size(saved_tags)) {
			switch (saved_tags->hdr.tag) {
			case ATAG_INITRD:
			case ATAG_INITRD2:
			case ATAG_NONE:
				// skip these tags
				break;
			case ATAG_CMDLINE:
                                cmdline_len = strlen(saved_tags->u.cmdline.cmdline) + 1;
                                if(cmdline_len > COMMAND_LINE_SIZE)
                                    die("Command line overflow\n");
                                strncpy(cmdline_buf, saved_tags->u.cmdline.cmdline, COMMAND_LINE_SIZE);
                                cmdline_buf[COMMAND_LINE_SIZE - 1] = '\0';
                                break;
			default:
				// copy all other tags
				memcpy(params, saved_tags, byte_size(saved_tags));
				params = tag_next(params);
			}
			saved_tags = tag_next(saved_tags);
		}
	} else {
		params->hdr.size = 2;
		params->hdr.tag = ATAG_CORE;
		params = tag_next(params);
	}

	if (initrd) {
		params->hdr.size = tag_size(tag_initrd);
		params->hdr.tag = ATAG_INITRD2;
		initrd_start = &params->u.initrd.start;
		params->u.initrd.size = initrd_len;
		params = tag_next(params);
	}

	if (command_line) {
                command_line_len = command_line_len + cmdline_len -1;
                if(command_line_len > COMMAND_LINE_SIZE)
                    die("Command line overflow\n");
                strncat(cmdline_buf, command_line, COMMAND_LINE_SIZE - 1);
		params->hdr.size = (sizeof(struct tag_header) + command_line_len + 3) >> 2;
		params->hdr.tag = ATAG_CMDLINE;
		memcpy(params->u.cmdline.cmdline, cmdline_buf,
			command_line_len);
		params->u.cmdline.cmdline[command_line_len - 1] = '\0';
		params = tag_next(params);
	}

	params->hdr.size = 0;
	params->hdr.tag = ATAG_NONE;
	len = ((char *)params - buf) + sizeof(struct tag_header);

	add_segment(info, buf, len, base, len);

	if (initrd) {
		struct memory_range *range;
		int ranges;
		get_memory_ranges(&range, &ranges, info->kexec_flags);
		for (i=0; range[i].start; i++) {
			printf("Memory Ranges: range[%d].start = 0x%x\n", 
							i, range[i].start);
		}

		//*initrd_start = locate_hole(info, initrd_len, getpagesize(), range[0].start + 0x800000, ULONG_MAX, INT_MAX);
		/* Allocate memory from 0x400000 offset from start of capture kernel*/
		if (range[ranges-1].start > 0)
			*initrd_start = range[ranges-1].start +  0x400000;

		printf("*initrd_start = %p\n", *initrd_start);
		if (*initrd_start == ULONG_MAX)
			return -1;
		add_segment(info, initrd, initrd_len, *initrd_start, initrd_len);
	}

	return 0;
}
예제 #19
0
/*
 * Execute a private command on the interface
 */
static int
set_private(int		skfd,		/* Socket */
	    char *	args[],		/* Command line args */
	    int		count,		/* Args count */
	    char *	ifname)		/* Dev name */
{
  u_char	buffer[1024];
  struct iwreq		wrq;
  int		i = 0;		/* Start with first arg */
  int		k;
  iwprivargs	priv[16];
  int		number;

  /* Read the private ioctls */
  number = get_priv_info(skfd, ifname, priv);

  /* Is there any ? */
  if(number <= 0)
    {
      /* Could skip this message ? */
      fprintf(stderr, "%-8.8s  no private ioctls.\n\n",
	      ifname);
      return(-1);
    }

  /* Search the correct ioctl */
  k = -1;
  while((++k < number) && strcmp(priv[k].name, args[i]));

  /* If not found... */
  if(k == number)
    {
      fprintf(stderr, "Invalid command : %s\n", args[i]);
      return(-1);
    }
	  
  /* Next arg */
  i++;

  /* If we have to set some data */
  if((priv[k].set_args & IW_PRIV_TYPE_MASK) &&
     (priv[k].set_args & IW_PRIV_SIZE_MASK))
    {
      switch(priv[k].set_args & IW_PRIV_TYPE_MASK)
	{
	case IW_PRIV_TYPE_BYTE:
	  /* Number of args to fetch */
	  wrq.u.data.length = count - 1;
	  if(wrq.u.data.length > (priv[k].set_args & IW_PRIV_SIZE_MASK))
	    wrq.u.data.length = priv[k].set_args & IW_PRIV_SIZE_MASK;

	  /* Fetch args */
	  for(; i < wrq.u.data.length + 1; i++)
	    sscanf(args[i], "%d", (int *)(buffer + i - 1));
	  break;

	case IW_PRIV_TYPE_INT:
	  /* Number of args to fetch */
	  wrq.u.data.length = count - 1;
	  if(wrq.u.data.length > (priv[k].set_args & IW_PRIV_SIZE_MASK))
	    wrq.u.data.length = priv[k].set_args & IW_PRIV_SIZE_MASK;

	  /* Fetch args */
	  for(; i < wrq.u.data.length + 1; i++)
	    sscanf(args[i], "%d", ((u_int *) buffer) + i - 1);
	  break;

	case IW_PRIV_TYPE_CHAR:
	  if(i < count)
	    {
	      /* Size of the string to fetch */
	      wrq.u.data.length = strlen(args[i]) + 1;
	      if(wrq.u.data.length > (priv[k].set_args & IW_PRIV_SIZE_MASK))
		wrq.u.data.length = priv[k].set_args & IW_PRIV_SIZE_MASK;

	      /* Fetch string */
	      memcpy(buffer, args[i], wrq.u.data.length);
	      buffer[sizeof(buffer) - 1] = '\0';
	      i++;
	    }
	  else
	    {
	      wrq.u.data.length = 1;
	      buffer[0] = '\0';
	    }
	  break;

	default:
	  fprintf(stderr, "Not yet implemented...\n");
	  return(-1);
	}
	  
      if((priv[k].set_args & IW_PRIV_SIZE_FIXED) &&
	 (wrq.u.data.length != (priv[k].set_args & IW_PRIV_SIZE_MASK)))
	{
	  printf("The command %s need exactly %d argument...\n",
		 priv[k].name, priv[k].set_args & IW_PRIV_SIZE_MASK);
	  return(-1);
	}
    }	/* if args to set */
  else
    {
      wrq.u.data.length = 0L;
    }

  strncpy(wrq.ifr_name, ifname, IFNAMSIZ);

  if((priv[k].set_args & IW_PRIV_SIZE_FIXED) &&
     (byte_size(priv[k].set_args) < IFNAMSIZ))
    memcpy(wrq.u.name, buffer, IFNAMSIZ);
  else
    {
      wrq.u.data.pointer = (caddr_t) buffer;
      wrq.u.data.flags = 0;
    }

  /* Perform the private ioctl */
  if(ioctl(skfd, priv[k].cmd, &wrq) < 0)
    {
      fprintf(stderr, "Interface doesn't accept private ioctl...\n");
      fprintf(stderr, "%X: %s\n", priv[k].cmd, strerror(errno));
      return(-1);
    }

  /* If we have to get some data */
  if((priv[k].get_args & IW_PRIV_TYPE_MASK) &&
     (priv[k].get_args & IW_PRIV_SIZE_MASK))
    {
      int	j;
      int	n = 0;		/* number of args */

      printf("%-8.8s  %s:", ifname, priv[k].name);

      if((priv[k].get_args & IW_PRIV_SIZE_FIXED) &&
	 (byte_size(priv[k].get_args) < IFNAMSIZ))
	{
	  memcpy(buffer, wrq.u.name, IFNAMSIZ);
	  n = priv[k].get_args & IW_PRIV_SIZE_MASK;
	}
      else
	n = wrq.u.data.length;

      switch(priv[k].get_args & IW_PRIV_TYPE_MASK)
	{
	case IW_PRIV_TYPE_BYTE:
	  /* Display args */
	  for(j = 0; j < n; j++)
	    printf("%d  ", buffer[j]);
	  printf("\n");
	  break;

	case IW_PRIV_TYPE_INT:
	  /* Display args */
	  for(j = 0; j < n; j++)
	    printf("%d  ", ((u_int *) buffer)[j]);
	  printf("\n");
	  break;

	case IW_PRIV_TYPE_CHAR:
	  /* Display args */
	  buffer[wrq.u.data.length - 1] = '\0';
	  printf("%s\n", buffer);
	  break;

	default:
	  fprintf(stderr, "Not yet implemented...\n");
	  return(-1);
	}
    }	/* if args to set */

  return(0);
}
예제 #20
0
 iterator end() noexcept {
     return iterator(data() + byte_size());
 }
예제 #21
0
 //--------------------------------------------------------------------------
 bool is_empty() const { return byte_size() == 0; }
예제 #22
0
 //--------------------------------------------------------------------------
 bool is_full() const { return byte_size() == byte_capacity(); }
static
int atag_arm_load(struct kexec_info *info, unsigned long base,
	const char *command_line, off_t command_line_len,
	const char *initrd, off_t initrd_len, off_t initrd_off)
{
	struct tag *saved_tags = atag_read_tags();
	char *buf;
	off_t len;
	struct tag *params;
	uint32_t *initrd_start = NULL;
	
	buf = xmalloc(getpagesize());
	if (!buf) {
		fprintf(stderr, "Compiling ATAGs: out of memory\n");
		return -1;
	}

	memset(buf, 0xff, getpagesize());
	params = (struct tag *)buf;

	if (saved_tags) {
		// Copy tags
		saved_tags = (struct tag *) saved_tags;
		while(byte_size(saved_tags)) {
			switch (saved_tags->hdr.tag) {
			case ATAG_INITRD:
			case ATAG_INITRD2:
			case ATAG_CMDLINE:
			case ATAG_NONE:
				// skip these tags
				break;
			default:
				// copy all other tags
				memcpy(params, saved_tags, byte_size(saved_tags));
				params = tag_next(params);
			}
			saved_tags = tag_next(saved_tags);
		}
	} else {
		params->hdr.size = 2;
		params->hdr.tag = ATAG_CORE;
		params = tag_next(params);
	}

	if (initrd) {
		params->hdr.size = tag_size(tag_initrd);
		params->hdr.tag = ATAG_INITRD2;
		initrd_start = &params->u.initrd.start;
		params->u.initrd.size = initrd_len;
		params = tag_next(params);
	}

	if (command_line) {
		params->hdr.size = (sizeof(struct tag_header) + command_line_len + 3) >> 2;
		params->hdr.tag = ATAG_CMDLINE;
		memcpy(params->u.cmdline.cmdline, command_line,
			command_line_len);
		params->u.cmdline.cmdline[command_line_len - 1] = '\0';
		params = tag_next(params);
	}

	params->hdr.size = 0;
	params->hdr.tag = ATAG_NONE;

	len = ((char *)params - buf) + sizeof(struct tag_header);

	add_segment(info, buf, len, base, len);

	if (initrd) {
		*initrd_start = locate_hole(info, initrd_len, getpagesize(),
				initrd_off, ULONG_MAX, INT_MAX);
		if (*initrd_start == ULONG_MAX)
			return -1;
		add_segment(info, initrd, initrd_len, *initrd_start, initrd_len);
	}

	return 0;
}
예제 #24
0
 bool empty() const noexcept {
     return sizeof(NodeRefList) == byte_size();
 }
예제 #25
0
 // Size computations.  Sizes are in bytes.
 size_t capacity()     const { return byte_size(bottom(), end()); }