示例#1
0
 void test_lazy_load()
 {
     Engine engine(Engine::READ_ONLY);
     setup_log(engine);
     Session session(Yb::theSchema(), &engine);
     OrmTest dobj(session, ORM_TEST_ID1);
     CPPUNIT_ASSERT_EQUAL((int)DataObject::Ghost, (int)dobj.get_data_object()->status());
     CPPUNIT_ASSERT_EQUAL(string("item"), NARROW(dobj.a.value()));
     CPPUNIT_ASSERT_EQUAL((int)DataObject::Sync, (int)dobj.get_data_object()->status());
     dobj.a = _T("new_item");
     CPPUNIT_ASSERT_EQUAL(string("new_item"), NARROW(dobj.a.value()));
     CPPUNIT_ASSERT_EQUAL((int)DataObject::Dirty, (int)dobj.get_data_object()->status());
 }
示例#2
0
文件: Console.c 项目: berkus/nemesis
static bool_t ConsoleControl_AddOffer_m (
    ConsoleControl_cl       *self,
    IDCOffer_clp    offer   /* IN */,
    bool_t flush)
{
    Console_st     *st = self->st;
    struct output * NOCLOBBER o;

    if (!TypeSystem$IsType(Pvs(types), IDCOffer$Type(offer), Wr_clp__code))
	return False;

    o=Heap$Malloc(Pvs(heap), sizeof(*o));

    o->offer=offer;
    o->flush=flush;

    TRY {
#if 0
	o->binding=IDCOffer$Bind(offer, Pvs(gkpr), &any);
	o->wr=NARROW(&any, Wr_clp);
#else
	o->wr=IDC_BIND(offer, Wr_clp);
#endif /* 0 */
    } CATCH_ALL {
	FREE(o);
	RERAISE;
    } ENDTRY;

    MU_LOCK(&st->mu);
    LINK_ADD_TO_HEAD(&st->outputs, o);
    MU_RELEASE(&st->mu);
    return True;
}
示例#3
0
文件: io.c 项目: berkus/nemesis
static IDCClientBinding_clp IDCOffer_Bind_m (
        IDCOffer_cl     *self,
        Gatekeeper_clp  gk      /* IN */,
        Type_Any        *cl     /* OUT */ )
{
    IDCOffer_st   *st = self->st;
    FileIO_st     *fio;

    FTRC("entered, self=%p, gk=%p, cl=%p.\n", self, gk, cl);

    /* Allocate memory for client-side stuff */
    fio           = Heap$Malloc(Pvs(heap), sizeof(*fio));
    fio->binding  = IDCOffer$Bind(st->io_offer, gk, &fio->io_any);
    fio->io       = NARROW(&fio->io_any,IO_clp);

    CL_INIT(fio->cl, &fileio_ms, fio);

    fio->blocksize = st->blocksize;
    fio->length    = st->length;

    /* XXX SMH: init our client surrogate and return it to client. */
    ANY_INIT(&fio->srgt, FileIO_clp, &fio->cl);
    ANY_COPY(cl, &fio->srgt);    

    return fio->binding;        /* XXX should really invent our own */
}
示例#4
0
void
SQLiteCursorBackend::exec_direct(const String &sql)
{
    int rs = sqlite3_exec(conn_, NARROW(sql).c_str(), 0, 0, 0);
    if (SQLITE_OK != sqlite3_errcode(conn_)) {
        const char *err = sqlite3_errmsg(conn_);
        throw DBError(WIDEN(err));
    }
}
示例#5
0
void
SOCICursorBackend::exec_direct(const String &sql)
{
    try {
        conn_->once << NARROW(sql);
    }
    catch (const soci::soci_error &e) {
        throw DBError(WIDEN(e.what()));
    }
}
示例#6
0
void
SQLiteCursorBackend::prepare(const String &sql)
{
    close();
    sqlite3_prepare_v2(conn_, NARROW(sql).c_str(), -1, &stmt_, 0);
    if (SQLITE_OK != sqlite3_errcode(conn_) || !stmt_) {
        const char *err = sqlite3_errmsg(conn_);
        throw DBError(WIDEN(err));
    }
}
示例#7
0
void
SQLiteConnectionBackend::open(SqlDialect *dialect, const SqlSource &source)
{
    close();
    ScopedLock lock(drv_->conn_mux_);
    own_handle_ = true;
    sqlite3_open(NARROW(source.db()).c_str(), &conn_);
    if (SQLITE_OK != sqlite3_errcode(conn_)) {
        const char *err = sqlite3_errmsg(conn_);
        throw DBError(WIDEN(err));
    }
}
示例#8
0
static
const String
format_stats(const String &source_id, int count = -1, int pool_size = -1)
{
    std::ostringstream stats;
    stats << " [source: " << NARROW(source_id);
    if (count >= 0 && pool_size >= 0)
        stats << ", total open: " << (count + pool_size)
            << ", in pool: " << pool_size;
    stats << "]";
    return WIDEN(stats.str());
}
示例#9
0
YBORM_DECL bool
load_xml_file(const String &name, string &where)
{
    ifstream tfile(NARROW(name).c_str());
    if (!tfile)
        return false;
    while (tfile.good()) {
        char ch;
        tfile.get(ch);
        where.push_back(ch);
    }
    return true;
}
示例#10
0
文件: ext2mod.c 项目: berkus/nemesis
static void L1_Initialise_m (USDCallback_cl  *self)
{
    L1_st   *st = self->st;
    Type_Any any;

    FTRC("entered: self=%p, st=%p offer=%p ext2fs_st=%p.\n", self, st,
	 st->l2_offer, st->ext2fs_st);
    
    FTRC("Binding to L2 USDCallback\n");
    IDCOffer$Bind(st->l2_offer, Pvs(gkpr), &any);
    st->l2_callback = NARROW(&any, USDCallback_clp);
    FTRC("Calling USDCallback$Initialise(L2)\n");
    USDCallback$Initialise(st->l2_callback);

    FTRC("leaving, succeded.\n");
}
示例#11
0
void
SOCICursorBackend::prepare(const String &sql)
{
    close();
    sql_ = NARROW(sql);
    is_select_ = starts_with(
            str_to_upper(trim_trailing_space(sql)), _T("SELECT"));
    try {
        stmt_ = new soci::statement(*conn_);
        stmt_->alloc();
        stmt_->prepare(sql_);
    }
    catch (const soci::soci_error &e) {
        throw DBError(WIDEN(e.what()));
    }
}
示例#12
0
static IO_clp bindIO(IOOffer_cl *io_offer, HeapMod_cl *hmod, Heap_clp *heap) 
{
    IO_clp res; 
    IOData_Shm *shm;
    
    if(io_offer != NULL) {

	if(*heap) {   /* We have some memory => bind using it */
	    Type_Any    any;
	    IDCClientBinding_clp cb;

	    shm = SEQ_NEW(IOData_Shm, 1, Pvs(heap));
	    
	    SEQ_ELEM(shm, 0).buf.base = 
		HeapMod$Where(hmod, *heap, &(SEQ_ELEM(shm, 0).buf.len));
	    SEQ_ELEM(shm, 0).param.attrs  = 0;
	    SEQ_ELEM(shm, 0).param.awidth = PAGE_WIDTH;
	    SEQ_ELEM(shm, 0).param.pwidth = PAGE_WIDTH;
	    
	    cb = IOOffer$ExtBind(io_offer, shm, Pvs(gkpr), &any);
	    if(!ISTYPE(&any, IO_clp)) {
		eprintf("udp_socket.c [bindIO]: IOOffer$ExtBind failed.\n");
		if(cb) IDCClientBinding$Destroy(cb);
		RAISE_TypeSystem$Incompatible();
	    }
	    res = NARROW (&any, IO_clp);
	} else { 
	    /* Just bind to offer and create a heap afterwards. */
	    res = IO_BIND(io_offer);
	    shm = IO$QueryShm(res); 
	    if(SEQ_LEN(shm) != 1) 
		eprintf("udp_socket.c [bindIO]: "
			"got > 1 data areas in channel!\n");

	    /* Ignore extra areas for now */
	    *heap = HeapMod$NewRaw(hmod, SEQ_ELEM(shm, 0).buf.base, 
				   SEQ_ELEM(shm, 0).buf.len);
	}

	return res; 
    } 
    
    return (IO_cl *)NULL;
}
示例#13
0
void
SOCIConnectionBackend::open(SqlDialect *dialect, const SqlSource &source)
{
    close();
    own_handle_ = true;
    try {
        String driver = source.driver();
        std::string soci_backend = "odbc";
        if (driver == _T("SOCI"))
            soci_backend = soci_convert_dialect(dialect->get_name());
        conn_ = new soci::session(soci_backend, NARROW(source.db()));
#ifdef YB_SOCI_DEBUG
        conn_->set_log_stream(&cerr);
#endif
    }
    catch (const soci::soci_error &e) {
        throw DBError(WIDEN(e.what()));
    }
}
示例#14
0
void
SQLiteCursorBackend::exec(const Values &params)
{
    if (exec_count_)
        sqlite3_reset(stmt_);
    ++exec_count_;
    vector<string> str_params(params.size());
    for (size_t i = 0; i < params.size(); ++i) {
        if (params[i].get_type() == Value::INTEGER
                || params[i].get_type() == Value::LONGINT)
        {
            sqlite3_bind_int(stmt_, i + 1, params[i].as_integer());
            if (SQLITE_OK != sqlite3_errcode(conn_)) {
                const char *err = sqlite3_errmsg(conn_);
                throw DBError(WIDEN(err));
            }
        } else if (params[i].is_null()) {
            sqlite3_bind_null(stmt_, i + 1);
            if (SQLITE_OK != sqlite3_errcode(conn_)) {
                const char *err = sqlite3_errmsg(conn_);
                throw DBError(WIDEN(err));
            }
        } else {
            str_params[i] = NARROW(params[i].as_string());
            sqlite3_bind_text(stmt_, i + 1,
                    str_params[i].c_str(), str_params[i].size(), SQLITE_STATIC);
            if (SQLITE_OK != sqlite3_errcode(conn_)) {
                const char *err = sqlite3_errmsg(conn_);
                throw DBError(WIDEN(err));
            }
        }
    }
    last_code_ = sqlite3_step(stmt_);
    if (last_code_ != SQLITE_DONE && last_code_ != SQLITE_ROW
            && last_code_ != SQLITE_OK)
        throw DBError(WIDEN(sqlite3_errmsg(conn_)));
}
示例#15
0
文件: login.c 项目: berkus/nemesis
static IDCOffer_clp UnixLoginMod_New_m (
    UnixLoginMod_cl     *self,
    IDCOffer_clp    fs      /* IN */,
    string_t        passwd  /* IN */,
    string_t        group   /* IN */ )
{
    UnixLoginMod_st     *lst;
    Login_st        *st;
    FSClient_clp     fsclient;
    Type_Any         any, *dirany;
    FSTypes_RC       rc;
    FSDir_clp        dir;
    FileIO_clp       fileio;
    Rd_clp           rd;
    FSUtil_clp       fsutil;
    StringTblMod_clp strtbl;
    IDCTransport_clp shmt;
    IDCOffer_clp     offer;
    IDCService_clp   service;
    char buff[124];

    TRC(printf("UnixLoginMod_New_m(%p, %s, %s)\n",fs,passwd,group));

    fsutil=NAME_FIND("modules>FSUtil", FSUtil_clp);
    strtbl=NAME_FIND("modules>StringTblMod", StringTblMod_clp);
    shmt=NAME_FIND("modules>ShmTransport", IDCTransport_clp);

    lst=Heap$Malloc(Pvs(heap), sizeof(*lst));
    lst->heap=Pvs(heap);

    /* Bind to security service */
    TRC(printf(" + binding to security service\n"));
    lst->sec=IDC_OPEN("sys>SecurityOffer", Security_clp);

    /* Bind to FS */
    TRC(printf(" + binding to filesystem\n"));
    fsclient=IDC_BIND(fs, FSClient_clp);
    
    rc=FSClient$GetDir(fsclient, "", True, &dirany);
    if (rc!=FSTypes_RC_OK) {
	printf("UnixLoginMod: couldn't get directory\n");
	FREE(lst);
	return NULL;
    }

    dir=NARROW(dirany, FSDir_clp);
    FREE(dirany);

    /* Create tables */
    TRC(printf(" + creating tables\n"));
    lst->users=StringTblMod$New(strtbl, lst->heap);
    lst->groups=StringTblMod$New(strtbl, lst->heap);
    lst->certificate_tbl=StringTblMod$New(strtbl, lst->heap);
    lst->certificate_id = 1;

    /* Read in passwd file */
    TRC(printf(" + reading password file\n"));
    rc=FSDir$Lookup(dir, passwd, True);
    if (rc!=FSTypes_RC_OK) {
	printf("UnixLoginMod: couldn't lookup passwd file\n");
	FREE(lst);
	return NULL;
    }

    rc=FSDir$Open(dir, 0, FSTypes_Mode_Read, 0, &fileio);
    if (rc!=FSTypes_RC_OK) {
	printf("UnixLoginMod: couldn't open passwd file\n");
	FREE(lst);
	return NULL;
    }

    rd=FSUtil$GetRd(fsutil, fileio, lst->heap, True);
    
    while (!Rd$EOF(rd))
    {
	uint32_t l;
	l=Rd$GetLine(rd, buff, 120);
	buff[l]=0;
	/* TRC(printf("->%s\n",buff)); */
	add_passwd_line(lst, buff);
    }

    Rd$Close(rd);

    /* Read in group file */
    TRC(printf(" + reading group file\n"));
    rc=FSDir$Lookup(dir, group, True);
    if (rc!=FSTypes_RC_OK) {
	printf("UnixLoginMod: couldn't lookup group file\n");
	FREE(lst);
	return NULL;
    }

    rc=FSDir$Open(dir, 0, FSTypes_Mode_Read, 0, &fileio);
    if (rc!=FSTypes_RC_OK) {
	printf("UnixLoginMod: couldn't open group file\n");
	FREE(lst);
	return NULL;
    }

    rd=FSUtil$GetRd(fsutil, fileio, lst->heap, True);

    while (!Rd$EOF(rd))
    {
	uint32_t l;
	l=Rd$GetLine(rd, buff, 120);
	buff[l]=0;
	/* TRC(printf("=>%s\n",buff)); */
	add_group_line(lst, buff);
    }

    Rd$Close(rd);

    /* We don't need the filesystem any more */
    FSDir$Close(dir);

    LINK_INITIALISE(&lst->certificate_list);

    MU_INIT(&lst->mu);

    /* Closure for local access to the server */

    st=Heap$Malloc(lst->heap, sizeof(*st));
    CL_INIT(st->cl, &login_ms, st);
    st->id=VP$DomainID(Pvs(vp));
    st->lst=lst;

    /* Export */
    TRC(printf(" + exporting Login service\n"));
    ANY_INIT(&any, Login_clp, &st->cl);
    CL_INIT(lst->callback, &callback_ms, lst);
    offer=IDCTransport$Offer(shmt, &any, &lst->callback, lst->heap,
			     Pvs(gkpr), Pvs(entry), &service);

    return offer;
}
示例#16
0
文件: Nemesis.c 项目: berkus/nemesis
static void NemesisMainThread(kernel_st *kst)
{
    DomainMgrMod_clp	dmm;
    DomainMgr_clp	dm;

    TRC(printf("NemesisMainThread: entered.\n"));
    
    TRC(printf( " + Finding DomainMgr...\n"));
    dmm = NAME_FIND("modules>DomainMgrMod",DomainMgrMod_clp);
    dm  = NAME_FIND("sys>DomainMgr",DomainMgr_clp);
    
    TRC(printf( " + Completing Domain Manager initialisation.\n"));
    DomainMgrMod$Done (dmm, dm);

    /* Get a tag for ourselves and tell the world about it */
    TRC(printf( " + Creating a Security.Tag for the system.\n"));
    {
	Security_Tag tag;
	Security_clp sec;
	Type_Any any;

	sec=IDC_OPEN("sys>SecurityOffer", Security_clp);
	/* XXX will be local, so we don't need to worry about dropping
	   it on the floor */
	if (Security$CreateTag(sec, &tag)) {
	    ANY_INIT(&any, Security_Tag, tag);
	    Context$Add (Pvs(root), "sys>SystemTag", &any);
	} else {
	    printf("Error: couldn't create system tag\n");
	    ntsc_dbgstop();
	}
    }


#if defined(CONFIG_MEMSYS_STD) || defined(CONFIG_MEMSYS_EXPT)
    TRC(printf( " + Creating mmentry.\n"));
    {
	MMEntryMod_cl *mmemod;
	MMEntry_cl    *mmentry; 
	MMNotify_cl   *mmnfy;

	mmemod  = NAME_FIND("modules>MMEntryMod", MMEntryMod_clp);
	mmnfy   = NAME_FIND("sys>MMNotify", MMNotify_clp);
	mmentry = MMEntryMod$New(mmemod, mmnfy, (ThreadF_cl *)Pvs(thds), 
				 Pvs(heap), 10 /* XXX should be param? */);
    }
#endif

    TRC(printf( " + Register binder's protection domain.\n"));
    {
	ProtectionDomain_ID pdid = VP$ProtDomID(Pvs(vp));
	ANY_DECL(tmpany,ProtectionDomain_ID, pdid); 
	Context$Add (Pvs(root), "sys>BinderPDom",&tmpany);
    } 
    
    TRC(printf( " + Register standard root context.\n"));
    CX_ADD ("sys>StdRoot", Pvs(root), Context_clp);

    /* Interrupt Allocation Module */
    TRC(printf( " + Init interrupt allocation module.\n"));
    {
	Interrupt_clp ipt;
	
	/* Find the interrupt allocation module */
	ipt = InterruptInit(kst);
	TRC(printf(" + Created an Interrupt server at %p.\n", ipt));
	TRC(printf(" +   exporting... "));
	IDC_EXPORT ("sys>InterruptOffer", Interrupt_clp, ipt);
	TRC(printf("done\n"));
    }
    
#ifdef CONFIG_CALLPRIV
    /* CallPriv allocation module */
    TRC(printf( " + Init CallPriv allocation module.\n"));
    {
	CallPriv_clp cp;

	/* Find the callpriv module */
	cp = CallPrivInit(kst);
	TRC(printf(" + created a CallPriv server at %p\n", cp));
	TRC(printf(" +   exporting... "));
	IDC_EXPORT ("sys>CallPrivOffer", CallPriv_clp, cp);
	TRC(printf("done.\n"));
    }
#endif /* CONFIG_CALLPRIV */

#ifdef CONFIG_MODULE_OFFSET_DATA
    /* Module offset data module */
    TRC(printf( " + Init ModData module.\n"));
    {
	ModData_clp md;

	md=ModDataInit();
	TRC(printf(" + created a ModData server at %p\n", md));
	TRC(printf(" +   exporting... "));
	IDC_EXPORT ("sys>ModDataOffer", ModData_clp, md);
	TRC(printf("done.\n"));
    }
#endif /* CONFIG_MODULE_OFFSET_DATA */

    {
	Type_Any any;
	if (Context$Get(Pvs(root), "modules>PCIBiosInstantiate", &any)) {
	    Closure_clp pcibiosinstantiate;
	    pcibiosinstantiate = NARROW(&any, Closure_clp);
	    TRC(printf( " + Init PCIBios allocation module.\n"));
	    Closure$Apply(pcibiosinstantiate);
	}
    }
	   
#ifdef AXP3000 
    TRC(printf( " + Probing Turbochannel...\n"));
    {
	char name[TC_ROMNAMLEN+2]; /* 1 extra for number, one for '\0' */
	volatile uint32_t *romptr;
	volatile uint32_t *mchk_expected = &(kst->mchk_expected);
	volatile uint32_t *mchk_taken = &(kst->mchk_taken);
	Context_clp tc_cx;
	NOCLOBBER int i, j, k;
	NOCLOBBER char added, dev_no;
	
	tc_cx = CX_NEW("sys>tc");

	for(i=0; i < 6; i++) {
	    /* get a pointer to the 'name' of the card current slot */
	    romptr = (uint32_t *)((char *)slots[i].addr+(TC_NAME_OFFSET*2));
	    
	    /* setup kernel to ignore a mchk (such as TC read timeout) */
	    *mchk_expected = True;
	    *mchk_taken    = 0;

	    /* dereference the romptr & see if we get a mchk */
	    *((uint32_t *)TC_EREG) = 0; /* unlock tcerr */
	    *romptr;

	    if(!(*mchk_taken)) { /* all is ok => read out the name */
#define TC_ROM_STRIDE 2
		for (j = 0, k = 0; j < TC_ROMNAMLEN; j++, k += TC_ROM_STRIDE) 
		    name[j] = (char)romptr[k];
		name[TC_ROMNAMLEN] = name[TC_ROMNAMLEN+1] = ' ';
		
		/* Get rid of extra spaces at the end & add in device number */
		dev_no= '0';
		added = False;

		for (j = 0; name[j]!=' '; j++)
		    ;
		name[j]   = dev_no;
		name[j+1] = '\0'; 

	        while(!added) {
		    TRY {
			CX_ADD_IN_CX(tc_cx, (char *)name, 
				     &(slots[i]), TCOpt_SlotP);
			added= True;
		    } CATCH_Context$Exists() {
			name[j]= dev_no++;
		    } ENDTRY;
		}

		TRC(printf(" +++ probed slot %d: added card, name= \"%s\"\n", 
			i, name));

	    } else {
#define MCHK_K_TC_TIMEOUT_RD   0x14
		if(*mchk_taken==MCHK_K_TC_TIMEOUT_RD) {
		    TRC(printf(" +++ slot %d is empty.\n", i));
		} else {
		    TRC(printf(" *** Bad MCHK (code 0x%x) taken in TC probe."
			    "Halting.\n",
			    *mchk_taken));
		}
	    }
	}

	
	*((uint32_t *)TC_EREG) = 0; /* unlock tcerr */
	*mchk_expected =  False;    /* enable mchks again */

	TRC(printf(" + Turbochannel probe done.\n"));
    }
示例#17
0
void
SOCICursorBackend::exec(const Values &params)
{
    try {
        if (!executed_ && in_params_.size())
            bound_first_ = true;
        if (!bound_first_) {
            if (executed_) {
                delete stmt_;
                stmt_ = new soci::statement(*conn_);
                stmt_->alloc();
                stmt_->prepare(sql_);
                in_params_.clear();
                in_flags_.clear();
            }
            TypeCodes types(params.size());
            for (size_t i = 0; i < params.size(); ++i)
                types[i] = params[i].get_type();
            bind_params(types);
        }
        executed_ = true;
        for (size_t i = 0; i < params.size(); ++i) {
            const Value &param = params[i];
            if (param.is_null()) {
                in_flags_[i] = soci::i_null;
                continue;
            }
            in_flags_[i] = soci::i_ok;
            switch (param_types_[i]) {
                case Value::INTEGER: {
                    int &x = *(int *)&(in_params_[i][0]);
                    x = param.as_integer();
                    break;
                }
                case Value::LONGINT: {
                    LongInt &x = *(LongInt *)&(in_params_[i][0]);
                    x = param.as_longint();
                    break;
                }
                case Value::FLOAT: {
                    double &x = *(double *)&(in_params_[i][0]);
                    x = param.as_float();
                    break;
                }
                case Value::DATETIME: {
                    std::tm &x = *(std::tm *)&(in_params_[i][0]);
                    memset(&x, 0, sizeof(x));
                    const DateTime &d = param.as_date_time();
                    x.tm_year = dt_year(d) - 1900;
                    x.tm_mon = dt_month(d) - 1;
                    x.tm_mday = dt_day(d);
                    x.tm_hour = dt_hour(d);
                    x.tm_min = dt_minute(d);
                    x.tm_sec = dt_second(d);
                    break;
                }
                default: {
                    in_params_[i] = NARROW(param.as_string());
                }
            }
        }
        stmt_->execute(!is_select_);
    }
    catch (const soci::soci_error &e) {
        throw DBError(WIDEN(e.what()));
    }
}
示例#18
0
文件: Binder.c 项目: berkus/nemesis
PerDomain_st *Binder_InitDomain(DomainMgr_st *dm_st, 
				dcb_ro_t *rop, dcb_rw_t *rwp,
				StretchAllocator_clp salloc)
{
    Client_t	*bcl;
    Server_t    *bsv;
    PerDomain_st  *bst;
    IDCStubs_Info stubinfo;
  
    /* Allocate bsv, bcl and bst */
    bst = ROP_TO_PDS(rop);
    memset(bst, 0, sizeof(*bst));
    bsv = &bst->s;
    bcl = (Client_t *)&(rwp->binder_rw);
    
    TRC (eprintf("Binder_NewDomain: state at %x\n", bst));

#if 0
    /* Block until the boot domains are ready */
/* XXX XXX see comment in DomainMgr.c about Intel and ARM */

    TRC(eprintf("Dom ID = %qx, boot_regs = %qx\n", rop->id, 
		EC_READ(dm_st->boot_regs)));

#ifdef SRCIT
#undef DOM_USER
#define DOM_USER DOM_SERIAL
#endif
#ifndef __ALPHA__
    EC_AWAIT (dm_st->boot_regs,
	      ((rop->id < DOM_USER) ? rop->id : DOM_USER)&0xffffffff);
#else
    EC_AWAIT (dm_st->boot_regs,
	      (rop->id < DOM_USER) ? rop->id : DOM_USER);
#endif
#endif /* 0 */
    
    /* Create IDC buffers for the new domain's channel to the binder */
    bst->args    = STR_NEW_SALLOC(dm_st->sysalloc, FRAME_SIZE);
    bst->results = STR_NEW_SALLOC(dm_st->sysalloc, FRAME_SIZE);
    
    /* Map the stretches. */
    SALLOC_SETPROT(dm_st->sysalloc, bst->results, rop->pdid, 
		   SET_ELEM(Stretch_Right_Read) );
    SALLOC_SETPROT(dm_st->sysalloc, bst->args, rop->pdid, 
		   SET_ELEM(Stretch_Right_Read)|
		   SET_ELEM(Stretch_Right_Write));

    /*
     * Next, initialise as much of the Client structure as we can at
     * this stage, given that we're in the Binder's domain and the
     * client won't have a threads package anyway. The rest of this
     * state will be initialised when the client domain calls Bind on 
     * the Binder offer.  Compare with lib/nemesis/IDC/ShmTransport.c:
     * notice that we have to init the state to what the methods in
     * Shm[Client|Server]Binding_op are expecting.
     */


    stubinfo = NAME_FIND (IDC_CONTEXT">Binder", IDCStubs_Info);
    
    TRC(eprintf("Binder_NewDomain: creating Binder client IDC state.\n"));
    {
	Binder_clp client_cl = 
	    NARROW ((Type_Any *)(&stubinfo->surr), Binder_clp);

	CL_INIT(bcl->client_cl,  (addr_t) client_cl->op,  bcl);
	CL_INIT(bcl->binding_cl, &BinderClientBinding_op, bcl);
    }
    ANY_INIT (&bcl->cs.srgt, Binder_clp, &bcl->client_cl);
    bcl->cs.binding = &bcl->binding_cl;
    bcl->cs.marshal = dm_st->shmidc;

    /* The client ShmConnection_t immediately follows the Client_t 
       (aka bcl) in the binder_rw. */
    bcl->conn      = (ShmConnection_t *)(bcl+1);

    if(stubinfo->clnt) {
	/* Let the stubs set up any required run-time state */
	IDCClientStubs$InitState(stubinfo->clnt, &bcl->cs);
    }

    /* Now setup the client side ShmConnection */

    /* XXX Leave mu_init to user */

    /* Transmit buffer rec */
    bcl->conn->txbuf.base  = STR_RANGE(bst->args, &bcl->conn->txsize);
    bcl->conn->txbuf.ptr   = bcl->conn->txbuf.base;
    bcl->conn->txbuf.space = bcl->conn->txsize;
    bcl->conn->txbuf.heap  = NULL;
    
    /* Receive buffer rec */
    bcl->conn->rxbuf.base  = STR_RANGE(bst->results, &bcl->conn->rxsize);
    bcl->conn->rxbuf.ptr   = bcl->conn->rxbuf.base;
    bcl->conn->rxbuf.space = bcl->conn->rxsize;
    bcl->conn->rxbuf.heap  = NULL;
    
    /* Event counts will be filled in by the domain */
    bcl->conn->evs.tx	  = NULL_EVENT;
    bcl->conn->evs.rx     = NULL_EVENT;
    
    /* We can call the new domain's VP interface to get end-points */
    bcl->conn->eps.tx	  = VP$AllocChannel (&rop->vp_cl);
    bcl->conn->eps.rx	  = VP$AllocChannel (&rop->vp_cl);
  
    bcl->conn->call       = 0;

    bcl->conn->dom        = dm_st->dm_dom->id;
    /* XXX SMH: for some reason we don't know our own pdom. Hoho. */
    bcl->conn->pdid       = NULL_PDID;

    /* bcl->offer is not used normally; in BINDER_MUX it is inited below */

    /*
     * Initialise the server idc state.
     */

    /* First we setup the server connection state */
    MU_INIT (&bst->sconn.mu); /* XXX - unused; entry SYNC on server */
  
    bst->sconn.txbuf      = bcl->conn->rxbuf;
    bst->sconn.txsize     = bst->sconn.txbuf.space;
    
    bst->sconn.rxbuf      = bcl->conn->txbuf;
    bst->sconn.rxbuf.heap = Pvs(heap); /* XXX */
    bst->sconn.rxsize     = bst->sconn.rxbuf.space;
  
    bst->sconn.call	  = 0;
    
    bst->sconn.eps.tx	  = Events$AllocChannel(Pvs(evs));
    bst->sconn.eps.rx	  = Events$AllocChannel(Pvs(evs));
    
    bst->sconn.evs.tx     = EC_NEW();
    bst->sconn.evs.rx     = NULL_EVENT; /* we use "Entry" synch. on server */

    bst->sconn.dom        = rop->id;
    bst->sconn.pdid       = rop->pdid; 


#ifdef CONFIG_BINDER_MUX
    /* Initialise the (de)muxing server. */
    TRC(eprintf("Binder_NewDomain: creating Binder MuxIDC server state.\n"));

    CL_INIT (bst->mux.cntrl_cl, &MuxStubs_ms, &bst->mux);
    CL_INIT (bst->mux.cntrl_cl, &MuxStubs_ms, &bst->mux);

    /* We use the connection state we setup above */
    bst->mux.conn = &bst->sconn;
    bst->mux.ss.service = NULL; /* There's no specific service */
    bst->mux.ss.binding = &bsv->binding_cl;
    
#endif
    TRC(eprintf("Binder_NewDomain: creating Binder IDC server state.\n"));
    bsv->ss.service = &bst->binder;
    bsv->ss.binding = &bsv->binding_cl;
    bsv->ss.marshal = dm_st->shmidc;


    CL_INIT (bsv->cntrl_cl,    stubinfo->stub->op,  bsv);
    CL_INIT (bsv->binding_cl, &ShmServerBinding_op, bsv);
    
    /* We use (or share!) the connection state we setup above */
    bsv->conn = &bst->sconn;

    /* Hijack offer field for PerDomain_st */
    bsv->offer            = (Offer_t *) bst;
    

    /* XXX PRB Moved this before the Plumber_Connect since otherwise
       Events$Attach does an ntsc_send causing the new domain to be woken
       up! */
    Events$Attach (Pvs(evs), bsv->conn->evs.tx, 
		   bsv->conn->eps.tx,  Channel_EPType_TX);
    
    /* Connect the event channels */
    Plumber$Connect (Plumber, dm_st->dm_dom, rop, 
		     bsv->conn->eps.tx, 
		     bcl->conn->eps.rx);
    Plumber$Connect (Plumber, rop, dm_st->dm_dom, 
		     bcl->conn->eps.tx, 
		     bsv->conn->eps.rx);

#ifdef CONFIG_BINDER_MUX
    /* Register the binder server with the demuxing server */
    bcl->offer = (Offer_t *)RegisterServer(&bst->mux, &bsv->cntrl_cl);
    
    if(bcl->offer == (Offer_t *)-1) {
	eprintf("Binder_NewDomain: addition of binder to mux svr failed!\n");
	ntsc_halt();
    }

#endif

    /* Initialise the rest of the per-domain state */
    TRC(eprintf("Binder_NewDomain: creating Binder per-domain state.\n"));
    bst->rop      = rop;
    bst->rwp      = rwp;
    bst->dm_st    = dm_st;

    /* refCount starts at 1, to allow for the following references to
       the rop/rwp to be held (update as necessary):
       
       1: the server binding (possibly muxed)
       
       */
       
    bst->refCount = 1;
    bst->callback = NULL;
    CL_INIT (bst->binder, &binder_ops, bst);

    /* The offer closure is a special hand crafted one */
    CL_INIT (bst->offer_cl, &offer_ops, bcl);

    rop->binder_offer = &bst->offer_cl;
    
#define panic(format, args...) \
do { eprintf(format, ## args); ntsc_halt(); } while(0)

    TRC(eprintf("Binder_NewDomain: registering entry.\n"));
    TRY {
#ifdef CONFIG_BINDER_MUX
	Entry$Bind (Pvs(entry), bst->mux.conn->eps.rx, &(bst->mux.cntrl_cl));
#else
	Entry$Bind (Pvs(entry), bsv->conn->eps.rx, &bsv->cntrl_cl );
#endif
    } CATCH_Entry$TooManyChannels() {
	eprintf("Too many channels registering Binder\n");
    } ENDTRY;

    TRC(eprintf("Binder_NewDomain: done.\n"));
    return bst;
}
示例#19
0
文件: ext2mod.c 项目: berkus/nemesis
static IDCOffer_clp Mount_m(MountLocal_cl     *self, 
			    IDCOffer_clp       drive,
			    uint32_t           partition,
			    MountLocal_Options options, 
			    Context_clp        settings)
{
    IDCOffer_clp  res;
    ext2fs_st	 *st;
    Type_Any      any;
    Heap_clp      heap;
    struct inode *root            = NULL;
    uint32_t      blockcache_size = 1024*128; /* Size of blockcache in bytes */
    CSClientStubMod_cl *stubmod_clp; 


    TRC(printf("ext2fs: mount %d from %p\n", partition, drive));
    /* It's probably a good idea to have a separate heap for the filesystem.
       For now let's just use Pvs(heap), but eventually create a stretch
       of our own. */

    heap = Pvs(heap);

    if(!(st = Heap$Malloc(heap, sizeof(*st)))) {
	fprintf(stderr, "ext2fs: cannot allocate state.\n");
	RAISE_MountLocal$Failure();
    }

    /* Where is this declared? */
    bzero(st, sizeof(*st));

    /* Fill in the fields that we can initialise without accessing the
       filesystem */
    st->heap = heap;

    st->entrymod     = NAME_FIND("modules>EntryMod", EntryMod_clp);
    st->shmtransport = NAME_FIND("modules>ShmTransport", IDCTransport_clp);
    st->csidc        = NAME_FIND("modules>CSIDCTransport", CSIDCTransport_clp);


    st->client.entry = Pvs(entry);
    /* It's not clearn how many entries we are going to require yet
       We probably want separate ones for the USDCallback and the
       FSClient offers. We need to arrange that the entry threads die
       properly when the FS is unmounted. */


    /* Interpret mount flags */
    st->fs.readonly = SET_IN(options,MountLocal_Option_ReadOnly);
    st->fs.debug    = SET_IN(options,MountLocal_Option_Debug);


    /* Place the drive in the state. */
    st->disk.partition     = partition;
    st->disk.drive_offer   = drive;
    st->disk.drive_binding = IDCOffer$Bind(drive, Pvs(gkpr), &any);
    st->disk.usddrive      = NARROW(&any, USDDrive_clp);

 
    TRC(printf("ext2fs: state at [%p, %p]\n",st, (void *)st + sizeof(*st)));
    DBO(printf("ext2fs: debugging output is switched on\n"));

    /* Connect to the disk */
    init_usd(st);

    /* We need a stretch shared between us and the USD to allow us to read
       and write metadata. We'll use this stretch as a cache of blocks read
       from the disk. Because we won't know the blocksize until we have
       managed to read the superblock, we'd better make this buffer a
       multiple of 8k long (8k is currently the maximum blocksize). */

    st->cache.str = Gatekeeper$GetStretch(Pvs(gkpr), IDCOffer$PDID(drive), 
					  blockcache_size, 
					  SET_ELEM(Stretch_Right_Read) |
					  SET_ELEM(Stretch_Right_Write), 
					  PAGE_WIDTH, PAGE_WIDTH);
    st->cache.buf = STR_RANGE(st->cache.str, &st->cache.size);

    TRC(printf("ext2fs: buf is %d bytes at %p\n", st->cache.size,
	       st->cache.buf));
    if (st->cache.size < blockcache_size) {
	printf("ext2fs: warning: couldn't allocate a large blockcache\n");
    }

    /* Now we can get at the disk. Read the superblock, and calculate
       constants from it. */
    if (!read_superblock(st)) {
	printf("ext2fs: couldn't read superblock\n");
	shutdown_usd(st);
	RAISE_MountLocal$BadFS(MountLocal_Problem_BadSuperblock);
    }

    /* XXX should sanity check filesystem size with partition size */
    TRC(printf("ext2fs: filesystem size %d blocks (%d phys)\n"
	   "	    partition size %d blocks (%d phys)\n",
	   st->superblock->s_blocks_count,
	   PHYS_BLKS(st, st->superblock->s_blocks_count),
	   LOGICAL_BLKS(st, st->disk.partition_size),
	   st->disk.partition_size));
    if (st->disk.partition_size < 
	PHYS_BLKS(st, st->superblock->s_blocks_count)) {
	printf("WARNING - filesystem is larger than partition **********\n");
	/* XXX should probably give up now */
    }

    /* Now that we know the logical block size we can initialise the block
       cache */
    init_block_cache(st);

    /* From this point on, all access to the filesystem should be done
       through the block cache. DON'T call logical_read, call bread
       instead. Remember to free blocks once you're finished with them. */

    init_groups(st);

    if(!init_inodes(st)) {
	fprintf(stderr, "ext2fs: failed to initialise inode cache.\n");
	shutdown_usd(st);
	RAISE_MountLocal$Failure();
    }

    /* Checking this probably isn't a bad idea, but let's wait until later */

    /* Ok, now we are capable of reading the root inode (I hope!) */
    TRC(printf("ext2fs: checking root inode.\n"));
    root = get_inode(st, EXT2_ROOT_INO);
    if(!root) {
	fprintf(stderr, "ext2fs: failed to read root inode.\n");
	shutdown_usd(st);
	RAISE_MountLocal$BadFS(MountLocal_Problem_BadRoot);
    }
    
    if(!S_ISDIR(root->i_mode)) {
	fprintf(stderr, "ext2fs: urk!\n"
		"	 inode %d does not refer to a directory\n", 
		EXT2_ROOT_INO);
	shutdown_usd(st);
	RAISE_MountLocal$BadFS(MountLocal_Problem_BadRoot);
    }

    release_inode(st, root);

    /* *thinks* should probably do something about deallocating state
       if we fail, too. */

    /* Initialise the list of clients */
    LINK_INIT(&st->client.clients);
    /* We create a server for the local domain; it lives in the head
       of the list of clients. The call to CSIDCTransport$Offer() will
       set up client-side stubs for this domain and put them in the
       object table. */
    create_client(st, &st->client.clients, NULL);

    /* Now we do all the export stuff */
    CL_INIT(st->client.callback, &client_callback_ms, st);
    ANY_INIT(&any, Ext2_clp, &st->client.clients.cl);
    stubmod_clp = Heap$Malloc(st->heap, sizeof(*stubmod_clp)); 
    CLP_INIT(stubmod_clp, &stubmod_ms, NULL);
    res = CSIDCTransport$Offer (
	st->csidc, &any, FSClient_clp__code, stubmod_clp,
	&st->client.callback, /* XXX produces a warning */
	st->heap, Pvs(gkpr), st->client.entry, &st->client.service);

    TRC(printf("ext2fs: offer at %p\n",res));

    return res;
}
示例#20
0
文件: ext2mod.c 项目: berkus/nemesis
static void init_usd(ext2fs_st *st)
{
    USD_PartitionInfo	 info;
    Type_Any		 any;
    IDCOffer_clp         partition;

    
    USDTRC(printf("ext2fs: Creating USDCallbacks\n"));
    {
	IDCTransport_clp    shmt;
	IDCOffer_clp        offer;
	IDCService_clp      service;
	L1_st              *l1_st;

	/* Get a heap writable by the USD domain */
	st->disk.heap = 
	    Gatekeeper$GetHeap(Pvs(gkpr), 
			       IDCOffer$PDID(st->disk.drive_offer), 0, 
			       SET_ELEM(Stretch_Right_Read) | 
			       SET_ELEM(Stretch_Right_Write),
			       True);

	/* The L1 callback executes there */
	l1_st = Heap$Malloc(st->disk.heap, sizeof(L1_st));
	l1_st->ext2fs_st = st;	/* our state is read-only in USD
				   domain */
	st->disk.l1_callback = &(l1_st->l1_callback);
	CLP_INIT(st->disk.l1_callback, &L1_ms, l1_st);

	/* Create an offer for the L2 Callback */
	CL_INIT(st->disk.l2_callback, &L2_ms, st);
	ANY_INIT(&any,USDCallback_clp, &st->disk.l2_callback);
	shmt  = NAME_FIND ("modules>ShmTransport", IDCTransport_clp);
	offer = IDCTransport$Offer (shmt, &any, NULL,
				    Pvs(heap), Pvs(gkpr),
				    Pvs(entry), &service); 
	
	/* Put it in the L1 callback's state record */
	l1_st->l2_offer = offer;
    }

    USDTRC(printf("ext2fs: Getting USDCtl offer\n"));
    if(!USDDrive$GetPartition(st->disk.usddrive,
			      st->disk.partition,
			      st->disk.l1_callback,
			      &partition)) {
	return;
    }
    
	
    USDTRC(printf("ext2fs: Binding to USDCtl offer\n"));
    /* Bind to the USD. Do this explicitly rather than through the object
       table; we don't want anybody else getting hold of this one. */
    st->disk.binding = IDCOffer$Bind(partition, Pvs(gkpr), &any);
    st->disk.usdctl  = NARROW(&any, USDCtl_clp);

    /* Find out some information */
    USDTRC(printf("ext2fs: fetching partition info\n"));
    if(!USDDrive$GetPartitionInfo(st->disk.usddrive, 
				  st->disk.partition, 
				  &info)) {
	return;
    }

    st->disk.phys_block_size = info.blocksize;
    st->disk.partition_size  = info.size;
    DBO(printf("ext2fs: blocksize %d, partition size %d blocks,\n"
	       "	partition type %s\n",
	       st->disk.phys_block_size, 
	       st->disk.partition_size,
	       info.osname));
    FREE(info.osname);

    return; 
}
示例#21
0
RowPtr SOCICursorBackend::fetch_row()
{
    try {
        if (!stmt_->fetch()) {
#ifdef YB_SOCI_DEBUG
            cerr << "fetch(): false" << endl;
#endif
            return RowPtr();
        }
        RowPtr result(new Row);
        int col_count = row_.size();
#ifdef YB_SOCI_DEBUG
        cerr << "fetch(): col_count=" << col_count << endl;
#endif
        for (int i = 0; i < col_count; ++i) {
            const soci::column_properties &props = row_.get_properties(i);
            String name = str_to_upper(WIDEN(props.get_name()));
            Value v;
            if (row_.get_indicator(i) != soci::i_null) {
                std::tm when;
                unsigned long long x;
                switch (props.get_data_type()) {
                case soci::dt_string:
                    v = Value(WIDEN(row_.get<string>(i)));
                    break;
                case soci::dt_double:
                    v = Value(row_.get<double>(i));
                    break;
                case soci::dt_integer:
                    v = Value(row_.get<int>(i));
                    break;
#if 0
                case soci::dt_unsigned_long:
                    x = row_.get<unsigned long>(i);
                    v = Value((LongInt)x);
                    break;
#endif
                case soci::dt_long_long:
                    x = row_.get<long long>(i);
                    v = Value((LongInt)x);
                    break;
                case soci::dt_unsigned_long_long:
                    x = row_.get<unsigned long long>(i);
                    v = Value((LongInt)x);
                    break;
                case soci::dt_date:
                    when = row_.get<std::tm>(i);
                    v = Value(dt_make(when.tm_year + 1900, when.tm_mon + 1,
                                when.tm_mday, when.tm_hour,
                                when.tm_min, when.tm_sec));
                    break;
                }
            }
#ifdef YB_SOCI_DEBUG
            cerr << "fetch(): col[" << i << "]: name=" << props.get_name()
                << " type=" << props.get_data_type()
                << " value=" << NARROW(v.sql_str()) << endl;
#endif
            result->push_back(make_pair(name, v));
        }
        return result;
    }
    catch (const soci::soci_error &e) {
        throw DBError(WIDEN(e.what()));
    }
}
示例#22
0
void main(int argc, char **argv)
{
	if(argc < 1)
		return;
	
	// get path
	int dat, l = 0, h = 0, w = 0, n = 0;
	bool prev = false;
	FILE *fs, *fd;

	char root[_MAX_PATH], file[_MAX_PATH];
	char tmp1[_MAX_PATH], tmp2[_MAX_PATH], dest[_MAX_PATH];
	GetModuleFileName(NULL, root, _MAX_PATH);
	int p = strlen(root);
	while(root[p] != '\\')
		p--;
	root[p] = '\0';

	strcpy(tmp1, argv[1]);
	p = strlen(tmp1);
	while(p != 0 && tmp1[p] != '\\')
		p--;
	if(p)
		strcpy(file, &tmp1[p + 1]);
	else
		strcpy(file, argv[1]);

	sprintf(tmp1, "%s\\tmp1.txt", root);
	sprintf(tmp2, "%s\\tmp2.txt", root);
	sprintf(dest, "%s\\dest.cas", root);
	
	if(strcmp(file, "tmp1.txt") == 0) {
		printf("skip wav->pulse\n");
		goto label1;
	}
	if(strcmp(file, "tmp2.txt") == 0) {
		printf("skip wav->pulse\n");
		printf("skip pulse->bit\n");
		goto label2;
	}
	
	// convert #1 (wav -> pulse)
	fs = fopen(argv[1], "rb");
	fd = fopen(tmp1, "w");
	
	while((dat = fgetc(fs)) != EOF) {
		bool current = dat & 0x80 ? false : true;
		if(prev && !current) {
			if(NARROW(l) && (NARROW(h) || WIDE(h)))
				fputc('N', fd);
			else if(WIDE(l) && (WIDE(h) || NARROW(h)))
				fputc('w', fd);
			else
				fprintf(fd, "[%d,%d]", l, h);
			l = h = 0;
		}
		if(current)
			h++;
		else
			l++;
		prev = current;
	}
	fclose(fd);
	fclose(fs);
	
label1:
	
	// convert #2 (pulse -> bit)
	fs = fopen(tmp1, "rb");
	fd = fopen(tmp2, "w");
	prev = true;
	
	while((dat = fgetc(fs)) != EOF) {
		if(dat != 'w' && dat != 'N') {
			fputc(dat, fd);
			continue;
		}
		bool current = (dat == 'w') ? true : false;
		if(prev != current) {
			if(w)
				fprintf(fd, "[W%d]", w);
			if(n)
				fprintf(fd, "[n%d]", n);
			w = n = 0;
		}
		prev = current;
		
		if(current)
			w++;
		else
			n++;
		if(w == 2) {
			fputc('w', fd);
			w = n = 0;
		}
		if(n == 4) {
			fputc('N', fd);
			w = n = 0;
		}
	}
	fclose(fd);
	fclose(fs);
	
label2:
	
	// convert #3 (bit -> byte)
	fs = fopen(tmp2, "rb");
	fd = fopen(dest, "wb");
	
	while((dat = fgetc2(fs)) != EOF) {
		if(dat != 'N')
			continue;
		if(fgetc2(fs) != 'N')
			continue;
label3:
		dat = fgetc2(fs);
		if(dat == EOF)
			break;
		if(dat != 'w')
			goto label3;
		int d = 0;
		d |= (fgetc2(fs) == 'N') ? 0x01 : 0;
		d |= (fgetc2(fs) == 'N') ? 0x02 : 0;
		d |= (fgetc2(fs) == 'N') ? 0x04 : 0;
		d |= (fgetc2(fs) == 'N') ? 0x08 : 0;
		d |= (fgetc2(fs) == 'N') ? 0x10 : 0;
		d |= (fgetc2(fs) == 'N') ? 0x20 : 0;
		d |= (fgetc2(fs) == 'N') ? 0x40 : 0;
		d |= (fgetc2(fs) == 'N') ? 0x80 : 0;
		fputc(d, fd);
	}
	fclose(fd);
	fclose(fs);
}