]> git.saurik.com Git - apple/dyld.git/blob - testing/kernel-cache-tests/fixups-arm64e/test.py
dyld-851.27.tar.gz
[apple/dyld.git] / testing / kernel-cache-tests / fixups-arm64e / test.py
1 #!/usr/bin/python2.7
2
3 import os
4 import KernelCollection
5
6
7 def check(kernel_cache):
8 kernel_cache.buildKernelCollection("arm64e", "/fixups-arm64e/main.kc", "/fixups-arm64e/main.kernel", "/fixups-arm64e/extensions", ["com.apple.foo", "com.apple.bar"], [])
9 kernel_cache.analyze("/fixups-arm64e/main.kc", ["-layout", "-arch", "arm64e"])
10
11 assert len(kernel_cache.dictionary()["cache-segments"]) == 6
12 assert kernel_cache.dictionary()["cache-segments"][0]["name"] == "__TEXT"
13 assert kernel_cache.dictionary()["cache-segments"][0]["vmAddr"] == "0xFFFFFFF007004000"
14 assert kernel_cache.dictionary()["cache-segments"][1]["name"] == "__PRELINK_TEXT"
15 assert kernel_cache.dictionary()["cache-segments"][1]["vmAddr"] == "0xFFFFFFF007008000"
16 assert kernel_cache.dictionary()["cache-segments"][2]["name"] == "__TEXT_EXEC"
17 assert kernel_cache.dictionary()["cache-segments"][2]["vmAddr"] == "0xFFFFFFF007010000"
18 assert kernel_cache.dictionary()["cache-segments"][3]["name"] == "__PRELINK_INFO"
19 assert kernel_cache.dictionary()["cache-segments"][3]["vmAddr"] == "0xFFFFFFF00701C000"
20 assert kernel_cache.dictionary()["cache-segments"][4]["name"] == "__DATA"
21 assert kernel_cache.dictionary()["cache-segments"][4]["vmAddr"] == "0xFFFFFFF007020000"
22 assert kernel_cache.dictionary()["cache-segments"][5]["name"] == "__LINKEDIT"
23 assert kernel_cache.dictionary()["cache-segments"][5]["vmAddr"] == "0xFFFFFFF007030000"
24
25 assert len(kernel_cache.dictionary()["dylibs"]) == 3
26 # main.kernel
27 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
28 assert len(kernel_cache.dictionary()["dylibs"][0]["segments"]) == 4
29 assert kernel_cache.dictionary()["dylibs"][0]["segments"][0]["name"] == "__TEXT"
30 assert kernel_cache.dictionary()["dylibs"][0]["segments"][0]["vmAddr"] == "0xFFFFFFF007010000"
31 assert kernel_cache.dictionary()["dylibs"][0]["segments"][1]["name"] == "__DATA"
32 assert kernel_cache.dictionary()["dylibs"][0]["segments"][1]["vmAddr"] == "0xFFFFFFF007020000"
33 assert kernel_cache.dictionary()["dylibs"][0]["segments"][2]["name"] == "__TEXT_EXEC"
34 assert kernel_cache.dictionary()["dylibs"][0]["segments"][2]["vmAddr"] == "0xFFFFFFF007014000"
35 assert kernel_cache.dictionary()["dylibs"][0]["segments"][3]["name"] == "__LINKEDIT"
36 assert kernel_cache.dictionary()["dylibs"][0]["segments"][3]["vmAddr"] == "0xFFFFFFF007030000"
37 # bar.kext
38 assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.bar"
39 assert len(kernel_cache.dictionary()["dylibs"][1]["segments"]) == 4
40 assert kernel_cache.dictionary()["dylibs"][1]["segments"][0]["name"] == "__TEXT"
41 assert kernel_cache.dictionary()["dylibs"][1]["segments"][0]["vmAddr"] == "0xFFFFFFF007008000"
42 assert kernel_cache.dictionary()["dylibs"][1]["segments"][1]["name"] == "__TEXT_EXEC"
43 assert kernel_cache.dictionary()["dylibs"][1]["segments"][1]["vmAddr"] == "0xFFFFFFF007018000"
44 assert kernel_cache.dictionary()["dylibs"][1]["segments"][2]["name"] == "__DATA"
45 assert kernel_cache.dictionary()["dylibs"][1]["segments"][2]["vmAddr"] == "0xFFFFFFF00702C000"
46 assert kernel_cache.dictionary()["dylibs"][1]["segments"][3]["name"] == "__LINKEDIT"
47 assert kernel_cache.dictionary()["dylibs"][1]["segments"][3]["vmAddr"] == "0xFFFFFFF007030000"
48 # foo.kext
49 assert kernel_cache.dictionary()["dylibs"][2]["name"] == "com.apple.foo"
50 assert len(kernel_cache.dictionary()["dylibs"][2]["segments"]) == 4
51 assert kernel_cache.dictionary()["dylibs"][2]["segments"][0]["name"] == "__TEXT"
52 assert kernel_cache.dictionary()["dylibs"][2]["segments"][0]["vmAddr"] == "0xFFFFFFF00700C000"
53 assert kernel_cache.dictionary()["dylibs"][2]["segments"][1]["name"] == "__TEXT_EXEC"
54 assert kernel_cache.dictionary()["dylibs"][2]["segments"][1]["vmAddr"] == "0xFFFFFFF007018040"
55 assert kernel_cache.dictionary()["dylibs"][2]["segments"][2]["name"] == "__DATA"
56 assert kernel_cache.dictionary()["dylibs"][2]["segments"][2]["vmAddr"] == "0xFFFFFFF00702C010"
57 assert kernel_cache.dictionary()["dylibs"][2]["segments"][3]["name"] == "__LINKEDIT"
58 assert kernel_cache.dictionary()["dylibs"][2]["segments"][3]["vmAddr"] == "0xFFFFFFF007030000"
59
60 # Check the fixups
61 kernel_cache.analyze("/fixups-arm64e/main.kc", ["-fixups", "-arch", "arm64e"])
62 assert len(kernel_cache.dictionary()["fixups"]) == 11
63 # main.kernel: S s = { &func, &func, &g, &func, &g };
64 assert kernel_cache.dictionary()["fixups"]["0x1C000"] == "kc(0) + 0xFFFFFFF007014000 auth(IA !addr 0)"
65 assert kernel_cache.dictionary()["fixups"]["0x1C008"] == "kc(0) + 0xFFFFFFF007014000 auth(IA !addr 0)"
66 assert kernel_cache.dictionary()["fixups"]["0x1C010"] == "kc(0) + 0xFFFFFFF00702802C"
67 assert kernel_cache.dictionary()["fixups"]["0x20000"] == "kc(0) + 0xFFFFFFF007014000 auth(IA !addr 0)"
68 assert kernel_cache.dictionary()["fixups"]["0x20008"] == "kc(0) + 0xFFFFFFF00702802C"
69 # main.kernel: PackedS ps = { 0, &func, &func, 0, &g, 0, &g };
70 assert kernel_cache.dictionary()["fixups"]["0x24004"] == "kc(0) + 0xFFFFFFF007014000 auth(IA !addr 0)"
71 assert kernel_cache.dictionary()["fixups"]["0x2400C"] == "kc(0) + 0xFFFFFFF007014000 auth(IA !addr 0)"
72 assert kernel_cache.dictionary()["fixups"]["0x24018"] == "kc(0) + 0xFFFFFFF00702802C"
73 assert kernel_cache.dictionary()["fixups"]["0x24024"] == "kc(0) + 0xFFFFFFF00702802C"
74 # bar.kext: __typeof(&bar) barPtr = &bar;
75 assert kernel_cache.dictionary()["fixups"]["0x28000"] == "kc(0) + 0xFFFFFFF007018000 auth(IA !addr 0)"
76 # foo.kext: int* gPtr = &g;
77 assert kernel_cache.dictionary()["fixups"]["0x28010"] == "kc(0) + 0xFFFFFFF00702C018"
78 assert len(kernel_cache.dictionary()["dylibs"]) == 3
79 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
80 assert kernel_cache.dictionary()["dylibs"][0]["fixups"] == "none"
81 assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.bar"
82 assert kernel_cache.dictionary()["dylibs"][1]["fixups"] == "none"
83 assert kernel_cache.dictionary()["dylibs"][2]["name"] == "com.apple.foo"
84 assert kernel_cache.dictionary()["dylibs"][2]["fixups"] == "none"
85
86 # [~]> xcrun -sdk iphoneos.internal cc -arch arm64e -std=c++11 -Wl,-static -mkernel -Wl,-fixup_chains -Wl,-kernel -nostdlib -Wl,-add_split_seg_info -Wl,-e,__start -Wl,-pie main.cpp -Wl,-pagezero_size,0x0 -Wl,-rename_section,__TEXT,__text,__TEXT_EXEC,__text -o main.kernel -Wl,-image_base,0xfffffff007004000 -Wl,-install_name,/usr/lib/swift/split.seg.v2.hack
87 # [~]> xcrun -sdk iphoneos.internal cc -arch arm64e -Wl,-kext -mkernel -nostdlib -Wl,-add_split_seg_info -Wl,-fixup_chains foo.c -o extensions/foo.kext/foo
88 # [~]> xcrun -sdk iphoneos.internal cc -arch arm64e -Wl,-kext -mkernel -nostdlib -Wl,-add_split_seg_info -Wl,-fixup_chains bar.c -o extensions/bar.kext/bar
89 # [~]> rm -r extensions/*.kext/*.ld
90