xref: /xnu-11417.101.15/tests/get_shared_cache_address.c (revision e3723e1f17661b24996789d8afc084c0c3303b26)
1*e3723e1fSApple OSS Distributions #include <sys/resource.h>
2*e3723e1fSApple OSS Distributions #include <unistd.h>
3*e3723e1fSApple OSS Distributions #include <stdlib.h>
4*e3723e1fSApple OSS Distributions #include <stdio.h>
5*e3723e1fSApple OSS Distributions #include <string.h>
6*e3723e1fSApple OSS Distributions #include <libproc.h>
7*e3723e1fSApple OSS Distributions #include <mach-o/dyld.h>
8*e3723e1fSApple OSS Distributions #include <mach-o/dyld_priv.h>
9*e3723e1fSApple OSS Distributions 
10*e3723e1fSApple OSS Distributions /*
11*e3723e1fSApple OSS Distributions  * Test helper to retrieve the address of the shared cache. The helper
12*e3723e1fSApple OSS Distributions  * also verifies that the process is correctly marked to have the shared
13*e3723e1fSApple OSS Distributions  * cache reslid when interrogated through proc_pid_rusage()
14*e3723e1fSApple OSS Distributions  */
15*e3723e1fSApple OSS Distributions int
main(int argc,char ** argv)16*e3723e1fSApple OSS Distributions main(int argc, char **argv)
17*e3723e1fSApple OSS Distributions {
18*e3723e1fSApple OSS Distributions 	size_t shared_cache_len = 0;
19*e3723e1fSApple OSS Distributions 	struct rusage_info_v5 ru = {};
20*e3723e1fSApple OSS Distributions 
21*e3723e1fSApple OSS Distributions 	if (argc != 2) {
22*e3723e1fSApple OSS Distributions 		fprintf(stderr, "Invalid helper invocation");
23*e3723e1fSApple OSS Distributions 		exit(1);
24*e3723e1fSApple OSS Distributions 	}
25*e3723e1fSApple OSS Distributions 
26*e3723e1fSApple OSS Distributions 	if (proc_pid_rusage(getpid(), RUSAGE_INFO_V5, (rusage_info_t *)&ru) != 0) {
27*e3723e1fSApple OSS Distributions 		perror("proc_pid_rusage() helper");
28*e3723e1fSApple OSS Distributions 		exit(1);
29*e3723e1fSApple OSS Distributions 	}
30*e3723e1fSApple OSS Distributions 
31*e3723e1fSApple OSS Distributions 	if (strcmp(argv[1], "check_rusage_flag") == 0) {
32*e3723e1fSApple OSS Distributions 		if (!(ru.ri_flags & RU_PROC_RUNS_RESLIDE)) {
33*e3723e1fSApple OSS Distributions 			fprintf(stderr, "Helper rusage flag check failed\n");
34*e3723e1fSApple OSS Distributions 			exit(1);
35*e3723e1fSApple OSS Distributions 		}
36*e3723e1fSApple OSS Distributions 	}
37*e3723e1fSApple OSS Distributions 
38*e3723e1fSApple OSS Distributions 	printf("%p\n", _dyld_get_shared_cache_range(&shared_cache_len));
39*e3723e1fSApple OSS Distributions 	exit(0);
40*e3723e1fSApple OSS Distributions }
41