plan 9 kernel history: overview | file list | diff list

1990/1115/port/devproc.c (diff list | history)

1990/1115/sys/src/9/port/devproc.c:22,491990/11211/sys/src/9/port/devproc.c:22,49 (short | long | prev | next)
1990/0227    
}; 
 
Dirtab procdir[]={ 
	"ctl",		Qctl,		0,			0600, 
	"mem",		Qmem,		0,			0600, 
	"note",		Qnote,		0,			0600, 
1990/1110    
	"notepg",	Qnotepg,	0,			0200, 
1990/0227    
	"proc",		Qproc,		sizeof(Proc),		0600, 
	"status",	Qstatus,	NAMELEN+12+6*12,	0600, 
	"text",		Qtext,		0,			0600, 
1990/11211    
	"ctl",		{Qctl},		0,			0600, 
	"mem",		{Qmem},		0,			0600, 
	"note",		{Qnote},	0,			0600, 
	"notepg",	{Qnotepg},	0,			0200, 
	"proc",		{Qproc},	sizeof(Proc),		0600, 
	"status",	{Qstatus},	NAMELEN+12+6*12,	0600, 
	"text",		{Qtext},	0,			0600, 
1990/0227    
}; 
 
/* 
 * Qids are, from bottom to top: 
1990/11211    
 * Qids are, in path: 
1990/0227    
 *	 4 bits of file type (qids above) 
 *	12 bits of process slot number + 1 
 *	15 bits of pid, for consistency checking 
1990/11211    
 *	24 bits of process slot number + 1 
 *	     in vers, 
 *	32 bits of pid, for consistency checking 
 * If notepg, c->pgrpid.path is pgrp slot, .vers is pgrpid. 
1990/0227    
 */ 
#define	NPROC	(sizeof procdir/sizeof(Dirtab)) 
#define	QSHIFT	4	/* location in qid of proc slot # */ 
#define	PIDSHIFT 16	/* location in qid of pid */ 
#define	PIDMASK	0x7FFF	/* low bits of pid used in qid */ 
#define	QID(q)	(((q)&0x0000000F)>>0) 
#define	SLOT(q)	((((q)&0x0000FFF0)>>QSHIFT)-1) 
#define	PID(q)	(((q)&0x7FFF0000)>>PIDSHIFT) 
1990/11211    
#define	QID(q)	(((q).path&0x0000000F)>>0) 
#define	SLOT(q)	((((q).path&0x0FFFFFFF0)>>QSHIFT)-1) 
#define	PID(q)	((q).vers) 
1990/0227    
 
int 
procgen(Chan *c, Dirtab *tab, int ntab, int s, Dir *dp) 
1990/1115/sys/src/9/port/devproc.c:52,581990/11211/sys/src/9/port/devproc.c:52,58
1990/0227    
	char buf[NAMELEN]; 
	ulong pid; 
 
	if(c->qid == CHDIR){ 
1990/11211    
	if(c->qid.path == CHDIR){ 
1990/0227    
		if(s >= conf.nproc) 
			return -1; 
		p = proctab(s); 
1990/1115/sys/src/9/port/devproc.c:60,661990/11211/sys/src/9/port/devproc.c:60,66
1990/0227    
		if(pid == 0) 
			return 0; 
		sprint(buf, "%d", pid); 
		devdir(c, CHDIR|(pid<<PIDSHIFT)|((s+1)<<QSHIFT), buf, 0, CHDIR|0500, dp); 
1990/11211    
		devdir(c, (Qid){CHDIR|((s+1)<<QSHIFT), pid}, buf, 0, CHDIR|0500, dp); 
1990/0227    
		return 1; 
	} 
	if(s >= NPROC) 
1990/1115/sys/src/9/port/devproc.c:68,741990/11211/sys/src/9/port/devproc.c:68,75
1990/0227    
	if(tab) 
		panic("procgen"); 
	tab = &procdir[s]; 
	devdir(c, (~CHDIR)&(c->qid|tab->qid), tab->name, tab->length, tab->perm, dp); 
1990/11211    
	devdir(c, (Qid){(~CHDIR)&(c->qid.path|tab->qid.path), c->qid.vers}, 
		tab->name, tab->length, tab->perm, dp); 
1990/0227    
	return 1; 
} 
 
