]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/_dyld_images_for_addresses.dtest/main.c
dyld-625.13.tar.gz
[apple/dyld.git] / testing / test-cases / _dyld_images_for_addresses.dtest / main.c
1
2 // BUILD: $CC foo.c -dynamiclib -install_name $RUN_DIR/libfoo.dylib -o $BUILD_DIR/libfoo.dylib
3 // BUILD: $CC main.c $BUILD_DIR/libfoo.dylib -o $BUILD_DIR/dyld_images_for_addresses.exe
4
5 // RUN: ./dyld_images_for_addresses.exe
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <uuid/uuid.h>
11 #include <mach-o/dyld_priv.h>
12
13 extern void* __dso_handle;
14
15 extern int foo1();
16 extern int foo2();
17 extern int foo3();
18
19
20 int myfunc()
21 {
22 return 3;
23 }
24
25 int myfunc2()
26 {
27 return 3;
28 }
29
30 static int mystaticfoo()
31 {
32 return 3;
33 }
34
35 int mydata = 5;
36 int myarray[10];
37
38
39 int main()
40 {
41 printf("[BEGIN] _dyld_images_for_addresses\n");
42 int mylocal;
43
44 const void* addresses[10];
45 addresses[0] = &myfunc;
46 addresses[1] = &myfunc2;
47 addresses[2] = &mystaticfoo;
48 addresses[3] = &__dso_handle;
49 addresses[4] = &mydata;
50 addresses[5] = &myarray;
51 addresses[6] = &mylocal; // not owned by dyld, so coresponding dyld_image_uuid_offset should be all zeros
52 addresses[7] = &foo1;
53 addresses[8] = &foo2;
54 addresses[9] = &foo3;
55
56 struct dyld_image_uuid_offset infos[10];
57 _dyld_images_for_addresses(10, addresses, infos);
58
59 for (int i=0; i < 10; ++i) {
60 uuid_string_t str;
61 uuid_unparse_upper(infos[i].uuid, str);
62 printf("0x%09llX 0x%08llX %s\n", (long long)infos[i].image, infos[i].offsetInImage, str);
63 }
64
65 if ( infos[0].image != infos[1].image )
66 printf("[FAIL] _dyld_images_for_addresses 1\n");
67 else if ( infos[0].image != infos[2].image )
68 printf("[FAIL] _dyld_images_for_addresses 2\n");
69 else if ( infos[0].image != infos[3].image )
70 printf("[FAIL] _dyld_images_for_addresses 3\n");
71 else if ( infos[0].image != infos[4].image )
72 printf("[FAIL] _dyld_images_for_addresses 4\n");
73 else if ( infos[0].image != infos[5].image )
74 printf("[FAIL] _dyld_images_for_addresses 5\n");
75 else if ( infos[6].image != NULL )
76 printf("[FAIL] _dyld_images_for_addresses 6\n");
77 else if ( infos[7].image != infos[8].image )
78 printf("[FAIL] _dyld_images_for_addresses 7\n");
79 else if ( infos[7].image != infos[9].image )
80 printf("[FAIL] _dyld_images_for_addresses 8\n");
81 else if ( infos[0].image == infos[7].image )
82 printf("[FAIL] _dyld_images_for_addresses 9\n");
83 else if ( uuid_compare(infos[0].uuid, infos[1].uuid) != 0 )
84 printf("[FAIL] _dyld_images_for_addresses 10\n");
85 else if ( uuid_compare(infos[0].uuid, infos[2].uuid) != 0 )
86 printf("[FAIL] _dyld_images_for_addresses 11\n");
87 else if ( uuid_compare(infos[0].uuid, infos[3].uuid) != 0 )
88 printf("[FAIL] _dyld_images_for_addresses 12\n");
89 else if ( uuid_compare(infos[0].uuid, infos[4].uuid) != 0 )
90 printf("[FAIL] _dyld_images_for_addresses 13\n");
91 else if ( uuid_compare(infos[0].uuid, infos[5].uuid) != 0 )
92 printf("[FAIL] _dyld_images_for_addresses 14\n");
93 else if ( uuid_is_null(infos[6].uuid) == 0 )
94 printf("[FAIL] _dyld_images_for_addresses 15\n");
95 else if ( uuid_compare(infos[7].uuid, infos[8].uuid) != 0 )
96 printf("[FAIL] _dyld_images_for_addresses 16\n");
97 else if ( uuid_compare(infos[7].uuid, infos[9].uuid) != 0 )
98 printf("[FAIL] _dyld_images_for_addresses 17\n");
99 else if ( uuid_compare(infos[0].uuid, infos[7].uuid) == 0 )
100 printf("[FAIL] _dyld_images_for_addresses 18\n");
101 else
102 printf("[PASS] _dyld_images_for_addresses\n");
103 return 0;
104 }
105