code: 9ferno

Download patch

ref: 98e5aeb994e29e3f52eb516f0cd2fddd1b5d721c
parent: 2a98788f4f7b67f06546cfb2a8ef6367796527a0
author: 9ferno <gophone2015@gmail.com>
date: Fri Nov 12 15:48:37 EST 2021

changes to make postnote work similar to swiproc

--- a/appl/cmd/sh/sh.b
+++ b/appl/cmd/sh/sh.b
@@ -809,13 +809,17 @@
 		if (DEBUG) debug(sys->sprint("runexternal npath %s\n", npath));
 		mod := load Command npath;
 		if (mod != nil) {
+			if (DEBUG) debug(sys->sprint("runexternal npath %s mod != nil\n", npath));
 			argv := list2stringlist(args);
 			export(ctxt.env.localenv);
 
+			if (DEBUG) debug(sys->sprint("runexternal mod != nil\n"));
 			if (last) {
 				{
 					sys->pctl(Sys->NEWFD, ctxt.keepfds);
+					if (DEBUG) debug(sys->sprint("runexternal before mod->init\n"));
 					mod->init(ctxt.drawcontext, argv);
+					if (DEBUG) debug(sys->sprint("runexternal after mod->init\n"));
 					exit;
 				} exception e {
 				EPIPE =>
@@ -830,6 +834,7 @@
 			if (DEBUG) debug("started external externalexec; pid is "+string pid);
 			return waitfor(ctxt, pid :: nil);
 		}
+		if (DEBUG) debug(sys->sprint("runexternal npath %s mod == nil\n", npath));
 		err = sys->sprint("%r");
 		if (nonexistent(err)) {
 			# try and run it as a shell script
--- a/emu/port/dev.c
+++ b/emu/port/dev.c
@@ -2,7 +2,7 @@
 #include	"fns.h"
 #include	"error.h"
 
-extern ulong	kerndate;
+extern u32	kerndate;
 
 void
 mkqid(Qid *q, vlong path, ulong vers, int type)
--- a/libinterp/readmod.c
+++ b/libinterp/readmod.c
@@ -13,7 +13,7 @@
 	int fd, n, dynld;
 	uchar *code;
 	Module *ans;
-	ulong length;
+	u32 length;
 
 	if(path[0] == '$') {
 		if(m == nil)
@@ -31,16 +31,21 @@
 
 	d = nil;
 	fd = kopen(path, OREAD);
-	if(fd < 0)
+	if(fd < 0){
+		DBG("readmod path %s, fd < 0\n", path);
 		goto done;
+	}
 
-	if((d = kdirfstat(fd)) == nil)
+	if((d = kdirfstat(fd)) == nil){
+		DBG("readmod (d = kdirfstat(fd)) == nil for path %s\n", path);
 		goto done;
+	}
 
 	if(m != nil) {
 		if(d->dev == m->dev && d->type == m->dtype &&
 		   d->mtime == m->mtime &&
 		   d->qid.type == m->qid.type && d->qid.path == m->qid.path && d->qid.vers == m->qid.vers) {
+			DBG("readmod check failed for path %s\n", path);
 			ans = m;
 			goto done;
 		}
@@ -61,6 +66,7 @@
 
 	n = kread(fd, code, length);
 	if(n != length) {
+		DBG("readmod kread failed on path %s length %d, read n %d\n", path, length, n);
 		free(code);
 		code = nil;
 	}
--- a/libinterp/xec.c
+++ b/libinterp/xec.c
@@ -794,7 +794,8 @@
 		m = readmod(n, lookmod(n), 1);
 		ml = linkmod(m, ldt, 1);
 	}
-
+	if(ml == nil)
+		print("iload module %s not loaded ml == nil\n", n);
 	mp = R.d;
 	t = *mp;
 	*mp = ml;
--- a/os/ip/devip.c
+++ b/os/ip/devip.c
@@ -131,7 +131,7 @@
 	int prot;
 	int len = 0;
 	Fs *f;
-	extern ulong	kerndate;
+	extern u32 kerndate;
 
 	f = ipfs[c->dev];
 
--- a/os/pc64/main.c
+++ b/os/pc64/main.c
@@ -14,7 +14,7 @@
 Conf conf;
 int idle_spin;
 
-extern ulong kerndate;
+extern u32 kerndate;
 extern void bootscreeninit(void);
 extern int main_pool_pcnt;
 extern int heap_pool_pcnt;
@@ -174,7 +174,7 @@
 	quotefmtinstall();
 	screeninit();
 	consdebug = rdb;
-	print("\nInferno release built at %lud\n", kerndate);
+	print("\nInferno release built at %ud\n", kerndate);
 	showconfig();
 	cpuidentify();
 	meminit0();			/* builds the memmap */
--- a/os/port/chan.c
+++ b/os/port/chan.c
@@ -1508,7 +1508,8 @@
 
 			/* save registers else error() in open has wrong value of c saved */
 			saveregisters();
-
+			DBG("namec walk c->type %d devtab[c->type]->name %s c->path %s\n",
+					c->type, devtab[c->type]->name, chanpath(c));
 			c = devtab[c->type]->open(c, omode&~OCEXEC);
 			if(omode & ORCLOSE)
 				c->flag |= CRCLOSE;
--- a/os/port/dev.c
+++ b/os/port/dev.c
@@ -5,10 +5,10 @@
 #include	"fns.h"
 #include	"../port/error.h"
 
-extern ulong	kerndate;
+extern u32	kerndate;
 
 void
-mkqid(Qid *q, vlong path, ulong vers, int type)
+mkqid(Qid *q, s64 path, u32 vers, u32 type)
 {
 	q->type = type;
 	q->vers = vers;
@@ -224,8 +224,10 @@
 			switch((*gen)(nc, n, tab, ntab, i, &dir)){
 			case -1:
 			Notfound:
-				if(j == 0)
+				if(j == 0){
+/* print("devwalk c %s nc %s n %s name %s caller 0x%p\n", chanpath(c), chanpath(nc), n, *name, getcallerpc(&c)); */
 					error(Enonexist);
+				}
 				kstrcpy(up->env->errstr, Enonexist, ERRMAX);
 				goto Done;
 			case 0:
--- a/os/port/devmnt.c
+++ b/os/port/devmnt.c
@@ -47,10 +47,10 @@
 	Mnt*	list;		/* Mount devices in use */
 	Mnt*	mntfree;	/* Free list */
 	Mntrpc*	rpcfree;
-	ulong	nrpcfree;
-	ulong	nrpcused;
-	ulong	id;
-	u32int	tagmask[NMASK];
+	u32	nrpcfree;
+	u32	nrpcused;
+	u32	id;
+	u32	tagmask[NMASK];
 } mntalloc;
 
 static Chan*	mntchan(void);
@@ -62,7 +62,7 @@
 static void	mntgate(Mnt*);
 static void	mntqrm(Mnt*, Mntrpc*);
 static Mntrpc*	mntralloc(Chan*);
-static long	mntrdwr(int, Chan*, void*, long, vlong);
+static s32	mntrdwr(int, Chan*, void*, s32, s64);
 static int	mntrpcread(Mnt*, Mntrpc*);
 static void	mountio(Mnt*, Mntrpc*);
 static void	mountmux(Mnt*, Mntrpc*);
@@ -701,13 +701,13 @@
 	}
 }
 
-static long
-mntrdwr(int type, Chan *c, void *buf, long n, vlong off)
+static s32
+mntrdwr(int type, Chan *c, void *buf, s32 n, s64 off)
 {
 	Mnt *m;
  	Mntrpc *r;
 	char *uba;
-	ulong cnt, nr, nreq;
+	u32 cnt, nr, nreq;
 
 	m = mntchk(c);
 	uba = buf;
@@ -728,6 +728,7 @@
 
 		r = mntralloc(c);
 		if(waserror()) {
+			DBG("mntrdwr something failed\n");
 			mntfree(r);
 			nexterror();
 		}
@@ -999,7 +1000,7 @@
 	default:
 		if(t == r->request.type+1)
 			break;
-		print("mnt: proc %s %lud: mismatch from %s %s rep %#p tag %d fid %d T%d R%d rp %d\n",
+		print("mnt: proc %s %ud: mismatch from %s %s rep %#p tag %d fid %d T%d R%d rp %d\n",
 			up->text, up->pid, chanpath(m->c), chanpath(r->c),
 			r, r->request.tag, r->request.fid, r->request.type,
 			r->reply.type, r->reply.tag);
--- a/os/port/devtest.c
+++ b/os/port/devtest.c
@@ -72,7 +72,7 @@
 {
 }
 
-extern ulong kerndate;
+extern u32 kerndate;
 
 static long
 testread(Chan* c, void* a, long n, vlong offset)
--- a/os/port/dis.c
+++ b/os/port/dis.c
@@ -980,9 +980,8 @@
 			if(pc != nil)
 				R.PC = r->R.PC = (Inst*)strtol(pc+3, nil, 0);	/* for debugging */
 		}
-		print("[%s] Broken: \"%s\"\n", m->name, estr);
+		print("[%s] Broken: \"%s\" at 0x%p\n", m->name, estr, up->env->errpc);
 	}
-
 	if(r->exstr != nil)
 		DBG("progexit pid %d name %s estr %s exval %p exstr %s\n",
 			r->pid, m->name, estr, r->exval, r->exstr);
--- a/os/port/mkdevc
+++ b/os/port/mkdevc
@@ -210,7 +210,7 @@
 			printf "%s\n", code[i];
 
 		printf "char* conffile = \"%s\";\n", ARGV[1];
-		printf "ulong kerndate = KERNDATE;\n";
+		printf "u32 kerndate = KERNDATE;\n";
 
 		exit
 }' $*
--- a/os/port/portdat.h
+++ b/os/port/portdat.h
@@ -685,7 +685,7 @@
 /*	char	*errstr;	*//* reason we're unwinding the error stack, errbuf1 or 0 */
 /*	char	errbuf0[ERRMAX];*/
 /*	char	errbuf1[ERRMAX];*/
-	char	genbuf[128];	/* buffer used e.g. for last name element from namec */
+	char	genbuf[ERRMAX];	/* buffer used e.g. for last name element from namec */
 /*	Chan	*slash; part of Pgrp in inferno */
 /*	Chan	*dot; part of Pgrp in inferno */
 
--- a/os/port/portfns.h
+++ b/os/port/portfns.h
@@ -172,7 +172,7 @@
 int			memusehigh(void);
 void		microdelay(int);
 uvlong		mk64fract(uvlong, uvlong);
-void		mkqid(Qid*, vlong, ulong, int);
+void		mkqid(Qid*, s64, u32, u32);
 void		modinit(void);
 Chan*		mntattach(Chan*, Chan*, char*, int);
 Chan*		mntauth(Chan*, char*);
@@ -294,6 +294,7 @@
 void		setrealloctag(void*, uintptr);
 void		setupwatchpts(Proc*, Watchpt*, int);
 void	showconf(void);
+void	shownotes(Proc*);
 char*		skipslash(char*);
 void		sleep(Rendez*, int(*)(void*), void*);
 void*		smalloc(uintptr);
--- a/os/port/proc.c
+++ b/os/port/proc.c
@@ -429,6 +429,7 @@
 	p->psstate = "New";
 	p->fpstate = FPinit;
 	p->procctl = 0;
+	p->ureg = nil;
 	p->dbgreg = nil;
 	p->nerrlab = 0;
 	p->type = Unknown;
@@ -447,6 +448,12 @@
 	p->env->errstr = p->env->errbuf0;
 	p->env->syserrstr = p->env->errbuf1;
 
+	/* clear any previous notes */
+	p->nnote = 0;
+	p->notify = nil;
+	p->notified = 0;
+	p->notepending = 0;
+
 	/* sched params */
 	p->mp = 0;
 	p->wired = 0;
@@ -605,6 +612,7 @@
 	}
 
 	if(up->notepending) {
+		up->nnote = 0;
 		up->notepending = 0;
 		splx(s);
 		interrupted();
@@ -700,6 +708,18 @@
 	splx(s);
 
 	return p;
+}
+
+void
+shownotes(Proc *p)
+{
+	int i;
+
+	print("p 0x%p pid %d nnote %d notified %d lastnote flag %d msg %s\n",
+		p, p->pid, p->nnote, p->notified, p->lastnote.flag, p->lastnote.msg);
+	for(i = 0; i < p->nnote; i++){
+		print("i %d msg %s flag %d\n", i, p->note[i].msg, p->note[i].flag);
+	}
 }
 
 /*
--- a/os/port/qlock.c
+++ b/os/port/qlock.c
@@ -14,12 +14,12 @@
 } rwstats;
 
 /*
-	lock()
+	*lock()
 		blockinglock = qpc = nil
-	unlock()
+	*unlock()
 		blockinglock = qpc = nil
 
-	lock()
+	*lock()
 		blockinglock = qpc = nil
 	placed in the queue
 		blockinglock = lock address
@@ -27,7 +27,7 @@
 	out of the queue, ready to run
 		blockinglock = nil
 		qpc = pc that called lock()
-	unlock()
+	*unlock()
 		blockinglock = qpc = nil
  */
 
--- a/os/port/sysfile.c
+++ b/os/port/sysfile.c
@@ -882,12 +882,15 @@
 	int fd;
 	Chan *c;
 
-	if(waserror())
+	if(waserror()){
+		DBG("kopen: namec failed on path %s\n", path);
 		return -1;
+	}
 
 	openmode(mode);                         /* error check only */
 	c = namec(path, Aopen, mode, 0);
 	if(waserror()){
+		DBG("kopen: newfd failed on path %s\n", path);
 		cclose(c);
 		nexterror();
 	}