1990/1115/sys/src/9/port/devproc.c:117,1321990/11211/sys/src/9/port/devproc.c:118,133
1990/0227    
	Orig *o; 
	Chan *tc; 
 
1990/03081    
	if(c->qid == CHDIR){ 
1990/11211    
	if(c->qid.path == CHDIR){ 
1990/03081    
		if(omode != OREAD) 
			error(0, Eperm); 
1990/11211    
			error(Eperm); 
1990/03081    
		goto done; 
	} 
1990/0227    
	p = proctab(SLOT(c->qid)); 
1990/1110    
	pg = p->pgrp; 
1990/0227    
	if((p->pid&PIDMASK) != PID(c->qid)) 
1990/11211    
	if(p->pid != PID(c->qid)) 
1990/0227    
    Died: 
		error(0, Eprocdied); 
1990/11211    
		error(Eprocdied); 
1990/0227    
	omode = openmode(omode); 
 
	switch(QID(c->qid)){ 
1990/1115/sys/src/9/port/devproc.c:144,1501990/11211/sys/src/9/port/devproc.c:145,151
1990/0227    
		} 
		if(!(tc->flag&COPEN) || tc->mode!=OREAD) 
			goto Close; 
		if((p->pid&PIDMASK) != PID(c->qid)) 
1990/11211    
		if(p->pid != PID(c->qid)) 
1990/0227    
			goto Close; 
		qlock(tc); 
		tc->offset = 0; 
1990/1115/sys/src/9/port/devproc.c:156,1631990/11211/sys/src/9/port/devproc.c:157,165
1990/1110    
 
	case Qnotepg: 
1990/1115    
		if(omode!=OWRITE || pg->pgrpid==1)	/* easy to do by mistake */ 
1990/1110    
			error(0, Eperm); 
		c->pgrpid = (pg->pgrpid<<PIDSHIFT)|((pg->index+1)<<QSHIFT); 
1990/11211    
			error(Eperm); 
		c->pgrpid.path = pg->index+1; 
		c->pgrpid.vers = pg->pgrpid; 
1990/1110    
		break; 
 
1990/0227    
	case Qdir: 
1990/1115/sys/src/9/port/devproc.c:165,1811990/11211/sys/src/9/port/devproc.c:167,183
1990/0227    
	case Qproc: 
	case Qstatus: 
1990/1110    
		if(omode != OREAD) 
1990/0424    
			error(0, Eperm); 
1990/11211    
			error(Eperm); 
1990/0424    
		break; 
1990/0227    
	default: 
		pprint("unknown qid in devopen\n"); 
		error(0, Egreg); 
1990/11211    
		error(Egreg); 
1990/0227    
	} 
	/* 
	 * Affix pid to qid 
	 */ 
	if(p->state != Dead) 
		c->qid |= (p->pid&PIDMASK)<<PIDSHIFT; 
1990/11211    
		c->qid.vers = p->pid; 
1990/03081    
   done: 
1990/0227    
	c->mode = omode; 
	c->flag |= COPEN; 
1990/1115/sys/src/9/port/devproc.c:186,2041990/11211/sys/src/9/port/devproc.c:188,206
1990/0227    
void 
proccreate(Chan *c, char *name, int omode, ulong perm) 
{ 
	error(0, Eperm); 
1990/11211    
	error(Eperm); 
1990/0227    
} 
 
void 
procremove(Chan *c) 
{ 
	error(0, Eperm); 
1990/11211    
	error(Eperm); 
1990/0227    
} 
 
void 
procwstat(Chan *c, char *db) 
{ 
	error(0, Eperm); 
1990/11211    
	error(Eperm); 
1990/0227    
} 
 
void 
1990/1115/sys/src/9/port/devproc.c:222,2281990/11211/sys/src/9/port/devproc.c:224,230
1990/0227    
	long pid; 
	User *up; 
 
	if(c->qid & CHDIR) 
