]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/kernel-fixups.dtest/main.c
dyld-851.27.tar.gz
[apple/dyld.git] / testing / test-cases / kernel-fixups.dtest / main.c
1
2 // BOOT_ARGS: amfi=3 cs_enforcement_disable=1
3
4 // BUILD(macos,ios,tvos,bridgeos|x86_64,arm64,arm64e): $CC main.c -o $BUILD_DIR/kernel-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
5 // BUILD(macos,ios,tvos,bridgeos|x86_64,arm64,arm64e): $APP_CACHE_UTIL -create-kernel-collection $BUILD_DIR/kernel.kc -kernel $BUILD_DIR/kernel-fixups.exe
6
7 // BUILD(watchos):
8
9
10 // RUN_STATIC: $RUN_STATIC ./kernel.kc
11
12 #include "../kernel-test-runner.h"
13 #include "../kernel-fixups.h"
14 #include "../kernel-classic-relocs.h"
15
16 #define printf(...) funcs->printf(__VA_ARGS__)
17
18 int x = 1;
19 int *g = &x;
20
21 #if __x86_64__
22 __attribute__((section(("__HIB, __text"))))
23 #else
24 __attribute__((section(("__TEXT_EXEC, __text"))))
25 #endif
26 int _start(const TestRunnerFunctions* funcs)
27 {
28 setFuncs(funcs);
29
30 const void* slideBasePointers[4];
31 slideBasePointers[0] = funcs->basePointers[0];
32 slideBasePointers[1] = funcs->basePointers[1];
33 slideBasePointers[2] = funcs->basePointers[2];
34 slideBasePointers[3] = funcs->basePointers[3];
35 int slideReturnCode = slide(funcs->mhs[0], slideBasePointers, funcs->printf);
36 if ( slideReturnCode != 0 ) {
37 FAIL("slide = %d\n", slideReturnCode);
38 return 0;
39 }
40
41 int slideClassicReturnCode = slideClassic(funcs->mhs[0], funcs->printf);
42 if ( slideClassicReturnCode != 0 ) {
43 FAIL("mhs[0] slide classic = %d\n", slideClassicReturnCode);
44 return 0;
45 }
46
47 LOG("Done sliding");
48
49 if ( g[0] != x ) {
50 FAIL("g[0] != x, %d != %d\n", g[0], x);
51 return 0;
52 }
53
54 PASS("Success");
55 return 0;
56 }
57
58