mmap_test: determine page size at run time rather than compile time

Sponsored by:	Netflix
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D52735
This commit is contained in:
Chuck Silvers
2025-10-13 09:13:22 -07:00
parent 24458c2431
commit d5cfca008d
+16 -15
View File
@@ -36,21 +36,6 @@
#include <stdio.h>
#include <stdlib.h>
static const struct {
void *addr;
int ok[2]; /* Depending on security.bsd.map_at_zero {0, !=0}. */
} map_at_zero_tests[] = {
{ (void *)0, { 0, 1 } }, /* Test sysctl. */
{ (void *)1, { 0, 0 } },
{ (void *)(PAGE_SIZE - 1), { 0, 0 } },
{ (void *)PAGE_SIZE, { 1, 1 } },
{ (void *)-1, { 0, 0 } },
{ (void *)(-PAGE_SIZE), { 0, 0 } },
{ (void *)(-1 - PAGE_SIZE), { 0, 0 } },
{ (void *)(-1 - PAGE_SIZE - 1), { 0, 0 } },
{ (void *)(0x1000 * PAGE_SIZE), { 1, 1 } },
};
#define MAP_AT_ZERO "security.bsd.map_at_zero"
#ifdef __LP64__
@@ -68,6 +53,22 @@ ATF_TC_BODY(mmap__map_at_zero, tc)
int map_at_zero;
bool allow_wx;
int prot_flags;
size_t pgsz = getpagesize();
const struct {
void *addr;
int ok[2]; /* Depending on security.bsd.map_at_zero {0, !=0}. */
} map_at_zero_tests[] = {
{ (void *)0, { 0, 1 } }, /* Test sysctl. */
{ (void *)1, { 0, 0 } },
{ (void *)(pgsz - 1), { 0, 0 } },
{ (void *)pgsz, { 1, 1 } },
{ (void *)-1, { 0, 0 } },
{ (void *)(-pgsz), { 0, 0 } },
{ (void *)(-1 - pgsz), { 0, 0 } },
{ (void *)(-1 - pgsz - 1), { 0, 0 } },
{ (void *)(0x1000 * pgsz), { 1, 1 } },
};
len = sizeof(map_at_zero);
if (sysctlbyname(MAP_AT_ZERO, &map_at_zero, &len, NULL, 0) == -1) {