Integrate 'sofar' into sized_allocs
[akaros.git] / kern / drivers / dev / proc.c
index e11f2f7..c6479fc 100644 (file)
@@ -17,8 +17,6 @@
  * rather than excise code that won't work, I'm bracketing it with
  * #if 0 until we know we don't want it
  */
-#include <vfs.h>
-#include <kfs.h>
 #include <slab.h>
 #include <kmalloc.h>
 #include <kref.h>
@@ -29,6 +27,7 @@
 #include <cpio.h>
 #include <pmap.h>
 #include <smp.h>
+#include <umem.h>
 #include <arch/vmm/vmm.h>
 #include <ros/vmm.h>
 
@@ -43,21 +42,25 @@ enum {
        Qdir,
        Qtrace,
        Qtracepids,
+       Qself,
        Qns,
        Qargs,
        Qctl,
        Qfd,
        Qfpregs,
        Qkregs,
+       Qmaps,
        Qmem,
        Qnote,
        Qnoteid,
        Qnotepg,
        Qproc,
        Qregs,
+       Quser,
        Qsegment,
        Qstatus,
        Qstrace,
+       Qstrace_traceset,
        Qvmstatus,
        Qtext,
        Qwait,
@@ -69,28 +72,10 @@ enum {
 enum {
        CMclose,
        CMclosefiles,
-       CMfixedpri,
        CMhang,
-       CMkill,
-       CMnohang,
-       CMnoswap,
-       CMpri,
-       CMprivate,
-       CMprofile,
-       CMstart,
-       CMstartstop,
-       CMstartsyscall,
-       CMstop,
-       CMtrace,
-       CMwaitstop,
-       CMwired,
-       CMcore,
-       CMvminit,
-       CMvmstart,
-       CMvmkill,
        CMstraceme,
        CMstraceall,
-       CMstraceoff,
+       CMstrace_drop,
 };
 
 enum {
@@ -111,6 +96,7 @@ struct dirtab procdir[] = {
        {"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},
@@ -118,9 +104,11 @@ struct dirtab procdir[] = {
        {"ns", {Qns}, 0, 0444},
        {"proc", {Qproc}, 0, 0400},
        //  {"regs",        {Qregs},    sizeof(Ureg),       0000},
+       {"user", {Quser}, 0, 0444},
        {"segment", {Qsegment}, 0, 0444},
        {"status", {Qstatus}, STATSIZE, 0444},
-       {"strace", {Qstrace}, 0, 0666},
+       {"strace", {Qstrace}, 0, 0444},
+       {"strace_traceset", {Qstrace_traceset}, 0, 0666},
        {"vmstatus", {Qvmstatus}, 0, 0444},
        {"text", {Qtext}, 0, 0000},
        {"wait", {Qwait}, 0, 0400},
@@ -132,31 +120,11 @@ struct dirtab procdir[] = {
 static
 struct cmdtab proccmd[] = {
        {CMclose, "close", 2},
-       {CMclosefiles, "closefiles", 1},
-       {CMfixedpri, "fixedpri", 2},
-       {CMhang, "hang", 1},
-       {CMnohang, "nohang", 1},
-       {CMnoswap, "noswap", 1},
-       {CMkill, "kill", 1},
-       {CMpri, "pri", 2},
-       {CMprivate, "private", 1},
-       {CMprofile, "profile", 1},
-       {CMstart, "start", 1},
-       {CMstartstop, "startstop", 1},
-       {CMstartsyscall, "startsyscall", 1},
-       {CMstop, "stop", 1},
-       {CMtrace, "trace", 0},
-       {CMwaitstop, "waitstop", 1},
-       {CMwired, "wired", 2},
-       {CMcore, "core", 2},
-       {CMcore, "core", 2},
-       {CMcore, "core", 2},
-       {CMvminit, "vminit", 0},
-       {CMvmstart, "vmstart", 0},
-       {CMvmkill, "vmkill", 0},
+       {CMclosefiles, "closefiles", 0},
+       {CMhang, "hang", 0},
        {CMstraceme, "straceme", 0},
        {CMstraceall, "straceall", 0},
-       {CMstraceoff, "straceoff", 0},
+       {CMstrace_drop, "strace_drop", 2},
 };
 
 /*
@@ -221,7 +189,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);
-               devdir(c, qid, devname(), 0, eve, 0555, dp);
+               devdir(c, qid, devname(), 0, eve.name, 0555, dp);
                return 1;
        }
 
@@ -229,16 +197,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);
-                       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);
-                       devdir(c, qid, get_cur_genbuf(), 0, eve, 0444, dp);
+                       devdir(c, qid, get_cur_genbuf(), 0, eve.name, 0444, dp);
                        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);
@@ -266,24 +241,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);
-                       kref_put(&p->p_kref);
+                       proc_decref(p);
                        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);
-               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);
-               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))
@@ -322,8 +297,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);
-       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;
 }
 
@@ -383,12 +358,12 @@ static struct chan *procattach(char *spec)
 }
 
 static struct walkqid *procwalk(struct chan *c, struct chan *nc, char **name,
-                                                               int nname)
+                                                               unsigned int nname)
 {
        return devwalk(c, nc, name, nname, 0, 0, procgen);
 }
 
-static int procstat(struct chan *c, uint8_t * db, int n)
+static size_t procstat(struct chan *c, uint8_t *db, size_t n)
 {
        return devstat(c, db, n, 0, 0, procgen);
 }
@@ -405,7 +380,7 @@ static void nonone(struct proc *p)
 #if 0
        if (p == up)
                return;
-       if (strcmp(current->user, "none") != 0)
+       if (strcmp(current->user.name, "none") != 0)
                return;
        if (iseve())
                return;
@@ -413,6 +388,66 @@ static void nonone(struct proc *p)
 #endif
 }
 
+struct bm_helper {
+       struct sized_alloc                      *sza;
+       size_t                                          buflen;
+};
+
+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;
+       struct sized_alloc *sza = bmh->sza;
+       size_t old_sofar;
+       char path_buf[MAX_FILENAME_SZ];
+       char *path;
+       unsigned long inode_nr;
+
+       if (vmr_has_file(vmr)) {
+               path = foc_abs_path(vmr->__vm_foc, path_buf, sizeof(path_buf));
+               inode_nr = 0; /* TODO: do we care about this? */
+       } else {
+               strlcpy(path_buf, "[heap]", sizeof(path_buf));
+               path = path_buf;
+               inode_nr = 0;
+       }
+
+       old_sofar = sza->sofar;
+       sza_printf(sza, "%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' : 's',
+                       vmr_has_file(vmr) ? vmr->vm_foff : 0,
+                       vmr_has_file(vmr) ? 1 : 0,      /* VFS == 1 for major */
+                       0,
+                       inode_nr);
+       /* Align the filename to the 74th char, like Linux (73 chars so far) */
+       sza_printf(sza, "%*s", 73 - (sza->sofar - old_sofar), "");
+       sza_printf(sza, "%s\n", path);
+}
+
+static struct sized_alloc *build_maps(struct proc *p)
+{
+       struct bm_helper bmh[1];
+
+       /* 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);
+       bmh->sza = sized_kzmalloc(bmh->buflen, MEM_WAIT);
+       enumerate_vmrs(p, build_maps_cb, bmh);
+       return bmh->sza;
+}
+
 static struct chan *procopen(struct chan *c, int omode)
 {
        ERRSTACK(2);
@@ -479,7 +514,7 @@ static struct chan *procopen(struct chan *c, int omode)
        //qlock(&p->debug);
        if (waserror()) {
                //qunlock(&p->debug);
-               kref_put(&p->p_kref);
+               proc_decref(p);
                nexterror();
        }
        pid = PID(c->qid);
@@ -498,7 +533,7 @@ static struct chan *procopen(struct chan *c, int omode)
                        tc->offset = 0;
                        poperror();
                        qunlock(&p->debug);
-                       kref_put(&p->p_kref);
+                       proc_decref(p);
                        cclose(c);
                        return tc;
 */
@@ -537,6 +572,7 @@ static struct chan *procopen(struct chan *c, int omode)
                                error(EPERM, ERROR_FIXME);
                        c->aux = kzmalloc(sizeof(struct mntwalk), MEM_WAIT);
                        break;
+               case Quser:
                case Qstatus:
                case Qvmstatus:
                case Qctl:
@@ -545,12 +581,32 @@ static struct chan *procopen(struct chan *c, int omode)
                case Qstrace:
                        if (!p->strace)
                                error(ENOENT, "Process does not have tracing enabled");
+                       spin_lock(&p->strace->lock);
+                       if (p->strace->tracing) {
+                               spin_unlock(&p->strace->lock);
+                               error(EBUSY, "Process is already being traced");
+                       }
+                       /* It's not critical that we reopen before setting tracing, but it's
+                        * a little cleaner (concurrent syscalls could be trying to use the
+                        * queue before it was reopened, and they'd throw). */
+                       qreopen(p->strace->q);
+                       p->strace->tracing = TRUE;
+                       spin_unlock(&p->strace->lock);
                        /* the ref we are upping is the one we put in __proc_free, which is
                         * the one we got from CMstrace{on,me}.  We have a ref on p, so we
                         * know we won't free until we decref the proc. */
                        kref_get(&p->strace->users, 1);
                        c->aux = p->strace;
                        break;
+               case Qstrace_traceset:
+                       if (!p->strace)
+                               error(ENOENT, "Process does not have tracing enabled");
+                       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
@@ -583,11 +639,11 @@ static struct chan *procopen(struct chan *c, int omode)
        tc = devopen(c, omode, 0, 0, procgen);
        poperror();
        //qunlock(&p->debug);
-       kref_put(&p->p_kref);
+       proc_decref(p);
        return tc;
 }
 
-static int procwstat(struct chan *c, uint8_t * db, int n)
+static size_t procwstat(struct chan *c, uint8_t *db, size_t n)
 {
        ERRSTACK(2);
        error(ENOSYS, ERROR_FIXME);
@@ -608,7 +664,7 @@ static int procwstat(struct chan *c, uint8_t * db, int n)
        qlock(&p->debug);
        if (waserror()) {
                qunlock(&p->debug);
-               kref_put(&p->p_kref);
+               proc_decref(p);
                kfree(d);
                nexterror();
        }
@@ -616,25 +672,25 @@ static int procwstat(struct chan *c, uint8_t * db, int n)
        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);
 
        d = kzmalloc(sizeof(struct dir) + n, MEM_WAIT);
        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
-                       kstrdup(&p->user, d->uid);
+                       proc_set_username(p, d->uid);
        }
-       if (d->mode != ~0UL)
+       if (d->mode != -1)
                p->procmode = d->mode & 0777;
 
        poperror();
        qunlock(&p->debug);
-       kref_put(&p->p_kref);
+       proc_decref(p);
        kfree(d);
 
        return n;
@@ -752,9 +808,21 @@ static void procclose(struct chan *c)
        }
        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;
 
+               assert(c->flag & COPEN);        /* only way aux should have been set */
+               s->tracing = FALSE;
+               qhangup(s->q, NULL);
+               kref_put(&s->users);
+               c->aux = NULL;
+       }
+       if (QID(c->qid) == Qstrace_traceset && c->aux != 0) {
+               struct strace *s = c->aux;
+
+               assert(c->flag & COPEN);
                kref_put(&s->users);
                c->aux = NULL;
        }
@@ -826,7 +894,8 @@ static int eventsavailable(void *)
        return tproduced > tconsumed;
 }
 #endif
-static long procread(struct chan *c, void *va, long n, int64_t off)
+
+static size_t procread(struct chan *c, void *va, size_t n, off64_t off)
 {
        ERRSTACK(1);
        struct proc *p;
@@ -838,6 +907,7 @@ static long procread(struct chan *c, void *va, long n, int64_t off)
        uint8_t *rptr;
        struct mntwalk *mw;
        struct strace *s;
+       struct sized_alloc *sza;
 
        if (c->qid.type & QTDIR) {
                int nn;
@@ -852,23 +922,34 @@ static long procread(struct chan *c, void *va, long n, int64_t off)
         * already have the chan open, and all we want to do is read the queue,
         * which exists because of our kref on it. */
        switch (QID(c->qid)) {
-               case Qstrace:
-                       s = c->aux;
-                       n = qread(s->q, va, n);
-                       return n;
+       case Qstrace:
+               s = c->aux;
+               n = qread(s->q, va, n);
+               return n;
+       case Qstrace_traceset:
+               s = c->aux;
+               return readmem(offset, va, n, s->trace_set,
+                              bitmap_size(MAX_SYSCALL_NR));
        }
 
        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:
-                       kref_put(&p->p_kref);
+                       proc_decref(p);
                        break;
+               case Quser: {
+                               int i;
+
+                               i = readstr(off, va, n, p->user.name);
+                               proc_decref(p);
+                               return i;
+                       }
                case Qstatus:{
                                /* the old code grew the stack and was hideous.
                                 * status is not a high frequency operation; just malloc. */
@@ -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));
-                               kref_put(&p->p_kref);
+                               proc_decref(p);
                                i = readstr(off, va, n, buf);
                                kfree(buf);
                                return i;
@@ -906,7 +987,7 @@ static long procread(struct chan *c, void *va, long n, int64_t off)
                                        }
                                }
                                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;
