1*c54f35caSApple OSS Distributions #include <darwintest.h>
2*c54f35caSApple OSS Distributions #include <mach/vm_page_size.h>
3*c54f35caSApple OSS Distributions
4*c54f35caSApple OSS Distributions T_GLOBAL_META(
5*c54f35caSApple OSS Distributions T_META_NAMESPACE("vm_page_size_overrides")
6*c54f35caSApple OSS Distributions );
7*c54f35caSApple OSS Distributions
8*c54f35caSApple OSS Distributions static void
verify_page_size(int expected_shift,int page_shift,vm_size_t page_size,vm_size_t page_mask)9*c54f35caSApple OSS Distributions verify_page_size(
10*c54f35caSApple OSS Distributions int expected_shift,
11*c54f35caSApple OSS Distributions int page_shift,
12*c54f35caSApple OSS Distributions vm_size_t page_size,
13*c54f35caSApple OSS Distributions vm_size_t page_mask)
14*c54f35caSApple OSS Distributions {
15*c54f35caSApple OSS Distributions T_ASSERT_EQ(page_shift, expected_shift, "page_shift");
16*c54f35caSApple OSS Distributions T_ASSERT_EQ(page_size, 1UL << expected_shift, "page_size");
17*c54f35caSApple OSS Distributions T_ASSERT_EQ(page_mask, page_size - 1, "page_mask");
18*c54f35caSApple OSS Distributions }
19*c54f35caSApple OSS Distributions
20*c54f35caSApple OSS Distributions
21*c54f35caSApple OSS Distributions T_DECL(kernel_4k,
22*c54f35caSApple OSS Distributions "Can override vm_kernel_page_size",
23*c54f35caSApple OSS Distributions T_META_ENVVAR("VM_KERNEL_PAGE_SIZE_4K=1"),
24*c54f35caSApple OSS Distributions T_META_ENVVAR("MallocGuardEdges=0"),
25*c54f35caSApple OSS Distributions T_META_ENVVAR("MallocDoNotProtectPrelude=1"),
26*c54f35caSApple OSS Distributions T_META_ENVVAR("MallocDoNotProtectPostlude=1"))
27*c54f35caSApple OSS Distributions {
28*c54f35caSApple OSS Distributions verify_page_size(12, vm_kernel_page_shift, vm_kernel_page_size, vm_kernel_page_mask);
29*c54f35caSApple OSS Distributions }
30*c54f35caSApple OSS Distributions
31*c54f35caSApple OSS Distributions T_DECL(invalid,
32*c54f35caSApple OSS Distributions "Invalid overrides",
33*c54f35caSApple OSS Distributions T_META_ENVVAR("VM_KERNEL_PAGE_SIZE_4K=2"),
34*c54f35caSApple OSS Distributions T_META_ENVVAR("VM_KERNEL_PAGE_SIZE=4K"),
35*c54f35caSApple OSS Distributions T_META_ENVVAR("VM_KERNEL_PAGE_SIZE="))
36*c54f35caSApple OSS Distributions {
37*c54f35caSApple OSS Distributions /*
38*c54f35caSApple OSS Distributions * This test just verifies that libkernel_init doesn't
39*c54f35caSApple OSS Distributions * crash when handling invalid overrides.
40*c54f35caSApple OSS Distributions * So if we got here, we can pass the test.
41*c54f35caSApple OSS Distributions */
42*c54f35caSApple OSS Distributions T_PASS("Test process spawned");
43*c54f35caSApple OSS Distributions }
44