Beispiel #1
0
static void
uartclose(Chan *c)
{
	Uart *p;

	if(c->qid.type & QTDIR)
		return;
	if((c->flag & COPEN) == 0)
		return;
	switch(NETTYPE(c->qid.path)){
	case Ndataqid:
	case Nctlqid:
		p = uart[NETID(c->qid.path)];
		qlock(p);
		if(--(p->opens) == 0){
			qclose(p->iq);
			ilock(&p->rlock);
			p->ir = p->iw = p->istage;
			iunlock(&p->rlock);

			/*
			 */
			qhangup(p->oq, nil);
			if(!waserror()){
				uartdrainoutput(p);
				poperror();
			}
			qclose(p->oq);
			uartdisable(p);
			p->dcd = p->dsr = p->dohup = 0;
		}
		qunlock(p);
		break;
	}
}
Beispiel #2
0
static bool test_all(void){
    test( linux_file_vfs_open() );

    // write
    int fid = qopen( "./a.txt", O_RDWR | O_CREAT | O_TRUNC, NULL );
    test( 0 != fid );
    test( 5 == qwrite( fid, "12345", 5 ) );
    {
        struct qstat buf;
        test( qfstat( fid, &buf ) );
        test( 5 == buf.size );
    }
    test( qclose( fid ) );
    fid = 0;

    // read
    fid = qopen( "./a.txt", O_RDONLY, NULL );
    test( 0 != fid );
    {
        struct qstat buf;
        test( qfstat( fid, &buf ) );
        test( 5 == buf.size );
    }
    char buf[100];
    memset( buf, 0, sizeof( buf ) );
    test( 5 == qread( fid, buf, sizeof(buf) ) );
    test( 0 == memcmp( buf, "12345", 5 ) );
    test( qclose( fid ) );
    fid = 0;

    return true;
}
Beispiel #3
0
Datei: gre.c Projekt: 8l/inferno
static void
greclose(Conv *c)
{
	qclose(c->rq);
	qclose(c->wq);
	qclose(c->eq);
	ipmove(c->laddr, IPnoaddr);
	ipmove(c->raddr, IPnoaddr);
	c->lport = 0;
	c->rport = 0;
}
Beispiel #4
0
static void
pipeclose(Chan *c)
{
	Pipe *p;

	p = c->aux;
	qlock(p);

	if(c->flag & COPEN){
		/*
		 *  closing either side hangs up the stream
		 */
		switch(NETTYPE(c->qid.path)){
		case Qdata0:
			p->qref[0]--;
			if(p->qref[0] == 0){
				qhangup(p->q[1], 0);
				qclose(p->q[0]);
			}
			break;
		case Qdata1:
			p->qref[1]--;
			if(p->qref[1] == 0){
				qhangup(p->q[0], 0);
				qclose(p->q[1]);
			}
			break;
		}
	}


	/*
	 *  if both sides are closed, they are reusable
	 */
	if(p->qref[0] == 0 && p->qref[1] == 0){
		qreopen(p->q[0]);
		qreopen(p->q[1]);
	}

	/*
	 *  free the structure on last close
	 */
	p->ref--;
	if(p->ref == 0){
		qunlock(p);
		free(p->q[0]);
		free(p->q[1]);
		free(p);
	} else
		qunlock(p);
}
Beispiel #5
0
Datei: esp.c Projekt: npe9/harvey
static void
espclose(Conv *c)
{
	Espcb *ecb;

	qclose(c->rq);
	qclose(c->wq);
	qclose(c->eq);
	ipmove(c->laddr, IPnoaddr);
	ipmove(c->raddr, IPnoaddr);

	ecb = (Espcb*)c->ptcl;
	free(ecb->espstate);
	free(ecb->ahstate);
	memset(ecb, 0, sizeof(Espcb));
}
Beispiel #6
0
void iprouterclose(struct Fs *f)
{
	qlock(&(&f->iprouter)->qlock);
	f->iprouter.opens--;
	if (f->iprouter.opens == 0)
		qclose(f->iprouter.q);
	qunlock(&(&f->iprouter)->qlock);
}
Beispiel #7
0
/*
 *  detach a device from an interface, close the interface
 *  called with ifc->conv closed
 */
