Plan 9 from Bell Labs’s /usr/web/sources/contrib/uriel/changes/2005/1110/5

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


64-bit fixes.
 [rsc] --rw-rw-r-- M 15674 glenda sys 5615 Nov 10 16:50 sys/src/cmd/snap/take.c
	/n/sourcesdump/2005/1110/plan9/sys/src/cmd/snap/take.c:96,102 - 
	/n/sourcesdump/2005/1111/plan9/sys/src/cmd/snap/take.c:96,102
	  }
	  
	  static Seg*
	- readseg(int fd, long off, ulong len, char *name)
	+ readseg(int fd, vlong off, ulong len, char *name)
	  {
	  	char buf[Pagesize];
	  	Page **pg;
	/n/sourcesdump/2005/1110/plan9/sys/src/cmd/snap/take.c:187,193 - 
	/n/sourcesdump/2005/1111/plan9/sys/src/cmd/snap/take.c:187,193
	  	switch(mach->szreg) {
	  	case 2:	return machdata->swab(*(ushort*)q);
	  	case 4:	return machdata->swal(*(ulong*)q);
	- 	case 8:	/* too much code assumes stackptr fits in ulong */
	+ 	case 8:	return machdata->swav(*(uvlong*)q);
	  	default:
	  		fprint(2, "register size is %d bytes?\n", mach->szreg);
	  		return 0;
	/n/sourcesdump/2005/1110/plan9/sys/src/cmd/snap/take.c:200,209 - 
	/n/sourcesdump/2005/1111/plan9/sys/src/cmd/snap/take.c:200,209
	  	Data *d;
	  	Proc *proc;
	  	Seg **s;
	- 	char *segdat, *q, *f[128+1], buf[128];
	+ 	char *name, *segdat, *q, *f[128+1], buf[128];
	  	int fd, i, stacki, nf, np;
	- 	ulong off, len, stackoff, stacklen;
	- 	ulong sp;
	+ 	uvlong off, len, stackoff, stacklen;
	+ 	uvlong sp;
	  
	  	proc = emalloc(sizeof(*proc));
	  	proc->pid = pid;
	/n/sourcesdump/2005/1110/plan9/sys/src/cmd/snap/take.c:263,278 - 
	/n/sourcesdump/2005/1111/plan9/sys/src/cmd/snap/take.c:263,277
	  	for(i=0; i<nf; i++) {
	  		if(q = strchr(f[i], ' ')) 
	  			*q = 0;
	- 		q = f[i];
	- 		off = strtoul(q+10, 0, 16);
	- 		len = strtoul(q+10+8+1, 0, 16) - off;
	- 
	- 		if(strcmp(q, "Stack") == 0) {
	+ 		name = f[i];
	+ 		off = strtoull(name+10, &q, 16);
	+ 		len = strtoull(q, &q, 16) - off;
	+ 		if(strcmp(name, "Stack") == 0) {
	  			stackoff = off;
	  			stacklen = len;
	  			stacki = i;
	  		} else
	- 			s[i] = readseg(fd, off, len, q);
	+ 			s[i] = readseg(fd, off, len, name);
	  	}
	  	proc->nseg = nf;
	  	proc->seg = s;
 [rsc] --rw-rw-r-- M 15674 glenda sys 1453 Nov 10 16:50 sys/src/cmd/snap/write.c
	/n/sourcesdump/2005/1110/plan9/sys/src/cmd/snap/write.c:22,34 - 
	/n/sourcesdump/2005/1111/plan9/sys/src/cmd/snap/write.c:22,38
	  	Page **pp, *p;
	  	int type;
	  
	- 	type = proc->text ==  s ? 't' : 'm';
	+ 	if(s == nil){
	+ 		Bprint(b, "%-11ud %-11ud ", 0, 0);
	+ 		return;
	+ 	}
	  
	+ 	type = proc->text ==  s ? 't' : 'm';
	  	npg = (s->len+Pagesize-1)/Pagesize;
	  	if(npg != s->npg)
	  		abort();
	  
	- 	Bprint(b, "%-11lud %-11lud ", s->offset, s->len);
	+ 	Bprint(b, "%-11llud %-11llud ", s->offset, s->len);
	  	if(s->len == 0)
	  		return;
	  
	/n/sourcesdump/2005/1110/plan9/sys/src/cmd/snap/write.c:38,44 - 
	/n/sourcesdump/2005/1111/plan9/sys/src/cmd/snap/write.c:42,48
	  				Bprint(b, "z");
	  				continue;
	  			}
	- 			Bprint(b, "%c%-11ld %-11lud ", p->type, p->pid, p->offset);
	+ 			Bprint(b, "%c%-11ld %-11llud ", p->type, p->pid, p->offset);
	  		} else {
	  			Bprint(b, "r");
	  			Bwrite(b, p->data, p->len);
 [rsc] --rw-rw-r-- M 15674 glenda sys 4287 Nov 10 16:50 sys/src/cmd/snap/read.c
	/n/sourcesdump/2005/1110/plan9/sys/src/cmd/snap/read.c:23,29 - 
	/n/sourcesdump/2005/1111/plan9/sys/src/cmd/snap/read.c:23,29
	  }
	  
	  Page*
	- findpage(Proc *plist, long pid, int type, ulong off)
	+ findpage(Proc *plist, long pid, int type, uvlong off)
	  {
	  	Seg *s;
	  	int i;
	/n/sourcesdump/2005/1110/plan9/sys/src/cmd/snap/read.c:58,63 - 
	/n/sourcesdump/2005/1111/plan9/sys/src/cmd/snap/read.c:58,116
	  	return s->pg[off/Pagesize];
	  }
	  
	+ static int
	+ Breadnumber(Biobuf *b, char *buf)
	+ {
	+ 	int i;
	+ 	int c;
	+ 	int havedigits;
	+ 	
	+ 	havedigits = 0;
	+ 	for(i=0; i<22; i++){
	+ 		if((c = Bgetc(b)) == Beof)
	+ 			return -1;
	+ 		if('0' <= c && c <= '9'){
	+ 			*buf++ = c;
	+ 			havedigits = 1;
	+ 		}else if(c == ' '){
	+ 			if(havedigits){
	+ 				while((c = Bgetc(b)) == ' ')
	+ 					;
	+ 				if(c != Beof)
	+ 					Bungetc(b);
	+ 				break;
	+ 			}
	+ 		}else{
	+ 			werrstr("bad character %.2ux", c);
	+ 			return -1;
	+ 		}
	+ 	}
	+ 	*buf = 0;
	+ 	return 0;
	+ }
	+ 
	+ static int
	+ Breadulong(Biobuf *b, ulong *x)
	+ {
	+ 	char buf[32];
	+ 	
	+ 	if(Breadnumber(b, buf) < 0)
	+ 		return -1;
	+ 	*x = strtoul(buf, 0, 0);
	+ 	return 0;
	+ }
	+ 
	+ static int
	+ Breaduvlong(Biobuf *b, uvlong *x)
	+ {
	+ 	char buf[32];
	+ 	
	+ 	if(Breadnumber(b, buf) < 0)
	+ 		return -1;
	+ 	*x = strtoull(buf, 0, 0);
	+ 	return 0;
	+ }
	+ 
	  static Data*
	  readdata(Biobuf *b)
	  {
	/n/sourcesdump/2005/1110/plan9/sys/src/cmd/snap/read.c:84,99 - 
	/n/sourcesdump/2005/1111/plan9/sys/src/cmd/snap/read.c:137,152
	  	int i, npg;
	  	int t;
	  	int len;
	- 	ulong pid, off;
	+ 	ulong pid;
	+ 	uvlong off;
	  	char buf[Pagesize];
	  	static char zero[Pagesize];
	  
	  	s = emalloc(sizeof *s);
	- 	if(Bread(b, buf, 2*12) != 2*12)
	+ 	if(Breaduvlong(b, &s->offset) < 0
	+ 	|| Breaduvlong(b, &s->len) < 0)
	  		panic("error reading segment");
	  
	- 	s->offset = atoi(buf);
	- 	s->len = atoi(buf+12);
	  	npg = (s->len + Pagesize-1)/Pagesize;
	  	s->npg = npg;
	  
	/n/sourcesdump/2005/1110/plan9/sys/src/cmd/snap/read.c:113,140 - 
	/n/sourcesdump/2005/1111/plan9/sys/src/cmd/snap/read.c:166,193
	  		case 'z':
	  			pp[i] = datapage(zero, len);
	  			if(debug)
	- 				fprint(2, "0x%.8lux all zeros\n", s->offset+i*Pagesize);
	+ 				fprint(2, "0x%.8llux all zeros\n", s->offset+i*Pagesize);
	  			break;
	  		case 'm':
	  		case 't':
	- 			if(Bread(b, buf, 2*12) != 2*12)
	- 				panic("error reading segment");
	- 			pid = atol(buf);
	- 			off = atol(buf+12);
	+ 			if(Breadulong(b, &pid) < 0 
	+ 			|| Breaduvlong(b, &off) < 0)
	+ 				panic("error reading segment x");
	  			pp[i] = findpage(plist, pid, t, off);
	  			if(pp[i] == nil)
	  				panic("bad page reference in snapshot");
	  			if(debug)
	- 				fprint(2, "0x%.8lux same as %s pid %lud 0x%.8lux\n", s->offset+i*Pagesize, t=='m'?"mem":"text", pid, off);
	+ 				fprint(2, "0x%.8llux same as %s pid %lud 0x%.8llux\n", s->offset+i*Pagesize, t=='m'?"mem":"text", pid, off);
	  			break;
	  		case 'r':
	  			if(Bread(b, buf, len) != len)
	- 				panic("error reading segment");
	+ 				panic("error reading segment xx");
	  			pp[i] = datapage(buf, len);
	  			if(debug)
	- 				fprint(2, "0x%.8lux is raw data\n", s->offset+i*Pagesize);
	+ 				fprint(2, "0x%.8llux is raw data\n", s->offset+i*Pagesize);
	  			break;
	  		default:
	+ 			fprint(2, "bad type char %#.2ux\n", t);
	  			panic("error reading segment");
	  		}
	  	}
 [rsc] --rw-rw-r-- M 15674 glenda sys 985 Nov 10 16:50 sys/src/cmd/snap/snap.h
	/n/sourcesdump/2005/1110/plan9/sys/src/cmd/snap/snap.h:25,32 - 
	/n/sourcesdump/2005/1111/plan9/sys/src/cmd/snap/snap.h:25,32
	  
	  struct Seg {
	  	char*	name;
	- 	ulong	offset;
	- 	ulong	 len;
	+ 	uvlong	offset;
	+ 	uvlong	 len;
	  	Page**	pg;
	  	int	npg;
	  };
	/n/sourcesdump/2005/1110/plan9/sys/src/cmd/snap/snap.h:40,46 - 
	/n/sourcesdump/2005/1111/plan9/sys/src/cmd/snap/snap.h:40,46
	  	int	written;
	  	int	type;
	  	ulong	pid;
	- 	ulong	offset;
	+ 	uvlong	offset;
	  };
	  
	  struct Proc {
	/n/sourcesdump/2005/1110/plan9/sys/src/cmd/snap/snap.h:61,66 - 
	/n/sourcesdump/2005/1111/plan9/sys/src/cmd/snap/snap.h:61,66
	  void	writesnap(Biobuf*, Proc*);
	  Page*	datapage(char *p, long len);
	  Proc*	readsnap(Biobuf *b);
	- Page*	findpage(Proc *plist, long pid, int type, ulong off);
	+ Page*	findpage(Proc *plist, long pid, int type, uvlong off);
	  
	  int	debug;
 [rsc] --rw-rw-r-- M 15674 glenda sys 5615 Nov 10 16:50 sys/src/cmd/snap/take.c
 [rsc] --rw-rw-r-- M 15674 glenda sys 1453 Nov 10 16:50 sys/src/cmd/snap/write.c


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.