1*27b03b36SApple OSS Distributions #include <stdio.h>
2*27b03b36SApple OSS Distributions #include <mach-o/dyld.h>
3*27b03b36SApple OSS Distributions #include <mach-o/dyld_images.h>
4*27b03b36SApple OSS Distributions #include <libproc.h>
5*27b03b36SApple OSS Distributions
6*27b03b36SApple OSS Distributions /*
7*27b03b36SApple OSS Distributions * Returns 1 if the standard Rosetta runtime is loaded, 2 if the alternative
8*27b03b36SApple OSS Distributions * runtime is loaded, and 0 if no runtime was detected.
9*27b03b36SApple OSS Distributions */
10*27b03b36SApple OSS Distributions int
main(int argc,const char * argv[])11*27b03b36SApple OSS Distributions main(int argc, const char * argv[])
12*27b03b36SApple OSS Distributions {
13*27b03b36SApple OSS Distributions unsigned depth = 1;
14*27b03b36SApple OSS Distributions vm_size_t size = 0;
15*27b03b36SApple OSS Distributions vm_address_t address = 0;
16*27b03b36SApple OSS Distributions vm_address_t end_address;
17*27b03b36SApple OSS Distributions kern_return_t err = KERN_SUCCESS;
18*27b03b36SApple OSS Distributions mach_msg_type_number_t count = VM_REGION_SUBMAP_INFO_COUNT_64;
19*27b03b36SApple OSS Distributions struct vm_region_submap_info_64 info;
20*27b03b36SApple OSS Distributions char path_buffer[MAXPATHLEN + 1] = {0};
21*27b03b36SApple OSS Distributions
22*27b03b36SApple OSS Distributions while (1) {
23*27b03b36SApple OSS Distributions err = vm_region_recurse_64(mach_task_self(), &address, &size, &depth, (vm_region_info_t)&info, &count);
24*27b03b36SApple OSS Distributions if (err != KERN_SUCCESS) {
25*27b03b36SApple OSS Distributions break;
26*27b03b36SApple OSS Distributions }
27*27b03b36SApple OSS Distributions
28*27b03b36SApple OSS Distributions end_address = address + size;
29*27b03b36SApple OSS Distributions err = proc_regionfilename(getpid(), address, path_buffer, MAXPATHLEN);
30*27b03b36SApple OSS Distributions if (err == KERN_SUCCESS) {
31*27b03b36SApple OSS Distributions if (strcmp(path_buffer, "/usr/libexec/rosetta/runtime") == 0) {
32*27b03b36SApple OSS Distributions printf("0x%016lx-0x%016lx %s\n", address, end_address, path_buffer);
33*27b03b36SApple OSS Distributions return 1;
34*27b03b36SApple OSS Distributions } else if (strcmp(path_buffer, "/usr/local/libexec/rosetta/runtime_internal") == 0) {
35*27b03b36SApple OSS Distributions printf("0x%016lx-0x%016lx %s\n", address, end_address, path_buffer);
36*27b03b36SApple OSS Distributions return 2;
37*27b03b36SApple OSS Distributions }
38*27b03b36SApple OSS Distributions }
39*27b03b36SApple OSS Distributions
40*27b03b36SApple OSS Distributions address = end_address;
41*27b03b36SApple OSS Distributions }
42*27b03b36SApple OSS Distributions return 0;
43*27b03b36SApple OSS Distributions }
44