]>
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 #include "test_support.h"
16 extern void* myalloc1(size_t);
17 extern void* myalloc2(size_t);
19 int main(int argc
, const char* argv
[], const char* envp
[], const char* apple
[]) {
20 char* p1
= malloc(10);
21 if ( strncmp(p1
+10, "##########", 10) != 0 ) {
22 FAIL("malloc() from main executable not interposed");
25 void* p2
= myalloc1(6);
26 if ( strncmp(p2
+6, "######", 6) != 0 ) {
27 FAIL("myalloc1() from libfoo.dylib not interposed");
30 void* p3
= myalloc2(10);
31 if ( strncmp(p3
+10, "##########", 10) != 0 ) {
32 FAIL("myalloc2() from libfoo.dylib not interposed");
35 void* p4
= strdup("hello");
36 if ( strncmp(p4
+6, "#######", 6) != 0 ) {
37 FAIL("malloc() from strdup not interposed");
40 LOG("%p %p %p %p", p1
, p2
, p3
, p4
);