]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/amfi-hardened-dlopen-leaf.dtest/main.c
1 // BOOT_ARGS: dyld_flags=2
3 // BUILD(macos): $CC my.c -dynamiclib -o $BUILD_DIR/libmy.dylib -install_name $RUN_DIR/libmy.dylib
4 // BUILD(macos): $CC main.c -o $BUILD_DIR/amfi-hardened-dlopen-leaf.exe -DHARDENED=1
5 // BUILD(macos): $CC main.c -o $BUILD_DIR/amfi-not-hardened-dlopen-leaf.exe
7 // BUILD(ios,tvos,watchos,bridgeos):
9 // RUN: DYLD_AMFI_FAKE=0x14 ./amfi-hardened-dlopen-leaf.exe
10 // RUN: DYLD_AMFI_FAKE=0x3F ./amfi-not-hardened-dlopen-leaf.exe
17 #include <mach/host_info.h>
18 #include <mach/mach.h>
19 #include <mach/mach_host.h>
21 #include "test_support.h"
23 void tryPath(const char* prog
, const char* path
)
25 void* handle
= dlopen(path
, RTLD_LAZY
);
27 if ( handle
!= NULL
) {
28 FAIL("dlopen(%s) unexpectedly succeeded", path
);
32 if ( handle
== NULL
) {
33 FAIL("dlopen(%s) - %s", path
, dlerror());
40 int main(int argc
, const char* argv
[], const char* envp
[], const char* apple
[]) {
41 // verify leaf name leads to dylib in /usr/lib/
42 void* handle
= dlopen("libc.dylib", RTLD_LAZY
);
43 if ( handle
== NULL
) {
44 FAIL("dlopen - %s", dlerror());
47 // verify file system relative paths: hardened should fail
48 tryPath(argv
[0], "libmy.dylib");
49 tryPath(argv
[0], "./libmy.dylib");
50 tryPath(argv
[0], "../amfi-hardened-dlopen-leaf/libmy.dylib");