Skip to contentSkip to conversation

*-user: probe_guest_base improvments

PATCH In review Richard Henderson 3 participants 4 messages Jun 18

lore
Share & tools
lore
#0 lore raw

v4 cover *-user: probe_guest_base improvments

OMG.

Changes for v4:
- Really, really include the read_self_maps rewrite from Warner.

Only sending patch 10 this time. :-(

r~

Richard Henderson (13):
linux-user: Introduce PGBRange
linux-user: Use PGBRange in load_elf_image
linux-user: Drop hiaddr out-of-range check in probe_guest_base
linux-user: Pass image_range to probe_guest_base
linux-user: Use PGBRange for commpage
common-user: Move mmap_min_addr from linux-user
common-user: Initialize mmap_min_addr for FreeBSD include/user/guest-host: Include missing cpu.h
common-user: Move selfmap from util
common-user: Implement read_self_maps for FreeBSD
common-user: Move probe_guest_base from linux-user
bsd-user: Use probe_guest_base
common-user: Move guest_base, have_guest_base to probe-guest-base.c

 include/user/guest-host.h        |   1 +
 include/user/mmap-min-addr.h     |  12 +
 include/user/probe-guest-base.h  |  37 +++
 include/{qemu => user}/selfmap.h |   0
 linux-user/arm/target_elf.h      |   2 +-
 linux-user/hppa/target_elf.h     |   2 +-
 linux-user/user-internals.h      |  17 +-
 bsd-user/elfload.c               |  37 +--
 bsd-user/main.c                  |  42 +---
 common-user/mmap-min-addr.c      |  50 ++++
 common-user/probe-guest-base.c   | 347 +++++++++++++++++++++++++++
 {util => common-user}/selfmap.c  |  49 +++-
 linux-user/arm/elfload.c         |   2 +-
 linux-user/elfload.c             | 400 ++-----------------------------
 linux-user/flatload.c            |   3 +-
 linux-user/hppa/elfload.c        |   4 +-
 linux-user/main.c                |  35 +--
 linux-user/mmap.c                |   1 +
 linux-user/syscall.c             |   2 +-
 common-user/meson.build          |   3 +
 util/meson.build                 |   4 -
 21 files changed, 564 insertions(+), 486 deletions(-)
 create mode 100644 include/user/mmap-min-addr.h
 create mode 100644 include/user/probe-guest-base.h
 rename include/{qemu => user}/selfmap.h (100%)
 create mode 100644 common-user/mmap-min-addr.c
 create mode 100644 common-user/probe-guest-base.c
 rename {util => common-user}/selfmap.c (68%)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v4 10/13 common-user: Implement read_self_maps for FreeBSD

Use sysctl to fetch the vm map of the current process.

---
 common-user/selfmap.c | 45 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)
common-user/selfmap.c +44 -1
index a1b88dee66..139dae15e8 100644
@@ -9,6 +9,10 @@
 #include "qemu/osdep.h"
 #include "qemu/cutils.h"
 #include "user/selfmap.h"
+#ifdef __FreeBSD__
+#include <sys/sysctl.h>
+#include <sys/user.h>
+#endif
 
 IntervalTreeRoot *read_self_maps(void)
 {
@@ -80,9 +84,48 @@ IntervalTreeRoot *read_self_maps(void)
     g_strfreev(lines);
     g_free(maps);
 
+    return root;
+#elif defined(__FreeBSD__)
+    int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_VMMAP, getpid() };
+    size_t len = 0;
+    g_autofree void *buf = NULL;
+    IntervalTreeRoot *root;
+
+    /* Probe for buffer size. */
+    if (sysctl(mib, ARRAY_SIZE(mib), NULL, &len, NULL, 0) < 0) {
+        return NULL;
+    }
+
+    buf = g_malloc(len);
+    if (sysctl(mib, ARRAY_SIZE(mib), buf, &len, NULL, 0) < 0) {
+        return NULL;
+    }
+
+    root = g_new0(IntervalTreeRoot, 1);
+
+    for (size_t i = 0; i < len; ) {
+        struct kinfo_vmentry *k = buf + i;
+        MapInfo *e = g_new0(MapInfo, 1);
+
+        e->itree.start = k->kve_start;
+        e->itree.last = k->kve_end - 1;
+
+        /*
+         * TODO: The rest of the fields in MapInfo are used by linux-user
+         * for the implementation of open_self_maps().  These fields are
+         * quite specific to the textual format of /proc/self/maps.
+         *
+         * We may need something different to emulate KERN_PROC_VMMAP
+         * in bsd-user, but so far they're unused -- leave them zeroed.
+         */
+
+        interval_tree_insert(&e->itree, root);
+        i += k->kve_structsize;
+    }
+
     return root;
 #else
-    return NULL;
+# error
 #endif
 }
 
Signature · 1 line
2.43.0
Reviewed-by on v4 10/13
#2 lore raw

Re: [PATCH v4 10/13] common-user: Implement read_self_maps for FreeBSD

Quoted 2 lines · Richard Henderson

Use sysctl to fetch the vm map of the current process.

Co-developed with Warner?

Quoted 4 lines
---
  common-user/selfmap.c | 45 ++++++++++++++++++++++++++++++++++++++++++-
  1 file changed, 44 insertions(+), 1 deletion(-)
#3 lore raw

Re: [PATCH v4 10/13] common-user: Implement read_self_maps for FreeBSD

Quoted 6 lines · Philippe Mathieu-Daudé
Quoted 2 lines · Richard Henderson

Use sysctl to fetch the vm map of the current process.

Co-developed with Warner?

I'm good with whatever we do here... I'm easy.

Quoted 9 lines
Quoted 4 lines
---
  common-user/selfmap.c | 45 ++++++++++++++++++++++++++++++++++++++++++-
  1 file changed, 44 insertions(+), 1 deletion(-)