shithub: drawterm-fdroid

Download patch

ref: 5797fdc0c0206e5e006e37597662b9a7b308d74d
parent: af11a9e1293c2fb4a66ca00c19bc1b6a73d277d5
author: Russ Cox <rsc@swtch.com>
date: Sun May 21 12:32:29 EDT 2006

amd64 fixes

--- a/exportfs/exportsrv.c
+++ b/exportfs/exportsrv.c
@@ -434,7 +434,7 @@
 			if(p->busy == 0) {
 				f->pid = p->pid;
 				p->busy = 1;
-				pid = rendezvous(p->pid, (ulong)f);
+				pid = (uintptr)rendezvous((void*)(uintptr)p->pid, f);
 				if(pid != p->pid)
 					fatal("rendezvous sync fail");
 				return;
@@ -459,7 +459,7 @@
 		Proclist = p;
 
 DEBUG(DFD, "parent %d rendez\n", pid);
-		rendezvous(pid, (ulong)p);
+		rendezvous((void*)(uintptr)pid, p);
 DEBUG(DFD, "parent %d went\n", pid);
 	}
 }
@@ -479,12 +479,12 @@
 	pid = getpid();
 
 DEBUG(DFD, "blockingslave %d rendez\n", pid);
-	m = (Proc*)rendezvous(pid, 0);
+	m = (Proc*)rendezvous((void*)(uintptr)pid, 0);
 DEBUG(DFD, "blockingslave %d rendez got %p\n", pid, m);
 	
 	for(;;) {
-		p = (Fsrpc*)rendezvous(pid, pid);
-		if((int)p == ~0)			/* Interrupted */
+		p = rendezvous((void*)(uintptr)pid, (void*)(uintptr)pid);
+		if((uintptr)p == ~(uintptr)0)			/* Interrupted */
 			continue;
 
 		DEBUG(DFD, "\tslave: %d %F b %d p %d\n", pid, &p->work, p->busy, p->pid);
--- a/gui-x11/screen.c
+++ b/gui-x11/screen.c
@@ -566,6 +566,8 @@
 		 * some displays say MSB even though they run on LSB.
 		 * Besides, this is more anal.
 		 */
+		if(xscreendepth != DefaultDepth(xdisplay, DefaultScreen(xdisplay)))
+			xcmap = XCreateColormap(xdisplay, w, xvis, AllocNone);
 
 		c = map[19];
 		/* find out index into colormap for our RGB */
--- a/gui-x11/xmem.h
+++ b/gui-x11/xmem.h
@@ -31,7 +31,7 @@
 	int	dirty;
 	Rectangle dirtyr;
 	Rectangle r;
-	ulong pc;	/* who wrote into xi */
+	uintptr pc;	/* who wrote into xi */
 };
 
 extern	int		xtblbit;
--- a/include/lib.h
+++ b/include/lib.h
@@ -236,7 +236,7 @@
 extern	int	fmtvprint(Fmt*, char*, va_list);
 extern	void*	mallocz(ulong, int);
 
-extern	ulong	getcallerpc(void*);
+extern	uintptr	getcallerpc(void*);
 extern	char*	cleanname(char*);
 extern	void	sysfatal(char*, ...);
 extern	char*	strecpy(char*, char*, char*);
@@ -250,6 +250,7 @@
 extern	int	enc64(char*, int, uchar*, int);
 extern	int	dec32(uchar*, int, char*, int);
 extern	int	enc32(char*, int, uchar*, int);
+extern	int	enc16(char*, int, uchar*, int);
 void		hnputs(void *p, unsigned short v);
 extern	int	dofmt(Fmt*, char*);
 extern	double	__NaN(void);
--- a/include/user.h
+++ b/include/user.h
@@ -74,13 +74,13 @@
 extern	int	iounit(int);
 extern	long	pread(int, void*, long, vlong);
 extern	long	pwrite(int, void*, long, vlong);
-extern	ulong	rendezvous(ulong, ulong);
+extern	void*	rendezvous(void*, void*);
 extern	int	kproc(char*, void(*)(void*), void*);
 extern	int	getpid(void);
 extern	void	panic(char*, ...);
 extern	void	sleep(int);
 extern	void	osyield(void);
-extern	void	setmalloctag(void*, ulong);
+extern	void	setmalloctag(void*, uintptr);
 extern	int	errstr(char*, uint);
 extern	int	rerrstr(char*, uint);
 extern	int	encrypt(void*, void*, int);
