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

1992/0711/port/pgrp.c (diff list | history)

1992/0711/sys/src/9/port/pgrp.c:8,141992/0824/sys/src/9/port/pgrp.c:8,60 (short | long | prev | next)
1992/0619    
static Ref pgrpid; 
static Ref mountid; 
1990/0227    
 
1992/0824    
struct 
{ 
	Lock; 
	Crypt	*free; 
} cryptalloc; 
 
/* 
 * crypt entries are allocated from a pool rather than allocated using malloc so 
 * the memory can be protected from reading by devproc. The base and top of the 
 * crypt arena is stored in palloc for devproc. 
 */ 
Crypt* 
newcrypt(void) 
{ 
	Crypt *c; 
 
	lock(&cryptalloc); 
	if(cryptalloc.free) { 
		c = cryptalloc.free; 
		cryptalloc.free = c->next; 
		unlock(&cryptalloc); 
		return c; 
	} 
 
	cryptalloc.free = malloc(sizeof(Crypt)*conf.nproc); 
	if(cryptalloc.free == 0) 
		panic("newcrypt"); 
 
	for(c = cryptalloc.free+1; c < cryptalloc.free+conf.nproc-1; c++) 
		c->next = c+1; 
 
	palloc.cmembase = (ulong)cryptalloc.free; 
	palloc.cmembase = palloc.cmembase+(sizeof(Crypt)*conf.nproc); 
	unlock(&cryptalloc); 
	return newcrypt(); 
} 
 
1990/0227    
void 
1992/0824    
freecrypt(Crypt *c) 
{ 
	lock(&cryptalloc); 
	c->next = cryptalloc.free; 
	cryptalloc.free = c; 
	unlock(&cryptalloc); 
} 
 
