]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/amfi-interpose.dtest/main.c
dyld-832.7.1.tar.gz
[apple/dyld.git] / testing / test-cases / amfi-interpose.dtest / main.c
1 // BOOT_ARGS: dyld_flags=2
2
3 // BUILD: $CC interposer.c -dynamiclib -o $BUILD_DIR/libmyalloc.dylib -install_name $RUN_DIR/libmyalloc.dylib
4 // BUILD: $CC main.c $BUILD_DIR/libmyalloc.dylib -o $BUILD_DIR/amfi-interpose.exe
5 // BUILD: $DYLD_ENV_VARS_ENABLE $BUILD_DIR/amfi-interpose.exe
6
7 // RUN: DYLD_AMFI_FAKE=0x7F ./amfi-interpose.exe
8 // RUN: DYLD_AMFI_FAKE=0x3F ./amfi-interpose.exe
9
10 //
11 // Tests that AMFI_DYLD_OUTPUT_ALLOW_LIBRARY_INTERPOSING bit from AMFI blocks interposing
12 //
13
14 #include <stdio.h>
15 #include <stdbool.h>
16 #include <stdlib.h>
17 #include <string.h>
18
19 #include <libamfi.h>
20
21 #include "test_support.h"
22
23 int main()
24 {
25 // interposed malloc() doubles alloction size and prefills allocation with '#'
26 char* p1 = malloc(10);
27 bool interposed = (strncmp(p1, "####################", 20) == 0);
28
29 const char* amfiBits = getenv("DYLD_AMFI_FAKE");
30 if ( amfiBits == NULL ) {
31 FAIL("amfi-interpose: DYLD_AMFI_FAKE not set");
32 }
33 #ifdef AMFI_RETURNS_INTERPOSING_FLAG
34 bool allowInterposing = (strcmp(amfiBits, "0x7F") == 0);
35 #else
36 bool allowInterposing = true;
37 #endif
38
39 if ( interposed == allowInterposing )
40 PASS("Success");
41 else if ( interposed )
42 FAIL("amfi-interpose: malloc interposed, but amfi said to block it");
43 else
44 FAIL("amfi-interpose: malloc not interposed, but amfi said to allow it");
45 }