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