--- a/kern/allocb.c
+++ b/kern/allocb.c
@@ -20,7 +20,7 @@
 _allocb(int size)
 {
 	Block *b;
-	ulong addr;
+	uintptr addr;
 
 	if((b = mallocz(sizeof(Block)+size+Hdrspc, 0)) == nil)
 		return nil;
@@ -31,13 +31,13 @@
 	b->flag = 0;
 
 	/* align start of data portion by rounding up */
-	addr = (ulong)b;
+	addr = (uintptr)b;
 	addr = ROUND(addr + sizeof(Block), BLOCKALIGN);
 	b->base = (uchar*)addr;
 
 	/* align end of data portion by rounding down */
 	b->lim = ((uchar*)b) + sizeof(Block)+size+Hdrspc;
-	addr = (ulong)(b->lim);
+	addr = (uintptr)(b->lim);
 	addr = addr & ~(BLOCKALIGN-1);
 	b->lim = (uchar*)addr;
 
@@ -60,7 +60,7 @@
 	 * Can still error out of here, though.
 	 */
 	if(up == nil)
-		panic("allocb without up: %luX\n", getcallerpc(&size));
+		panic("allocb without up: %p\n", getcallerpc(&size));
 	if((b = _allocb(size)) == nil){
 		panic("allocb: no memory for %d bytes\n", size);
 	}
--- a/kern/chan.c
+++ b/kern/chan.c
@@ -112,7 +112,7 @@
 	x = --r->ref;
 	unlock(&r->lk);
 	if(x < 0)
-		panic("decref, pc=0x%lux", getcallerpc(&r));
+		panic("decref, pc=0x%p", getcallerpc(&r));
 
 	return x;
 }
@@ -354,7 +354,7 @@
 cclose(Chan *c)
 {
 	if(c->flag&CFREE)
-		panic("cclose %lux", getcallerpc(&c));
+		panic("cclose %p", getcallerpc(&c));
 
 	if(decref(&c->ref))
 		return;
--- a/kern/dat.h
+++ b/kern/dat.h
@@ -401,8 +401,8 @@
 	int	notepending;	/* note issued but not acted on */
 	int	kp;		/* true if a kernel process */
 
-	ulong	rendtag;	/* Tag for rendezvous */
-	ulong	rendval;	/* Value for rendezvous */
+	void*	rendtag;	/* Tag for rendezvous */
+	void*	rendval;	/* Value for rendezvous */
 	Proc	*rendhash;	/* Hash list for tag values */
 
 	int	nerrlab;
--- a/kern/devaudio-unix.c
+++ b/kern/devaudio-unix.c
@@ -179,4 +179,5 @@
 audiodevread(void *v, int n)
 {
 	error("no reading");
+	return -1;
 }
--- a/kern/devdraw.c
+++ b/kern/devdraw.c
@@ -867,12 +867,17 @@
 	p->y = BGLONG(a+1*4);
 }
 
+#define isvgascreen(dst) 1
+
+
 Point
