]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/_dyld_images_for_addresses.dtest/main.c
dyld-750.6.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 #include "test_support.h"
14
15 extern void* __dso_handle;
16
17 extern int foo1();
18 extern int foo2();
19 extern int foo3();
20
21
22 int myfunc()
23 {
24 return 3;
25 }
26
27 int myfunc2()
28 {
29 return 3;
30 }
31
32 static int mystaticfoo()
33 {
34 return 3;
35 }
36
37 int mydata = 5;
38 int myarray[10];
39
40
41 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
42 int mylocal;
43
44 const void* addresses[12];
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 addresses[10] = &fopen;
56 addresses[11] = &fclose;
57
58 struct dyld_image_uuid_offset infos[12];
59 _dyld_images_for_addresses(12, addresses, infos);
60
61 for (int i=0; i < 12; ++i) {
62 uuid_string_t str;
63 uuid_unparse_upper(infos[i].uuid, str);
64 LOG("0x%09llX 0x%08llX %s", (long long)infos[i].image, infos[i].offsetInImage, str);
65 }
66
67 if ( infos[0].image != infos[1].image )
68 FAIL("0 vs 1");
69 else if ( infos[0].image != infos[2].image )
70 FAIL("0 vs 2");
71 else if ( infos[0].image != infos[3].image )
72 FAIL("0 vs 3");
73 else if ( infos[0].image != infos[4].image )
74 FAIL("0 vs 4");
75 else if ( infos[0].image != infos[5].image )
76 FAIL("0 vs 5");
77 else if ( infos[6].image != NULL )
78 FAIL("6 vs null ");
79 else if ( infos[7].image != infos[8].image )
80 FAIL("7 vs 8");
81 else if ( infos[7].image != infos[9].image )
82 FAIL("7 vs 9");
83 else if ( infos[0].image == infos[7].image )
84 FAIL("0 vs 7");
85 else if ( infos[10].image != infos[11].image )
86 FAIL("10 vs 11");
87 else if ( uuid_compare(infos[0].uuid, infos[1].uuid) != 0 )
88 FAIL("uuid 0 vs 1");
89 else if ( uuid_compare(infos[0].uuid, infos[2].uuid) != 0 )
90 FAIL("uuid 0 vs 2");
91 else if ( uuid_compare(infos[0].uuid, infos[3].uuid) != 0 )
92 FAIL("uuid 0 vs 3");
93 else if ( uuid_compare(infos[0].uuid, infos[4].uuid) != 0 )
94 FAIL("uuid 0 vs 4");
95 else if ( uuid_compare(infos[0].uuid, infos[5].uuid) != 0 )
96 FAIL("uuid 0 vs 5");
97 else if ( uuid_is_null(infos[6].uuid) == 0 )
98 FAIL("uuid 6 vs null");
99 else if ( uuid_compare(infos[7].uuid, infos[8].uuid) != 0 )
100 FAIL("uuid 7 vs 8");
101 else if ( uuid_compare(infos[7].uuid, infos[9].uuid) != 0 )
102 FAIL("uuid 7 vs 9");
103 else if ( uuid_compare(infos[0].uuid, infos[7].uuid) == 0 )
104 FAIL("uuid 0 vs 7");
105 else if ( uuid_compare(infos[10].uuid, infos[11].uuid) != 0 )
106 FAIL("uuid 10 vs 11");
107 else
108 PASS("Success");
109 }
110