~kris/9p

9hist

6ee959115f3ba5d888cb68f26422b5385d34bb56 — David du Colombier 28 years ago 481ff58
Plan 9 from Bell Labs 1998-08-06
5 files changed, 99 insertions(+), 57 deletions(-)

M pc/trap.c
M port/devssl.c
M port/portdat.h
M port/proc.c
M port/qlock.c
M pc/trap.c => pc/trap.c +12 -9
@@ 18,21 18,24 @@ static Irqctl *irqctl[256];
void
intrenable(int v, void (*f)(Ureg*, void*), void* a, int tbdf)
{
	Irq * irq;
	Irq *irq;
	Irqctl *ctl;

	lock(&irqctllock);
	if(irqctl[v] == 0){
		ctl = xalloc(sizeof(Irqctl));
		if(v >= VectorINTR && arch->intrenable(v, tbdf, ctl) == -1){
			unlock(&irqctllock);
			//print("intrenable: didn't find v %d, tbdf 0x%uX\n", v, tbdf);
	if(irqctl[v] == 0)
		irqctl[v] = xalloc(sizeof(Irqctl));
	ctl = irqctl[v];

	if(v >= VectorINTR && arch->intrenable(v, tbdf, ctl) == -1){
		if(ctl->irq == nil){
			irqctl[v] = nil;
			xfree(ctl);
			return;
		}
		irqctl[v] = ctl;
		unlock(&irqctllock);
		print("intrenable: didn't find v %d, tbdf 0x%uX\n", v, tbdf);
		return;
	}
	ctl = irqctl[v];

	irq = xalloc(sizeof(Irq));
	irq->f = f;
	irq->a = a;

M port/devssl.c => port/devssl.c +81 -4
@@ 10,6 10,8 @@

#include	<libcrypt.h>

#define NOSPOOKS 1

typedef struct OneWay OneWay;
struct OneWay
{


@@ 728,6 730,40 @@ initDESkey(OneWay *w)
		error("secret too short");
}

/*
 *  40 bit DES is the same as 56 bit DES.  However,
 *  16 bits of the key are masked to zero.
 */
static void
initDESkey_40(OneWay *w)
{
	if(w->state){
		free(w->state);
		w->state = 0;
	}

	if(w->slen >= 16) {
		w->secret[8] &= 0x0f; 
		w->secret[10] &= 0x0f; 
		w->secret[12] &= 0x0f; 
		w->secret[14] &= 0x0f;
	}
	if(w->slen >= 8) {
		w->secret[0] &= 0x0f; 
		w->secret[2] &= 0x0f; 
		w->secret[4] &= 0x0f; 
		w->secret[6] &= 0x0f;
	}

	w->state = malloc(sizeof(DESstate));
	if(w->slen >= 16)
		setupDESstate(w->state, w->secret, w->secret+8);
	else if(w->slen >= 8)
		setupDESstate(w->state, w->secret, 0);
	else
		error("secret too short");
}

static void
initRC4key(OneWay *w)
{


@@ 740,12 776,34 @@ initRC4key(OneWay *w)
	setupRC4state(w->state, w->secret, w->slen);
}

/*
 *  40 bit RC4 is the same as n-bit RC4.  However,
 *  we ignore all but the first 40 bits of the key.
 */
static void
initRC4key_40(OneWay *w)
{
	if(w->state){
		free(w->state);
		w->state = 0;
	}

	if(w->slen > 5)
		w->slen = 5;

	w->state = malloc(sizeof(RC4state));
	setupRC4state(w->state, w->secret, w->slen);
}

typedef struct Hashalg Hashalg;
struct Hashalg
{
	char	*name;
	int	diglen;
	DigestState *(*hf)(uchar*, ulong, uchar*, DigestState*);
} hashtab[] =
};

Hashalg hashtab[] =
{
	{ "md4", MD4dlen, md4, },
	{ "md5", MD5dlen, md5, },


@@ 756,7 814,7 @@ struct Hashalg
static int
parsehashalg(char *p, Dstate *s)
{
	struct Hashalg *ha;
	Hashalg *ha;

	for(ha = hashtab; ha->name; ha++){
		if(strcmp(p, ha->name) == 0){


@@ 770,24 828,43 @@ parsehashalg(char *p, Dstate *s)
	return -1;
}

typedef struct Encalg Encalg;
struct Encalg
{
	char	*name;
	int	blocklen;
	int	alg;
	void	(*keyinit)(OneWay*);
} encrypttab[] =
};

#ifdef NOSPOOKS
Encalg encrypttab[] =
{
	{ "descbc", 8, DESCBC, initDESkey, },
	{ "desebc", 8, DESECB, initDESkey, },
	{ "descbc_40", 8, DESCBC, initDESkey_40, },
	{ "desebc_40", 8, DESECB, initDESkey_40, },
	{ "rc4", 1, RC4, initRC4key, },
	{ "rc4_40", 1, RC4, initRC4key_40, },
	{ 0 }
};
#else
Encalg encrypttab[] =
{
	{ "descbc", 8, DESCBC, initDESkey_40, },
	{ "desebc", 8, DESECB, initDESkey_40, },
	{ "descbc_40", 8, DESCBC, initDESkey_40, },
	{ "desebc_40", 8, DESECB, initDESkey_40, },
	{ "rc4", 1, RC4, initRC4key_40, },
	{ "rc4_40", 1, RC4, initRC4key_40, },
	{ 0 }
};
#endif NOSPOOKS

static int
parseencryptalg(char *p, Dstate *s)
{
	struct Encalg *ea;
	Encalg *ea;

	for(ea = encrypttab; ea->name; ea++){
		if(strcmp(p, ea->name) == 0){

M port/portdat.h => port/portdat.h +1 -2
@@ 68,8 68,6 @@ struct RWlock
	Proc	*tail;
	int	readers;	/* number of readers */
	int	writer;		/* number of writers */
//	int	pidw;
//	int	pidr[10];
};

struct Talarm


@@ 498,6 496,7 @@ enum
	Scheding,
	Running,
	Queueing,
	QueueingR,
	QueueingW,
	Wakeme,
	Broken,

M port/proc.c => port/proc.c +1 -0
@@ 41,6 41,7 @@ char *statename[] =
	"Scheding",
	"Running",
	"Queueing",
	"QueueingR",
	"QueueingW",
	"Wakeme",
	"Broken",

M port/qlock.c => port/qlock.c +4 -42
@@ 78,20 78,9 @@ rlock(RWlock *q)
	Proc *p, *mp;

	lock(&q->use);
//{int i;
//for(i=0; i<nelem(q->pidr); i++)
//if(q->pidr[i]==up->pid)
//print("***already %d\n", up->pid);
//}
rwstats.rlock++;
	if(q->writer == 0 && q->head == nil){
		/* no writer, go for it */
//{int i;
//for(i=0; i<nelem(q->pidr); i++)
//if(q->pidr[i]==0) {
//q->pidr[i]=up->pid;
//break;
//}}
		q->readers++;
		unlock(&q->use);
		return;


@@ 106,8 95,7 @@ rwstats.rlockq++;
		p->qnext = mp;
	q->tail = mp;
	mp->qnext = 0;
	mp->state = Queueing;
//print("%d rl for w%d\n", up->pid, q->pidw);
	mp->state = QueueingR;
	unlock(&q->use);
	sched();
}


@@ 118,12 106,6 @@ runlock(RWlock *q)
	Proc *p;

	lock(&q->use);
//{int i;
//for(i=0; i<nelem(q->pidr); i++)
//if(q->pidr[i]==up->pid) {
//q->pidr[i] = 0;
//break;
//}}
	p = q->head;
	if(--(q->readers) > 0 || p == nil){
		unlock(&q->use);


@@ 137,7 119,6 @@ runlock(RWlock *q)
	if(q->head == 0)
		q->tail = 0;
	q->writer = 1;
//q->pidw = p->pid;
	unlock(&q->use);
	ready(p);
}


@@ 151,14 132,13 @@ wlock(RWlock *q)
rwstats.wlock++;
	if(q->readers == 0 && q->writer == 0){
		/* noone waiting, go for it */
//q->pidw = up->pid;
		q->writer = 1;
		unlock(&q->use);
		return;
	}

	/* wait */
//rwstats.wlockq++;
rwstats.wlockq++;
	p = q->tail;
	mp = up;
	if(p == nil)


@@ 168,14 148,6 @@ rwstats.wlock++;
	q->tail = mp;
	mp->qnext = 0;
	mp->state = QueueingW;
//print("%d wl for %d%d", up->pid, q->readers, q->writer);
//if(q->pidw) print(" w%d", q->pidw);
//{int i;
//for(i=0; i<nelem(q->pidr); i++)
//if(q->pidr[i])
//print(" %d", q->pidr[i]);
//print("\n");
//}
	unlock(&q->use);
	sched();
}


@@ 186,9 158,6 @@ wunlock(RWlock *q)
	Proc *p;

	lock(&q->use);
//if(q->pidw!=up->pid)
//print("not qw\n");
//q->pidw = 0;
	p = q->head;
	if(p == nil){
		q->writer = 0;


@@ 196,7 165,6 @@ wunlock(RWlock *q)
		return;
	}
	if(p->state == QueueingW){
//q->pidw = p->pid;
		/* start waiting writer */
		q->head = p->qnext;
		if(q->head == nil)


@@ 206,17 174,11 @@ wunlock(RWlock *q)
		return;
	}

	if(p->state != Queueing)
	if(p->state != QueueingR)
		panic("wunlock");

	/* waken waiting readers */
	while(q->head != nil && q->head->state == Queueing){
//{int i;
//for(i=0;i<nelem(q->pidr); i++)
//if(q->pidr[i]==0) {
//q->pidr[i] = p->pid;
//break;
//}}
	while(q->head != nil && q->head->state == QueueingR){
		p = q->head;
		q->head = p->qnext;
		q->readers++;