static char*
ipifcunbind(Ipifc *ifc)
{
	Proc *up = externup();
	char *err;

	if(waserror()){
		wunlock(ifc);
		nexterror();
	}
	wlock(ifc);

	/* dissociate routes */
	if(ifc->medium != nil && ifc->medium->unbindonclose == 0)
		ifc->conv->inuse--;
	ifc->ifcid++;

	/* disassociate logical interfaces (before zeroing ifc->arg) */
	while(ifc->lifc){
		err = ipifcremlifc(ifc, ifc->lifc);
		/*
		 * note: err non-zero means lifc not found,
		 * which can't happen in this case.
		 */
		if(err)
			error(err);
	}

	/* disassociate device */
	if(ifc->medium && ifc->medium->unbind)
		(*ifc->medium->unbind)(ifc);
	memset(ifc->dev, 0, sizeof(ifc->dev));
	ifc->arg = nil;
	ifc->reassemble = 0;

	/* close queues to stop queuing of packets */
	qclose(ifc->conv->rq);
	qclose(ifc->conv->wq);
	qclose(ifc->conv->sq);

	ifc->medium = nil;
	wunlock(ifc);
	poperror();
	return nil;
}
Beispiel #8
0
static void
tkclose(Chan* c)
{
	if(c->qid.type & QTDIR || (c->flag & COPEN) == 0)
		return;
	qlock(&tkevents.l);
	if(decref(&tkevents.inuse) == 0)
		qclose(tkevents.eq);
	qunlock(&tkevents.l);
}
Beispiel #9
0
void
netifclose(Netif *nif, Chan *c)
{
	Netfile *f;
	int t;
	Netaddr *ap;

	if((c->flag & COPEN) == 0)
		return;

	t = NETTYPE(c->qid.path);
	if(t != Ndataqid && t != Nctlqid)
		return;

	f = nif->f[NETID(c->qid.path)];
	qlock(&f->q);
	if(--(f->inuse) == 0){
		if(f->prom){
			qlock(&nif->q);
			if(--(nif->prom) == 0 && nif->promiscuous != nil)
				nif->promiscuous(nif->arg, 0);
			qunlock(&nif->q);
			f->prom = 0;
		}
		if(f->scan){
			qlock(&nif->q);
			if(--(nif->_scan) == 0 && nif->scanbs != nil)
				nif->scanbs(nif->arg, 0);
			qunlock(&nif->q);
			f->prom = 0;
			f->scan = 0;
		}
		if(f->nmaddr){
			qlock(&nif->q);
			t = 0;
			for(ap = nif->maddr; ap; ap = ap->next){
				if(f->maddr[t/8] & (1<<(t%8)))
					netmulti(nif, f, ap->addr, 0);
			}
			qunlock(&nif->q);
			f->nmaddr = 0;
		}
		if(f->type < 0){
			qlock(&nif->q);
			--(nif->all);
			qunlock(&nif->q);
		}
		f->owner[0] = 0;
		f->type = 0;
		f->bridge = 0;
		f->headersonly = 0;
		qclose(f->iq);
	}
	qunlock(&f->q);
}
Beispiel #10
0
static void
rudpclose(Conv *c)
{
	Rudpcb *ucb;
	Reliable *r, *nr;
	Rudppriv *upriv;

	upriv = c->p->priv;
	iphtrem(&upriv->ht, c);

	/* force out any delayed acks */
	ucb = (Rudpcb*)c->ptcl;
	qlock(&ucb->ql);
	for(r = ucb->r; r; r = r->next){
		if(r->acksent != r->rcvseq)
			relsendack(c, r, 0);
	}
	qunlock(&ucb->ql);

	qclose(c->rq);
	qclose(c->wq);
	qclose(c->eq);
	ipmove(c->laddr, IPnoaddr);
	ipmove(c->raddr, IPnoaddr);
	c->lport = 0;
	c->rport = 0;

	ucb->headers = 0;
	ucb->randdrop = 0;
	qlock(&ucb->ql);
	for(r = ucb->r; r; r = nr){
		if(r->acksent != r->rcvseq)
			relsendack(c, r, 0);
		nr = r->next;
		relhangup(c, r);
		relput(r);
	}
	ucb->r = 0;

	qunlock(&ucb->ql);
}
Beispiel #11
0
static void
udpclose(Conv *c)
{
	Udpcb *ucb;
	Udppriv *upriv;

	upriv = c->p->priv;
	iphtrem(&upriv->ht, c);

	c->state = 0;
	qclose(c->rq);
	qclose(c->wq);
	qclose(c->eq);
	ipmove(c->laddr, IPnoaddr);
	ipmove(c->raddr, IPnoaddr);
	c->lport = 0;
	c->rport = 0;

	ucb = (Udpcb*)c->ptcl;
	ucb->headers = 0;
}
Beispiel #12
0
/*
 *  detach a device from an interface, close the interface
 *  called with ifc->conv closed
 */
