]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/_dyld_get_image_slide.dtest/main.c
dyld-732.8.tar.gz
[apple/dyld.git] / testing / test-cases / _dyld_get_image_slide.dtest / main.c
1
2 // BUILD: $CC main.c -o $BUILD_DIR/_dyld_get_image_slide-test.exe
3
4 // RUN: ./_dyld_get_image_slide-test.exe
5
6
7 #include <stdio.h>
8 #include <string.h>
9 #include <dlfcn.h>
10 #include <mach-o/dyld.h>
11 #include <mach-o/dyld_priv.h>
12
13
14 int main()
15 {
16 printf("[BEGIN] _dyld_get_image_slide-test\n");
17
18 int count = _dyld_image_count();
19 for (int i=0; i < count; ++i) {
20 const struct mach_header* mh = _dyld_get_image_header(i);
21 const char* name = _dyld_get_image_name(i);
22 intptr_t slide = _dyld_get_image_slide(mh);
23 intptr_t vmaddrSlide = _dyld_get_image_vmaddr_slide(i);
24 if ( slide != vmaddrSlide ) {
25 printf("[FAIL] _dyld_get_image_slide-test: %lld != %lld in %s\n",
26 (uint64_t)slide, (uint64_t)vmaddrSlide, name);
27 return 0;
28 }
29 }
30
31 // Check that garbage values return 0
32 uintptr_t notMagic = 0;
33 intptr_t slide = _dyld_get_image_slide((const struct mach_header*)&notMagic);
34 if (slide != 0) {
35 printf("[FAIL] _dyld_get_image_slide-test: slide value %lld for bad magic\n",
36 (uint64_t)slide);
37 }
38
39 intptr_t vmaddrSlide = _dyld_get_image_vmaddr_slide(count + 1);
40 if (vmaddrSlide != 0) {
41 printf("[FAIL] _dyld_get_image_slide-test: vmaddr slide value %lld for index %d\n",
42 (uint64_t)vmaddrSlide, count + 1);
43 }
44
45 printf("[PASS] _dyld_get_image_slide-test\n");
46 return 0;
47 }
48