]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/kernel-fixups-x86_64.dtest/main.c
f5bc35193ac9d8055ed1268f49b3aec18e5dbe8e
[apple/dyld.git] / testing / test-cases / kernel-fixups-x86_64.dtest / main.c
1
2 // BOOT_ARGS: amfi=3 cs_enforcement_disable=1
3
4 // BUILD(macos|x86_64): $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
5 // BUILD(macos|x86_64): $APP_CACHE_UTIL -create-kernel-collection $BUILD_DIR/kernel.kc -kernel $BUILD_DIR/kernel-fixups.exe
6
7 // BUILD(ios,tvos,watchos,bridgeos):
8
9 // RUN_STATIC: $RUN_STATIC ./kernel.kc
10
11 // This tests that unaligned fixups work in x86_64
12
13 #include "../kernel-test-runner.h"
14 #include "../kernel-fixups.h"
15 #include "../kernel-classic-relocs.h"
16
17 #define printf(...) funcs->printf(__VA_ARGS__)
18
19 int x = 1;
20
21 struct __attribute__((packed)) __attribute__((aligned((4096)))) PackedS {
22 int i0; // aligned to 8
23 int* p0; // aligned to 4
24 int i1; // aligned to 4
25 int* p1; // aligned to 8
26 char i2; // aligned to 8
27 int* p2; // aligned to 1
28 };
29 struct PackedS ps = { 0, &x, 0, &x, 0, &x };
30
31 __attribute__((section(("__HIB, __text"))))
32 int _start(const TestRunnerFunctions* funcs)
33 {
34 setFuncs(funcs);
35
36 const void* slideBasePointers[4];
37 slideBasePointers[0] = funcs->basePointers[0];
38 slideBasePointers[1] = funcs->basePointers[1];
39 slideBasePointers[2] = funcs->basePointers[2];
40 slideBasePointers[3] = funcs->basePointers[3];
41 int slideReturnCode = slide(funcs->mhs[0], slideBasePointers, funcs->printf);
42 if ( slideReturnCode != 0 ) {
43 FAIL("slide = %d\n", slideReturnCode);
44 return 0;
45 }
46
47 int slideClassicReturnCode = slideClassic(funcs->mhs[0], funcs->printf);
48 if ( slideClassicReturnCode != 0 ) {
49 FAIL("mhs[0] slide classic = %d\n", slideClassicReturnCode);
50 return 0;
51 }
52
53 LOG("Done sliding");
54
55 if ( ps.p0[0] != x ) {
56 FAIL("ps.p1[0] != x, %d != %d\n", ps.p0[0], x);
57 return 0;
58 }
59
60 if ( ps.p1[0] != x ) {
61 FAIL("ps.p1[0] != x, %d != %d\n", ps.p1[0], x);
62 return 0;
63 }
64
65 if ( ps.p2[0] != x ) {
66 FAIL("ps.p2[0] != x, %d != %d\n", ps.p2[0], x);
67 return 0;
68 }
69
70 PASS("Success");
71 return 0;
72 }
73
74