Browse Source

deanonymize: do more

This is not even close to the end, btw: see the proc struct.

It's a big task.

Change-Id: I0fdba3c332d587308e8de4b168e5dcff9ca641a0
Signed-off-by: Ronald G. Minnich <rminnich@gmail.com>
Ronald G. Minnich 8 years ago
parent
commit
a71cd8999a
6 changed files with 70 additions and 70 deletions
  1. 2 2
      sys/src/9/port/edf.c
  2. 27 27
      sys/src/9/port/page.c
  3. 8 8
      sys/src/9/port/pager.c
  4. 18 18
      sys/src/9/port/portclock.c
  5. 4 4
      sys/src/9/port/portdat.h
  6. 11 11
      sys/src/9/port/proc.c

+ 2 - 2
sys/src/9/port/edf.c

@@ -575,7 +575,7 @@ edfready(Proc *p)
 	sch = procsched(p);
 	rq = &sch->runq[PriEdf];
 	/* insert in queue in earliest deadline order */
-	lock(sch);
+	lock(&sch->l);
 	l = nil;
 	for(pp = rq->head; pp; pp = pp->rnext){
 		if(pp->edf->d > e->d)
@@ -595,7 +595,7 @@ edfready(Proc *p)
 	p->priority = PriEdf;
 	p->readytime = machp()->ticks;
 	p->state = Ready;
-	unlock(sch);
+	unlock(&sch->l);
 	if(p->trace)
 		proctrace(p, SReady, 0);
 	return 1;

+ 27 - 27
sys/src/9/port/page.c

@@ -42,13 +42,13 @@ seprintpagestats(char *s, char *e)
 {
 	int i;
 
-	lock(&pga);
+	lock(&pga.l);
 	for(i = 0; i < sys->npgsz; i++)
 		if(sys->pgsz[i] != 0)
 			s = seprint(s, e, "%uld/%d %dK user pages avail\n",
 				pga.pgsza[i].freecount,
 				pga.pgsza[i].npages.ref, sys->pgsz[i]/KiB);
-	unlock(&pga);
+	unlock(&pga.l);
 	return s;
 }
 
@@ -81,10 +81,10 @@ pageinit(void)
 			}
 			DBG("pageinit: alloced pa %#P sz %#ux color %d\n",
 				pg->pa, sys->pgsz[si], pg->color);
-			lock(&pga);
+			lock(&pga.l);
 			pg->ref = 0;
 			pagechainhead(pg);
-			unlock(&pga);
+			unlock(&pga.l);
 		}
 	}
 
