]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/_dyld_get_image_slide.dtest/main.c
dyld-750.5.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 #include "test_support.h"
14
15 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
16 int count = _dyld_image_count();
17 for (int i=0; i < count; ++i) {
18 const struct mach_header* mh = _dyld_get_image_header(i);
19 const char* name = _dyld_get_image_name(i);
20 intptr_t slide = _dyld_get_image_slide(mh);
21 intptr_t vmaddrSlide = _dyld_get_image_vmaddr_slide(i);
22 if ( slide != vmaddrSlide ) {
23 FAIL("%lld != %lld in %s", (uint64_t)slide, (uint64_t)vmaddrSlide, name);
24 return 0;
25 }
26 }
27
28 // Check that garbage values return 0
29 uintptr_t notMagic = 0;
30 intptr_t slide = _dyld_get_image_slide((const struct mach_header*)&notMagic);
31 if (slide != 0) {
32 FAIL("slide value %lld for bad magic", (uint64_t)slide);
33 }
34
35 intptr_t vmaddrSlide = _dyld_get_image_vmaddr_slide(count + 1);
36 if (vmaddrSlide != 0) {
37 FAIL("vmaddr slide value %lld for index %d", (uint64_t)vmaddrSlide, count + 1);
38 }
39
40 PASS("Success");
41 }
42