]> git.saurik.com Git - apple/xnu.git/blob - tests/restrict_jit.c
xnu-7195.101.1.tar.gz
[apple/xnu.git] / tests / restrict_jit.c
1 #include <stdlib.h>
2 #include <unistd.h>
3 #include <sys/sysctl.h>
4 #include <sys/mman.h>
5
6 #include <darwintest.h>
7
8
9 /*
10 * macOS only test. Try to map 2 different MAP_JIT regions. 2nd should fail.
11 */
12 T_DECL(restrict_jit, "macOS restricted JIT entitlement test")
13 {
14 #if TARGET_OS_OSX
15 void *addr1;
16 void *addr2;
17 size_t size = 64 * 1024;
18
19
20 addr1 = mmap(NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE | MAP_JIT, -1, 0);
21 T_ASSERT_NE_PTR(addr1, MAP_FAILED, "First map MAP_JIT");
22
23 addr2 = mmap(NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE | MAP_JIT, -1, 0);
24 if (addr2 == MAP_FAILED) {
25 T_PASS("Only one MAP_JIT was allowed");
26 } else {
27 T_FAIL("Second MAP_JIT was allowed");
28 }
29
30 #else
31 T_SKIP("Not macOS");
32 #endif
33 }