From da8c54306e151c62b373d382a8b41033082802cf Mon Sep 17 00:00:00 2001 From: cludwig Date: Thu, 26 Feb 2026 14:05:25 +0000 Subject: [PATCH] regress/mmap: Test hints in VM-area edge cases Test mmap(2) with hint above VM_MAXUSER_ADDRESS without MAP_FIXED. This tests uvm_map.c,v 1.355. Also test the lower boundary below PAGE_SIZE. ok kettenis@ --- regress/sys/uvm/mmap_hint/mmap_hint.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/regress/sys/uvm/mmap_hint/mmap_hint.c b/regress/sys/uvm/mmap_hint/mmap_hint.c index 95ba5e60144..e3aeffc15ac 100644 --- a/regress/sys/uvm/mmap_hint/mmap_hint.c +++ b/regress/sys/uvm/mmap_hint/mmap_hint.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mmap_hint.c,v 1.6 2021/12/13 16:56:50 deraadt Exp $ */ +/* $OpenBSD: mmap_hint.c,v 1.7 2026/02/26 14:05:25 cludwig Exp $ */ /* * Copyright (c) 2011 Ariane van der Steldt * @@ -52,7 +52,8 @@ mmap_hint(void *hint) else delta = p - hint; - if (hint != NULL && delta > MAX_HINT_DIST) { + if (hint != NULL && hint < (void *)VM_MAXUSER_ADDRESS && + delta > MAX_HINT_DIST) { warnx("hinted allocation more than %#zx bytes away from hint: " "hint %p, result %p", delta, hint, p); errors++; @@ -100,5 +101,15 @@ main() } skip4: + /* Check hinted allocation below PAGE_SIZE. */ + hint = (void *)1UL; + fprintf(stderr, "5: Checking hint below PAGE_SIZE %p mmap\n", hint); + p = mmap_hint(hint); + + /* Check hinted allocation above userspace. */ + hint = (void *)VM_MAX_ADDRESS; + fprintf(stderr, "6: Checking hint at VM_MAX_ADDRESS %p mmap\n", hint); + p = mmap_hint(hint); + return errors; }