Ejemplo n.º 1
0
space_t space_clone() {
    uint32_t i;
    space_t dest;
    frame_t *exmap, *extbl;

    /* Create new address space */
    dest = space_alloc();

    /* Exmap in new address space */
    space_exmap(dest);
    extbl = (void*) TMP_MAP;
    exmap = (void*) (TMP_MAP + 0x3FF000);

    /* Clone/clear userspace */
    for (i = 0; i < 1023; i++) {
        if (cmap[i] & PF_PRES) {
            if (i >= KSPACE / SEGSZ) {
                exmap[i] = cmap[i];
            }
            else {
                segment_clone(extbl, exmap, i * SEGSZ);
            }
        }
    }

    return dest;
}
Ejemplo n.º 2
0
static void read_output(struct space *space, struct file *f, off_t *poff,
			struct bitcoin_transaction_output *output)
{
	output->amount = pull_u64(f, poff);
	output->script_length = pull_varint(f, poff);
	output->script = space_alloc(space, output->script_length);
	pull_bytes(f, poff, output->script, output->script_length);
}
Ejemplo n.º 3
0
static void read_input(struct space *space, struct file *f, off_t *poff,
		       struct bitcoin_transaction_input *input)
{
	pull_hash(f, poff, input->hash);
	input->index = pull_u32(f, poff);
	input->script_length = pull_varint(f, poff);
	input->script = space_alloc(space, input->script_length);
	pull_bytes(f, poff, input->script, input->script_length);

	input->sequence_number = pull_u32(f, poff);
}
Ejemplo n.º 4
0
byte *block_alloc(byte type, size_t size)
{
  int s, b, found = 0, blocks = BLOCKS(size);
  byte *block_map;
  byte *space;

  if (arena_state != INITIALIZED)
    arena_init();

  if (blocks > BLOCKS_PER_SPACE)
    error("Trying to allocate too many contiguous blocks.");

  for(s=0; s<SPACES_IN_ARENA; ++s) {
    if (space_type[s] == TYPE_BLOCKS) {
      block_map = SPACE_MAP(s);
      for (b=0; b<BLOCKS_PER_SPACE; b++) {
	if (block_map[b] == TYPE_FREE) {
	  found ++;
	  if(found >= blocks) {
	    int start = b+1-found, k;

	    for(k=start; k<=b; ++k)
	      block_map[k] = type;
	    map(BLOCK_BASE(s,start), GRAINROUND(page_size, size));
	    return(BLOCK_BASE(s,start));
	  }
	}
	else
	  found = 0;
      }
      found = 0;
    }
  }

  /* None of the existing block spaces have room; let's make a new one */

  space = space_alloc(TYPE_BLOCKS,0);    /* allocate the new space */
  s = SPACE(space);
  block_map = SPACE_MAP(s) = block_maps + s*BLOCKS_PER_SPACE;
  /* This is where the map is */

  for(b=0; b< blocks; ++b)
    block_map[b] = type;
  for (b=blocks; b < BLOCKS_PER_SPACE; b++)
    block_map[b] = TYPE_FREE;		 /* ... and initialize it */

  map(space, GRAINROUND(page_size, size));
  return(space);
}