1990/11211    
	if(c->qid.path & CHDIR) 
1990/0227    
		return devdirread(c, a, n, 0, 0, procgen); 
 
	/* 
1990/1115/sys/src/9/port/devproc.c:229,2361990/11211/sys/src/9/port/devproc.c:231,238
1990/0227    
	 * BUG: should lock(&p->debug)? 
	 */ 
	p = proctab(SLOT(c->qid)); 
	if((p->pid&PIDMASK) != PID(c->qid)) 
		error(0, Eprocdied); 
1990/11211    
	if(p->pid != PID(c->qid)) 
		error(Eprocdied); 
1990/0227    
 
	switch(QID(c->qid)){ 
	case Qmem: 
1990/1115/sys/src/9/port/devproc.c:243,2571990/11211/sys/src/9/port/devproc.c:245,259
1990/0227    
		if(s){ 
			o = s->o; 
			if(o == 0) 
				error(0, Eprocdied); 
1990/11211    
				error(Eprocdied); 
1990/0227    
			lock(o); 
			if(s->o!=o || (p->pid&PIDMASK)!=PID(c->qid)){ 
1990/11211    
			if(s->o!=o || p->pid!=PID(c->qid)){ 
1990/0227    
				unlock(o); 
				error(0, Eprocdied); 
1990/11211    
				error(Eprocdied); 
1990/0227    
			} 
			if(seg(p, c->offset) != s){ 
				unlock(o); 
				error(0, Egreg); 
1990/11211    
				error(Egreg); 
1990/0227    
			} 
1990/0614    
			pte = &o->pte[(c->offset-o->va)>>PGSHIFT]; 
			if(s->mod){ 
1990/1115/sys/src/9/port/devproc.c:281,2881990/11211/sys/src/9/port/devproc.c:283,290
1990/0227    
			if(c->offset+n > USERADDR+BY2PG) 
				n = USERADDR+BY2PG - c->offset; 
			pg = p->upage; 
			if(pg==0 || (p->pid&PIDMASK)!=PID(c->qid)) 
				error(0, Eprocdied); 
1990/11211    
			if(pg==0 || p->pid!=PID(c->qid)) 
				error(Eprocdied); 
1990/0614    
			k = kmap(pg); 
			b = (char*)VA(k); 
1990/0227    
			memcpy(a, b+(c->offset-USERADDR), n); 
1990/1115/sys/src/9/port/devproc.c:296,3071990/11211/sys/src/9/port/devproc.c:298,303
1990/0614    
				n = KZERO+conf.npage0*BY2PG - c->offset; 
1990/0914    
			memcpy(a, (char*)c->offset, n); 
			return n; 
1990/1110    
		}else if(c->offset>=UNCACHED && c->offset<UNCACHED+conf.npage0*BY2PG){ 
			/* BUT mips only TAKE IT OUT */ 
1990/0914    
			if(c->offset+n > UNCACHED+conf.npage0*BY2PG) 
				n = UNCACHED+conf.npage0*BY2PG - c->offset; 
1990/0227    
			memcpy(a, (char*)c->offset, n); 
			return n; 
		} 
		return 0; 
		break; 
1990/1115/sys/src/9/port/devproc.c:312,3281990/11211/sys/src/9/port/devproc.c:308,324
1990/0227    
			unlock(&p->debug); 
			nexterror(); 
		} 
		if((p->pid&PIDMASK) != PID(c->qid)) 
			error(0, Eprocdied); 
1990/11211    
		if(p->pid != PID(c->qid)) 
			error(Eprocdied); 
1990/0614    
		k = kmap(p->upage); 
		up = (User*)VA(k); 
1990/0227    
		if(up->p != p){ 
1990/0614    
			kunmap(k); 
1990/0227    
			pprint("note read u/p mismatch"); 
			error(0, Egreg); 
1990/11211    
			error(Egreg); 
1990/0227    
		} 
		if(n < ERRLEN) 
			error(0, Etoosmall); 
1990/11211    
			error(Etoosmall); 
1990/0227    
		if(up->nnote == 0) 
			n = 0; 
		else{ 
1990/1115/sys/src/9/port/devproc.c:359,3651990/11211/sys/src/9/port/devproc.c:355,361
1990/0227    
		memcpy(a, statbuf+c->offset, n); 
		return n; 
	} 
	error(0, Egreg); 
1990/11211    
	error(Egreg); 
1990/0227    
} 
 
 
1990/1115/sys/src/9/port/devproc.c:372,3911990/11211/sys/src/9/port/devproc.c:368,387
1990/0614    
	KMap *k; 
1990/0227    
	char buf[ERRLEN]; 
 
	if(c->qid & CHDIR) 
		error(0, Eisdir); 
1990/11211    
	if(c->qid.path & CHDIR) 
		error(Eisdir); 
1990/1110    
 
	/* 
	 * Special case: don't worry about process, just use remembered group 
	 */ 
	if(QID(c->qid) == Qnotepg){ 
		pg = pgrptab(SLOT(c->pgrpid)); 
1990/11211    
		pg = pgrptab(c->pgrpid.path-1); 
1990/1110    
		lock(&pg->debug); 
		if(waserror()){ 
			unlock(&pg->debug); 
			nexterror(); 
		} 
		if((pg->pgrpid&PIDMASK) != PID(c->pgrpid)){ 
1990/11211    
		if(pg->pgrpid != c->pgrpid.vers){ 
1990/1110    
			unlock(&pg->debug); 
  	  		goto Died; 
		} 
1990/1115/sys/src/9/port/devproc.c:400,4081990/11211/sys/src/9/port/devproc.c:396,404
1990/0227    
		unlock(&p->debug); 
		nexterror(); 
	} 
	if((p->pid&PIDMASK) != PID(c->qid)) 
1990/11211    
	if(p->pid != PID(c->qid)) 
1990/0227    
    Died: 
		error(0, Eprocdied); 
1990/11211    
		error(Eprocdied); 
1990/0227    
 
	switch(QID(c->qid)){ 
	case Qctl: 
1990/1115/sys/src/9/port/devproc.c:409,4151990/11211/sys/src/9/port/devproc.c:405,411
1990/0227    
		if(p->state==Broken && n>=4 && strncmp(va, "exit", 4)==0) 
			ready(p); 
		else 
			error(0, Ebadctl); 
1990/11211    
			error(Ebadctl); 
1990/0227    
		break; 
	case Qnote: 
1990/0614    
		k = kmap(p->upage); 
1990/1115/sys/src/9/port/devproc.c:417,4501990/11211/sys/src/9/port/devproc.c:413,434
1990/0227    
		if(up->p != p){ 
1990/0614    
			kunmap(k); 
1990/0227    
			pprint("note write u/p mismatch"); 
			error(0, Egreg); 
1990/11211    
			error(Egreg); 
1990/0227    
		} 
1990/0614    
		kunmap(k); 
1990/0227    
		if(n >= ERRLEN-1) 
			error(0, Etoobig); 
1990/11211    
			error(Etoobig); 
1990/0227    
		if(n>=4 && strncmp(va, "sys:", 4)==0) 
			error(0, Ebadarg); 
1990/11211    
			error(Ebadarg); 
1990/0227    
		memcpy(buf, va, n); 
		buf[n] = 0; 
		if(!postnote(p, 0, buf, NUser)) 
			error(0, Enonote); 
1990/11211    
			error(Enonote); 
1990/0227    
		break; 
	default: 
		pprint("unknown qid in procwrite\n"); 
		error(0, Egreg); 
1990/11211    
		error(Egreg); 
1990/0227    
	} 
	unlock(&p->debug); 
	return n; 
} 
                 
void 
procuserstr(Error *e, char *buf) 
{ 
	consuserstr(e, buf); 
} 
                 
void 
procerrstr(Error *e, char *buf) 
{ 
	rooterrstr(e, buf); 
} 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)