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