git: 3935c58c2157 - stable/13 - Have stpncpy tests ask the kernel for the page size
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 03 May 2022 14:04:45 UTC
The branch stable/13 has been updated by andrew:
URL: https://cgit.FreeBSD.org/src/commit/?id=3935c58c2157388f973d24495d4187ce4bfbd379
commit 3935c58c2157388f973d24495d4187ce4bfbd379
Author: Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2022-04-07 15:05:57 +0000
Commit: Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2022-05-03 14:04:04 +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.
(cherry picked from commit 748f7c8db756361f3ba43623612fcfd13cece268)
---
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);
}
}