]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/interpose-then-dlopen.dtest/main.c
1 // BUILD: $CC fooimpl.c -dynamiclib -o $BUILD_DIR/libfooimpl.dylib -install_name $RUN_DIR/libfooimpl.dylib
2 // BUILD: $CC foo.c -dynamiclib $BUILD_DIR/libfooimpl.dylib -o $BUILD_DIR/libfoo.dylib -Wl,-interposable_list,interposable.txt -install_name $RUN_DIR/libfoo.dylib
3 // BUILD: $CC bar.c -bundle $BUILD_DIR/libfooimpl.dylib -o $BUILD_DIR/libbar.bundle -Wl,-interposable_list,interposable.txt
4 // BUILD: $CC main.c -DRUN_DIR="$RUN_DIR" -Wl,-interposable_list,interposable.txt -o $BUILD_DIR/interpose-then-dlopen.exe
5 // BUILD: $DYLD_ENV_VARS_ENABLE $BUILD_DIR/interpose-then-dlopen.exe
6 // BUILD: $CC interposer.c -dynamiclib $BUILD_DIR/libfooimpl.dylib -o $BUILD_DIR/libinterposer.dylib -install_name libinterposer.dylib
8 // RUN: DYLD_INSERT_LIBRARIES=libinterposer.dylib ./interpose-then-dlopen.exe
17 // Note, libinterposer.dylib interposes interposableFoo
18 extern int interposableFoo();
20 // Note, libfoo interposes interposableBar
21 extern int interposableBar();
23 extern int callFunc();
26 static int tryImage(const char* path
, int expectedFoo
, int expectedBar
)
28 void* handle
= dlopen(path
, RTLD_LAZY
);
29 if ( handle
== NULL
) {
30 printf("dlerror(): %s\n", dlerror());
31 printf("[FAIL] interpose-then-dlopen %s\n", path
);
35 __typeof(&callFunc
) callFooSym
= (__typeof(&callFunc
))dlsym(handle
, "callFoo");
36 if ( callFooSym
== NULL
) {
37 printf("dlerror(): %s\n", dlerror());
38 printf("[FAIL] interpose-then-dlopen %s\n", path
);
42 int fooResult
= callFooSym();
43 if ( fooResult
!= expectedFoo
) {
44 printf("[FAIL] interpose-then-dlopen callFoo() from %s not interposed as it returned %d\n", path
, fooResult
);
48 __typeof(&callFunc
) callBarSym
= (__typeof(&callFunc
))dlsym(handle
, "callBar");
49 if ( callBarSym
== NULL
) {
50 printf("dlerror(): %s\n", dlerror());
51 printf("[FAIL] interpose-then-dlopen %s\n", path
);
55 int barResult
= callBarSym();
56 if ( barResult
!= expectedBar
) {
57 printf("[FAIL] interpose-then-dlopen callBar() from %s not interposed as it returned %d\n", path
, barResult
);
66 printf("[BEGIN] interpose-then-dlopen\n");
68 if (tryImage(RUN_DIR
"/libfoo.dylib", 4, 2))
71 if (tryImage(RUN_DIR
"/libbar.bundle", 4, 100))
74 //printf("%p %p %p %p\n", p1, p2, p3, p4);
75 printf("[PASS] interpose-then-dlopen\n");