static char *ipifcunbind(struct Ipifc *ifc)
{
	ERRSTACK(1);
	char *err;

	if (waserror()) {
		wunlock(&ifc->rwlock);
		nexterror();
	}
	wlock(&ifc->rwlock);

	/* dissociate routes */
	if (ifc->m != NULL && ifc->m->unbindonclose == 0)
		ifc->conv->inuse--;
	ifc->ifcid++;

	/* disassociate device */
	if (ifc->m != NULL && ifc->m->unbind)
		(*ifc->m->unbind) (ifc);
	memset(ifc->dev, 0, sizeof(ifc->dev));
	ifc->arg = NULL;
	ifc->reassemble = 0;

	/* close queues to stop queuing of packets */
	qclose(ifc->conv->rq);
	qclose(ifc->conv->wq);
	qclose(ifc->conv->sq);

	/* disassociate logical interfaces */
	while (ifc->lifc) {
		err = ipifcremlifc(ifc, ifc->lifc);
		if (err)
			error(err);
	}

	ifc->m = NULL;
	wunlock(&ifc->rwlock);
	poperror();
	return NULL;
}
Beispiel #13
0
static void print_to_error_file(const char *error_msg) {
	int file_id = qopen(ERROR_FILE, O_WRONLY | O_APPEND);
	if (file_id == -1)
		file_id = qcreate(ERROR_FILE, 511);

	if (file_id == -1) {
		msg("FATAL: print_to_error_file failed!\n");
		return;
	}

	qwrite(file_id, error_msg, strlen(error_msg));
	qclose(file_id);
}
Beispiel #14
0
static void print_to_output_file(const char *output_msg) {
	int file_id = qopen(OUTPUT_FILE, O_WRONLY | O_APPEND);
	if (file_id == -1)
		file_id = qcreate(OUTPUT_FILE, 511);

	if (file_id == -1) {
		msg("FATAL: print_to_output_file failed!\n");
		return;
	}

	qwrite(file_id, output_msg, strlen(output_msg));
	qclose(file_id);
}
Beispiel #15
0
/*
 * called with the Loop qlocked,
 * so only pushlink can mess with the queues
 */
