]> git.saurik.com Git - apple/dyld.git/blob - testing/kernel-cache-tests/ctf-arm64e/test.py
dyld-832.7.1.tar.gz
[apple/dyld.git] / testing / kernel-cache-tests / ctf-arm64e / test.py
1 #!/usr/bin/python2.7
2
3 import os
4 import KernelCollection
5
6 # This is the fixups-arm64e test, but with __CTF inserted so that we can see that CTF doesn't impact the result
7 # Note the ctf.txt file is 16k just to ensure that if its vm addr wasn't updated, we'd exceed the size of __LINKEDIT with the __CTF
8
9
10 def check(kernel_cache):
11 kernel_cache.buildKernelCollection("arm64e", "/ctf-arm64e/main.kc", "/ctf-arm64e/main.kernel", "/ctf-arm64e/extensions", ["com.apple.foo", "com.apple.bar"], [])
12 kernel_cache.analyze("/ctf-arm64e/main.kc", ["-layout", "-arch", "arm64e"])
13
14 assert len(kernel_cache.dictionary()["cache-segments"]) == 6
15 assert kernel_cache.dictionary()["cache-segments"][0]["name"] == "__TEXT"
16 assert kernel_cache.dictionary()["cache-segments"][0]["vmAddr"] == "0xFFFFFFF007004000"
17 assert kernel_cache.dictionary()["cache-segments"][1]["name"] == "__PRELINK_TEXT"
18 assert kernel_cache.dictionary()["cache-segments"][1]["vmAddr"] == "0xFFFFFFF007008000"
19 assert kernel_cache.dictionary()["cache-segments"][2]["name"] == "__TEXT_EXEC"
20 assert kernel_cache.dictionary()["cache-segments"][2]["vmAddr"] == "0xFFFFFFF007010000"
21 assert kernel_cache.dictionary()["cache-segments"][3]["name"] == "__PRELINK_INFO"
22 assert kernel_cache.dictionary()["cache-segments"][3]["vmAddr"] == "0xFFFFFFF00701C000"
23 assert kernel_cache.dictionary()["cache-segments"][4]["name"] == "__DATA"
24 assert kernel_cache.dictionary()["cache-segments"][4]["vmAddr"] == "0xFFFFFFF007020000"
25 assert kernel_cache.dictionary()["cache-segments"][5]["name"] == "__LINKEDIT"
26 assert kernel_cache.dictionary()["cache-segments"][5]["vmAddr"] == "0xFFFFFFF007030000"
27
28 assert len(kernel_cache.dictionary()["dylibs"]) == 3
29 # main.kernel
30 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
31 assert len(kernel_cache.dictionary()["dylibs"][0]["segments"]) == 5
32 assert kernel_cache.dictionary()["dylibs"][0]["segments"][0]["name"] == "__TEXT"
33 assert kernel_cache.dictionary()["dylibs"][0]["segments"][0]["vmAddr"] == "0xFFFFFFF007010000"
34 assert kernel_cache.dictionary()["dylibs"][0]["segments"][1]["name"] == "__DATA"
35 assert kernel_cache.dictionary()["dylibs"][0]["segments"][1]["vmAddr"] == "0xFFFFFFF007020000"
36 assert kernel_cache.dictionary()["dylibs"][0]["segments"][2]["name"] == "__TEXT_EXEC"
37 assert kernel_cache.dictionary()["dylibs"][0]["segments"][2]["vmAddr"] == "0xFFFFFFF007014000"
38 assert kernel_cache.dictionary()["dylibs"][0]["segments"][3]["name"] == "__CTF"
39 assert kernel_cache.dictionary()["dylibs"][0]["segments"][3]["vmAddr"] == "0xFFFFFFF007008000"
40 assert kernel_cache.dictionary()["dylibs"][0]["segments"][3]["vmSize"] == "0x0"
41 assert kernel_cache.dictionary()["dylibs"][0]["segments"][3]["sections"][0]["vmAddr"] == "0xFFFFFFF007008000"
42 assert kernel_cache.dictionary()["dylibs"][0]["segments"][3]["sections"][0]["vmSize"] == "0x0"
43 assert kernel_cache.dictionary()["dylibs"][0]["segments"][4]["name"] == "__LINKEDIT"
44 assert kernel_cache.dictionary()["dylibs"][0]["segments"][4]["vmAddr"] == "0xFFFFFFF007030000"
45 # bar.kext
46 assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.bar"
47 assert len(kernel_cache.dictionary()["dylibs"][1]["segments"]) == 4
48 assert kernel_cache.dictionary()["dylibs"][1]["segments"][0]["name"] == "__TEXT"
49 assert kernel_cache.dictionary()["dylibs"][1]["segments"][0]["vmAddr"] == "0xFFFFFFF007008000"
50 assert kernel_cache.dictionary()["dylibs"][1]["segments"][1]["name"] == "__TEXT_EXEC"
51 assert kernel_cache.dictionary()["dylibs"][1]["segments"][1]["vmAddr"] == "0xFFFFFFF007018000"
52 assert kernel_cache.dictionary()["dylibs"][1]["segments"][2]["name"] == "__DATA"
53 assert kernel_cache.dictionary()["dylibs"][1]["segments"][2]["vmAddr"] == "0xFFFFFFF00702C000"
54 assert kernel_cache.dictionary()["dylibs"][1]["segments"][3]["name"] == "__LINKEDIT"
55 assert kernel_cache.dictionary()["dylibs"][1]["segments"][3]["vmAddr"] == "0xFFFFFFF007030000"
56 # foo.kext
57 assert kernel_cache.dictionary()["dylibs"][2]["name"] == "com.apple.foo"
58 assert len(kernel_cache.dictionary()["dylibs"][2]["segments"]) == 4
59 assert kernel_cache.dictionary()["dylibs"][2]["segments"][0]["name"] == "__TEXT"
60 assert kernel_cache.dictionary()["dylibs"][2]["segments"][0]["vmAddr"] == "0xFFFFFFF00700C000"
61 assert kernel_cache.dictionary()["dylibs"][2]["segments"][1]["name"] == "__TEXT_EXEC"
62 assert kernel_cache.dictionary()["dylibs"][2]["segments"][1]["vmAddr"] == "0xFFFFFFF007018040"
63 assert kernel_cache.dictionary()["dylibs"][2]["segments"][2]["name"] == "__DATA"
64 assert kernel_cache.dictionary()["dylibs"][2]["segments"][2]["vmAddr"] == "0xFFFFFFF00702C010"
65 assert kernel_cache.dictionary()["dylibs"][2]["segments"][3]["name"] == "__LINKEDIT"
66 assert kernel_cache.dictionary()["dylibs"][2]["segments"][3]["vmAddr"] == "0xFFFFFFF007030000"
67
68 # Check the fixups
69 kernel_cache.analyze("/ctf-arm64e/main.kc", ["-fixups", "-arch", "arm64e"])
70 assert len(kernel_cache.dictionary()["fixups"]) == 11
71 # main.kernel: S s = { &func, &func, &g, &func, &g };
72 assert kernel_cache.dictionary()["fixups"]["0x1C000"] == "kc(0) + 0xFFFFFFF007014000 auth(IA !addr 0)"
73 assert kernel_cache.dictionary()["fixups"]["0x1C008"] == "kc(0) + 0xFFFFFFF007014000 auth(IA !addr 0)"
74 assert kernel_cache.dictionary()["fixups"]["0x1C010"] == "kc(0) + 0xFFFFFFF00702802C"
75 assert kernel_cache.dictionary()["fixups"]["0x20000"] == "kc(0) + 0xFFFFFFF007014000 auth(IA !addr 0)"
76 assert kernel_cache.dictionary()["fixups"]["0x20008"] == "kc(0) + 0xFFFFFFF00702802C"
77 # main.kernel: PackedS ps = { 0, &func, &func, 0, &g, 0, &g };
78 assert kernel_cache.dictionary()["fixups"]["0x24004"] == "kc(0) + 0xFFFFFFF007014000 auth(IA !addr 0)"
79 assert kernel_cache.dictionary()["fixups"]["0x2400C"] == "kc(0) + 0xFFFFFFF007014000 auth(IA !addr 0)"
80 assert kernel_cache.dictionary()["fixups"]["0x24018"] == "kc(0) + 0xFFFFFFF00702802C"
81 assert kernel_cache.dictionary()["fixups"]["0x24024"] == "kc(0) + 0xFFFFFFF00702802C"
82 # bar.kext: __typeof(&bar) barPtr = &bar;
83 assert kernel_cache.dictionary()["fixups"]["0x28000"] == "kc(0) + 0xFFFFFFF007018000 auth(IA !addr 0)"
84 # foo.kext: int* gPtr = &g;
85 assert kernel_cache.dictionary()["fixups"]["0x28010"] == "kc(0) + 0xFFFFFFF00702C018"
86 assert len(kernel_cache.dictionary()["dylibs"]) == 3
87 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
88 assert kernel_cache.dictionary()["dylibs"][0]["fixups"] == "none"
89 assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.bar"
90 assert kernel_cache.dictionary()["dylibs"][1]["fixups"] == "none"
91 assert kernel_cache.dictionary()["dylibs"][2]["name"] == "com.apple.foo"
92 assert kernel_cache.dictionary()["dylibs"][2]["fixups"] == "none"
93
94 # [~]> 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
95 # [~]> xcrun -sdk macosx.internal ctf_insert main.kernel -arch arm64e ctf.txt -o main.kernel
96 # [~]> 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
97 # [~]> 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
98 # [~]> rm -r extensions/*.kext/*.ld
99