Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F176972697
D41236.1793675391.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
D41236.1793675391.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_ARCH} != "powerpc" && \
+ ${MACHINE_ARCH} != "powerpcspe"
+ # 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,49 @@
+/*-
+ * 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>
+
+#define MAP_32BIT_MAX_ADDR ((vm_offset_t)1 << 31)
+
+int
+main(void)
+{
+ size_t pagesize;
+ void *s32;
+ int fd;
+
+ pagesize = getpagesize();
+ if (pagesize <= 0)
+ err(1, "pagesize");
+
+ 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 > MAP_32BIT_MAX_ADDR)
+ err(1, "mmap invalid result %p", s32);
+
+ close(fd);
+ munmap(s32, pagesize);
+
+ 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 > MAP_32BIT_MAX_ADDR)
+ err(1, "mmap invalid result %p", s32);
+
+ munmap(s32, pagesize);
+ 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,35 @@
+#
+# 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
Tue, Nov 3, 3:09 AM (5 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41354554
Default Alt Text
D41236.1793675391.diff (2 KB)
Attached To
Mode
D41236: tests: Add MAP_32BIT flag test
Attached
Detach File
Event Timeline