コード例 #1
0
ファイル: posixmain.c プロジェクト: berkus/nemesis
/* Define a Nemesis-style Main() function which will serve as the
 * entry point of the user program if they haven't defined one.  This
 * allows the user to have a posix-style main() function, and have it
 * called in the traditional manner by this piece of code.  Since this
 * is in an ar-archive, it will only be used if Main() is undefined -
 * precisely the semantics we want. */
void Main(Closure_clp cl)
{
    NOCLOBBER uint32_t            argc;
    char ** NOCLOBBER             argv;
    char                          *null_arg = NULL;
    int                           ret;
    struct __atexit_stack_element __atexit_stack[__MAX_ATEXIT_FUNCS];
    int                           __atexit_stack_length;
#ifdef SPEC
    Time_T NOCLOBBER              start_time;
#endif

#ifdef SPEC
    start_time = NOW();
#endif

    __atexit_stack_length = 0;

    /*
     * Argument handling
     */
    TRY {
      uint32_t       i;
      Context_clp    ctx;
      uint32_t       num;
      
      ctx = NAME_LOOKUP ("arguments", Pvs(root), Context_clp);
      num = SEQ_LEN( Context$List( ctx ) );
      argv = Heap$Malloc (Pvs(heap), (num + 1) * sizeof (char *));
      for (i = 0, argc=0; i < num; i++) {
	uchar_t name[32];
	sprintf (name, "a%d", i);
	TRY {
	  argv[argc] = NAME_LOOKUP (name, ctx, string_t);
	  argc++;
	} CATCH_ALL {
	  /* one argument didn't have the right form, ignore it */
	} ENDTRY;
      }
      argv[argc] = (char *)NULL;
    } CATCH_ALL {
      argc = 0;
      argv = &null_arg;
    } ENDTRY;
    
    /* Run the program with a correctly setup exit. */
    CX_ADD("__atexit_stack", __atexit_stack, addr_t);
    CX_ADD("__atexit_stack_length", &__atexit_stack_length, addr_t);


#ifdef SPEC
    /* For timing stuff */
    CX_ADD("__spec_start_time", start_time, Time_T);
    (void)posixmain_atexit(__print_time);
#endif
    ret = main(argc, argv);
    if (ret)
	printf("main() exited with non-zero return code %d\n", ret);
}
コード例 #2
0
ファイル: flowman.c プロジェクト: berkus/nemesis
static void
ARP_m (
        FlowMan_cl      *self,
        uint32_t        ipaddr  /* IN */,
	Net_EtherAddr	*hwaddr /* OUT */)
{
    flowman_st    *st = (flowman_st *) self->st;
    FlowMan_RouteInfo *ri;
    intf_st *ifst;
    char buf[20];
    Net_EtherAddrP NOCLOBBER ret = NULL;

    /* route the IP address to see which interface we ARP out of */
    ri = ip_route(st->host->routetab, ipaddr, 0);
    TRY {
	ifst = ifname2ifst(st->host, ri->ifname);
	if (!ifst)
	{
	    printf("ARP: interface not found, can't happen\n");
	    RAISE_FlowMan$NoRoute();
	}
	
	sprintf(buf, "Eth10:%08x", ipaddr);
	
	/* NB: raises Context$NotFound() if ARP fails => ok (see Flowman.if) */
	
	ret = NAME_LOOKUP(buf, ifst->card->arper, Net_EtherAddrP);

    } FINALLY {
	free(ri->type);
	free(ri->ifname);
	free(ri);
    } ENDTRY;
    
    TRC(printf("FlowMan$ARP: ARP for %x returning "
	       "%02x:%02x:%02x:%02x:%02x:%02x\n",
	       ntohl(ipaddr),
	       ret->a[0], ret->a[1], ret->a[2],
	       ret->a[3], ret->a[4], ret->a[5]));

    memcpy(hwaddr, ret, sizeof(*hwaddr));
}
コード例 #3
0
ファイル: Binder.c プロジェクト: berkus/nemesis
IDCOffer_clp Binder_MuxedOffer(DomainMgr_st *dm_st, dcb_ro_t *rop, 
			       dcb_rw_t *rwp , Type_Any *server)
{
    PerDomain_st  *bst =  ROP_TO_PDS(rop);
    Client_t      *bcl = (Client_t *)&(rwp->binder_rw);
    _generic_cl   *client_ops;
    Server_t      *new_server; 
    Client_t      *new_client; 
    IDCOffer_cl   *offer; 
    IDCStubs_Info  NOCLOBBER stubinfo;
#define TC_STRING_LEN (2*sizeof(Type_Code))
    char      tname[TC_STRING_LEN+1];

    TRY	{
	Context_clp   stub_ctxt = NAME_FIND (IDC_CONTEXT, Context_clp);
	TRC(eprintf ("Binder_MuxedOffer: got stub context.\n"));

	sprintf(tname, "%Q", server->type);
	TRC(eprintf ("Binder_MuxedOffer: looking for '%s'.\n", tname));

	stubinfo = NAME_LOOKUP (tname, stub_ctxt, IDCStubs_Info);
    } CATCH_ALL {
	
	eprintf("Binder_MuxedOffer: failed to find stub info!\n");
	RERAISE;
    }
    ENDTRY;

    /* Sort out the client side first */
    new_client = Heap$Calloc(Pvs(heap), 1, sizeof(Client_t));
    offer      = Heap$Calloc(Pvs(heap), 1, sizeof(IDCOffer_cl));
    
    client_ops = ((_generic_cl *)(stubinfo->surr.val))->op;

    CL_INIT(new_client->client_cl,   client_ops,             new_client);
    CL_INIT(new_client->binding_cl, &BinderClientBinding_op, new_client);
    
    ANY_INITC(&new_client->cs.srgt, server->type, 
	      (pointerval_t)&new_client->client_cl);
    new_client->cs.binding = &new_client->binding_cl;
    new_client->cs.marshal = dm_st->shmidc;
    
    new_client->conn      = bcl->conn;
    
    if(stubinfo->clnt) {
	/* Let the stubs set up any required run-time state */
	IDCClientStubs$InitState(stubinfo->clnt, &new_client->cs);
    }

    /* Now sort out the server side */
    new_server = Heap$Calloc(Pvs(heap), 1, sizeof(Server_t));
    
    new_server->ss.service = (addr_t)(pointerval_t)server->val;
    new_server->ss.binding = &new_server->binding_cl;
    new_server->ss.marshal = dm_st->shmidc;
    
    CL_INIT(new_server->cntrl_cl, stubinfo->stub->op, new_server);
    CL_INIT(new_server->binding_cl, &ShmServerBinding_op, new_server);
    
    new_server->conn  = &bst->sconn;
    
    /* Hijack offer field for PerDomain_st */
    new_server->offer = (Offer_t *)bst;

    new_client->offer = (Offer_t *)RegisterServer(&bst->mux, 
						  &new_server->cntrl_cl);
    if(new_client->offer == (Offer_t *)-1) {
	eprintf("Binder_MuxedOffer: adding new server to mux svr failed!\n");
	ntsc_halt();
    }

    
    /* We use our special binder offer ops, as for the binder binding. 
       Note that this means we cannot use ObjectTbl$Import() to deal 
       with this offer - we must call IDCOffer$Bind ourselves. */
    CLP_INIT(offer, &offer_ops, new_client);

    return offer; 
}
コード例 #4
0
ファイル: rid_manager.cpp プロジェクト: capel/brazos
  *done = true;
  integer * i = mkint((int)ridm->d1++);
  return i;
}

static ent_lookup internal_funcs[] = {
  {DEFAULT_LOOKUP_FUNC, managed_lookup_func_not_found},
  {"new!", new_rid},
};

MAKE_LOOKUP(internal_funcs);

static void cleanup() { printk("TODO"); }

static ent_funcs ridm_funcs = {
  .lookup = NAME_LOOKUP(internal_funcs),
  .link = disable_link,
  .unlink = disable_unlink,
  .map = disable_map,
  .unmap = disable_unmap,
  .cleanup = cleanup,
};

rid_manager* mkrid_manager()
{
  rid_manager *ridm = entalloc(&ridm_funcs);
  ridm->d1 = (void*)1;
  simple_managed_create(ridm);
  return ridm;
}