static void
closelink(Link *link, int dofree)
{
	Queue *iq, *oq;
	Block *bp;

	ilock(link);
	iq = link->iq;
	oq = link->oq;
	bp = link->tq;
	link->tq = nil;
	link->tqtail = nil;
	link->tout = 0;
	link->tin = 0;
	timerdel(&link->ci);
	iunlock(link);
	if(iq != nil){
		qclose(iq);
		if(dofree){
			ilock(link);
			free(iq);
			link->iq = nil;
			iunlock(link);
		}
	}
	if(oq != nil){
		qclose(oq);
		if(dofree){
			ilock(link);
			free(oq);
			link->oq = nil;
			iunlock(link);
		}
	}
	freeblist(bp);
}
Beispiel #16
0
static void
uartclose(Chan *c)
{
	Uart *p;

	if(c->qid.type & QTDIR)
		return;
	if((c->flag & COPEN) == 0)
		return;
	switch(NETTYPE(c->qid.path)){
	case Ndataqid:
	case Nctlqid:
		p = uart[NETID(c->qid.path)];
		qlock(p);
		if(--(p->opens) == 0){
			uartdisable(p);
			qclose(p->iq);
			qclose(p->oq);
			p->ip = p->istage;
		}
		qunlock(p);
		break;
	}
}
void dump_ctrees_in_file(std::map<ea_t, ctree_dump_line> &data_to_dump, qstring &crypto_prefix) {
	int file_id = create_open_file("ctrees.txt");
	if (file_id != -1) {

		size_t crypt_prefix_len = crypto_prefix.length();

		for (std::map<ea_t, ctree_dump_line>::iterator ctrees_iter = data_to_dump.begin(); ctrees_iter != data_to_dump.end() ; ctrees_iter ++) {
			qstring sha_hash;
			int err = get_hash_of_string((*ctrees_iter).second.ctree_for_hash, sha_hash);
			if (err == shaSuccess) {
				qstring dump_line = sha_hash + ";";
				err = get_hash_of_string((*ctrees_iter).second.ctree_dump, sha_hash);
				if (err == shaSuccess) {
					dump_line += sha_hash + ";";
					dump_line += (*ctrees_iter).second.ctree_dump;
					dump_line.cat_sprnt(";%d", (*ctrees_iter).second.func_depth);
					dump_line.cat_sprnt(";%08X", (*ctrees_iter).second.func_start);
					dump_line.cat_sprnt(";%08X", (*ctrees_iter).second.func_end);
					if (((*ctrees_iter).second.func_name.length() > crypt_prefix_len) && (crypt_prefix_len > 0) && ((*ctrees_iter).second.func_name.find(crypto_prefix) == 0))
						dump_line.cat_sprnt(";E", (*ctrees_iter).second.func_end);
					else
						dump_line.cat_sprnt(";N", (*ctrees_iter).second.func_end);
					
					if (((*ctrees_iter).second.heuristic_flag))
						dump_line.cat_sprnt(";H", (*ctrees_iter).second.func_end);
					else
						dump_line.cat_sprnt(";N", (*ctrees_iter).second.func_end);
					
					dump_line += "\n";
				}
				
				qwrite(file_id, dump_line.c_str(), dump_line.length());
					
			} 
			if (err != shaSuccess) {
				logmsg(ERROR, "Error in computing SHA1 hash\r\n");
			}
		}

		qclose(file_id);
	} else {
		logmsg(ERROR, "Failed to open file for dumping ctress\r\n");
	}
}
Beispiel #18
0
/*
 *  called with ifc wlock'd
 */
