]> git.saurik.com Git - apple/xnu.git/blame - tests/jumbo_va_spaces_28530648.c
xnu-6153.11.26.tar.gz
[apple/xnu.git] / tests / jumbo_va_spaces_28530648.c
CommitLineData
813fb2f6
A
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
cb323159 10T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
813fb2f6
A
11
12#define GB (1ULL * 1024 * 1024 * 1024)
13
14/*
15 * This test expects the entitlement to be the enabling factor for a process to
16 * allocate at least this many GB of VA space. i.e. with the entitlement, n GB
17 * must be allocatable; whereas without it, it must be less.
18 */
a39ff7e2 19#define ALLOC_TEST_GB 54
813fb2f6 20
0a7de745 21#if defined(ENTITLED)
813fb2f6 22T_DECL(jumbo_va_spaces_28530648,
0a7de745
A
23#else
24T_DECL(jumbo_va_spaces_28530648_unentitled,
25#endif
813fb2f6
A
26 "Verify that the \"dynamic-codesigning\" entitlement is required to utilize an extra-large "
27 "VA space on arm64",
28 T_META_NAMESPACE("xnu.vm"),
29 T_META_CHECK_LEAKS(false))
30{
31 int i;
32 void *res;
33
34 if (!dt_64_bit_kernel()) {
35 T_SKIP("This test is only applicable to arm64");
36 }
37
38 T_LOG("Attemping to allocate VA space in 1 GB chunks.");
39
40 for (i = 0; i < (ALLOC_TEST_GB * 2); i++) {
41 res = mmap(NULL, 1 * GB, PROT_NONE, MAP_PRIVATE | MAP_ANON, 0, 0);
42 if (res == MAP_FAILED) {
43 if (errno != ENOMEM) {
44 T_WITH_ERRNO;
45 T_LOG("mmap failed: stopped at %d of %d GB allocated", i, ALLOC_TEST_GB);
46 }
47 break;
48 } else {
49 T_LOG("%d: %p\n", i, res);
50 }
51 }
52
53#if defined(ENTITLED)
54 T_EXPECT_GE_INT(i, ALLOC_TEST_GB, "Allocate at least %d GB of VA space", ALLOC_TEST_GB);
55#else
56 T_EXPECT_LT_INT(i, ALLOC_TEST_GB, "Not permitted to allocate %d GB of VA space", ALLOC_TEST_GB);
57#endif
58}