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