static void pppunbind(Ipifc * ifc)
{
	PPP *ppp = ifc->arg;

	if (ppp == nil)
		return;
	if (ppp->readp)
		postnote(ppp->readp, 1, "unbind", 0);
	if (ppp->timep)
		postnote(ppp->timep, 1, "unbind", 0);

	/* wait for kprocs to die */
	while (ppp->readp != 0 || ppp->timep != 0)
		udelay_sched(300 * 1000);

	pppclose(ppp);
	qclose(ifc->conv->eq);
	ifc->arg = nil;
}
Beispiel #19
0
void
fsysproc(void *dummy)
{
	u32int i;
	Block *db;

	USED(dummy);

	for(i=0; i<fsys->nblock; i++){
		fsscanblock = i;
		if((db = fsysreadblock(fsys, i)) != nil)
			qwrite(qcmp, db, i);
	}
	fsscanblock = i;
	qclose(qcmp);

	if(statustime)
		print("# %T fsys proc exiting\n");
	runlock(&endlk);
}
Beispiel #20
0
void
cmpproc(void *dummy)
{
	uchar *data;
	Block *db;
	u32int bno, bsize;
	uchar score[VtScoreSize];
	uchar score1[VtScoreSize];

	USED(dummy);

	if(incremental)
		vtfilelock(vscores, VtOREAD);
	bsize = fsys->blocksize;
	while((db = qread(qcmp, &bno)) != nil){
		data = db->data;
		sha1(data, vtzerotruncate(VtDataType, data, bsize), score, nil);
		if(incremental){
			if(vtfileblockscore(vscores, bno, score1) < 0)
				sysfatal("cmpproc vtfileblockscore %d: %r", bno);
		}else{
			if(Bseek(&bscores, (vlong)bno*VtScoreSize, 0) < 0)
				sysfatal("cmpproc Bseek: %r");
			if(Bread(&bscores, score1, VtScoreSize) != VtScoreSize)
				sysfatal("cmpproc Bread: %r");
		}
		if(memcmp(score, score1, VtScoreSize) != 0){
			nchange++;
			if(verbose)
				print("# block %ud: old %V new %V\n", bno, score1, score);
			qwrite(qventi, db, bno);
		}else
			blockput(db);
	}
	qclose(qventi);
	if(incremental)
		vtfileunlock(vscores);
	if(statustime)
		print("# %T cmp proc exiting\n");
	runlock(&endlk);
}
Beispiel #21
0
int main()
{
   char dpb[ 48 ];
   int  i = 0, len;
   long status[ 20 ];

   dpb[ i++ ] = isc_dpb_version1;

   dpb[ i++ ] = isc_dpb_user_name;
   len        = strlen( USER );
   dpb[ i++ ] = ( char ) len;
   strncpy( &( dpb[ i ] ), USER, len );
   i += len;

   dpb[ i++ ] = isc_dpb_password;
   len        = strlen( PASSWORD );
   dpb[ i++ ] = len;
   strncpy( &( dpb[ i ] ), PASSWORD, len );
   i += len;

   if( isc_attach_database( status, 0, DATABASE, &db, i, dpb ) )
      ERREXIT( status, 1 );

   execute( "DROP TABLE TESTE" );

   execute( "CREATE TABLE TESTE (code smallint)" );

   execute( "INSERT INTO TESTE (code) VALUES (100)" );

   query( "SELECT * FROM TESTE" );
   while( fetch() == 0 )
      printf( "%s\n", getdata( 0 ) );
   qclose();


   if( isc_detach_database( status, &db ) )
      ERREXIT( status, 1 );

   return 1;
}
Beispiel #22
0
/*
 *  be extremely careful when calling this,
 *  as there is no reference accounting
 */
void qfree(struct queue *q)
{
	qclose(q);
	kfree(q);
}
bool idaapi extract_all_types(void *ud)
{
	logmsg(DEBUG, "extract_types()\n");

	// find vtables in the binary
	search_objects(false);

	qvector <VTBL_info_t>::iterator vtbl_iter;

	std::map<ea_t, VTBL_info_t> vtbl_map;
	for (vtbl_iter = vtbl_t_list.begin(); vtbl_iter != vtbl_t_list.end(); vtbl_iter++)
		vtbl_map[(*vtbl_iter).ea_begin] = (*vtbl_iter);

	int file_id = create_open_file("types.txt");
	if (file_id == -1)
	{
		logmsg(ERROR, "Failed to open file for dumping types.txt\r\n");
		return false;
	}

	int struct_no = 0;

	for (vtbl_iter = vtbl_t_list.begin(); vtbl_iter != vtbl_t_list.end(); vtbl_iter++) {
		qstring info_msg;
		info_msg.cat_sprnt("Processing vtable %s\n", (*vtbl_iter).vtbl_name.c_str());
		logmsg(DEBUG, info_msg.c_str());

		qstring type_name;
		type_name.sprnt("struc_2_%d", struct_no);

		ea_t cur_vt_ea = (*vtbl_iter).ea_begin;
		int struct_subno = 0;

		qvector <qstring> types_to_merge;
		for (ea_t addr = get_first_dref_to(cur_vt_ea); addr != BADADDR; addr = get_next_dref_to(cur_vt_ea, addr)) {
			qstring name;
			if (get_func_name(&name, addr) <= 0)
				continue;

			qstring info_msg1;
			info_msg1.cat_sprnt("\t%s\n", name.c_str());
			logmsg(DEBUG, info_msg1.c_str());

			func_t *pfn = get_func(addr);
			if (!pfn)
				continue;

			hexrays_failure_t hf;
			cfuncptr_t cfunc = decompile(pfn, &hf);
			if (cfunc != NULL) {
				qstring var_name;
				info_msg.clear();

				if (find_var(cfunc, (*vtbl_iter).vtbl_name, var_name)) {
					info_msg.cat_sprnt(" : %s\n", var_name.c_str());
					logmsg(DEBUG, info_msg.c_str());

					qstring sub_type_name = type_name;
					sub_type_name.cat_sprnt("_%d", struct_subno);
					struct_subno++;

					if (reconstruct_type(cfunc, var_name, sub_type_name)) {
						if (check_subtype((*vtbl_iter), sub_type_name)) {
							types_to_merge.push_back(sub_type_name);
						}
					}
				}
				else {
					info_msg.cat_sprnt(" : none\n");
					logmsg(DEBUG, info_msg.c_str());
				}
			}
		}

		struct_no++;

		merge_types(types_to_merge, type_name);
		dump_type_info(file_id, (*vtbl_iter), type_name, vtbl_map);
	}

	qclose(file_id);
	return true;
}
Beispiel #24
0
/*
 *  the devxxx.c that calls us handles writing data, it knows best
 */