void 
1992/0428    
pgrpnote(ulong noteid, char *a, long n, int flag) 
1990/1110    
{ 
1992/0428    
	Proc *p, *ep; 
1992/0711/sys/src/9/port/pgrp.c:26,361992/0824/sys/src/9/port/pgrp.c:72,82
1992/0428    
			continue; 
		if(p->noteid == noteid && p->kp == 0) { 
1991/1216    
			qlock(&p->debug); 
1992/0428    
			if(p->pid==0 || p->noteid != noteid){ 
1992/0824    
			if(p->pid == 0 || p->noteid != noteid){ 
1991/1216    
				qunlock(&p->debug); 
1990/1110    
				continue; 
			} 
1991/0125    
			if(!waserror()){ 
1992/0824    
			if(!waserror()) { 
1991/0125    
				postnote(p, 0, buf, flag); 
				poperror(); 
1990/1110    
			} 
1992/0711/sys/src/9/port/pgrp.c:44,971992/0824/sys/src/9/port/pgrp.c:90,103
1990/0227    
{ 
	Pgrp *p; 
 
1992/0619    
	p = smalloc(sizeof(Pgrp)+sizeof(Crypt)); 
1992/0824    
	p = smalloc(sizeof(Pgrp)); 
1992/0619    
	p->ref = 1; 
	/* This needs to have its own arena for protection */ 
	p->crypt = (Crypt*)((uchar*)p+sizeof(Pgrp)); 
1992/0824    
	p->crypt = newcrypt(); 
1992/0619    
	p->pgrpid = incref(&pgrpid); 
	return p; 
1991/0705    
} 
 
Fgrp* 
dupfgrp(Fgrp *f) 
{ 
	Fgrp *new; 
	Chan *c; 
	int i; 
                 
1992/0623    
	new = smalloc(sizeof(Fgrp)); 
	new->ref = 1; 
1991/0705    
                 
1992/0607    
	lock(f); 
1991/0705    
	new->maxfd = f->maxfd; 
	for(i = 0; i <= f->maxfd; i++) 
		if(c = f->fd[i]){ 
			incref(c); 
			new->fd[i] = c; 
		} 
1992/0607    
	unlock(f); 
1991/0705    
                 
	return new; 
} 
                 
void 
resrcwait(char *reason) 
{ 
1991/1110    
	char *p; 
                 
	p = u->p->psstate; 
	if(reason) { 
		u->p->psstate = reason; 
1991/0710    
		print("%s\n", reason); 
1991/1110    
	} 
1990/0227    
	if(u == 0) 
1991/0710    
		panic("resrcwait"); 
1992/0602    
                 
	tsleep(&u->p->sleep, return0, 0, 1000); 
1991/1110    
	u->p->psstate = p; 
1990/0227    
} 
                 
void 
closepgrp(Pgrp *p) 
{ 
1991/1011    
	Mhead **h, **e, *f, *next; 
1992/0711/sys/src/9/port/pgrp.c:110,1491992/0824/sys/src/9/port/pgrp.c:116,127
1990/0227    
			} 
1991/1011    
		} 
1991/0212    
		qunlock(&p->debug); 
1992/0824    
		freecrypt(p->crypt); 
1992/0619    
		free(p); 
1990/0227    
	} 
} 
 
1991/0705    
void 
closefgrp(Fgrp *f) 
{ 
	int i; 
	Chan *c; 
                 
	if(decref(f) == 0) { 
		for(i = 0; i <= f->maxfd; i++) 
			if(c = f->fd[i]) 
				close(c); 
                 
1992/0619    
		free(f); 
1991/0705    
	} 
} 
                 
                 
1990/0227    
Mount* 
1991/1011    
newmount(Mhead *mh, Chan *to) 
1990/0227    
{ 
1992/0711    
	Mount *m; 
1990/0227    
                 
1992/0619    
	m = smalloc(sizeof(Mount)); 
	m->to = to; 
	m->head = mh; 
	incref(to); 
	m->mountid = incref(&mountid); 
	return m; 
1991/0514    
} 
                 
void 
pgrpcpy(Pgrp *to, Pgrp *from) 
{ 
1991/1113    
	Mhead **h, **e, *f, **tom, **l, *mh; 
1992/0711/sys/src/9/port/pgrp.c:173,1791992/0824/sys/src/9/port/pgrp.c:151,209
1991/1011    
	runlock(&from->ns); 
} 
1991/0514    
 
1992/0824    
Fgrp* 
dupfgrp(Fgrp *f) 
{ 
	Fgrp *new; 
	Chan *c; 
	int i; 
 
	new = smalloc(sizeof(Fgrp)); 
	new->ref = 1; 
 
	lock(f); 
	new->maxfd = f->maxfd; 
	for(i = 0; i <= f->maxfd; i++) { 
		if(c = f->fd[i]){ 
			incref(c); 
			new->fd[i] = c; 
		} 
	} 
	unlock(f); 
 
	return new; 
} 
 
1991/1011    
void 
1992/0824    
closefgrp(Fgrp *f) 
{ 
	int i; 
	Chan *c; 
 
	if(decref(f) == 0) { 
		for(i = 0; i <= f->maxfd; i++) 
			if(c = f->fd[i]) 
				close(c); 
 
		free(f); 
	} 
} 
 
 
Mount* 
newmount(Mhead *mh, Chan *to) 
{ 
	Mount *m; 
 
	m = smalloc(sizeof(Mount)); 
	m->to = to; 
	m->head = mh; 
	incref(to); 
	m->mountid = incref(&mountid); 
	return m; 
} 
 
void 
1991/1011    
mountfree(Mount *m) 
{ 
	Mount *f; 
1992/0711/sys/src/9/port/pgrp.c:184,1871992/0824/sys/src/9/port/pgrp.c:214,234
1992/0705    
		free(m); 
		m = f; 
	} 
1992/0824    
} 
 
void 
resrcwait(char *reason) 
{ 
	char *p; 
 
	p = u->p->psstate; 
	if(reason) { 
		u->p->psstate = reason; 
		print("%s\n", reason); 
	} 
	if(u == 0) 
		panic("resrcwait"); 
 
	tsleep(&u->p->sleep, return0, 0, 1000); 
	u->p->psstate = p; 
1990/0227    
} 


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