devproc: change user from char* to struct username
[akaros.git] / kern / drivers / dev / proc.c
index ccbe92d..2c406e2 100644 (file)
@@ -43,12 +43,14 @@ enum {
        Qdir,
        Qtrace,
        Qtracepids,
        Qdir,
        Qtrace,
        Qtracepids,
+       Qself,
        Qns,
        Qargs,
        Qctl,
        Qfd,
        Qfpregs,
        Qkregs,
        Qns,
        Qargs,
        Qctl,
        Qfd,
        Qfpregs,
        Qkregs,
+       Qmaps,
        Qmem,
        Qnote,
        Qnoteid,
        Qmem,
        Qnote,
        Qnoteid,
@@ -81,7 +83,6 @@ enum {
        CMstartstop,
        CMstartsyscall,
        CMstop,
        CMstartstop,
        CMstartsyscall,
        CMstop,
-       CMtrace,
        CMwaitstop,
        CMwired,
        CMcore,
        CMwaitstop,
        CMwired,
        CMcore,
@@ -111,6 +112,7 @@ struct dirtab procdir[] = {
        {"fd", {Qfd}, 0, 0444},
        {"fpregs", {Qfpregs}, 0, 0000},
        //  {"kregs",   {Qkregs},   sizeof(Ureg),       0600},
        {"fd", {Qfd}, 0, 0444},
        {"fpregs", {Qfpregs}, 0, 0000},
        //  {"kregs",   {Qkregs},   sizeof(Ureg),       0600},
+       {"maps", {Qmaps}, 0, 0000},
        {"mem", {Qmem}, 0, 0000},
        {"note", {Qnote}, 0, 0000},
        {"noteid", {Qnoteid}, 0, 0664},
        {"mem", {Qmem}, 0, 0000},
        {"note", {Qnote}, 0, 0000},
        {"noteid", {Qnoteid}, 0, 0664},
@@ -145,7 +147,6 @@ struct cmdtab proccmd[] = {
        {CMstartstop, "startstop", 1},
        {CMstartsyscall, "startsyscall", 1},
        {CMstop, "stop", 1},
        {CMstartstop, "startstop", 1},
        {CMstartsyscall, "startsyscall", 1},
        {CMstop, "stop", 1},
-       {CMtrace, "trace", 0},
        {CMwaitstop, "waitstop", 1},
        {CMwired, "wired", 2},
        {CMcore, "core", 2},
        {CMwaitstop, "waitstop", 1},
        {CMwired, "wired", 2},
        {CMcore, "core", 2},
@@ -221,7 +222,7 @@ procgen(struct chan *c, char *name, struct dirtab *tab, int unused, int s,
        uint32_t path, perm, len;
        if (s == DEVDOTDOT) {
                mkqid(&qid, Qdir, 0, QTDIR);
        uint32_t path, perm, len;
        if (s == DEVDOTDOT) {
                mkqid(&qid, Qdir, 0, QTDIR);
-               devdir(c, qid, devname(), 0, eve, 0555, dp);
+               devdir(c, qid, devname(), 0, eve.name, 0555, dp);
                return 1;
        }
 
                return 1;
        }
 
@@ -229,16 +230,23 @@ procgen(struct chan *c, char *name, struct dirtab *tab, int unused, int s,
                if (s == 0) {
                        strlcpy(get_cur_genbuf(), "trace", GENBUF_SZ);
                        mkqid(&qid, Qtrace, -1, QTFILE);
                if (s == 0) {
                        strlcpy(get_cur_genbuf(), "trace", GENBUF_SZ);
                        mkqid(&qid, Qtrace, -1, QTFILE);
-                       devdir(c, qid, get_cur_genbuf(), 0, eve, 0444, dp);
+                       devdir(c, qid, get_cur_genbuf(), 0, eve.name, 0444, dp);
                        return 1;
                }
                if (s == 1) {
                        strlcpy(get_cur_genbuf(), "tracepids", GENBUF_SZ);
                        mkqid(&qid, Qtracepids, -1, QTFILE);
                        return 1;
                }
                if (s == 1) {
                        strlcpy(get_cur_genbuf(), "tracepids", GENBUF_SZ);
                        mkqid(&qid, Qtracepids, -1, QTFILE);
-                       devdir(c, qid, get_cur_genbuf(), 0, eve, 0444, dp);
+                       devdir(c, qid, get_cur_genbuf(), 0, eve.name, 0444, dp);
                        return 1;
                }
                        return 1;
                }
-               s -= 2;
+               if (s == 2) {
+                       p = current;
+                       strlcpy(get_cur_genbuf(), "self", GENBUF_SZ);
+                       mkqid(&qid, (p->pid + 1) << QSHIFT, p->pid, QTDIR);
+                       devdir(c, qid, get_cur_genbuf(), 0, p->user.name, DMDIR | 0555, dp);
+                       return 1;
+               }
+               s -= 3;
                if (name != NULL) {
                        /* ignore s and use name to find pid */
                        pid = strtol(name, &ename, 10);
                if (name != NULL) {
                        /* ignore s and use name to find pid */
                        pid = strtol(name, &ename, 10);
@@ -266,24 +274,24 @@ procgen(struct chan *c, char *name, struct dirtab *tab, int unused, int s,
                 */
                if (name != NULL && strcmp(name, get_cur_genbuf()) != 0) {
                        printk("pid-name mismatch, name: %s, pid %d\n", name, pid);
                 */
                if (name != NULL && strcmp(name, get_cur_genbuf()) != 0) {
                        printk("pid-name mismatch, name: %s, pid %d\n", name, pid);
-                       kref_put(&p->p_kref);
+                       proc_decref(p);
                        return -1;
                }
                mkqid(&qid, (s + 1) << QSHIFT, pid, QTDIR);
                        return -1;
                }
                mkqid(&qid, (s + 1) << QSHIFT, pid, QTDIR);
-               devdir(c, qid, get_cur_genbuf(), 0, p->user, DMDIR | 0555, dp);
-               kref_put(&p->p_kref);
+               devdir(c, qid, get_cur_genbuf(), 0, p->user.name, DMDIR | 0555, dp);
+               proc_decref(p);
                return 1;
        }
        if (c->qid.path == Qtrace) {
                strlcpy(get_cur_genbuf(), "trace", GENBUF_SZ);
                mkqid(&qid, Qtrace, -1, QTFILE);
                return 1;
        }
        if (c->qid.path == Qtrace) {
                strlcpy(get_cur_genbuf(), "trace", GENBUF_SZ);
                mkqid(&qid, Qtrace, -1, QTFILE);
-               devdir(c, qid, get_cur_genbuf(), 0, eve, 0444, dp);
+               devdir(c, qid, get_cur_genbuf(), 0, eve.name, 0444, dp);
                return 1;
        }
        if (c->qid.path == Qtracepids) {
                strlcpy(get_cur_genbuf(), "tracepids", GENBUF_SZ);
                mkqid(&qid, Qtracepids, -1, QTFILE);
                return 1;
        }
        if (c->qid.path == Qtracepids) {
                strlcpy(get_cur_genbuf(), "tracepids", GENBUF_SZ);
                mkqid(&qid, Qtracepids, -1, QTFILE);
-               devdir(c, qid, get_cur_genbuf(), 0, eve, 0444, dp);
+               devdir(c, qid, get_cur_genbuf(), 0, eve.name, 0444, dp);
                return 1;
        }
        if (s >= ARRAY_SIZE(procdir))
                return 1;
        }
        if (s >= ARRAY_SIZE(procdir))
@@ -322,8 +330,8 @@ procgen(struct chan *c, char *name, struct dirtab *tab, int unused, int s,
 #endif
 
        mkqid(&qid, path | tab->qid.path, c->qid.vers, QTFILE);
 #endif
 
        mkqid(&qid, path | tab->qid.path, c->qid.vers, QTFILE);
-       devdir(c, qid, tab->name, len, p->user, perm, dp);
-       kref_put(&p->p_kref);
+       devdir(c, qid, tab->name, len, p->user.name, perm, dp);
+       proc_decref(p);
        return 1;
 }
 
        return 1;
 }
 
@@ -405,7 +413,7 @@ static void nonone(struct proc *p)
 #if 0
        if (p == up)
                return;
 #if 0
        if (p == up)
                return;
-       if (strcmp(current->user, "none") != 0)
+       if (strcmp(current->user.name, "none") != 0)
                return;
        if (iseve())
                return;
                return;
        if (iseve())
                return;
@@ -413,6 +421,72 @@ static void nonone(struct proc *p)
 #endif
 }
 
 #endif
 }
 
+struct bm_helper {
+       void                                            *buf;
+       size_t                                          buflen;
+       size_t                                          sofar;
+};
+
+static void get_needed_sz_cb(struct vm_region *vmr, void *arg)
+{
+       struct bm_helper *bmh = (struct bm_helper*)arg;
+
+       /* ballpark estimate of a line */
+       bmh->buflen += 150;
+}
+
+static void build_maps_cb(struct vm_region *vmr, void *arg)
+{
+       struct bm_helper *bmh = (struct bm_helper*)arg;
+       size_t old_sofar;
+       char path_buf[MAX_FILENAME_SZ];
+       char *path;
+       unsigned long inode_nr;
+
+       if (vmr->vm_file) {
+               path = file_abs_path(vmr->vm_file, path_buf, sizeof(path_buf));
+               inode_nr = vmr->vm_file->f_dentry->d_inode->i_ino;
+       } else {
+               strlcpy(path_buf, "[heap]", sizeof(path_buf));
+               path = path_buf;
+               inode_nr = 0;
+       }
+
+       old_sofar = bmh->sofar;
+       bmh->sofar += snprintf(bmh->buf + bmh->sofar, bmh->buflen - bmh->sofar,
+                              "%08lx-%08lx %c%c%c%c %08x %02d:%02d %d ",
+                              vmr->vm_base, vmr->vm_end,
+                              vmr->vm_prot & PROT_READ    ? 'r' : '-',
+                              vmr->vm_prot & PROT_WRITE   ? 'w' : '-',
+                              vmr->vm_prot & PROT_EXEC    ? 'x' : '-',
+                              vmr->vm_flags & MAP_PRIVATE ? 'p' : '-',
+                              vmr->vm_file ? vmr->vm_foff : 0,
+                              vmr->vm_file ? 1 : 0,    /* VFS == 1 for major */
+                              0,
+                              inode_nr);
+       /* Align the filename to the 74th char, like Linux (73 chars so far) */
+       bmh->sofar += snprintf(bmh->buf + bmh->sofar, bmh->buflen - bmh->sofar,
+                              "%*s", 73 - (bmh->sofar - old_sofar), "");
+       bmh->sofar += snprintf(bmh->buf + bmh->sofar, bmh->buflen - bmh->sofar,
+                              "%s\n", path);
+}
+
+static struct sized_alloc *build_maps(struct proc *p)
+{
+       struct bm_helper bmh[1];
+       struct sized_alloc *sza;
+
+       /* Try to figure out the size needed: start with extra space, then add a bit
+        * for each VMR */
+       bmh->buflen = 150;
+       enumerate_vmrs(p, get_needed_sz_cb, bmh);
+       sza = sized_kzmalloc(bmh->buflen, MEM_WAIT);
+       bmh->buf = sza->buf;
+       bmh->sofar = 0;
+       enumerate_vmrs(p, build_maps_cb, bmh);
+       return sza;
+}
+
 static struct chan *procopen(struct chan *c, int omode)
 {
        ERRSTACK(2);
 static struct chan *procopen(struct chan *c, int omode)
 {
        ERRSTACK(2);
@@ -439,10 +513,10 @@ static struct chan *procopen(struct chan *c, int omode)
                topens++;
                if (tevents == NULL) {
                        tevents = (Traceevent *) kzmalloc(sizeof(Traceevent) * Nevents,
                topens++;
                if (tevents == NULL) {
                        tevents = (Traceevent *) kzmalloc(sizeof(Traceevent) * Nevents,
-                                                                                         KMALLOC_WAIT);
+                                                                                         MEM_WAIT);
                        if (tevents == NULL)
                                error(ENOMEM, ERROR_FIXME);
                        if (tevents == NULL)
                                error(ENOMEM, ERROR_FIXME);
-                       tpids = kzmalloc(Ntracedpids * 20, KMALLOC_WAIT);
+                       tpids = kzmalloc(Ntracedpids * 20, MEM_WAIT);
                        if (tpids == NULL) {
                                kfree(tpids);
                                tpids = NULL;
                        if (tpids == NULL) {
                                kfree(tpids);
                                tpids = NULL;
@@ -479,7 +553,7 @@ static struct chan *procopen(struct chan *c, int omode)
        //qlock(&p->debug);
        if (waserror()) {
                //qunlock(&p->debug);
        //qlock(&p->debug);
        if (waserror()) {
                //qunlock(&p->debug);
-               kref_put(&p->p_kref);
+               proc_decref(p);
                nexterror();
        }
        pid = PID(c->qid);
                nexterror();
        }
        pid = PID(c->qid);
@@ -498,7 +572,7 @@ static struct chan *procopen(struct chan *c, int omode)
                        tc->offset = 0;
                        poperror();
                        qunlock(&p->debug);
                        tc->offset = 0;
                        poperror();
                        qunlock(&p->debug);
-                       kref_put(&p->p_kref);
+                       proc_decref(p);
                        cclose(c);
                        return tc;
 */
                        cclose(c);
                        return tc;
 */
@@ -535,7 +609,7 @@ static struct chan *procopen(struct chan *c, int omode)
                case Qns:
                        if (omode != O_READ)
                                error(EPERM, ERROR_FIXME);
                case Qns:
                        if (omode != O_READ)
                                error(EPERM, ERROR_FIXME);
-                       c->aux = kzmalloc(sizeof(struct mntwalk), KMALLOC_WAIT);
+                       c->aux = kzmalloc(sizeof(struct mntwalk), MEM_WAIT);
                        break;
                case Qstatus:
                case Qvmstatus:
                        break;
                case Qstatus:
                case Qvmstatus:
@@ -551,6 +625,9 @@ static struct chan *procopen(struct chan *c, int omode)
                        kref_get(&p->strace->users, 1);
                        c->aux = p->strace;
                        break;
                        kref_get(&p->strace->users, 1);
                        c->aux = p->strace;
                        break;
+               case Qmaps:
+                       c->aux = build_maps(p);
+                       break;
                case Qnotepg:
                        error(ENOSYS, ERROR_FIXME);
 #if 0
                case Qnotepg:
                        error(ENOSYS, ERROR_FIXME);
 #if 0
@@ -583,7 +660,7 @@ static struct chan *procopen(struct chan *c, int omode)
        tc = devopen(c, omode, 0, 0, procgen);
        poperror();
        //qunlock(&p->debug);
        tc = devopen(c, omode, 0, 0, procgen);
        poperror();
        //qunlock(&p->debug);
-       kref_put(&p->p_kref);
+       proc_decref(p);
        return tc;
 }
 
        return tc;
 }
 
@@ -608,7 +685,7 @@ static int procwstat(struct chan *c, uint8_t * db, int n)
        qlock(&p->debug);
        if (waserror()) {
                qunlock(&p->debug);
        qlock(&p->debug);
        if (waserror()) {
                qunlock(&p->debug);
-               kref_put(&p->p_kref);
+               proc_decref(p);
                kfree(d);
                nexterror();
        }
                kfree(d);
                nexterror();
        }
@@ -616,25 +693,25 @@ static int procwstat(struct chan *c, uint8_t * db, int n)
        if (p->pid != PID(c->qid))
                error(ESRCH, ERROR_FIXME);
 
        if (p->pid != PID(c->qid))
                error(ESRCH, ERROR_FIXME);
 
-       if (strcmp(current->user, p->user) != 0 && strcmp(current->user, eve) != 0)
+       if (strcmp(current->user.name, p->user.name) != 0 && !iseve())
                error(EPERM, ERROR_FIXME);
 
                error(EPERM, ERROR_FIXME);
 
-       d = kzmalloc(sizeof(struct dir) + n, KMALLOC_WAIT);
+       d = kzmalloc(sizeof(struct dir) + n, MEM_WAIT);
        n = convM2D(db, n, &d[0], (char *)&d[1]);
        if (n == 0)
                error(ENOENT, ERROR_FIXME);
        n = convM2D(db, n, &d[0], (char *)&d[1]);
        if (n == 0)
                error(ENOENT, ERROR_FIXME);
-       if (!emptystr(d->uid) && strcmp(d->uid, p->user) != 0) {
-               if (strcmp(current->user, eve) != 0)
+       if (!emptystr(d->uid) && strcmp(d->uid, p->user.name) != 0) {
+               if (!iseve())
                        error(EPERM, ERROR_FIXME);
                else
                        error(EPERM, ERROR_FIXME);
                else
-                       kstrdup(&p->user, d->uid);
+                       proc_set_username(p, d->uid);
        }
        if (d->mode != ~0UL)
                p->procmode = d->mode & 0777;
 
        poperror();
        qunlock(&p->debug);
        }
        if (d->mode != ~0UL)
                p->procmode = d->mode & 0777;
 
        poperror();
        qunlock(&p->debug);
-       kref_put(&p->p_kref);
+       proc_decref(p);
        kfree(d);
 
        return n;
        kfree(d);
 
        return n;
@@ -752,6 +829,8 @@ static void procclose(struct chan *c)
        }
        if (QID(c->qid) == Qns && c->aux != 0)
                kfree(c->aux);
        }
        if (QID(c->qid) == Qns && c->aux != 0)
                kfree(c->aux);
+       if (QID(c->qid) == Qmaps && c->aux != 0)
+               kfree(c->aux);
        if (QID(c->qid) == Qstrace && c->aux != 0) {
                struct strace *s = c->aux;
 
        if (QID(c->qid) == Qstrace && c->aux != 0) {
                struct strace *s = c->aux;
 
@@ -788,11 +867,11 @@ static char *argcpy(char *s, char *p)
        if (n > 128)
                n = 128;
        if (n <= 0) {
        if (n > 128)
                n = 128;
        if (n <= 0) {
-               t = kzmalloc(1, KMALLOC_WAIT);
+               t = kzmalloc(1, MEM_WAIT);
                *t = 0;
                return t;
        }
                *t = 0;
                return t;
        }
-       t = kzmalloc(n, KMALLOC_WAIT);
+       t = kzmalloc(n, MEM_WAIT);
        tp = t;
        te = t + n;
 
        tp = t;
        te = t + n;
 
@@ -826,6 +905,7 @@ static int eventsavailable(void *)
        return tproduced > tconsumed;
 }
 #endif
        return tproduced > tconsumed;
 }
 #endif
+
 static long procread(struct chan *c, void *va, long n, int64_t off)
 {
        ERRSTACK(1);
 static long procread(struct chan *c, void *va, long n, int64_t off)
 {
        ERRSTACK(1);
@@ -838,6 +918,7 @@ static long procread(struct chan *c, void *va, long n, int64_t off)
        uint8_t *rptr;
        struct mntwalk *mw;
        struct strace *s;
        uint8_t *rptr;
        struct mntwalk *mw;
        struct strace *s;
+       struct sized_alloc *sza;
 
        if (c->qid.type & QTDIR) {
                int nn;
 
        if (c->qid.type & QTDIR) {
                int nn;
@@ -861,18 +942,18 @@ static long procread(struct chan *c, void *va, long n, int64_t off)
        if ((p = pid2proc(SLOT(c->qid))) == NULL)
                error(ESRCH, "%d: no such process", SLOT(c->qid));
        if (p->pid != PID(c->qid)) {
        if ((p = pid2proc(SLOT(c->qid))) == NULL)
                error(ESRCH, "%d: no such process", SLOT(c->qid));
        if (p->pid != PID(c->qid)) {
-               kref_put(&p->p_kref);
+               proc_decref(p);
                error(ESRCH, "weird: p->pid is %d, PID(c->qid) is %d: mismatch",
                      p->pid, PID(c->qid));
        }
        switch (QID(c->qid)) {
                default:
                error(ESRCH, "weird: p->pid is %d, PID(c->qid) is %d: mismatch",
                      p->pid, PID(c->qid));
        }
        switch (QID(c->qid)) {
                default:
-                       kref_put(&p->p_kref);
+                       proc_decref(p);
                        break;
                case Qstatus:{
                                /* the old code grew the stack and was hideous.
                                 * status is not a high frequency operation; just malloc. */
                        break;
                case Qstatus:{
                                /* the old code grew the stack and was hideous.
                                 * status is not a high frequency operation; just malloc. */
-                               char *buf = kmalloc(4096, KMALLOC_WAIT);
+                               char *buf = kmalloc(4096, MEM_WAIT);
                                char *s = buf, *e = buf + 4096;
                                int i;
 
                                char *s = buf, *e = buf + 4096;
                                int i;
 
@@ -884,7 +965,7 @@ static long procread(struct chan *c, void *va, long n, int64_t off)
                                        s = seprintf(s, e, " %d trace users %d traced procs",
                                                     kref_refcnt(&p->strace->users),
                                                     kref_refcnt(&p->strace->procs));
                                        s = seprintf(s, e, " %d trace users %d traced procs",
                                                     kref_refcnt(&p->strace->users),
                                                     kref_refcnt(&p->strace->procs));
-                               kref_put(&p->p_kref);
+                               proc_decref(p);
                                i = readstr(off, va, n, buf);
                                kfree(buf);
                                return i;
                                i = readstr(off, va, n, buf);
                                kfree(buf);
                                return i;
@@ -893,7 +974,7 @@ static long procread(struct chan *c, void *va, long n, int64_t off)
                case Qvmstatus:
                        {
                                size_t buflen = 50 * 65 + 2;
                case Qvmstatus:
                        {
                                size_t buflen = 50 * 65 + 2;
-                               char *buf = kmalloc(buflen, KMALLOC_WAIT);
+                               char *buf = kmalloc(buflen, MEM_WAIT);
                                int i, offset;
                                offset = 0;
                                offset += snprintf(buf + offset, buflen - offset, "{\n");
                                int i, offset;
                                offset = 0;
                                offset += snprintf(buf + offset, buflen - offset, "{\n");
@@ -906,7 +987,7 @@ static long procread(struct chan *c, void *va, long n, int64_t off)
                                        }
                                }
                                offset += snprintf(buf + offset, buflen - offset, "}\n");
                                        }
                                }
                                offset += snprintf(buf + offset, buflen - offset, "}\n");
-                               kref_put(&p->p_kref);
+                               proc_decref(p);
                                n = readstr(off, va, n, buf);
                                kfree(buf);
                                return n;
                                n = readstr(off, va, n, buf);
                                kfree(buf);
                                return n;
@@ -915,7 +996,7 @@ static long procread(struct chan *c, void *va, long n, int64_t off)
                        //qlock(&p->debug);
                        if (waserror()) {
                                //qunlock(&p->debug);
                        //qlock(&p->debug);
                        if (waserror()) {
                                //qunlock(&p->debug);
-                               kref_put(&p->p_kref);
+                               proc_decref(p);
                                nexterror();
                        }
                        if (p->pgrp == NULL || p->pid != PID(c->qid))
                                nexterror();
                        }
                        if (p->pgrp == NULL || p->pid != PID(c->qid))
@@ -924,7 +1005,7 @@ static long procread(struct chan *c, void *va, long n, int64_t off)
                        if (mw->cddone) {
                                poperror();
                                //qunlock(&p->debug);
                        if (mw->cddone) {
                                poperror();
                                //qunlock(&p->debug);
-                               kref_put(&p->p_kref);
+                               proc_decref(p);
                                return 0;
                        }
                        mntscan(mw, p);
                                return 0;
                        }
                        mntscan(mw, p);
@@ -933,7 +1014,7 @@ static long procread(struct chan *c, void *va, long n, int64_t off)
                                i = snprintf(va, n, "cd %s\n", p->dot->name->s);
                                poperror();
                                //qunlock(&p->debug);
                                i = snprintf(va, n, "cd %s\n", p->dot->name->s);
                                poperror();
                                //qunlock(&p->debug);
-                               kref_put(&p->p_kref);
+                               proc_decref(p);
                                return i;
                        }
                        int2flag(mw->cm->mflag, flag);
                                return i;
                        }
                        int2flag(mw->cm->mflag, flag);
@@ -949,7 +1030,12 @@ static long procread(struct chan *c, void *va, long n, int64_t off)
                                                         mw->cm->to->name->s, mw->mh->from->name->s);
                        poperror();
                        //qunlock(&p->debug);
                                                         mw->cm->to->name->s, mw->mh->from->name->s);
                        poperror();
                        //qunlock(&p->debug);
-                       kref_put(&p->p_kref);
+                       proc_decref(p);
+                       return i;
+               case Qmaps:
+                       sza = c->aux;
+                       i = readmem(off, va, n, sza->buf, sza->size);
+                       proc_decref(p);
                        return i;
        }
        error(EINVAL, "QID %d did not match any QIDs for #proc", QID(c->qid));
                        return i;
        }
        error(EINVAL, "QID %d did not match any QIDs for #proc", QID(c->qid));
@@ -1007,7 +1093,7 @@ static long procwrite(struct chan *c, void *va, long n, int64_t off)
                error(ESRCH, ERROR_FIXME);
 
        if (waserror()) {
                error(ESRCH, ERROR_FIXME);
 
        if (waserror()) {
-               kref_put(&p->p_kref);
+               proc_decref(p);
                nexterror();
        }
        if (p->pid != PID(c->qid))
                nexterror();
        }
        if (p->pid != PID(c->qid))
@@ -1023,7 +1109,7 @@ static long procwrite(struct chan *c, void *va, long n, int64_t off)
                        if (n >= sizeof buf - strlen(p->text) - 1)
                                error(E2BIG, ERROR_FIXME);
                        l = snprintf(buf, sizeof buf, "%s [%s]", p->text, (char *)va);
                        if (n >= sizeof buf - strlen(p->text) - 1)
                                error(E2BIG, ERROR_FIXME);
                        l = snprintf(buf, sizeof buf, "%s [%s]", p->text, (char *)va);
-                       args = kzmalloc(l + 1, KMALLOC_WAIT);
+                       args = kzmalloc(l + 1, MEM_WAIT);
                        if (args == NULL)
                                error(ENOMEM, ERROR_FIXME);
                        memmove(args, buf, l);
                        if (args == NULL)
                                error(ENOMEM, ERROR_FIXME);
                        memmove(args, buf, l);
@@ -1072,7 +1158,7 @@ static long procwrite(struct chan *c, void *va, long n, int64_t off)
                        error(EFAIL, "unknown qid %#llux in procwrite\n", c->qid.path);
        }
        poperror();
                        error(EFAIL, "unknown qid %#llux in procwrite\n", c->qid.path);
        }
        poperror();
-       kref_put(&p->p_kref);
+       proc_decref(p);
        return n;
 }
 
        return n;
 }
 
@@ -1256,7 +1342,7 @@ static void procctlreq(struct proc *p, char *va, int n)
        case CMstraceme:
                /* common allocation.  if we inherited, we might have one already */
                if (!p->strace) {
        case CMstraceme:
                /* common allocation.  if we inherited, we might have one already */
                if (!p->strace) {
-                       strace = kzmalloc(sizeof(*p->strace), KMALLOC_WAIT);
+                       strace = kzmalloc(sizeof(*p->strace), MEM_WAIT);
                        strace->q = qopen(65536, Qdropoverflow|Qcoalesce, NULL, NULL);
                        /* both of these refs are put when the proc is freed.  procs is for
                         * every process that has this p->strace.  users is procs + every
                        strace->q = qopen(65536, Qdropoverflow|Qcoalesce, NULL, NULL);
                        /* both of these refs are put when the proc is freed.  procs is for
                         * every process that has this p->strace.  users is procs + every
@@ -1286,9 +1372,6 @@ static void procctlreq(struct proc *p, char *va, int n)
        default:
                error(EFAIL, "Command not implemented");
                break;
        default:
                error(EFAIL, "Command not implemented");
                break;
-       case CMtrace:
-               systrace_trace_pid(p);
-               break;
        case CMclose:
                procctlclosefiles(p, 0, atoi(cb->f[1]));
                break;
        case CMclose:
                procctlclosefiles(p, 0, atoi(cb->f[1]));
                break;