Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/branches/feature_fixcpp/sys/src/cmd/snap/write.c – Rev 2

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include <u.h>
2
#include <libc.h>
3
#include <bio.h>
4
#include "snap.h"
5
 
6
char *pfile[Npfile] = {
7
	[Psegment]	"segment",
8
	[Pfd]			"fd",
9
	[Pfpregs]		"fpregs",
10
	[Pnoteid]		"noteid",
11
	[Pkregs]		"kregs",
12
	[Pns]			"ns",
13
	[Pproc]		"proc",
14
	[Pregs]		"regs",
15
	[Pstatus]		"status",
16
};
17
 
18
static void
19
writeseg(Biobuf *b, Proc *proc, Seg *s)
20
{
21
	int i, npg;
22
	Page **pp, *p;
23
	int type;
24
 
25
	if(s == nil){
26
		Bprint(b, "%-11ud %-11ud ", 0, 0);
27
		return;
28
	}
29
 
30
	type = proc->text ==  s ? 't' : 'm';
31
	npg = (s->len+Pagesize-1)/Pagesize;
32
	if(npg != s->npg)
33
		abort();
34
 
35
	Bprint(b, "%-11llud %-11llud ", s->offset, s->len);
36
	if(s->len == 0)
37
		return;
38
 
39
	for(i=0, pp=s->pg, p=*pp; i<npg; i++, pp++, p=*pp) {
40
		if(p->written) {
41
			if(p->type == 'z') {
42
				Bprint(b, "z");
43
				continue;
44
			}
45
			Bprint(b, "%c%-11ld %-11llud ", p->type, p->pid, p->offset);
46
		} else {
47
			Bprint(b, "r");
48
			Bwrite(b, p->data, p->len);
49
			if(p->len != Pagesize && i != npg-1)
50
				abort();
51
			p->written = 1;
52
			p->type = type;
53
			p->offset = s->offset + i*Pagesize;
54
			p->pid = proc->pid;
55
		}
56
	}
57
}
58
 
59
 
60
void
61
writesnap(Biobuf *b, Proc *p)
62
{
63
	int i, n;
64
	Data *d;
65
 
66
	for(i=0; i<Npfile; i++)
67
		if(d = p->d[i]) {
68
			Bprint(b, "%-11ld %s\n%-11lud ", p->pid, pfile[i], d->len);
69
			Bwrite(b, d->data, d->len);
70
		}
71
 
72
	if(p->text) {
73
		Bprint(b, "%-11ld text\n", p->pid);
74
		writeseg(b, p, p->text);
75
	}
76
 
77
	if(n = p->nseg) {
78
		Bprint(b, "%-11ld mem\n%-11d ", p->pid, n);
79
		for(i=0; i<n; i++)
80
			writeseg(b, p, p->seg[i]);
81
	}
82
}