now RBT is in userland, we can actually use the API instead of hand
rolling the copying of the tree topology.

ok?

Index: lib/libkvm/kvm_proc.c
===================================================================
RCS file: /cvs/src/lib/libkvm/kvm_proc.c,v
retrieving revision 1.58
diff -u -p -r1.58 kvm_proc.c
--- lib/libkvm/kvm_proc.c       7 Nov 2016 00:26:33 -0000       1.58
+++ lib/libkvm/kvm_proc.c       20 Jun 2017 01:03:05 -0000
@@ -77,6 +77,7 @@
 #include <sys/ioctl.h>
 #include <sys/tty.h>
 #include <stdlib.h>
+#include <stddef.h>
 #include <string.h>
 #include <unistd.h>
 #include <nlist.h>
@@ -108,6 +109,9 @@ static int  proc_verify(kvm_t *, const st
 static void    ps_str_a(struct ps_strings *, u_long *, int *);
 static void    ps_str_e(struct ps_strings *, u_long *, int *);
 
+RBT_PROTOTYPE(uvm_map_addr, vm_map_entry, daddrs.addr_entry,
+    uvm_mapentry_addrcmp);
+
 static struct vm_anon *
 _kvm_findanon(kvm_t *kd, struct vm_amap *amapp, int slot)
 {
@@ -166,7 +170,6 @@ _kvm_ureadm(kvm_t *kd, const struct kinf
        struct vm_anon *anonp, anon;
        struct vm_map_entry vme;
        struct vm_page pg;
-       unsigned long rboff;
 
        if (kd->swapspc == 0) {
                kd->swapspc = _kvm_malloc(kd, kd->nbpg);
@@ -174,26 +177,23 @@ _kvm_ureadm(kvm_t *kd, const struct kinf
                        return (NULL);
        }
 
-       rboff = (unsigned long)&vme.daddrs.addr_entry - (unsigned long)&vme;
-
        /*
         * Look through the address map for the memory object
         * that corresponds to the given virtual address.
         */
        if (KREAD(kd, (u_long)p->p_vmspace, &vm))
                return (NULL);
-       addr = (u_long)&vm.vm_map.addr.rbh_root.rbt_root;
+       addr = (u_long)RBT_ROOT(uvm_map_addr, &vm.vm_map.addr);
        while (1) {
                if (addr == 0)
                        return (NULL);
-               addr -= rboff;
                if (KREAD(kd, addr, &vme))
                        return (NULL);
 
                if (va < vme.start)
-                       addr = (u_long)vme.daddrs.addr_entry.rbt_left;
+                       addr = (u_long)RBT_LEFT(uvm_map_addr, &vme);
                else if (va >= vme.end + vme.guard + vme.fspace)
-                       addr = (u_long)vme.daddrs.addr_entry.rbt_right;
+                       addr = (u_long)RBT_RIGHT(uvm_map_addr, &vme);
                else if (va >= vme.end)
                        return (NULL);
                else
@@ -543,3 +543,13 @@ kvm_ureadm(kvm_t *kd, const struct kinfo
        }
        return (ssize_t)(cp - buf);
 }
+
+static inline int
+uvm_mapentry_addrcmp(const struct vm_map_entry *e1,
+    const struct vm_map_entry *e2)
+{
+       return e1->start < e2->start ? -1 : e1->start > e2->start;
+}
+
+RBT_GENERATE(uvm_map_addr, vm_map_entry, daddrs.addr_entry,
+    uvm_mapentry_addrcmp);
Index: lib/libkvm/shlib_version
===================================================================
RCS file: /cvs/src/lib/libkvm/shlib_version,v
retrieving revision 1.19
diff -u -p -r1.19 shlib_version
--- lib/libkvm/shlib_version    2 Oct 2016 23:11:55 -0000       1.19
+++ lib/libkvm/shlib_version    20 Jun 2017 01:03:05 -0000
@@ -1,2 +1,2 @@
 major=16
-minor=2
+minor=3
Index: usr.sbin/procmap/procmap.c
===================================================================
RCS file: /cvs/src/usr.sbin/procmap/procmap.c,v
retrieving revision 1.63
diff -u -p -r1.63 procmap.c
--- usr.sbin/procmap/procmap.c  16 Sep 2016 04:45:35 -0000      1.63
+++ usr.sbin/procmap/procmap.c  20 Jun 2017 01:03:05 -0000
@@ -580,10 +580,10 @@ load_vm_map_entries(kvm_t *kd, struct vm
 
        /* RBTs point at rb_entries inside nodes */
        ld = load_vm_map_entries(kd, RBT_LEFT(uvm_map_addr, result), result);
-       result->daddrs.addr_entry.rbt_left = &ld->daddrs.addr_entry;
+       RBT_SET_LEFT(uvm_map_addr, result, ld);
        ld = load_vm_map_entries(kd, RBT_RIGHT(uvm_map_addr, result), result);
-       result->daddrs.addr_entry.rbt_right = &ld->daddrs.addr_entry;
-       result->daddrs.addr_entry.rbt_parent = &parent->daddrs.addr_entry;
+       RBT_SET_RIGHT(uvm_map_addr, result, ld);
+       RBT_SET_PARENT(uvm_map_addr, result, parent);
 
        return result;
 }

Reply via email to