git: d017d1faa136 - stable/13 - Have the coredump_phnum test ask for the page size

From: Andrew Turner <andrew_at_FreeBSD.org>
Date: Tue, 03 May 2022 14:04:43 UTC
The branch stable/13 has been updated by andrew:

URL: https://cgit.FreeBSD.org/src/commit/?id=d017d1faa1363234f3e76045fe30f6ed9321fc9c

commit d017d1faa1363234f3e76045fe30f6ed9321fc9c
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2022-04-07 14:59:32 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2022-05-03 14:04:04 +0000

    Have the coredump_phnum test ask for the page size
    
    The page size may be dynamically selected on boot. Have the
    coredump_phnum test helper ask the kernel for the correct value.
    
    Sponsored by:   The FreeBSD Foundation
    
    (cherry picked from commit df696a2fb640aee06b38ff487985209f97b944aa)
---
 tests/sys/kern/coredump_phnum_helper.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/tests/sys/kern/coredump_phnum_helper.c b/tests/sys/kern/coredump_phnum_helper.c
index 0dff59b918d9..1cdd4a4a09ec 100644
--- a/tests/sys/kern/coredump_phnum_helper.c
+++ b/tests/sys/kern/coredump_phnum_helper.c
@@ -33,6 +33,7 @@
 #include <err.h>
 #include <stdint.h>
 #include <stdlib.h>
+#include <unistd.h>
 
 /*
  * This program is intended to create a bunch of segment mappings, then dump
@@ -42,10 +43,11 @@ int
 main(int argc __unused, char **argv __unused)
 {
 	void *v;
-	size_t i, pages;
+	size_t i, pages, page_size;
 
+	page_size = getpagesize();
 	pages = UINT16_MAX + 1000;
-	v = mmap(NULL, pages * PAGE_SIZE, PROT_READ | PROT_WRITE,
+	v = mmap(NULL, pages * page_size, PROT_READ | PROT_WRITE,
 	    MAP_ANON | MAP_PRIVATE, -1, 0);
 	if (v == NULL)
 		err(1, "mmap");
@@ -54,7 +56,7 @@ main(int argc __unused, char **argv __unused)
 		 * Alternate protections to interleave RW and R PT_LOAD
 		 * segments.
 		 */
-		if (mprotect((char *)v + i * PAGE_SIZE, PAGE_SIZE,
+		if (mprotect((char *)v + i * page_size, page_size,
 		    PROT_READ) != 0)
 			err(1, "mprotect");
 	}