Пример #1
0
struct region *
create_gas_cloud(struct level *lev, xchar x, xchar y, int radius, int damage)
{
    struct region *cloud;
    int i, nrect;
    struct nhrect tmprect;

    cloud = create_region(NULL, 0);
    nrect = radius;
    tmprect.lx = x;
    tmprect.hx = x;
    tmprect.ly = y - (radius - 1);
    tmprect.hy = y + (radius - 1);
    for (i = 0; i < nrect; i++) {
        add_rect_to_reg(cloud, &tmprect);
        tmprect.lx--;
        tmprect.hx++;
        tmprect.ly++;
        tmprect.hy--;
    }
    cloud->ttl = rn1(3, 4);
    if (!in_mklev && !flags.mon_moving)
        set_heros_fault(cloud); /* assume player has created it */
    cloud->inside_f = INSIDE_GAS_CLOUD;
    cloud->expire_f = EXPIRE_GAS_CLOUD;
    cloud->arg = damage;
    cloud->visible = TRUE;
    cloud->effect_id = dbuf_effect(E_MISC, E_gascloud);
    add_region(lev, cloud);
    return cloud;
}
Пример #2
0
  /*! \brief Replaces current process image with a new one.
   * 
   * Given a current context, replaces all core and stack regions with ones
   * created from an ELF file image in memory, including the creation of a process
   * data section with the given environmental variables*/
  int execve_elf (context_t * cur_process, void * elf_image, unsigned long length, const char * env) {
    bootvideo_printf ("elf image = %l\n", elf_image);
    if ((cur_process == 0) ||
        (elf_image == 0)) return 0;                 
    if (length >= 0x20000000) {
    bootvideo_printf ("Unsupported Length: %x\n", length);
    return -1;
  }
  /*We need to make a fake segment before 0x40000000 and copy the elf image
   * there so we can safely destroy all the process's memory regions */
  memory_region_t temp;

  temp.parent = cur_process->space;
  temp.type = MR_TYPE_KERNEL;
  temp.virtual_address = 0x20000000;
  temp.length = (length + PAGE_SIZE) / PAGE_SIZE;
  map_user_region_to_physical(&temp, 0); /*Make it be backed by mem*/
  memcpy ( (void *)0x20000000, elf_image, length);
  elf_image = (void *) 0x20000000;

  memory_region_t * cur;
  for (cur = cur_process->space->first; cur->next != cur_process->space->last;
      cur = cur->next) {
    if (cur->next->type == MR_TYPE_CORE) {
      delete_region (cur->next);
    }
  }

  Elf32_Ehdr * elf_header = (Elf32_Ehdr *) elf_image;
  Elf32_Phdr * prg_header = (Elf32_Phdr *) ((unsigned long) elf_image + elf_header->e_phoff);
  uint16 cur_phdr;

  /*Verify the header*/
  if ( !(elf_header->e_ident[EI_MAG0] == ELFMAG0) ||
       !(elf_header->e_ident[EI_MAG1] == ELFMAG1) ||
       !(elf_header->e_ident[EI_MAG2] == ELFMAG2) ||
       !(elf_header->e_ident[EI_MAG3] == ELFMAG3) ) {
    bootvideo_printf ("Not passed a valid ELF image\n");
    return -1;
  }

  for (cur_phdr = 0; cur_phdr < elf_header->e_phnum; ++cur_phdr, ++prg_header) {
   if (prg_header->p_type != PT_LOAD) continue;
   memory_region_t * mr = create_region (cur_process->space, prg_header->p_vaddr, ((prg_header->p_memsz + PAGE_SIZE) / PAGE_SIZE), MR_TYPE_CORE, 0, 0);
   map_user_region_to_physical (mr, 0);
   memcpy ( (char *)prg_header->p_vaddr,(char *) ((unsigned long)elf_image + prg_header->p_offset), prg_header->p_filesz);
  }
  cur_process->registers.eip = elf_header->e_entry;
  elf_header->e_ident[0] = *env;
  return 0;
}
Пример #3
0
static void test_json_report(CuTest * tc) {
    region * r;
    faction * f;
    unit * u;
    cJSON * json;

    cleargame(true);
    turn = 0;
    r = create_region(0, 1, 1, create_terrain("plain"));
    f = addplayer(r, 0, 0);
    u = r->units;
    update_world(0, 0, 1, 1);

    json = json_report(f);
    CuAssertIntEquals(tc, turn, cJSON_GetObjectItem(json, "turn")->valueint);
    free(json);
}
Пример #4
0
/*
 * Called when a TA is invoked. sess_ctx hold that value that was
 * assigned by TA_OpenSessionEntryPoint(). The rest of the paramters
 * comes from normal world.
 */
