]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/kernel-pageablekc-auxkc-fixups.dtest/main.c
dc1834db4974f2b20456c3eb98970933a0e102cb
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): $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
6 // 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
8 // Create the pageable kernel collection
9 // BUILD(macos,ios,tvos,bridgeos|x86_64,arm64,arm64e): $CP extensions/pageable.kext/Info.plist $BUILD_DIR/extensions/pageable-kext/Info.plist
10 // BUILD(macos,ios,tvos,bridgeos|x86_64,arm64,arm64e): $CC pageable.c -o $BUILD_DIR/extensions/pageable-kext/pageable -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
11 // BUILD(macos,ios,tvos,bridgeos|x86_64,arm64,arm64e): $APP_CACHE_UTIL -create-pageable-kernel-collection $BUILD_DIR/pageable.kc -kernel-collection $BUILD_DIR/kernel.kc -extensions $BUILD_DIR/extensions -bundle-id com.apple.pageable $DEPENDS_ON $BUILD_DIR/extensions/pageable-kext/Info.plist $DEPENDS_ON $BUILD_DIR/extensions/pageable-kext/pageable
13 // Create the aux kernel collection
14 // BUILD(macos,ios,tvos,bridgeos|x86_64,arm64,arm64e): $CP extensions/foo.kext/Info.plist $BUILD_DIR/extensions/foo-kext/Info.plist
15 // BUILD(macos,ios,tvos,bridgeos|x86_64,arm64,arm64e): $CP extensions/bar.kext/Info.plist $BUILD_DIR/extensions/bar-kext/Info.plist
16 // 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
17 // 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
18 // 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 -pageable-collection $BUILD_DIR/pageable.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
22 // RUN_STATIC: $RUN_STATIC $RUN_DIR/kernel.kc $RUN_DIR/pageable.kc - $RUN_DIR/aux.kc
24 #include "../kernel-test-runner.h"
25 #include "../kernel-fixups.h"
26 #include "../kernel-classic-relocs.h"
27 #include "../kernel-helpers.h"
29 #define printf(...) funcs->printf(__VA_ARGS__)
35 __attribute__((section(("__HIB, __text"))))
37 __attribute__((section(("__TEXT_EXEC, __text"))))
39 int _start(const TestRunnerFunctions
* funcs
)
43 const void* slideBasePointers
[4];
44 slideBasePointers
[0] = funcs
->basePointers
[0];
45 slideBasePointers
[1] = funcs
->basePointers
[1];
46 slideBasePointers
[2] = funcs
->basePointers
[2];
47 slideBasePointers
[3] = funcs
->basePointers
[3];
48 int slideReturnCode
= slide(funcs
->mhs
[0], slideBasePointers
, funcs
->printf
);
49 if ( slideReturnCode
!= 0 ) {
50 FAIL("mhs[0] slide = %d\n", slideReturnCode
);
54 int slideClassicReturnCode
= slideClassic(funcs
->mhs
[0], funcs
->printf
);
55 if ( slideClassicReturnCode
!= 0 ) {
56 FAIL("mhs[0] slide classic = %d\n", slideClassicReturnCode
);
61 FAIL("g[0] != x, %d != %d\n", g
[0], x
);
65 // First slide the pageableKC using the top level fixups. These handle the branch GOTs
66 slideReturnCode
= slide(funcs
->mhs
[1], slideBasePointers
, funcs
->printf
);
67 if ( slideReturnCode
!= 0 ) {
68 FAIL("mhs[1] slide = %d\n", slideReturnCode
);
72 // Then slide pageable using the fixups attached to the kexts own mach headers
73 slideReturnCode
= slideKextsInsideKernelCollection(funcs
->mhs
[1], slideBasePointers
, funcs
->printf
, funcs
);
74 if ( slideReturnCode
!= 0 ) {
75 FAIL("mhs[1] slide = %d\n", slideReturnCode
);
80 slideReturnCode
= slide(funcs
->mhs
[3], slideBasePointers
, funcs
->printf
);
81 if ( slideReturnCode
!= 0 ) {
82 FAIL("mhs[3] slide = %d\n", slideReturnCode
);
87 // On x86 only, slide the auxKC individually
88 // Then slide pageable using the fixups attached to the kexts own mach headers
89 slideReturnCode
= slideKextsInsideKernelCollection(funcs
->mhs
[3], slideBasePointers
, funcs
->printf
, funcs
);
90 if ( slideReturnCode
!= 0 ) {
91 FAIL("mhs[3] slide = %d\n", slideReturnCode
);
96 // If we have any mod init funcs, then lets run them now
97 // These are the tests inside the auxKC kexts
98 int runModInitFuncs
= runAllModInitFunctionsForAppCache(funcs
->mhs
[3], funcs
->printf
, funcs
);
99 if ( runModInitFuncs
!= 0 ) {
100 FAIL("runModInitFuncs = %d\n", runModInitFuncs
);