-drawchar(Memimage *dst, Point p, Memimage *src, Point *sp, DImage *font, int index, int op)
+drawchar(Memimage *dst, Memimage *rdst, Point p, 
+	Memimage *src, Point *sp, DImage *font, int index, int op)
 {
 	FChar *fc;
 	Rectangle r;
 	Point sp1;
+	static Memimage *tmp;
 
 	fc = &font->fchar[index];
 	r.min.x = p.x+fc->left;
@@ -881,7 +886,31 @@
 	r.max.y = r.min.y+(fc->maxy-fc->miny);
 	sp1.x = sp->x+fc->left;
 	sp1.y = sp->y+fc->miny;
-	memdraw(dst, r, src, sp1, font->image, Pt(fc->minx, fc->miny), op);
+	
+	/*
+	 * If we're drawing greyscale fonts onto a VGA screen,
+	 * it's very costly to read the screen memory to do the
+	 * alpha blending inside memdraw.  If this is really a stringbg,
+	 * then rdst is the bg image (in main memory) which we can
+	 * refer to for the underlying dst pixels instead of reading dst
+	 * directly.
+	 */
+	if(1 || (isvgascreen(dst) && !isvgascreen(rdst) /*&& font->image->depth > 1*/)){
+		if(tmp == nil || tmp->chan != dst->chan || Dx(tmp->r) < Dx(r) || Dy(tmp->r) < Dy(r)){
+			if(tmp)
+				freememimage(tmp);
+			tmp = allocmemimage(Rect(0,0,Dx(r),Dy(r)), dst->chan);
+			if(tmp == nil)
+				goto fallback;
+		}
+		memdraw(tmp, Rect(0,0,Dx(r),Dy(r)), rdst, r.min, memopaque, ZP, S);
+		memdraw(tmp, Rect(0,0,Dx(r),Dy(r)), src, sp1, font->image, Pt(fc->minx, fc->miny), op);
+		memdraw(dst, r, tmp, ZP, memopaque, ZP, S);
+	}else{
+	fallback:
+		memdraw(dst, r, src, sp1, font->image, Pt(fc->minx, fc->miny), op);
+	}
+
 	p.x += fc->width;
 	sp->x += fc->width;
 	return p;
@@ -1873,6 +1902,7 @@
 			clipr = dst->clipr;
 			dst->clipr = r;
 			op = drawclientop(client);
+			l = dst;
 			if(*a == 'x'){
 				/* paint background */
 				l = drawimage(client, a+47);
@@ -1901,7 +1931,7 @@
 					dst->clipr = clipr;
 					error(Eindex);
 				}
-				q = drawchar(dst, q, src, &sp, font, ci, op);
+				q = drawchar(dst, l, q, src, &sp, font, ci, op);
 				u += 2;
 			}
 			dst->clipr = clipr;
--- a/kern/devlfd.c
+++ b/kern/devlfd.c
@@ -15,7 +15,7 @@
 	
 	c = newchan();
 	c->type = devno('L', 0);
-	c->aux = (void*)fd;
+	c->aux = (void*)(uintptr)fd;
 	c->name = newcname("fd");
 	c->mode = ORDWR;
 	c->qid.type = 0;
@@ -76,7 +76,7 @@
 static void
 lfdclose(Chan *c)
 {
-	close((int)c->aux);
+	close((int)(uintptr)c->aux);
 }
 
 static long
