]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/interpose-malloc.dtest/main.c
dyld-851.27.tar.gz
[apple/dyld.git] / 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
5
6 // RUN: DYLD_INSERT_LIBRARIES=libmyalloc.dylib ./interpose-malloc.exe
7
8
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13
14 #include "test_support.h"
15
16 extern void* myalloc1(size_t);
17 extern void* myalloc2(size_t);
18
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");
23 }
24
25 void* p2 = myalloc1(6);
26 if ( strncmp(p2+6, "######", 6) != 0 ) {
27 FAIL("myalloc1() from libfoo.dylib not interposed");
28 }
29
30 void* p3 = myalloc2(10);
31 if ( strncmp(p3+10, "##########", 10) != 0 ) {
32 FAIL("myalloc2() from libfoo.dylib not interposed");
33 }
34
35 void* p4 = strdup("hello");
36 if ( strncmp(p4+6, "#######", 6) != 0 ) {
37 FAIL("malloc() from strdup not interposed");
38 }
39
40 LOG("%p %p %p %p", p1, p2, p3, p4);
41 PASS("Success");
42 }