Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F153986201
D41236.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D41236.diff
View Options
diff --git a/tests/sys/vm/Makefile b/tests/sys/vm/Makefile
--- a/tests/sys/vm/Makefile
+++ b/tests/sys/vm/Makefile
@@ -9,4 +9,12 @@
page_fault_signal \
shared_shadow_inval_test
+.if ${MACHINE_ARCH} != "i386" && ${MACHINE} != "arm" && \
+ (${MACHINE} != "powerpc" || ${MACHINE_ARCH} != "powerpc")
+ # MAP_32BIT is only available on 64-bit platforms
+BINDIR= ${TESTSDIR}
+ATF_TESTS_SH+= mmap_map_32bit_test
+PROGS+= mmap_map_32bit_helper
+.endif
+
.include <bsd.test.mk>
diff --git a/tests/sys/vm/mmap_map_32bit_helper.c b/tests/sys/vm/mmap_map_32bit_helper.c
new file mode 100644
--- /dev/null
+++ b/tests/sys/vm/mmap_map_32bit_helper.c
@@ -0,0 +1,51 @@
+/*-
+ * Copyright (c) 2023 Dmitry Chagin <dchagin@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <sys/mman.h>
+
+#include <err.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+_Static_assert(sizeof(vm_offset_t) >= 8, "Test is not intended for ILP32");
+#define MAP_32BIT_MAX_ADDR ((vm_offset_t)1 << 31)
+
+int
+main(void)
+{
+ size_t pagesize;
+ void *s32;
+ int fd;
+
+ if ((pagesize = getpagesize()) <= 0)
+ err(1, "getpagesize");
+
+ fd = open("/dev/zero", O_RDONLY);
+ if (fd <= 0)
+ err(1, "open failed");
+
+ s32 = mmap(NULL, pagesize, PROT_READ, MAP_32BIT | MAP_PRIVATE, fd, 0);
+ if (s32 == MAP_FAILED)
+ err(1, "mmap MAP_32BIT | MAP_PRIVATE failed");
+ if (((vm_offset_t)s32 + pagesize) > MAP_32BIT_MAX_ADDR)
+ errx(1, "mmap invalid result %p", s32);
+
+ close(fd);
+ if (munmap(s32, pagesize) != 0)
+ err(1, "munmap failed");
+
+ s32 = mmap(NULL, pagesize, PROT_READ | PROT_WRITE,
+ MAP_32BIT | MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+ if (s32 == MAP_FAILED)
+ err(1, "mmap MAP_32BIT | MAP_ANONYMOUS | MAP_PRIVATE failed");
+ if (((vm_offset_t)s32 + pagesize) > MAP_32BIT_MAX_ADDR)
+ errx(1, "mmap invalid result %p", s32);
+
+ if (munmap(s32, pagesize) != 0)
+ err(1, "munmap failed");
+ exit(0);
+}
diff --git a/tests/sys/vm/mmap_map_32bit_test.sh b/tests/sys/vm/mmap_map_32bit_test.sh
new file mode 100644
--- /dev/null
+++ b/tests/sys/vm/mmap_map_32bit_test.sh
@@ -0,0 +1,37 @@
+#
+# Copyright (c) 2022 Dmitry Chagin <dchagin@FreeBSD.org>
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Simple test of MAP_32BIT flag w/wo ASLR
+
+map_32bit_w_aslr_head()
+{
+ atf_set descr "MAP_32BIT with ASLR"
+ atf_set require.progs proccontrol
+}
+
+map_32bit_w_aslr_body()
+{
+ atf_check -s exit:0 -x proccontrol -m aslr -s enable \
+ $(atf_get_srcdir)/mmap_map_32bit_helper
+}
+
+map_32bit_wo_aslr_head()
+{
+ atf_set descr "MAP_32BIT without ASLR"
+ atf_set require.progs proccontrol
+}
+
+map_32bit_wo_aslr_body()
+{
+ atf_check -s exit:0 -x proccontrol -m aslr -s disable \
+ $(atf_get_srcdir)/mmap_map_32bit_helper
+}
+
+
+atf_init_test_cases()
+{
+ atf_add_test_case map_32bit_w_aslr
+ atf_add_test_case map_32bit_wo_aslr
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Apr 26, 6:42 AM (1 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
32170352
Default Alt Text
D41236.diff (2 KB)
Attached To
Mode
D41236: tests: Add MAP_32BIT flag test
Attached
Detach File
Event Timeline
Log In to Comment