@@ -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);
-                               kref_put(&p->p_kref);
+                               proc_decref(p);
                                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);
-                               kref_put(&p->p_kref);
+                               proc_decref(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);
-                               kref_put(&p->p_kref);
+                               proc_decref(p);
                                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);
-                       kref_put(&p->p_kref);
+                       proc_decref(p);
+                       return i;
+               case Qmaps:
+                       sza = c->aux;
+                       i = readstr(off, va, n, sza->buf);
+                       proc_decref(p);
                        return i;
        }
        error(EINVAL, "QID %d did not match any QIDs for #proc", QID(c->qid));
@@ -991,14 +1077,15 @@ static void mntscan(struct mntwalk *mw, struct proc *p)
        runlock(&pg->ns);
 }
 
-static long procwrite(struct chan *c, void *va, long n, int64_t off)
+static size_t procwrite(struct chan *c, void *va, size_t n, off64_t off)
 {
        ERRSTACK(2);
 
        struct proc *p, *t;
        int i, id, l;
        char *args;
-       uintptr_t offset;
+       uintptr_t offset = off;
+       struct strace *s;
 
        if (c->qid.type & QTDIR)
                error(EISDIR, ERROR_FIXME);
@@ -1007,7 +1094,7 @@ static long procwrite(struct chan *c, void *va, long n, int64_t off)
                error(ESRCH, ERROR_FIXME);
 
        if (waserror()) {
-               kref_put(&p->p_kref);
+               proc_decref(p);
                nexterror();
        }
        if (p->pid != PID(c->qid))
@@ -1058,21 +1145,19 @@ static long procwrite(struct chan *c, void *va, long n, int64_t off)
                case Qctl:
                        procctlreq(p, va, n);
                        break;
-
-               /* this lets your write a marker into the data stream,
-                * which is a very powerful tool. */
-               case Qstrace:
-                       assert(c->aux);
-                       /* it is possible that the q hungup and is closed.  that would be
-                        * the case if all of the procs closed and decref'd.  if the q is
-                        * closed, qwrite() will throw an error. */
-                       n = qwrite(((struct strace*)c->aux)->q, va, n);
+               case Qstrace_traceset:
+                       s = c->aux;
+                       if (n + offset > bitmap_size(MAX_SYSCALL_NR))
+                               error(EINVAL, "strace_traceset: Short write (%llu at off %llu)",
+                                     n, offset);
+                       if (memcpy_from_user(current, (void*)s->trace_set + offset, va, n))
+                               error(EFAULT, "strace_traceset: Bad addr (%p + %llu)", va, n);
                        break;
                default:
                        error(EFAIL, "unknown qid %#llux in procwrite\n", c->qid.path);
        }
        poperror();
