]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/kernel-pageablekc-auxkc-fixups.dtest/main.c
dyld-851.27.tar.gz
[apple/dyld.git] / testing / test-cases / kernel-pageablekc-auxkc-fixups.dtest / main.c
1
2 // BOOT_ARGS: amfi=3 cs_enforcement_disable=1
3
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 -ftrivial-auto-var-init=uninitialized
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
7
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
12
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
19
20 // BUILD(watchos):
21
22 // RUN_STATIC: $RUN_STATIC $RUN_DIR/kernel.kc $RUN_DIR/pageable.kc - $RUN_DIR/aux.kc
23
24 #include "../kernel-test-runner.h"
25 #include "../kernel-fixups.h"
26 #include "../kernel-classic-relocs.h"
27 #include "../kernel-helpers.h"
28
29 #define printf(...) funcs->printf(__VA_ARGS__)
30
31 int x = 1;
32 int *g = &x;
33
34 #if __x86_64__
35 __attribute__((section(("__HIB, __text"))))
36 #else
37 __attribute__((section(("__TEXT_EXEC, __text"))))
38 #endif
39 int _start(const TestRunnerFunctions* funcs)
40 {
41 setFuncs(funcs);
42
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);
51 return 0;
52 }
53
54 int slideClassicReturnCode = slideClassic(funcs->mhs[0], funcs->printf);
55 if ( slideClassicReturnCode != 0 ) {
56 FAIL("mhs[0] slide classic = %d\n", slideClassicReturnCode);
57 return 0;
58 }
59
60 if ( g[0] != x ) {
61 FAIL("g[0] != x, %d != %d\n", g[0], x);
62 return 0;
63 }
64
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);
69 return 0;
70 }
71
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);
76 return 0;
77 }
78
79 // Slide the auc KC
80 slideReturnCode = slide(funcs->mhs[3], slideBasePointers, funcs->printf);
81 if ( slideReturnCode != 0 ) {
82 FAIL("mhs[3] slide = %d\n", slideReturnCode);
83 return 0;
84 }
85
86 #if __x86_64__
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);
92 return 0;
93 }
94 #endif
95
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);
101 return 0;
102 }
103
104 PASS("Success");
105 return 0;
106 }
107
108