]>
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,$SRC_DIR/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,$SRC_DIR/interposable.txt
4 // BUILD: $CC main.c -DRUN_DIR="$RUN_DIR" -Wl,-interposable_list,$SRC_DIR/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 #include "test_support.h"
19 // Note, libinterposer.dylib interposes interposableFoo
20 extern int interposableFoo();
22 // Note, libfoo interposes interposableBar
23 extern int interposableBar();
25 extern int callFunc();
28 static void tryImage(const char* path
, int expectedFoo
, int expectedBar
)
30 void* handle
= dlopen(path
, RTLD_LAZY
);
31 if ( handle
== NULL
) {
32 FAIL("dlopen(\"%s\") error: %s", path
, dlerror());
35 __typeof(&callFunc
) callFooSym
= (__typeof(&callFunc
))dlsym(handle
, "callFoo");
36 if ( callFooSym
== NULL
) {
37 FAIL("dlsym(\"callFoo\") error: %s", dlerror());
40 int fooResult
= callFooSym();
41 if ( fooResult
!= expectedFoo
) {
42 FAIL("callFoo() from %s not interposed as it returned %d", path
, fooResult
);
45 __typeof(&callFunc
) callBarSym
= (__typeof(&callFunc
))dlsym(handle
, "callBar");
46 if ( callBarSym
== NULL
) {
47 FAIL("dlsym(\"callBar\") error: %s", dlerror());
50 int barResult
= callBarSym();
51 if ( barResult
!= expectedBar
) {
52 FAIL("callBar() from %s not interposed as it returned %d", path
, barResult
);
57 int main(int argc
, const char* argv
[], const char* envp
[], const char* apple
[]) {
58 tryImage(RUN_DIR
"/libfoo.dylib", 4, 2);
59 tryImage(RUN_DIR
"/libbar.bundle", 4, 100);