git: 748f7c8db756 - main - Have stpncpy tests ask the kernel for the page size

From: Andrew Turner <andrew_at_FreeBSD.org>
Date: Thu, 07 Apr 2022 15:14:14 UTC
The branch main has been updated by andrew:

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

commit 748f7c8db756361f3ba43623612fcfd13cece268
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2022-04-07 15:05:57 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2022-04-07 15:08:37 +0000

    Have stpncpy tests ask the kernel for the page size
    
    It may be dynamic so we can't rely on PAGE_SIZE being present or
    correct.
---
 lib/libc/tests/string/stpncpy_test.c | 13 ++++++++-----
 lib/libc/tests/string/wcsnlen_test.c | 13 ++++++++-----
 2 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/lib/libc/tests/string/stpncpy_test.c b/lib/libc/tests/string/stpncpy_test.c
index 0a7b1d28e9c1..618fa7d0a2ce 100644
--- a/lib/libc/tests/string/stpncpy_test.c
+++ b/lib/libc/tests/string/stpncpy_test.c
@@ -40,16 +40,19 @@ static char *
 makebuf(size_t len, int guard_at_end)
 {
 	char *buf;
-	size_t alloc_size = roundup2(len, PAGE_SIZE) + PAGE_SIZE;
+	size_t alloc_size, page_size;
+
+	page_size = getpagesize();
+	alloc_size = roundup2(len, page_size) + page_size;
 
 	buf = mmap(NULL, alloc_size, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0);
 	assert(buf);
 	if (guard_at_end) {
-		assert(munmap(buf + alloc_size - PAGE_SIZE, PAGE_SIZE) == 0);
-		return (buf + alloc_size - PAGE_SIZE - len);
+		assert(munmap(buf + alloc_size - page_size, page_size) == 0);
+		return (buf + alloc_size - page_size - len);
 	} else {
-		assert(munmap(buf, PAGE_SIZE) == 0);
-		return (buf + PAGE_SIZE);
+		assert(munmap(buf, page_size) == 0);
+		return (buf + page_size);
 	}
 }
 
diff --git a/lib/libc/tests/string/wcsnlen_test.c b/lib/libc/tests/string/wcsnlen_test.c
index 07870e3a5ca0..7bcd046de5af 100644
--- a/lib/libc/tests/string/wcsnlen_test.c
+++ b/lib/libc/tests/string/wcsnlen_test.c
@@ -41,16 +41,19 @@ static void *
 makebuf(size_t len, int guard_at_end)
 {
 	char *buf;
-	size_t alloc_size = roundup2(len, PAGE_SIZE) + PAGE_SIZE;
+	size_t alloc_size, page_size;
+
+	page_size = getpagesize();
+	alloc_size = roundup2(len, page_size) + page_size;
 
 	buf = mmap(NULL, alloc_size, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0);
 	ATF_CHECK(buf);
 	if (guard_at_end) {
-		ATF_CHECK(munmap(buf + alloc_size - PAGE_SIZE, PAGE_SIZE) == 0);
-		return (buf + alloc_size - PAGE_SIZE - len);
+		ATF_CHECK(munmap(buf + alloc_size - page_size, page_size) == 0);
+		return (buf + alloc_size - page_size - len);
 	} else {
-		ATF_CHECK(munmap(buf, PAGE_SIZE) == 0);
-		return (buf + PAGE_SIZE);
+		ATF_CHECK(munmap(buf, page_size) == 0);
+		return (buf + page_size);
 	}
 }