]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/interpose-malloc.dtest/main.c
1 // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/libfoo.dylib -install_name $RUN_DIR/libfoo.dylib
2 // BUILD: $CC main.c $BUILD_DIR/libfoo.dylib -o $BUILD_DIR/interpose-malloc.exe
3 // BUILD: $DYLD_ENV_VARS_ENABLE $BUILD_DIR/interpose-malloc.exe
4 // BUILD: $CC interposer.c -dynamiclib -o $BUILD_DIR/libmyalloc.dylib -install_name libmyalloc.dylib
6 // RUN: DYLD_INSERT_LIBRARIES=libmyalloc.dylib ./interpose-malloc.exe
14 extern void* myalloc1(size_t);
15 extern void* myalloc2(size_t);
19 printf("[BEGIN] interpose-malloc\n");
21 char* p1
= malloc(10);
22 if ( strncmp(p1
+10, "##########", 10) != 0 ) {
23 printf("[FAIL] interpose-malloc malloc() from main executable not interposed\n");
27 void* p2
= myalloc1(6);
28 if ( strncmp(p2
+6, "######", 6) != 0 ) {
29 printf("[FAIL] interpose-malloc myalloc1() from libfoo.dylib not interposed\n");
33 void* p3
= myalloc2(10);
34 if ( strncmp(p3
+10, "##########", 10) != 0 ) {
35 printf("[FAIL] interpose-malloc myalloc2() from libfoo.dylib not interposed\n");
39 void* p4
= strdup("hello");
40 if ( strncmp(p4
+6, "#######", 6) != 0 ) {
41 printf("[FAIL] interpose-malloc malloc() from strdup not interposed\n");
45 //printf("%p %p %p %p\n", p1, p2, p3, p4);
46 printf("[PASS] interpose-malloc\n");