]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/kernel-auxkc-fixups.dtest/main.c
2 // BOOT_ARGS: amfi=3 cs_enforcement_disable=1
4 // Create the base kernel collection
5 // BUILD(macos,ios,tvos,bridgeos|x86_64,arm64,arm64e): $CP extensions/kernel-export.kext/Info.plist $BUILD_DIR/extensions/kernel-export-kext/Info.plist
6 // BUILD(macos,ios,tvos,bridgeos|x86_64,arm64,arm64e): $CC main.c -o $BUILD_DIR/kernel-auxkc-fixups.exe -Wl,-static -mkernel -nostdlib -Wl,-add_split_seg_info -Wl,-e,__start -Wl,-pie -Wl,-pagezero_size,0x0 -Wl,-install_name,/usr/lib/swift/split.seg.v2.hack -fno-stack-protector -fno-builtin -ffreestanding -Wl,-segprot,__HIB,rx,rx -Wl,-image_base,0x8000 -Wl,-segaddr,__HIB,0x4000 -fno-ptrauth-function-pointer-type-discrimination
7 // BUILD(macos,ios,tvos,bridgeos|x86_64,arm64,arm64e): $CC kernel-export.c -o $BUILD_DIR/extensions/kernel-export-kext/kernel-export -Wl,-kext -Wl,-kext_objects_dir,$BUILD_DIR/KextObjects -mkernel -nostdlib -Wl,-add_split_seg_info -Wl,-install_name,/usr/lib/swift/split.seg.v2.hack -fno-ptrauth-function-pointer-type-discrimination
8 // BUILD(macos,ios,tvos,bridgeos|x86_64,arm64,arm64e): $APP_CACHE_UTIL -create-kernel-collection $BUILD_DIR/kernel.kc -kernel $BUILD_DIR/kernel-auxkc-fixups.exe -extensions $BUILD_DIR/extensions -bundle-id com.apple.kernel.export $DEPENDS_ON $BUILD_DIR/extensions/kernel-export-kext/Info.plist $DEPENDS_ON $BUILD_DIR/extensions/kernel-export-kext/kernel-export
10 // Create the aux kernel collection
11 // BUILD(macos,ios,tvos,bridgeos|x86_64,arm64,arm64e): $CP extensions/foo.kext/Info.plist $BUILD_DIR/extensions/foo-kext/Info.plist
12 // BUILD(macos,ios,tvos,bridgeos|x86_64,arm64,arm64e): $CP extensions/bar.kext/Info.plist $BUILD_DIR/extensions/bar-kext/Info.plist
13 // BUILD(macos,ios,tvos,bridgeos|x86_64,arm64,arm64e): $CC foo.c -o $BUILD_DIR/extensions/foo-kext/foo -Wl,-kext -Wl,-kext_objects_dir,$BUILD_DIR/KextObjects -mkernel -nostdlib -Wl,-add_split_seg_info -Wl,-install_name,/usr/lib/swift/split.seg.v2.hack -fno-ptrauth-function-pointer-type-discrimination
14 // BUILD(macos,ios,tvos,bridgeos|x86_64,arm64,arm64e): $CC bar.c -o $BUILD_DIR/extensions/bar-kext/bar -Wl,-kext -Wl,-kext_objects_dir,$BUILD_DIR/KextObjects -mkernel -nostdlib -Wl,-add_split_seg_info -Wl,-install_name,/usr/lib/swift/split.seg.v2.hack -fno-ptrauth-function-pointer-type-discrimination
15 // BUILD(macos,ios,tvos,bridgeos|x86_64,arm64,arm64e): $APP_CACHE_UTIL -create-aux-kernel-collection $BUILD_DIR/aux.kc -kernel-collection $BUILD_DIR/kernel.kc -extensions $BUILD_DIR/extensions -bundle-id com.apple.foo $DEPENDS_ON $BUILD_DIR/extensions/foo-kext/Info.plist $DEPENDS_ON $BUILD_DIR/extensions/bar-kext/Info.plist $DEPENDS_ON $BUILD_DIR/extensions/foo-kext/foo $DEPENDS_ON $BUILD_DIR/extensions/bar-kext/bar
19 // RUN_STATIC: $RUN_STATIC $RUN_DIR/kernel.kc - - $RUN_DIR/aux.kc
21 #include "../kernel-test-runner.h"
22 #include "../kernel-fixups.h"
23 #include "../kernel-classic-relocs.h"
24 #include "../kernel-helpers.h"
26 #define printf(...) funcs->printf(__VA_ARGS__)
32 __attribute__((section(("__HIB, __text"))))
34 __attribute__((section(("__TEXT_EXEC, __text"))))
36 int _start(const TestRunnerFunctions
* funcs
)
40 const void* slideBasePointers
[4];
41 slideBasePointers
[0] = funcs
->basePointers
[0];
42 slideBasePointers
[1] = funcs
->basePointers
[1];
43 slideBasePointers
[2] = funcs
->basePointers
[2];
44 slideBasePointers
[3] = funcs
->basePointers
[3];
45 int slideReturnCode
= slide(funcs
->mhs
[0], slideBasePointers
, funcs
->printf
);
46 if ( slideReturnCode
!= 0 ) {
47 FAIL("mhs[0] slide = %d\n", slideReturnCode
);
51 int slideClassicReturnCode
= slideClassic(funcs
->mhs
[0], funcs
->printf
);
52 if ( slideClassicReturnCode
!= 0 ) {
53 FAIL("mhs[0] slide classic = %d\n", slideClassicReturnCode
);
58 FAIL("g[0] != x, %d != %d\n", g
[0], x
);
62 // First slide the auxKC using the top level fixups. These handle the branch GOTs
63 slideReturnCode
= slide(funcs
->mhs
[3], slideBasePointers
, funcs
->printf
);
64 if ( slideReturnCode
!= 0 ) {
65 FAIL("mhs[3] slide = %d\n", slideReturnCode
);
70 // On x86 only, slide the auxKC individually
71 // Then slide pageable using the fixups attached to the kexts own mach headers
72 slideReturnCode
= slideKextsInsideKernelCollection(funcs
->mhs
[3], slideBasePointers
, funcs
->printf
, funcs
);
73 if ( slideReturnCode
!= 0 ) {
74 FAIL("mhs[3] slide = %d\n", slideReturnCode
);
79 // If we have any mod init funcs, then lets run them now
80 int runModInitFuncs
= runAllModInitFunctionsForAppCache(funcs
->mhs
[3], funcs
->printf
, funcs
);
81 if ( runModInitFuncs
!= 0 ) {
82 FAIL("runModInitFuncs = %d\n", runModInitFuncs
);