37 typedef struct Aux Aux;
38 typedef struct Dirtab Dirtab;
53 "args", {Qargs}, 0, 0660,
54 "ctl", {Qctl}, 0, 0600,
56 "fpregs", {Qfpregs}, 0, 0400,
57 "kregs", {Qkregs}, 18 * 4, 0400,
58 "mem", {Qmem}, 0, 0400,
59 "note", {Qnote}, 0, 0000,
60 "noteid", {Qnoteid}, 0, 0664,
61 "notepg", {Qnotepg}, 0, 0000,
63 "proc", {Qproc}, 0, 0400,
64 "regs", {Qregs}, 18 * 4, 0400,
65 "segment", {Qsegment}, 0, 0444,
66 "status", {Qstatus}, 176, 0444,
67 "text", {Qtext}, 0, 0400,
68 "wait", {Qwait}, 0, 0400,
69 "profile", {Qprofile}, 0, 0400,
70 "syscall", {Qsyscall}, 0, 0400,
75 readin(int pid, char *file)
80 name = smprint("#p/%d/%s", pid, file);
81 fd = open(name, OREAD);
85 rc = read(fd, buf, 1023);
100 for(i = 0; i < SEGNUM; i++) {
107 r = (r + 1023) / 1024;
112 copymem(Process *p, char *buf, u32int addr, int len)
118 for(i = 0; i < SEGNUM; i++) {
121 if(p->S[i]->start <= addr && p->S[i]->start + p->S[i]->size > addr)
125 werrstr("bad arg in syscall");
128 n = p->S[i]->start + p->S[i]->size - addr;
131 memcpy(buf, (char*)p->S[i]->data + addr - p->S[i]->start, n);
142 static char *names[] = {
152 for(i = 0; i < SEGNUM; i++) {
155 s += sprint(s, "%-7s%c %.8ux %.8ux %4ld\n", names[i], i == SEGTEXT ? 'R' : ' ', p->S[i]->start, p->S[i]->start + p->S[i]->size, p->S[i]->dref->ref);
163 req->fid->qid = (Qid) {0, 0, 0x80};
164 req->fid->aux = emallocz(sizeof(Aux));
165 ((Aux *) req->fid->aux)->fd = -1;
166 req->ofcall.qid = req->fid->qid;
171 procwalk(Fid *fid, char *name, Qid *qid)
179 if(fid->qid.path == 0) {
181 sprint(buf, "%d", pid);
182 if(strcmp(buf, name) != 0 || (a->p = findproc(pid)) == nil)
183 return "file does not exist";
184 *qid = (Qid) {pid * NQid, 0, 0x80};
188 if((fid->qid.path % NQid) == 0) {
189 for(d = procdir; d->name[0] != 0; d++)
190 if(strcmp(d->name, name) == 0)
193 return "file does not exist";
195 qid->path += fid->qid.path;
200 return "the front fell off";
204 procclone(Fid *old, Fid *new)
206 new->aux = emallocz(sizeof(Aux));
207 memcpy(new->aux, old->aux, sizeof(Aux));
217 switch((int)(req->fid->qid.path % NQid)) {
219 a->fd = open((char*)(a->p->path + 1), OREAD);
232 procdestroyfid(Fid *fid)
241 procgen(int n, Dir *d, void *)
254 d->uid = estrdup9p(luser);
255 d->gid = estrdup9p(luser);
256 d->muid = estrdup9p(luser);
257 d->name = smprint("%d", p->pid);
258 d->mode = DMDIR | 0555;
259 d->qid = (Qid) {p->pid * NQid, 0, 0x80};
264 procsubgen(int n, Dir *d, void *)
268 if(n >= nelem(procdir) - 1)
272 d->uid = estrdup9p(luser);
273 d->gid = estrdup9p(luser);
274 d->muid = estrdup9p(luser);
275 d->name = estrdup9p(di->name);
277 d->length = di->length;
292 respond(req, "the front fell off");
295 if(req->fid->qid.path == 0) {
296 dirread9p(req, procgen, nil);
301 switch((int)(req->fid->qid.path % NQid)) {
303 dirread9p(req, procsubgen, nil);
307 buf = readin(p->pid, "status");
311 memset(buf, ' ', 27);
312 memcpy(buf, p->name, strlen(p->name));
313 sprint(buf + 149, "%d", calcmem(p));
314 buf[strlen(buf)] = ' ';
327 rc = pread(a->fd, req->ofcall.data, req->ifcall.count, req->ifcall.offset);
329 req->ofcall.count = rc;
335 rc = copymem(p, req->ofcall.data, req->ifcall.offset, req->ifcall.count);
337 req->ofcall.count = rc;
343 buf = emallocz(18 * 4);
344 memcpy(buf, p->R, 15 * 4);
345 memcpy(buf + 16 * 4, &p->CPSR, 4);
346 memcpy(buf + 17 * 4, p->R + 15, 4);
347 readbuf(req, buf, 18 * 4);
352 respond(req, "the front fell off");
357 writeto(Req *req, char *fmt, ...)
364 file = vsmprint(fmt, va);
366 fd = open(file, OWRITE);
372 rc = write(fd, req->ifcall.data, req->ifcall.count);
373 req->ofcall.count = rc;
374 if(rc < req->ifcall.count)
384 switch((int)(req->fid->qid.path % NQid)) {
386 writeto(req, "#p/%lld/note", req->fid->qid.path / NQid);
389 respond(req, "the front fell off");
402 respond(req, "the front fell off");
405 d->qid = req->fid->qid;
407 d->mode = a->d->perm;
408 d->length = a->d->length;
409 d->name = strdup(a->d->name);
411 d->mode = 0555 | DMDIR;
413 d->name = smprint("%lld", d->qid.path / NQid);
415 d->uid = strdup(luser);
416 d->gid = strdup(luser);
417 d->muid = strdup(luser);
421 static Srv procsrv = {
422 .attach = procattach,
425 .destroyfid = procdestroyfid,
432 initfs(char *name, char *mtpt)
435 remove("/srv/armproc");
436 postmountsrv(&procsrv, name, mtpt, MREPL);