]>
git.saurik.com Git - apple/xnu.git/blob - tests/sr_entitlement.c
b0c496d15d1a6c5d1fd6830ecea96a8a19a66063
3 #include <sys/sysctl.h>
5 #include <darwintest.h>
6 #include <darwintest_utils.h>
8 T_GLOBAL_META(T_META_RUN_CONCURRENTLY(false));
10 static int after_regions
= 0;
13 * No system(3c) on watchOS, so provide our own.
16 my_system(const char *command
)
20 const char *argv
[] = {
27 if (dt_launch_tool(&pid
, (char **)(void *)argv
, FALSE
, NULL
, NULL
)) {
30 sleep(2); /* let the child start running */
32 size_t size
= sizeof(after_regions
);
33 int ret
= sysctlbyname("vm.shared_region_pager_count", &after_regions
, &size
, NULL
, 0);
34 T_QUIET
; T_EXPECT_POSIX_SUCCESS(ret
, "get shared_region_pager_count after");
36 if (!dt_waitpid(pid
, &status
, NULL
, 30)) {
46 * If shared regions by entitlement was not originally active, turn it back off.
48 static int orig_setting
= 0;
54 size_t size_off
= sizeof(off
);
56 if (orig_setting
== 0) {
57 ret
= sysctlbyname("vm.vm_shared_region_by_entitlement", NULL
, NULL
, &off
, size_off
);
58 T_QUIET
; T_EXPECT_POSIX_SUCCESS(ret
, "turning sysctl back off");
64 * - looks at the number of shared region pagers,
65 * - launches a helper app that has entitlement for unique signing
66 * - gets the number of shared region pagers again.
67 * It expects to see additional shared region pager(s) to exist.
70 T_DECL(sr_entitlement
, "shared region by entitlement test")
74 int before_regions
= 0;
76 size_t size_on
= sizeof(on
);
78 T_SKIP("No pointer authentication support");
81 * Check if the sysctl vm_shared_region_by_entitlement exists and if so make
84 size
= sizeof(orig_setting
);
85 ret
= sysctlbyname("vm.vm_shared_region_by_entitlement", &orig_setting
, &size
, &on
, size_on
);
87 T_SKIP("No pointer authentication support");
92 size
= sizeof(before_regions
);
93 ret
= sysctlbyname("vm.shared_region_pager_count", &before_regions
, &size
, NULL
, 0);
94 T_QUIET
; T_EXPECT_POSIX_SUCCESS(ret
, "get shared_region_pager_count before");
95 T_QUIET
; T_EXPECT_GE_INT(before_regions
, 1, "invalid before number of regions");
97 ret
= my_system("./sr_entitlement_helper");
99 T_ASSERT_FAIL("Couldn't run helper first time ret = %d", ret
);
102 T_EXPECT_GT_INT(after_regions
, before_regions
, "expected additional SR pagers after running helper");