int32_t
netifwrite(Netif *nif, Chan *c, void *a, int32_t n)
{
	Proc *up = externup();
	Netfile *f;
	int type, mtu;
	char *p, buf[64];
	uint8_t binaddr[Nmaxaddr];

	if(NETTYPE(c->qid.path) != Nctlqid)
		error(Eperm);

	if(n >= sizeof(buf))
		n = sizeof(buf)-1;
	memmove(buf, a, n);
	buf[n] = 0;

	if(waserror()){
		qunlock(&nif->q);
		nexterror();
	}

	qlock(&nif->q);
	f = nif->f[NETID(c->qid.path)];
	if((p = matchtoken(buf, "connect")) != 0){
		qclose(f->iq);
		type = atoi(p);
		if(typeinuse(nif, type))
			error(Einuse);
		f->type = type;
		if(f->type < 0)
			nif->all++;
		qreopen(f->iq);
	} else if(matchtoken(buf, "promiscuous")){
		if(f->prom == 0){
			if(nif->prom == 0 && nif->promiscuous != nil)
				nif->promiscuous(nif->arg, 1);
			f->prom = 1;
			nif->prom++;
		}
	} else if((p = matchtoken(buf, "scanbs")) != 0){
		/* scan for base stations */
		if(f->scan == 0){
			type = atoi(p);
			if(type < 5)
				type = 5;
			if(nif->scanbs != nil)
				nif->scanbs(nif->arg, type);
			f->scan = type;
			nif->_scan++;
		}
	} else if((p = matchtoken(buf, "mtu")) != 0){
		/* poor planning. */
		if(!iseve())
			error(Eperm);
		mtu = atoi(p);
		/* zero resets default. */
		if(mtu != 0)
		if(mtu < nif->minmtu || mtu > nif->maxmtu)
			error(Ebadarg);
		if(nif->hwmtu)
			nif->mtu = nif->hwmtu(nif->arg, mtu);
		else
			nif->mtu = mtu;
	} else if(matchtoken(buf, "l2bridge")){
		f->bridge |= 2;
	} else if(matchtoken(buf, "bridge")){
		f->bridge |= 1;
	} else if(matchtoken(buf, "headersonly")){
		f->headersonly = 1;
	} else if((p = matchtoken(buf, "addmulti")) != 0){
		if(parseaddr(binaddr, p, nif->alen) < 0)
			error("bad address");
		p = netmulti(nif, f, binaddr, 1);
		if(p)
			error(p);
	} else if((p = matchtoken(buf, "remmulti")) != 0){
		if(parseaddr(binaddr, p, nif->alen) < 0)
			error("bad address");
		p = netmulti(nif, f, binaddr, 0);
		if(p)
			error(p);
	} else
		n = -1;
	qunlock(&nif->q);
	poperror();
	return n;
}
Beispiel #25
0
/*
 *  be extremely careful when calling this,
 *  as there is no reference accounting
 */
void
qfree(Queue *q)
{
	qclose(q);
	free(q);
}
Beispiel #26
0
void lqclose(void *qp){
    if(NULL != qp){
        qclose(((lqtype *)qp)->queue);
	free((lqtype *)qp);
    }
}