@@ -139,7 +139,7 @@ pageunchain(Page *p)
 {
 	Pgsza *pa;
 
-	if(canlock(&pga))
+	if(canlock(&pga.l))
 		panic("pageunchain");
 	pa = &pga.pgsza[p->pgszi];
 	if(p->prev)
@@ -159,7 +159,7 @@ pagechaintail(Page *p)
 {
 	Pgsza *pa;
 
-	if(canlock(&pga))
+	if(canlock(&pga.l))
 		panic("pagechaintail");
 	pa = &pga.pgsza[p->pgszi];
 	if(pa->tail) {
@@ -180,7 +180,7 @@ pagechainhead(Page *p)
 {
 	Pgsza *pa;
 
-	if(canlock(&pga))
+	if(canlock(&pga.l))
 		panic("pagechainhead");
 	pa = &pga.pgsza[p->pgszi];
 	if(pa->head) {
@@ -224,7 +224,7 @@ newpage(int clear, Segment **s, uintptr_t va, usize size, int color)
 //iprint("(remove this print and diea)newpage, size %x, si %d\n", size, si);
 	pa = &pga.pgsza[si];
 
-	lock(&pga);
+	lock(&pga.l);
 	/*
 	 * Beware, new page may enter a loop even if this loop does not
 	 * loop more than once, if the segment is lost and fault calls us
@@ -254,7 +254,7 @@ newpage(int clear, Segment **s, uintptr_t va, usize size, int color)
 		 * 3. out of memory, try with the pager.
 		 * but release the segment (if any) while in the pager.
 		 */
-		unlock(&pga);
+		unlock(&pga.l);
 
 		dontalloc = 0;
 		if(s && *s) {
@@ -278,7 +278,7 @@ newpage(int clear, Segment **s, uintptr_t va, usize size, int color)
 		if(dontalloc)
 			return 0;
 
-		lock(&pga);
+		lock(&pga.l);
 	}
 
 	assert(p != nil);
@@ -297,7 +297,7 @@ newpage(int clear, Segment **s, uintptr_t va, usize size, int color)
 	for(i = 0; i < nelem(p->cachectl); i++)
 		p->cachectl[i] = ct;
 	unlock(&p->l);
-	unlock(&pga);
+	unlock(&pga.l);
 
 	if(clear) {
 		k = kmap(p);
@@ -330,7 +330,7 @@ putpage(Page *p)
 	Pgsza *pa;
 	int rlse;
 
-	lock(&pga);
+	lock(&pga.l);
 	lock(&p->l);
 
 	if(p->ref == 0)
@@ -338,7 +338,7 @@ putpage(Page *p)
 
 	if(--p->ref > 0) {
 		unlock(&p->l);
-		unlock(&pga);
+		unlock(&pga.l);
 		return;
 	}
 	rlse = 0;
@@ -359,7 +359,7 @@ putpage(Page *p)
 	unlock(&p->l);
 	if(rlse)
 		pgfree(p);
-	unlock(&pga);
+	unlock(&pga.l);
 }
 
 /*
@@ -376,11 +376,11 @@ auxpage(usize size)
 	int si;
 
 	si = getpgszi(size);
-	lock(&pga);
+	lock(&pga.l);
 	pa = &pga.pgsza[si];
 	p = pa->head;
 	if(pa->freecount < Nminfree){
-		unlock(&pga);
+		unlock(&pga.l);
 		return nil;
 	}
 	pageunchain(p);
@@ -390,7 +390,7 @@ auxpage(usize size)
 	p->ref++;
 	uncachepage(p);
 	unlock(&p->l);
-	unlock(&pga);
+	unlock(&pga.l);
 
 	return p;
 }
@@ -425,11 +425,11 @@ retry:
 
 	/*
 	 *  normal lock ordering is to call
-	 *  lock(&pga) before lock(&p->l).
+	 *  lock(&pga.l) before lock(&p->l).
 	 *  To avoid deadlock, we have to drop
 	 *  our locks and try again.
 	 */
-	if(!canlock(&pga)){
+	if(!canlock(&pga.l)){
 		unlock(&p->l);
 		if(up)
 			sched();
@@ -440,7 +440,7 @@ retry:
 	pa = &pga.pgsza[p->pgszi];
 	/* No freelist cache when memory is very low */
 	if(pa->freecount < Nminfree){
-		unlock(&pga);
+		unlock(&pga.l);
 		uncachepage(p);
 		return 1;
 	}
@@ -452,7 +452,7 @@ retry:
 
 	/* No page of the correct color */
 	if(np == 0){
-		unlock(&pga);
+		unlock(&pga.l);
 		uncachepage(p);
 		return 1;
 	}
@@ -475,7 +475,7 @@ retry:
 	 * deadlock, even following the pga, pg lock ordering. -nemo
 	 */
 	lock(&np->l);
-	unlock(&pga);
+	unlock(&pga.l);
 
 	/* Cache the new version */
 	uncachepage(np);
@@ -582,16 +582,16 @@ lookpage(Image *i, uint32_t daddr)
 		if(f->image == i && f->daddr == daddr){
 			unlock(&pga.hashlock);
 
-			lock(&pga);
+			lock(&pga.l);
 			lock(&f->l);
 			if(f->image != i || f->daddr != daddr){
 				unlock(&f->l);
-				unlock(&pga);
+				unlock(&pga.l);
 				return 0;
 			}
 			if(++f->ref == 1)
 				pageunchain(f);
-			unlock(&pga);
+			unlock(&pga.l);
 			unlock(&f->l);
 
 			return f;
@@ -613,7 +613,7 @@ pagereclaim(Image *i)
 	Page *p;
 	uint64_t ticks;
 
-	lock(&pga);
+	lock(&pga.l);
 	ticks = fastticks(nil);
 
 	/*
@@ -630,7 +630,7 @@ pagereclaim(Image *i)
 		}
 	}
 	ticks = fastticks(nil) - ticks;
-	unlock(&pga);
+	unlock(&pga.l);
 
 	return ticks;
 }

+ 8 - 8
sys/src/9/port/pager.c

@@ -205,14 +205,14 @@ freepages(int si, int once)
 		if(pa->freecount > 0){
 			DBG("kickpager() up %#p: releasing %udK pages\n",
 				up, sys->pgsz[si]/KiB);
-			lock(&pga);
+			lock(&pga.l);
 			if(pa->freecount == 0){
-				unlock(&pga);
+				unlock(&pga.l);
 				continue;
 			}
 			p = pa->head;
 			pageunchain(p);
-			unlock(&pga);
+			unlock(&pga.l);
 			if(p->ref != 0)
 				panic("freepages pa %#ullx", p->pa);
 			pgfree(p);
@@ -229,9 +229,9 @@ tryalloc(int pgszi, int color)
 
 	p = pgalloc(sys->pgsz[pgszi], color);
 	if(p != nil){
-		lock(&pga);
+		lock(&pga.l);
 		pagechainhead(p);
-		unlock(&pga);
+		unlock(&pga.l);
 		return 0;
 	}
 	return -1;
@@ -242,13 +242,13 @@ hascolor(Page *pl, int color)
 {
 	Page *p;
 
-	lock(&pga);
+	lock(&pga.l);
 	for(p = pl; p != nil; p = p->next)
 		if(color == NOCOLOR || p->color == color){
-			unlock(&pga);
+			unlock(&pga.l);
 			return 1;
 		}
-	unlock(&pga);
+	unlock(&pga.l);
 	return 0;
 }
 

+ 18 - 18
sys/src/9/port/portclock.c

@@ -17,7 +17,7 @@
 
 struct Timers
 {
-	Lock;
+	Lock l;
 	Timer	*head;
 };
 
@@ -117,19 +117,19 @@ timeradd(Timer *nt)
 	int64_t when;
 
 	/* Must lock Timer struct before Timers struct */
-	ilock(nt);
+	ilock(&nt->l);
 	if(tt = nt->tt){
-		ilock(tt);
+		ilock(&tt->l);
 		tdel(nt);
-		iunlock(tt);
+		iunlock(&tt->l);
 	}
 	tt = &timers[machp()->machno];
-	ilock(tt);
+	ilock(&tt->l);
 	when = tadd(tt, nt);
 	if(when)
 		timerset(when);
-	iunlock(tt);
-	iunlock(nt);
+	iunlock(&tt->l);
+	iunlock(&nt->l);
 }
 
 
@@ -139,15 +139,15 @@ timerdel(Timer *dt)
 	Timers *tt;
 	int64_t when;
 
-	ilock(dt);
+	ilock(&dt->l);
 	if(tt = dt->tt){
-		ilock(tt);
+		ilock(&tt->l);
 		when = tdel(dt);
 		if(when && tt == &timers[machp()->machno])
 			timerset(tt->head->twhen);
-		iunlock(tt);
+		iunlock(&tt->l);
 	}
-	iunlock(dt);
+	iunlock(&dt->l);
 }
 
 void
@@ -203,7 +203,7 @@ timerintr(Ureg *u, int64_t j)
 	callhzclock = 0;
 	tt = &timers[machp()->machno];
 	now = fastticks(nil);
-	ilock(tt);
+	ilock(&tt->l);
 	while(t = tt->head){
 		/*
 		 * No need to ilock t here: any manipulation of t
@@ -214,7 +214,7 @@ timerintr(Ureg *u, int64_t j)
 		when = t->twhen;
 		if(when > now){
 			timerset(when);
-			iunlock(tt);
+			iunlock(&tt->l);
 			if(callhzclock)
 				hzclock(u);
 			return;
@@ -223,16 +223,16 @@ timerintr(Ureg *u, int64_t j)
 		assert(t->tt == tt);
 		t->tt = nil;
 		fcallcount[machp()->machno]++;
-		iunlock(tt);
+		iunlock(&tt->l);
 		if(t->tf)
 			(*t->tf)(u, t);
 		else
 			callhzclock++;
-		ilock(tt);
+		ilock(&tt->l);
 		if(t->tmode == Tperiodic)
 			tadd(tt, t);
 	}
-	iunlock(tt);
+	iunlock(&tt->l);
 }
 
 void
@@ -267,11 +267,11 @@ addclock0link(void (*f)(void), int ms)
 	nt->tt = nil;
 	nt->tf = (void (*)(Ureg*, Timer*))f;
 
-	ilock(&timers[0]);
+	ilock(&timers[0].l);
 	when = tadd(&timers[0], nt);
 	if(when)
 		timerset(when);
-	iunlock(&timers[0]);
+	iunlock(&timers[0].l);
 	return nt;
 }
 

+ 4 - 4
sys/src/9/port/portdat.h

@@ -643,7 +643,7 @@ struct Pgsza
 
 struct Pgalloc
 {
-	Lock;
+	Lock l;
 	int	userinit;	/* working in user init mode */
 	Pgsza	pgsza[NPGSZ];	/* allocs for m->npgsz page sizes */
 	Page*	hash[PGHSIZE];	/* only used for user pages */
@@ -675,7 +675,7 @@ struct Timer
 	void	(*tf)(Ureg*, Timer*);
 	void	*ta;
 	/* Internal */
-	Lock;
+	Lock l;
 	Timers	*tt;		/* Timers queue this timer runs on */
 	int64_t	twhen;		/* ns represented in fastticks */
 	Timer	*tnext;
@@ -772,7 +772,7 @@ struct Schedq
 
 struct Sched
 {
-	Lock;			/* runq */
+	Lock l;			/* runq */
 	int	nrdy;
 	uint32_t delayedscheds;	/* statistics */
 	int32_t skipscheds;
@@ -1024,7 +1024,7 @@ enum
  *  action log
  */
 struct Log {
-	Lock;
+	Lock l;
 	int	opens;
 	char*	buf;
 	char	*end;

+ 11 - 11
sys/src/9/port/proc.c

@@ -158,7 +158,7 @@ schedinit(void)		/* never returns */
 			 *	pga
 			 */
 			mmurelease(up);
-			unlock(&pga);
+			unlock(&pga.l);
 
 			psrelease(up);
 			unlock(&procalloc);
@@ -208,7 +208,7 @@ sched(void)
 		if(up->nlocks)
 		if(up->state != Moribund)
 		if(up->delaysched < 20
-		|| pga.Lock.p == up
+		|| pga.l.p == up
 		|| procalloc.Lock.p == up){
 			up->delaysched++;
  			run.delayedscheds++;
@@ -483,8 +483,8 @@ queueproc(Sched *sch, Schedq *rq, Proc *p, int locked)
 
 	pri = rq - sch->runq;
 	if(!locked)
-		lock(sch);
-	else if(canlock(sch))
+		lock(&sch->l);
+	else if(canlock(&sch->l))
 		panic("queueproc: locked and can lock");
 	p->priority = pri;
 	p->rnext = 0;
@@ -497,7 +497,7 @@ queueproc(Sched *sch, Schedq *rq, Proc *p, int locked)
 	sch->nrdy++;
 	sch->runvec |= 1<<pri;
 	if(!locked)
-		unlock(sch);
+		unlock(&sch->l);
 }
 
 /*
@@ -508,7 +508,7 @@ dequeueproc(Sched *sch, Schedq *rq, Proc *tp)
 {
 	Proc *l, *p;
 
-	if(!canlock(sch))
+	if(!canlock(&sch->l))
 		return nil;
 
 	/*
@@ -527,7 +527,7 @@ dequeueproc(Sched *sch, Schedq *rq, Proc *tp)
 	 */
 
 	if(p == 0 || p->mach){
-		unlock(sch);
+		unlock(&sch->l);
 		return nil;
 	}
 	if(p->rnext == 0)
@@ -543,7 +543,7 @@ dequeueproc(Sched *sch, Schedq *rq, Proc *tp)
 	if(p->state != Ready)
 		print("dequeueproc %s %d %s\n", p->text, p->pid, statename[p->state]);
 
-	unlock(sch);
+	unlock(&sch->l);
 	return p;
 }
 
@@ -992,7 +992,7 @@ canpage(Proc *p)
 
 	splhi();
 	sch = procsched(p);
-	lock(sch);
+	lock(&sch->l);
 	/* Only reliable way to see if we are Running */
 	if(p->mach == 0) {
 		p->newtlb = 1;
@@ -1000,7 +1000,7 @@ canpage(Proc *p)
 	}
 	else
 		ok = 0;
-	unlock(sch);
+	unlock(&sch->l);
 	spllo();
 
 	return ok;
@@ -1619,7 +1619,7 @@ pexit(char *exitstr, int freemem)
 
 	/* Sched must not loop for these locks */
 	lock(&procalloc);
-	lock(&pga);
+	lock(&pga.l);
 
 	stopac();
 	edfstop(up);