@samitouri / QOSamiQemu / commits / 7c1a3ad10e

common-user: Initialize mmap_min_addr for FreeBSD

Use sysctl to fetch the vm layout of the current process. Reviewed-by: Helge Deller <deller@gmx.de> Reviewed-by: Warner Losh <imp@bsdimp.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Richard Henderson committed May 29, 2026 at 21:16 UTC 7c1a3ad10e2dc6a252d4ff62ecca221864a78f2c
1 file changed +13
common-user/mmap-min-addr.c
+13
@@ -5,6 +5,10 @@
5
6 #include "qemu/osdep.h"
7 #include "user/mmap-min-addr.h"
8 +#ifdef __FreeBSD__
9 +#include <sys/sysctl.h>
10 +#include <sys/user.h>
11 +#endif
12
13 uintptr_t mmap_min_addr;
14
@@ -31,6 +35,15 @@ static void __attribute__((constructor)) init(void)
35 fclose(fp);
36 }
37 mmap_min_addr = min_addr;
38 +#elif defined(__FreeBSD__)
39 + int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_VM_LAYOUT, getpid() };
40 + struct kinfo_vm_layout info;
41 + size_t info_len = sizeof(info);
42 +
43 + mmap_min_addr =
44 + (sysctl(mib, ARRAY_SIZE(mib), &info, &info_len, NULL, 0) < 0
45 + ? qemu_real_host_page_size()
46 + : info.kvm_min_user_addr);
47 #else
48 # error
49 #endif