Example #1
0
File: devprog.c Project: 8l/inferno
static int
progsize(Prog *p)
{
	int size;
	Frame *f;
	uchar *fp;
	Modlink *m;

	m = p->R.M;
	size = 0;
	if(m->MP != H)
		size += hmsize(D2H(m->MP));
	if(m->prog != nil)
		size += msize(m->prog);

	fp = p->R.FP;
	while(fp != nil) {
		f = (Frame*)fp;
		fp = f->fp;
		if(f->mr != nil) {
			if(f->mr->MP != H)
				size += hmsize(D2H(f->mr->MP));
			if(f->mr->prog != nil)
				size += msize(f->mr->prog);
		}
		if(f->t == nil)
			size += msize(SEXTYPE(f));
	}
	return size/1024;
}
void cdcacm_init_serial() {
    int offset = 4 + USBManufacturerLen + 2 + USBProductLen + 2 + 6;
    cdcacm_string_descriptor[offset + 0] = D2H(DEVID >> 28);
    cdcacm_string_descriptor[offset + 2] = D2H(DEVID >> 24);
    cdcacm_string_descriptor[offset + 4] = D2H(DEVID >> 20);
    cdcacm_string_descriptor[offset + 6] = D2H(DEVID >> 16);
    cdcacm_string_descriptor[offset + 8] = D2H(DEVID >> 12);
    cdcacm_string_descriptor[offset + 10] = D2H(DEVID >> 8);
    cdcacm_string_descriptor[offset + 12] = D2H(DEVID >> 4);
    cdcacm_string_descriptor[offset + 14] = D2H(DEVID);
    cdcacm_string_descriptor[offset + 16] = D2H(DEVCFG3 >> 12);
    cdcacm_string_descriptor[offset + 18] = D2H(DEVCFG3 >> 8);
    cdcacm_string_descriptor[offset + 20] = D2H(DEVCFG3 >> 4);
    cdcacm_string_descriptor[offset + 22] = D2H(DEVCFG3);
}
Example #3
0
void
incmem(void *vw, Type *t)
{
	Heap *h;
	uchar *p;
	int i, c, m;
	WORD **w, **q, *wp;

	w = (WORD**)vw;
	p = t->map;
	for(i = 0; i < t->np; i++) {
		c = *p++;
		if(c != 0) {
			q = w;
			for(m = 0x80; m != 0; m >>= 1) {
				if((c & m) && (wp = *q) != H) {
					h = D2H(wp);
					h->ref++;
					Setmark(h);
				}
				q++;
			}
		}
		w += 8;
	}
Example #4
0
void
destroy(void *v)
{
	Heap *h;
	Type *t;

	if(v == H)
		return;

	h = D2H(v);
	{ Bhdr *b; D2B(b, h); }		/* consistency check */

	if(--h->ref > 0 || gchalt > 64) 	/* Protect 'C' thread stack */
		return;

	if(heapmonitor != nil)
		heapmonitor(1, h, 0);
	t = h->t;
	if(t != nil) {
		gclock();
		t->free(h, 0);
		gcunlock();
		freetype(t);
	}
	poolfree(heapmem, h);
}
Example #5
0
File: devsrv.c Project: 8l/inferno
static void
srvretype(Channel *c, SrvFile *f, Type *t)
{
	Heap *h;

	h = D2H(c);
	freetype(h->t);
	h->t = t;
	t->ref++;
	c->aux = f;
}
Example #6
0
BOOL ListProcessModules( DWORD dwPID, HANDLE *hnd )
{
  HANDLE hModuleSnap = INVALID_HANDLE_VALUE;
  MODULEENTRY32 me32;

  // Take a snapshot of all modules in the specified process.
  hModuleSnap = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE, dwPID );
  if( hModuleSnap == INVALID_HANDLE_VALUE )
  {
    //printError( TEXT("CreateToolhelp32Snapshot (of modules)") );
	printf( "CreateToolhelp32Snapshot (of modules)" );
    return( FALSE );
  }

  // Set the size of the structure before using it.
  me32.dwSize = sizeof( MODULEENTRY32 );

  // Retrieve information about the first module,
  // and exit if unsuccessful
  if( !Module32First( hModuleSnap, &me32 ) )
  {
    //printError( TEXT("Module32First") );  // show cause of failure
	printf( "Module32First" );
    CloseHandle( hModuleSnap );           // clean the snapshot object
    return( FALSE );
  }

  // Now walk the module list of the process,
  // and display information about each module
  do
  {
  	if( strcmp( me32.szModule, "client.dll" ) == 0 ) {	
		//printf( "addr: %x\n", me32.modBaseAddr );
		D2H( hnd, &me32.modBaseAddr );
	}

		
	/*
    _tprintf( TEXT("\n\n     MODULE NAME:     %s"),   me32.szModule );
    _tprintf( TEXT("\n     Executable     = %s"),     me32.szExePath );
    _tprintf( TEXT("\n     Process ID     = 0x%08X"),         me32.th32ProcessID );
    _tprintf( TEXT("\n     Ref count (g)  = 0x%04X"),     me32.GlblcntUsage );
    _tprintf( TEXT("\n     Ref count (p)  = 0x%04X"),     me32.ProccntUsage );
    _tprintf( TEXT("\n     Base address   = 0x%08X"), (DWORD) me32.modBaseAddr );
    _tprintf( TEXT("\n     Base size      = %d"),             me32.modBaseSize );
	*/
  } while( Module32Next( hModuleSnap, &me32 ) );

  CloseHandle( hModuleSnap );
  return( TRUE );
}
Example #7
0
void*
checktype(void *v, Type *t, char *name, int newref)
{
	Heap *h;

	if(v == H || v == nil)
		error(exNilref);
	h = D2H(v);
	if(t == nil || h->t != t)
		errorf("%s: %s", exType, name);
	if(newref){
		h->ref++;
		Setmark(h);
	}
	return v;
}
Example #8
0
void
freelist(Heap *h, int swept)
{
	Type *t;
	List *l;
	Heap *th;

	l = H2D(List*, h);
	t = l->t;

	if(t != nil) {
		if(!swept && t->np)
			freeptrs(l->data, t);
		t->ref--;
		if(t->ref == 0) {
			free(t->initialize);
			free(t);
		}
	}
	if(swept)
		return;
	l = l->tail;
	while(l != (List*)H) {
		t = l->t;
		th = D2H(l);
		if(th->ref-- != 1)
			break;
		th->t->ref--;	/* should be &Tlist and ref shouldn't go to 0 here nor be 0 already */
		if(t != nil) {
			if (t->np)
				freeptrs(l->data, t);
			t->ref--;
			if(t->ref == 0) {
				free(t->initialize);
				free(t);
			}
		}
		l = l->tail;
		if(heapmonitor != nil)
			heapmonitor(1, th, 0);
		poolfree(heapmem, th);
	}
}
Example #9
0
File: iconbox.c Project: 8l/inferno
PCompound*
iconbox(Prefab_Environ *e, Draw_Point p, String *titletext, Draw_Image *icon, Draw_Image *mask)
{
	Draw_Rect er, r, ir;
	PCompound *pc;
	Prefab_Compound *c;
	PElement *elem, *title;
	Image *disp;
	Draw_Image *ddisp;
	Screen *screen;
	Heap *h;
	Rectangle t;
	Point pt;

	screen = lookupscreen(e->screen);
	if(screen == nil)
		return H;
	h = heapz(TCompound);
	if(h == H)
		return H;
	pc = H2D(PCompound*, h);
	c = &pc->c;

	gchalt++;
	title = H;
	if(titletext != H){
		er.min.x = 0;
		er.min.y = 0;
		er.max.x = Dx(icon->r)-5;
		er.max.y = 0;
		title = textelement(e, titletext, er, ETitle);
		if(title == H){
    Err:
			destroy(c);
			gchalt--;
			return H;
		}
		c->title = (Prefab_Element*)title;
	}

	r = icon->r;
	if(title != H)
		r.max.y += 2+1+title->nkids*e->style->titlefont->height+1;

	er = edgerect(e, p, &r);

	R2R(t, er);
	disp = allocwindow(screen, t, Refbackup /*refreshcompound*/, DWhite);
	if(disp == nil)
		goto Err;

	if((ddisp=mkdrawimage(disp, e->screen, e->screen->display, nil)) == H){
		freeimage(disp);
		goto Err;
	}

	ir = r;
	if(title != H){
		ir = r;
		pt.x = r.min.x+3;
		pt.y = r.min.y+3;
		translateelement(&title->e, pt);
		ir.min.y = title->e.r.max.y+1;
	}

	elem = iconelement(e, ir, icon, mask);
	c->r = r;
	c->image = ddisp;
	c->environ = e;
	D2H(e)->ref++;
	c->contents = (Prefab_Element*)elem;
	pc->display = screen->display;
	gchalt--;
	return pc;
}
Example #10
0
File: dis.c Project: 8l/inferno
Prog*
newprog(Prog *p, Modlink *m)
{
	Heap *h;
	Prog *n, **ph;
	Osenv *on, *op;
	static int pidnum;

	if(p != nil){
		if(p->group != nil)
			p->flags |= p->group->flags & Pkilled;
		if(p->kill != nil)
			error(p->kill);
		if(p->flags & Pkilled)
			error("");
	}
	n = malloc(sizeof(Prog)+sizeof(Osenv));
	if(n == 0){
		if(p == nil)
			panic("no memory");
		else
			error(exNomem);
	}

	n->pid = ++pidnum;
	if(n->pid <= 0)
		panic("no pids");
	n->group = nil;

	if(isched.tail != nil) {
		n->prev = isched.tail;
		isched.tail->next = n;
	}
	else {
		isched.head = n;
		n->prev = nil;
	}
	isched.tail = n;

	ph = pidlook(n->pid);
	if(*ph != nil)
		panic("dup pid");
	n->pidlink = nil;
	*ph = n;

	n->osenv = (Osenv*)((uchar*)n + sizeof(Prog));
	n->xec = xec;
	n->quanta = PQUANTA;
	n->flags = 0;
	n->exval = H;

	h = D2H(m);
	h->ref++;
	Setmark(h);
	n->R.M = m;
	n->R.MP = m->MP;
	if(m->MP != H)
		Setmark(D2H(m->MP));
	addrun(n);

	if(p == nil){
		newgrp(n);
		return n;
	}

	addgrp(n, p);
	n->flags = p->flags;
	if(p->flags & Prestrict)
		n->flags |= Prestricted;
	memmove(n->osenv, p->osenv, sizeof(Osenv));
	op = p->osenv;
	on = n->osenv;
	on->waitq = op->childq;
	on->childq = nil;
	on->debug = nil;
	incref(on->pgrp);
	incref(on->fgrp);
	if(on->egrp != nil)
		incref(on->egrp);
	if(on->sigs != nil)
		incref(on->sigs);
	on->user = nil;
	kstrdup(&on->user, op->user);
	on->errstr = on->errbuf0;
	on->syserrstr = on->errbuf1;

	return n;
}
Example #11
0
File: devsrv.c Project: 8l/inferno
static long
srvwrite(Chan *c, void *va, long count, vlong offset)
{
	long l;
	Heap * volatile h;
	SrvFile *sp;
	Channel *wc;
	Channel *wr;
	Pending wait;
	Sys_Rwrite * volatile w;
	Sys_FileIO_write req;

	if(c->qid.type & QTDIR)
		error(Eperm);

	acquire();
	if(waserror()){
		release();
		nexterror();
	}

	sp = c->aux;
	wr = sp->write;
	if(wr == H)
		error(Ehungup);

	wc = cnewc(dev.Rwrite, movtmp, 1);
	ptradd(D2H(wc));
	if(waserror()){
		ptrdel(D2H(wc));
		destroy(wc);
		nexterror();
	}

	req.t0 = offset;
	req.t1 = mem2array(va, count);
	req.t2 = c->fid;
	req.t3 = wc;

	ptradd(D2H(req.t1));

	if(waserror()){
		ptrdel(D2H(req.t1));
		destroy(req.t1);
		nexterror();
	}

	csend(wr, &req);

	poperror();
	ptrdel(D2H(req.t1));
	destroy(req.t1);

	h = heap(dev.Rwrite);
	w = H2D(Sys_Rwrite *, h);
	ptradd(h);

	if(waserror()){
		ptrdel(h);
		destroy(w);
		nexterror();
	}

	wait.fid = c->fid;
	wait.rc = nil;
	wait.wc = wc;
	addwaiting(sp, &wait);
	if(waserror()){
		delwaiting(&wait);
		nexterror();
	}
	crecv(wc, w);
	poperror();
	delwaiting(&wait);

	if(w->t1 != H)
		error(string2c(w->t1));
	poperror();
	ptrdel(h);
	l = w->t0;
	destroy(w);

	poperror();
	ptrdel(D2H(wc));
	destroy(wc);

	poperror();
	release();
	if(l < 0)
		l = 0;
	return l;
}
Example #12
0
File: devsrv.c Project: 8l/inferno
static long
srvread(Chan *c, void *va, long count, vlong offset)
{
	int l;
	Heap * volatile h;
	Array *a;
	SrvFile *sp;
	Channel *rc;
	Channel *rd;
	Pending wait;
	Sys_Rread * volatile r;
	Sys_FileIO_read req;

	if(c->qid.type & QTDIR){
		qlock(&dev.l);
		if(waserror()){
			qunlock(&dev.l);
			nexterror();
		}
		l = devdirread(c, va, count, 0, 0, srvgen);
		poperror();
		qunlock(&dev.l);
		return l;
	}

	sp = c->aux;

	acquire();
	if(waserror()){
		release();
		nexterror();
	}

	rd = sp->read;
	if(rd == H)
		error(Ehungup);

	rc = cnewc(dev.Rread, movtmp, 1);
	ptradd(D2H(rc));
	if(waserror()){
		ptrdel(D2H(rc));
		destroy(rc);
		nexterror();
	}

	req.t0 = offset;
	req.t1 = count;
	req.t2 = c->fid;
	req.t3 = rc;
	csend(rd, &req);

	h = heap(dev.Rread);
	r = H2D(Sys_Rread *, h);
	ptradd(h);
	if(waserror()){
		ptrdel(h);
		destroy(r);
		nexterror();
	}

	wait.fid = c->fid;
	wait.rc = rc;
	wait.wc = nil;
	addwaiting(sp, &wait);
	if(waserror()){
		delwaiting(&wait);
		nexterror();
	}
	crecv(rc, r);
	poperror();
	delwaiting(&wait);

	if(r->t1 != H)
		error(string2c(r->t1));

	a = r->t0;
	l = 0;
	if(a != H){
		l = a->len;
		if(l > count)
			l = count;
		memmove(va, a->data, l);
	}

	poperror();
	ptrdel(h);
	destroy(r);

	poperror();
	ptrdel(D2H(rc));
	destroy(rc);

	poperror();
	release();

	return l;
}
Example #13
0
File: devprog.c Project: 8l/inferno
static int
progheap(Heapqry *hq, char *va, int count, ulong offset)
{
	WORD *w;
	void *p;
	List *hd;
	Array *a;
	char *fmt, *str;
	Module *m;
	Modlink *ml;
	Channel *c;
	ulong addr;
	String *ss;
	union { REAL r; LONG l; WORD w[2]; } rock;
	int i, s, n, len, signed_off;
	Type *t;

	n = 0;
	s = 0;
	signed_off = offset;
	addr = hq->addr;
	for(i = 0; i < hq->count; i++) {
		switch(hq->fmt) {
		case 'W':
			if(addr & 3)
				return -1;
			n += snprint(va+n, count-n, "%d\n", *(WORD*)addr);
			s = sizeof(WORD);
			break;
		case 'B':
			n += snprint(va+n, count-n, "%d\n", *(BYTE*)addr);
			s = sizeof(BYTE);
			break;
		case 'V':
			if(addr & 3)
				return -1;
			w = (WORD*)addr;
			rock.w[0] = w[0];
			rock.w[1] = w[1];
			n += snprint(va+n, count-n, "%lld\n", rock.l);
			s = sizeof(LONG);
			break;
		case 'R':
			if(addr & 3)
				return -1;
			w = (WORD*)addr;
			rock.w[0] = w[0];
			rock.w[1] = w[1];
			n += snprint(va+n, count-n, "%g\n", rock.r);
			s = sizeof(REAL);
			break;
		case 'I':
			if(addr & 3)
				return -1;
			for(m = modules; m != nil; m = m->link)
				if(m == (Module*)hq->module)
					break;
			if(m == nil)
				error(Ebadctl);
			addr = (ulong)(m->prog+addr);
			n += snprint(va+n, count-n, "%D\n", (Inst*)addr);
			s = sizeof(Inst);
			break;
		case 'P':
			if(addr & 3)
				return -1;
			p = *(void**)addr;
			fmt = "nil\n";
			if(p != H)
				fmt = "%lux\n";
			n += snprint(va+n, count-n, fmt, p);
			s = sizeof(WORD);
			break;
		case 'L':
			if(addr & 3)
				return -1;
			hd = *(List**)addr;
			if(hd == H || D2H(hd)->t != &Tlist)
				return -1;
			n += snprint(va+n, count-n, "%lux.%lux\n", (ulong)&hd->tail, (ulong)hd->data);
			s = sizeof(WORD);
			break;
		case 'A':
			if(addr & 3)
				return -1;
			a = *(Array**)addr;
			if(a == H)
				n += snprint(va+n, count-n, "nil\n");
			else {
				if(D2H(a)->t != &Tarray)
					return -1;
				n += snprint(va+n, count-n, "%d.%lux\n", a->len, (ulong)a->data);
			}
			s = sizeof(WORD);
			break;
		case 'C':
			if(addr & 3)
				return -1;
			ss = *(String**)addr;
			if(ss == H)
				ss = &snil;
			else
			if(D2H(ss)->t != &Tstring)
				return -1;
			n += snprint(va+n, count-n, "%d.", abs(ss->len));
			str = string2c(ss);
			len = strlen(str);
			if(count-n < len)
				len = count-n;
			if(len > 0) {
				memmove(va+n, str, len);
				n += len;
			}
			break;
		case 'M':
			if(addr & 3)
				return -1;
			ml = *(Modlink**)addr;
			fmt = ml == H ? "nil\n" : "%lux\n";
			n += snprint(va+n, count-n, fmt, ml->MP);
			s = sizeof(WORD);
			break;
		case 'c':
			if(addr & 3)
				return -1;
			c = *(Channel**)addr;
			if(c == H)
				n += snprint(va+n, count-n, "nil\n");
			else{
				t = D2H(c)->t;
				if(t != &Tchannel && t != Trdchan && t != Twrchan)
					return -1;
				if(c->buf == H)
					n += snprint(va+n, count-n, "0.%lux\n", (ulong)c);
				else
					n += snprint(va+n, count-n, "%d.%lux.%d.%d\n", c->buf->len, (ulong)c->buf->data, c->front, c->size);
			}
			break;
			
		}
		addr += s;
		if(signed_off > 0) {
			signed_off -= n;
			if(signed_off < 0) {
				memmove(va, va+n+signed_off, -signed_off);
				n = -signed_off;
			}
			else
				n = 0;
		}
	}
	return n;
}
Example #14
0
int
heapref(void *v)
{
	return D2H(v)->ref;
}