-       kref_put(&p->p_kref);
+       proc_decref(p);
        return n;
 }
 
@@ -1183,20 +1268,8 @@ void procstopwait(struct proc *p, int ctl)
 static void procctlcloseone(struct proc *p, int fd)
 {
 // TODO: resolve this and sys_close
-       struct file *file = get_file_from_fd(&p->open_files, fd);
-       int retval = 0;
-       printd("%s %d\n", __func__, fd);
-       /* VFS */
-       if (file) {
-               put_file_from_fd(&p->open_files, fd);
-               kref_put(&file->f_kref);        /* Drop the ref from get_file */
-               return;
-       }
-       /* 9ns, should also handle errors (bad FD, etc) */
-       retval = sysclose(fd);
+       sysclose(fd);
        return;
-
-       //sys_close(p, fd);
 }
 
 void procctlclosefiles(struct proc *p, int all, int fd)
@@ -1213,7 +1286,7 @@ void procctlclosefiles(struct proc *p, int all, int fd)
 static void strace_shutdown(struct kref *a)
 {
        struct strace *strace = container_of(a, struct strace, procs);
-       static const char base_msg[] = "Traced ~%lu syscs, Dropped %lu";
+       static const char base_msg[] = "Traced ~%lu syscs, Dropped %lu";
        size_t msg_len = NUMSIZE64 * 2 + sizeof(base_msg);
        char *msg = kmalloc(msg_len, 0);
 
@@ -1254,10 +1327,16 @@ static void procctlreq(struct proc *p, char *va, int n)
        switch (ct->index) {
        case CMstraceall:
        case CMstraceme:
+       case CMstrace_drop:
                /* common allocation.  if we inherited, we might have one already */
                if (!p->strace) {
                        strace = kzmalloc(sizeof(*p->strace), MEM_WAIT);
-                       strace->q = qopen(65536, Qdropoverflow|Qcoalesce, NULL, NULL);
+                       spinlock_init(&strace->lock);
+                       bitmap_set(strace->trace_set, 0, MAX_SYSCALL_NR);
+                       strace->q = qopen(65536, Qmsg, NULL, NULL);
+                       /* The queue is reopened and hungup whenever we open the Qstrace
+                        * file.  This hangup might not be necessary, but is safer. */
+                       qhangup(strace->q, 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
                         * user (e.g. from open()).
@@ -1281,14 +1360,9 @@ static void procctlreq(struct proc *p, char *va, int n)
 
        /* actually do the command. */
        switch (ct->index) {
-       case CMvmstart:
-       case CMvmkill:
        default:
                error(EFAIL, "Command not implemented");
                break;
-       case CMtrace:
-               systrace_trace_pid(p);
-               break;
        case CMclose:
                procctlclosefiles(p, 0, atoi(cb->f[1]));
                break;
@@ -1299,33 +1373,19 @@ static void procctlreq(struct proc *p, char *va, int n)
                we may want this.Let us pause a proc.case CMhang:p->hang = 1;
                break;
 #endif
-       case CMkill:
-               p = pid2proc(strtol(cb->f[1], 0, 0));
-               if (!p)
-                       error(EFAIL, "No such proc\n");
-
-               enable_irqsave(&irq_state);
-               proc_destroy(p);
-               disable_irqsave(&irq_state);
-               proc_decref(p);
-               /* this is a little ghetto. it's not fully free yet, but we are also
-                * slowing it down by messing with it, esp with the busy waiting on a
-                * hyperthreaded core. */
-               spin_on(p->env_cr3);
-               break;
-       case CMvminit:
-               break;
        case CMstraceme:
-               p->strace_on = TRUE;
-               p->strace_inherit = FALSE;
+               p->strace->inherit = FALSE;
                break;
        case CMstraceall:
-               p->strace_on = TRUE;
-               p->strace_inherit = TRUE;
+               p->strace->inherit = TRUE;
                break;
-       case CMstraceoff:
-               p->strace_on = FALSE;
-               p->strace_inherit = FALSE;
+       case CMstrace_drop:
+               if (!strcmp(cb->f[1], "on"))
+                       p->strace->drop_overflow = TRUE;
+               else if (!strcmp(cb->f[1], "off"))
+                       p->strace->drop_overflow = FALSE;
+               else
+                       error(EINVAL, "strace_drop takes on|off %s", cb->f[1]);
                break;
        }
        poperror();