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