1*d8b80295SApple OSS Distributions #include <errno.h>
2*d8b80295SApple OSS Distributions #include <unistd.h>
3*d8b80295SApple OSS Distributions #include <sys/mman.h>
4*d8b80295SApple OSS Distributions
5*d8b80295SApple OSS Distributions #include <darwintest.h>
6*d8b80295SApple OSS Distributions
7*d8b80295SApple OSS Distributions #include "jumbo_va_spaces_common.h"
8*d8b80295SApple OSS Distributions
9*d8b80295SApple OSS Distributions #define GB (1ULL * 1024 * 1024 * 1024)
10*d8b80295SApple OSS Distributions
11*d8b80295SApple OSS Distributions /*
12*d8b80295SApple OSS Distributions * This test expects the entitlement to be the enabling factor for a process to
13*d8b80295SApple OSS Distributions * allocate at least this many GB of VA space. i.e. with the entitlement, n GB
14*d8b80295SApple OSS Distributions * must be allocatable; whereas without it, it must be less.
15*d8b80295SApple OSS Distributions * This value was determined experimentally to fit on applicable devices and to
16*d8b80295SApple OSS Distributions * be clearly distinguishable from the default VA limit.
17*d8b80295SApple OSS Distributions */
18*d8b80295SApple OSS Distributions #define ALLOC_TEST_GB 51
19*d8b80295SApple OSS Distributions
20*d8b80295SApple OSS Distributions void
verify_jumbo_va(bool entitled)21*d8b80295SApple OSS Distributions verify_jumbo_va(bool entitled)
22*d8b80295SApple OSS Distributions {
23*d8b80295SApple OSS Distributions T_LOG("Attemping to allocate VA space in 1 GB chunks.");
24*d8b80295SApple OSS Distributions void *res;
25*d8b80295SApple OSS Distributions int i;
26*d8b80295SApple OSS Distributions
27*d8b80295SApple OSS Distributions for (i = 0; i < (ALLOC_TEST_GB * 2); i++) {
28*d8b80295SApple OSS Distributions res = mmap(NULL, 1 * GB, PROT_NONE, MAP_PRIVATE | MAP_ANON, 0, 0);
29*d8b80295SApple OSS Distributions if (res == MAP_FAILED) {
30*d8b80295SApple OSS Distributions if (errno != ENOMEM) {
31*d8b80295SApple OSS Distributions T_WITH_ERRNO;
32*d8b80295SApple OSS Distributions T_LOG("mmap failed: stopped at %d of %d GB allocated", i, ALLOC_TEST_GB);
33*d8b80295SApple OSS Distributions }
34*d8b80295SApple OSS Distributions break;
35*d8b80295SApple OSS Distributions } else {
36*d8b80295SApple OSS Distributions T_LOG("%d: %p\n", i, res);
37*d8b80295SApple OSS Distributions }
38*d8b80295SApple OSS Distributions }
39*d8b80295SApple OSS Distributions
40*d8b80295SApple OSS Distributions if (entitled) {
41*d8b80295SApple OSS Distributions T_EXPECT_GE_INT(i, ALLOC_TEST_GB, "Allocate at least %d GB of VA space", ALLOC_TEST_GB);
42*d8b80295SApple OSS Distributions } else {
43*d8b80295SApple OSS Distributions T_EXPECT_LT_INT(i, ALLOC_TEST_GB, "Not permitted to allocate %d GB of VA space", ALLOC_TEST_GB);
44*d8b80295SApple OSS Distributions }
45*d8b80295SApple OSS Distributions }
46