@@ -83,7 +83,7 @@
 lfdread(Chan *c, void *buf, long n, vlong off)
 {
 	USED(off);	/* can't pread on pipes */
-	n = read((int)c->aux, buf, n);
+	n = read((int)(uintptr)c->aux, buf, n);
 	if(n < 0){
 		iprint("error %d\n", errno);
 		oserror();
@@ -96,7 +96,7 @@
 {
 	USED(off);	/* can't pread on pipes */
 
-	n = write((int)c->aux, buf, n);
+	n = write((int)(uintptr)c->aux, buf, n);
 	if(n < 0){
 		iprint("error %d\n", errno);
 		oserror();
--- a/kern/devmnt.c
+++ b/kern/devmnt.c
@@ -1037,7 +1037,7 @@
 
 	for(i = 0; i < NMASK; i++){
 		v = mntalloc.tagmask[i];
-		if(v == ~0UL)
+		if(v == ~0)
 			continue;
 		for(j = 0; j < 1<<TAGSHIFT; j++)
 			if((v & (1<<j)) == 0){
--- a/kern/devssl.c
+++ b/kern/devssl.c
@@ -358,7 +358,7 @@
 
 	if(!emptystr(dir->uid))
 		kstrdup(&s->user, dir->uid);
-	if(dir->mode != ~0UL)
+	if(dir->mode != ~0)
 		s->perm = dir->mode;
 
 	free(dir);
--- a/kern/devtls.c
+++ b/kern/devtls.c
@@ -224,7 +224,7 @@
 static void	put32(uchar *p, u32int);
 static void	put24(uchar *p, int);
 static void	put16(uchar *p, int);
-static u32int	get32(uchar *p);
+/* static u32int	get32(uchar *p); */
 static int	get16(uchar *p);
 static void	tlsSetState(TlsRec *tr, int new, int old);
 static void	rcvAlert(TlsRec *tr, int err);
@@ -241,14 +241,18 @@
 static void	pdump(int, void*, char*);
 
 static char *tlsnames[] = {
-[Qclonus]		"clone",
-[Qencalgs]	"encalgs",
-[Qhashalgs]	"hashalgs",
-[Qdata]		"data",
-[Qctl]		"ctl",
-[Qhand]		"hand",
-[Qstatus]		"status",
-[Qstats]		"stats",
+	/* unused */ 0,
+	/* topdir */ 0,
+	/* protodir */ 0,
+	"clone",
+	"encalgs",
+	"hashalgs",
+	/* convdir */ 0,
+	"data",
+	"ctl",
+	"hand",
+	"status",
+	"stats",
 };
 
 static int convdir[] = { Qctl, Qdata, Qhand, Qstatus, Qstats };
@@ -2132,11 +2136,13 @@
 	p[1] = x;
 }
 
+/*
 static u32int
 get32(uchar *p)
 {
 	return (p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];
 }
+*/
 
 static int
 get16(uchar *p)
--- a/kern/posix.c
+++ b/kern/posix.c
@@ -6,6 +6,7 @@
 #include <pthread.h>
 #include <time.h>
 #include <sys/time.h>
+#include <sys/select.h>
 #include <signal.h>
 #include <pwd.h>
 #include <errno.h>
--- a/kern/qio.c
+++ b/kern/qio.c
@@ -96,7 +96,7 @@
 		}
 
 		if(bp->next)
-			panic("padblock 0x%luX", getcallerpc(&bp));
+			panic("padblock 0x%p", getcallerpc(&bp));
 		n = BLEN(bp);
 		padblockcnt++;
 		nbp = allocb(size+n);
@@ -110,7 +110,7 @@
 		size = -size;
 
 		if(bp->next)
-			panic("padblock 0x%luX", getcallerpc(&bp));
+			panic("padblock 0x%p", getcallerpc(&bp));
 
 		if(bp->lim - bp->wp >= size)
 			return bp;
@@ -1270,7 +1270,7 @@
 	uchar *p = vp;
 
 	QDEBUG if(!islo())
-		print("qwrite hi %lux\n", getcallerpc(&q));
+		print("qwrite hi %p\n", getcallerpc(&q));
 
 	sofar = 0;
 	do {
--- a/kern/stub.c
+++ b/kern/stub.c
@@ -139,7 +139,7 @@
 }
 
 void
-setmalloctag(void *v, ulong tag)
+setmalloctag(void *v, uintptr tag)
 {
 	USED(v);
 	USED(tag);
--- a/kern/sysfile.c
+++ b/kern/sysfile.c
@@ -1189,15 +1189,15 @@
 	return strlen(buf);
 }
 
-ulong
-_sysrendezvous(ulong arg0, ulong arg1)
+void*
+_sysrendezvous(void* arg0, void* arg1)
 {
-	ulong tag, val;
+	void *tag, *val;
 	Proc *p, **l;
 
 	tag = arg0;
-	l = &REND(up->rgrp, tag);
-	up->rendval = ~0UL;
+	l = &REND(up->rgrp, (uintptr)tag);
+	up->rendval = (void*)~0;
 
 	lock(&up->rgrp->ref.lk);
 	for(p = *l; p; p = p->rendhash) {
@@ -1228,15 +1228,15 @@
 	return up->rendval;
 }
 
-ulong
-sysrendezvous(ulong tag, ulong val)
+void*
+sysrendezvous(void *tag, void *val)
 {
-	ulong n;
+	void *n;
 
 	starterror();
 	if(waserror()){
 		_syserror();
-		return -1;
+		return (void*)~0;
 	}
 	n = _sysrendezvous(tag, val);
 	enderror();
--- a/libauth/auth_proxy.c
+++ b/libauth/auth_proxy.c
@@ -90,6 +90,7 @@
 
 	if(auth_rpc(rpc, "authinfo", nil, 0) != ARok)
 		return nil;
+	a = nil;
 	if(convM2AI((uchar*)rpc->arg, rpc->narg, &a) == nil){
 		werrstr("bad auth info from factotum");
 		return nil;
--- a/libc/dofmt.c
+++ b/libc/dofmt.c
@@ -333,7 +333,11 @@
 		break;
 	}
 	if(f->r == 'p'){
-		u = (ulong)va_arg(f->args, void*);
+		if(sizeof(void*) == sizeof(uvlong)){
+			isv = 1;
+			vu = (uvlong)va_arg(f->args, uvlong);
+		}else
+			u = (ulong)va_arg(f->args, ulong);
 		f->r = 'x';
 		fl |= FmtUnsigned;
 	}else if(fl & FmtVLong){
--- a/libc/lock.c
+++ b/libc/lock.c
@@ -38,7 +38,7 @@
 	for(;;) {
 		if(canlock(lk))
 			return;
-		iprint("lock loop %ld: val=%d &lock=%ux pc=%ux\n", getpid(), lk->key, lk, getcallerpc(&lk));
+		iprint("lock loop %ld: val=%d &lock=%ux pc=%p\n", getpid(), lk->key, lk, getcallerpc(&lk));
 		osmsleep(1000);
 	}
 }
--- a/libc/strtod.c
+++ b/libc/strtod.c
@@ -224,7 +224,7 @@
 	/* close approx by naive conversion */
 	mid[0] = 0;
 	mid[1] = 1;
-	for(i=0; c=a[i]; i++) {
+	for(i=0; (c=a[i]); i++) {
 		mid[0] = mid[0]*10 + (c-'0');
 		mid[1] = mid[1]*10;
 		if(i >= 8)
--- a/libmemdraw/alloc.c
+++ b/libmemdraw/alloc.c
@@ -19,7 +19,7 @@
 	md->base = to;
 
 	/* if allocmemimage changes this must change too */
-	md->bdata = (uchar*)&md->base[2];
+	md->bdata = (uchar*)md->base+sizeof(Memdata*)+sizeof(ulong);
 }
 
 Memimage*
@@ -70,7 +70,8 @@
 _allocmemimage(Rectangle r, ulong chan)
 {
 	int d;
-	ulong l, nw;
+	u32int l, nw;
+	uchar *p;
 	Memdata *md;
 	Memimage *i;
 
@@ -86,18 +87,21 @@
 		return nil;
 
 	md->ref = 1;
-	md->base = poolalloc(imagmem, (2+nw)*sizeof(ulong));
+	md->base = poolalloc(imagmem, sizeof(Memdata*)+(1+nw)*sizeof(ulong));
 	if(md->base == nil){
 		free(md);
 		return nil;
 	}
 
-	md->base[0] = (ulong)md;
-	md->base[1] = getcallerpc(&r);
+	p = (uchar*)md->base;
+	*(Memdata**)p = md;
+	p += sizeof(Memdata*);
 
-	/* if this changes, memimagemove must change too */
-	md->bdata = (uchar*)&md->base[2];
+	*(ulong*)p = getcallerpc(&r);
+	p += sizeof(ulong);
 
+	/* if this changes, memimagemove must change too */
+	md->bdata = p;
 	md->allocd = 1;
 
 	i = allocmemimaged(r, chan, md, nil);
@@ -129,7 +133,7 @@
 ulong*
 wordaddr(Memimage *i, Point p)
 {
-	return (ulong*) ((ulong)byteaddr(i, p) & ~(sizeof(ulong)-1));
+	return (ulong*) ((uintptr)byteaddr(i, p) & ~(sizeof(ulong)-1));
 }
 
 uchar*
--- a/libmemdraw/defont.c
+++ b/libmemdraw/defont.c
@@ -21,7 +21,7 @@
 	 * declared as char*, not ulong*.
 	 */
 	p = (char*)defontdata;
-	n = (ulong)p & 3;
+	n = (uintptr)p & 3;
 	if(n != 0){
 		memmove(p+(4-n), p, sizeofdefont-n);
 		p += 4-n;
binary files a/libsec/ranlib.core /dev/null differ
--- a/posix-386/getcallerpc.c
+++ b/posix-386/getcallerpc.c
@@ -1,8 +1,8 @@
 #include "u.h"
 #include "libc.h"
 
-ulong
+uintptr
 getcallerpc(void *a)
 {
-	return ((ulong*)a)[-1];
+	return ((uintptr*)a)[-1];
 }
--- a/posix-power/getcallerpc.c
+++ b/posix-power/getcallerpc.c
@@ -1,8 +1,8 @@
 #include "u.h"
 #include "libc.h"
 
-ulong
+uintptr
 getcallerpc(void *a)
 {
-	return ((ulong*)a)[-1];
+	return ((uintptr*)a)[-1];
 }
--- a/win32-386/getcallerpc.c
+++ b/win32-386/getcallerpc.c
@@ -1,8 +1,8 @@
 #include "u.h"
 #include "libc.h"
 
-ulong
+uintptr
 getcallerpc(void *a)
 {
-	return ((ulong*)a)[-1];
+	return ((uintptr*)a)[-1];
 }