]>
Commit | Line | Data |
---|---|---|
1 | #include <stdio.h> | |
2 | #include <errno.h> | |
3 | #include <string.h> | |
4 | #include <unistd.h> | |
5 | #include <sys/mman.h> | |
6 | ||
7 | #include <darwintest.h> | |
8 | #include <darwintest_utils.h> | |
9 | ||
10 | ||
11 | #define GB (1ULL * 1024 * 1024 * 1024) | |
12 | ||
13 | /* | |
14 | * This test expects the entitlement to be the enabling factor for a process to | |
15 | * allocate at least this many GB of VA space. i.e. with the entitlement, n GB | |
16 | * must be allocatable; whereas without it, it must be less. | |
17 | */ | |
18 | #define ALLOC_TEST_GB 54 | |
19 | ||
20 | #if defined(ENTITLED) | |
21 | T_DECL(jumbo_va_spaces_28530648, | |
22 | #else | |
23 | T_DECL(jumbo_va_spaces_28530648_unentitled, | |
24 | #endif | |
25 | "Verify that the \"dynamic-codesigning\" entitlement is required to utilize an extra-large " | |
26 | "VA space on arm64", | |
27 | T_META_NAMESPACE("xnu.vm"), | |
28 | T_META_CHECK_LEAKS(false)) | |
29 | { | |
30 | int i; | |
31 | void *res; | |
32 | ||
33 | if (!dt_64_bit_kernel()) { | |
34 | T_SKIP("This test is only applicable to arm64"); | |
35 | } | |
36 | ||
37 | T_LOG("Attemping to allocate VA space in 1 GB chunks."); | |
38 | ||
39 | for (i = 0; i < (ALLOC_TEST_GB * 2); i++) { | |
40 | res = mmap(NULL, 1 * GB, PROT_NONE, MAP_PRIVATE | MAP_ANON, 0, 0); | |
41 | if (res == MAP_FAILED) { | |
42 | if (errno != ENOMEM) { | |
43 | T_WITH_ERRNO; | |
44 | T_LOG("mmap failed: stopped at %d of %d GB allocated", i, ALLOC_TEST_GB); | |
45 | } | |
46 | break; | |
47 | } else { | |
48 | T_LOG("%d: %p\n", i, res); | |
49 | } | |
50 | } | |
51 | ||
52 | #if defined(ENTITLED) | |
53 | T_EXPECT_GE_INT(i, ALLOC_TEST_GB, "Allocate at least %d GB of VA space", ALLOC_TEST_GB); | |
54 | #else | |
55 | T_EXPECT_LT_INT(i, ALLOC_TEST_GB, "Not permitted to allocate %d GB of VA space", ALLOC_TEST_GB); | |
56 | #endif | |
57 | } |