On Sat, May 30, 2026 at 3:12 PM Richard Henderson < [email protected]> wrote:
> Use sysctl to fetch the vm layout of the current process. > > Signed-off-by: Richard Henderson <[email protected]> > --- > common-user/mmap-min-addr.c | 13 +++++++++++++ > 1 file changed, 13 insertions(+ > Reviewed-by: Warner Losh <[email protected]> I hardcoded my version to qemu_real_host_page_size(), but this is better than what I'd done. It keeps it from being 0, and the FreeBSD kernel won't map anything between this value and info.kvm_min_user_addr. I do know that x86 and aarch64 these are two are the same value, and those are the only hosts I care about at the moment (until I get through the upstreaming backlog). > diff --git a/common-user/mmap-min-addr.c b/common-user/mmap-min-addr.c > index b2b3762386..830c6f66a0 100644 > --- a/common-user/mmap-min-addr.c > +++ b/common-user/mmap-min-addr.c > @@ -5,6 +5,10 @@ > > #include "qemu/osdep.h" > #include "user/mmap-min-addr.h" > +#ifdef __FreeBSD__ > +#include <sys/sysctl.h> > +#include <sys/user.h> > +#endif > > uintptr_t mmap_min_addr; > > @@ -31,6 +35,15 @@ static void __attribute__((constructor)) init(void) > fclose(fp); > } > mmap_min_addr = min_addr; > +#elif defined(__FreeBSD__) > + int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_VM_LAYOUT, getpid() }; > + struct kinfo_vm_layout info; > + size_t info_len = sizeof(info); > + > + mmap_min_addr = > + (sysctl(mib, ARRAY_SIZE(mib), &info, &info_len, NULL, 0) < 0 > + ? qemu_real_host_page_size() > + : info.kvm_min_user_addr); > #else > # error > #endif > -- > 2.43.0 > >