TEE_Result TA_InvokeCommandEntryPoint(void *sess_ctx, uint32_t cmd_id,
			uint32_t param_types, TEE_Param params[4])
{
	(void)&sess_ctx; /* Unused parameter */


	switch (cmd_id) {
	case TA_SDP_CREATE_REGION:
		return create_region(param_types, params);
	case TA_SDP_DESTROY_REGION:
		return destroy_region(param_types, params);
	case TA_SDP_UPDATE_REGION:
		return update_region(param_types, params);
	case TA_SDP_DUMP_STATUS:
		return dump_status(param_types, params);
	default:
		return TEE_ERROR_BAD_PARAMETERS;
	}
}
Пример #5
0
/*! \brief Implements POSIX fork(). 
 *
 * \returns -1 if child, or the child's PID if parent
 */
int fork (isr_regs * regs) {
  context_t * new_context, *t;
  memory_region_t *newr;
  new_context = (context_t*)allocate_from_slab(context_slab);
  if (context_list == 0) {
    context_list = new_context;
  } else {
    for (t = context_list;
	 t->next != 0;
	 t = t->next); /*Get to end*/
    t->next = new_context;
  } 
  new_context->next = 0;
  new_context->pid = next_avail_pid;
  ++next_avail_pid;
  memcpy ((void *) &new_context->registers, (void *) regs, sizeof (isr_regs));
  new_context->registers.edx = 0;
  new_context->space = create_address_space ();
  for (newr = new_context->space->first->next; newr->next != new_context->space->stack; newr = newr->next);
  newr->next = new_context->space->stack->next;
  deallocate_from_slab (regions_slab, new_context->space->stack);

  new_context->status = PROCESS_STATUS_RUNNING;

  memory_region_t * mr = cur_process->space->first->next;
  unsigned long addr;
  while (mr->type != MR_TYPE_SENTINEL) {

    switch (mr->type) {
      case MR_TYPE_ANON:
      case MR_TYPE_CORE:
      case MR_TYPE_LIBRARY:
        newr = create_region (new_context->space, mr->virtual_address, mr->length,
            mr->type, mr->attributes, mr->parameter);
        map_user_region_to_physical(newr, 0);
        for (addr = newr->virtual_address; addr < newr->virtual_address + newr->length * PAGE_SIZE;
            addr += PAGE_SIZE) {
          void * a = (void * )map_user_virtual_to_kernel (new_context, addr);
          memcpy (a, (void *) addr, PAGE_SIZE);
          free_kernel_virtual_page ((unsigned long)a);
        }
        break;
      case MR_TYPE_STACK:
        newr = create_region (new_context->space, mr->virtual_address, mr->length,
            mr->type, mr->attributes, mr->parameter);
        for (addr = newr->virtual_address; addr < newr->virtual_address + newr->length * PAGE_SIZE;
           addr += PAGE_SIZE) {
          if (user_address_to_physical (cur_process->space, addr) != 0) {
            map_user_address (new_context->space->virt_cr3, addr, allocate_page (0) * PAGE_SIZE, 0);
            void * a = (void * )map_user_virtual_to_kernel (new_context, addr);
            memcpy (a, (void *) addr, PAGE_SIZE);
          }
        } 
        new_context->space->stack = newr;
        break;
      case MR_TYPE_IPC:
        newr = clone_region (new_context->space, mr, 0);
        kfifo_clone_fifo (newr->parameter, new_context->pid);
        break;
      default:
        break;
    }
    kfifo_update_senders (cur_process->pid, new_context->pid);

    mr = mr->next;
  }
  return new_context->pid;

}
New_region_from_property_dialog::
New_region_from_property_dialog( GsTL_project* proj,
                    QWidget* parent, const char* name ){
  if (name)
    setObjectName(name);
  project_ = proj;
  
  QVBoxLayout* main_layout = new QVBoxLayout( this);
  main_layout->setMargin(9);
  main_layout->setSpacing(-1);
  
  QGroupBox* grid_box = new QGroupBox( this);
  QGroupBox* new_region_box = new QGroupBox( this);
  QGroupBox* prop_box = new QGroupBox( this);
  
  QVBoxLayout *vg = new QVBoxLayout(grid_box);
  QVBoxLayout *vr = new QVBoxLayout(new_region_box);
  QVBoxLayout *vp = new QVBoxLayout(prop_box);

  vg->addWidget(new QLabel("Select grid",grid_box) );
  gridSelector_ = new GridSelectorBasic(grid_box, "grid", proj );
  vg->addWidget(gridSelector_ );
  grid_box->setLayout( vg );

  vr->addWidget(new QLabel("New region name",new_region_box) );
  new_region_ = new QLineEdit(new_region_box);
  vr->addWidget(new_region_ );
  new_region_box->setLayout( vr );

  vp->addWidget(new QLabel("Source property",prop_box) );
  propSelector_ = new SinglePropertySelector(prop_box, "property" );
  QHBoxLayout *h_min_max = new QHBoxLayout( prop_box );
  

  min_max_box_ = new QGroupBox( prop_box );
  QVBoxLayout *v_min = new QVBoxLayout( prop_box );
  QVBoxLayout *v_max = new QVBoxLayout( prop_box );

  v_min->addWidget(new QLabel("Min",prop_box));
  v_max->addWidget(new QLabel("Max",prop_box));
  minFilter_  = new QLineEdit(prop_box);
  maxFilter_  = new QLineEdit(prop_box);
  v_min->addWidget( minFilter_ );
  v_max->addWidget( maxFilter_ );

  h_min_max->addLayout(v_min);
  h_min_max->addLayout(v_max);
  min_max_box_->setLayout( h_min_max);
  min_max_box_->setTitle("Values between Min and Max will be inside the region");

  vp->addWidget( propSelector_ );
  vp->addWidget( min_max_box_ );
  min_max_box_->setHidden(true);


  category_box_ = new QGroupBox(prop_box);
  category_box_->setTitle("Select categories that define the region");
  QVBoxLayout *v_cat = new QVBoxLayout( prop_box );

  cat_selector_ = new MultipleCategorySelector();
  v_cat->addWidget(cat_selector_);
  category_box_->setLayout(v_cat);
  category_box_->setHidden(true);
  vp->addWidget( category_box_ );



  grid_box->setLayout(vg);
  new_region_box->setLayout(vr);
  prop_box->setLayout(vp);


  QHBoxLayout* bottom_layout = new QHBoxLayout( this);
  bottom_layout->setSpacing(9);
  QPushButton* ok = new QPushButton( "Create", this);
  QPushButton* close = new QPushButton( "Create and Close", this);
  QPushButton* cancel = new QPushButton( "Cancel", this);

  bottom_layout->addStretch();
  bottom_layout->addWidget( ok );
  bottom_layout->addWidget( close );
  bottom_layout->addWidget( cancel );

  main_layout->addWidget( grid_box );
  main_layout->addStretch();
  main_layout->addWidget( new_region_box );
  main_layout->addStretch();
  main_layout->addWidget( prop_box );
  main_layout->addStretch();
  main_layout->addLayout( bottom_layout );

  
  QObject::connect( gridSelector_, SIGNAL( activated( const QString& ) ),
                    propSelector_, SLOT( show_properties( const QString& ) ) );

  QObject::connect( propSelector_, SIGNAL( activated( const QString& ) ),
                    this, SLOT( set_filter_type(  ) ) );

  QObject::connect( propSelector_, SIGNAL( activated( const QString& ) ),
                    this, SLOT( populate_categories( ) ) );


  QObject::connect( ok, SIGNAL( clicked() ),
                    this, SLOT( create_region() ) );
  QObject::connect( close, SIGNAL( clicked() ),
                    this, SLOT( create_region_and_close() ) );
  QObject::connect( cancel, SIGNAL( clicked() ),
                    this, SLOT( reject() ) );

  setSizeGripEnabled( true );
}
void New_region_from_property_dialog::create_region_and_close(){
	bool ok = create_region();
	if(ok) accept();
}