]>
git.saurik.com Git - apple/xnu.git/blob - tests/sr_entitlement.c
bec6f4a8c734c553a7d9f3dfbe1dd4140cb091ad
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
);
79 T_SKIP("No pointer authentication support");
83 * Check if the sysctl vm_shared_region_by_entitlement exists and if so make
86 size
= sizeof(orig_setting
);
87 ret
= sysctlbyname("vm.vm_shared_region_by_entitlement", &orig_setting
, &size
, &on
, size_on
);
89 T_SKIP("No pointer authentication support");
94 size
= sizeof(before_regions
);
95 ret
= sysctlbyname("vm.shared_region_pager_count", &before_regions
, &size
, NULL
, 0);
96 T_QUIET
; T_EXPECT_POSIX_SUCCESS(ret
, "get shared_region_pager_count before");
97 T_QUIET
; T_EXPECT_GE_INT(before_regions
, 1, "invalid before number of regions");
99 ret
= my_system("./sr_entitlement_helper");
101 T_ASSERT_FAIL("Couldn't run helper first time ret = %d", ret
);
104 T_EXPECT_GT_INT(after_regions
, before_regions
, "expected additional SR pagers after running helper");