]> git.saurik.com Git - apple/dyld.git/blob - testing/kernel-cache-tests/kernel-base-address/test.py
dyld-851.27.tar.gz
[apple/dyld.git] / testing / kernel-cache-tests / kernel-base-address / 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("arm64", "/kernel-base-address/main.kc", "/kernel-base-address/main.kernel", None, [], [])
9
10 # Check the layout
11 kernel_cache.analyze("/kernel-base-address/main.kc", ["-layout", "-arch", "arm64"])
12
13 assert len(kernel_cache.dictionary()["cache-segments"]) == 6
14 assert kernel_cache.dictionary()["cache-segments"][0]["name"] == "__TEXT"
15 assert kernel_cache.dictionary()["cache-segments"][0]["vmAddr"] == "0xFFFFFFF007004000"
16 assert kernel_cache.dictionary()["cache-segments"][1]["name"] == "__PRELINK_TEXT"
17 assert kernel_cache.dictionary()["cache-segments"][1]["vmAddr"] == "0xFFFFFFF007008000"
18 assert kernel_cache.dictionary()["cache-segments"][2]["name"] == "__TEXT_EXEC"
19 assert kernel_cache.dictionary()["cache-segments"][2]["vmAddr"] == "0xFFFFFFF007008000"
20 assert kernel_cache.dictionary()["cache-segments"][3]["name"] == "__PRELINK_INFO"
21 assert kernel_cache.dictionary()["cache-segments"][3]["vmAddr"] == "0xFFFFFFF007010000"
22 assert kernel_cache.dictionary()["cache-segments"][4]["name"] == "__DATA"
23 assert kernel_cache.dictionary()["cache-segments"][4]["vmAddr"] == "0xFFFFFFF007014000"
24 assert kernel_cache.dictionary()["cache-segments"][5]["name"] == "__LINKEDIT"
25 assert kernel_cache.dictionary()["cache-segments"][5]["vmAddr"] == "0xFFFFFFF00701C000"
26
27 assert len(kernel_cache.dictionary()["dylibs"]) == 1
28 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
29 assert len(kernel_cache.dictionary()["dylibs"][0]["segments"]) == 4
30 assert kernel_cache.dictionary()["dylibs"][0]["segments"][0]["name"] == "__TEXT"
31 assert kernel_cache.dictionary()["dylibs"][0]["segments"][0]["vmAddr"] == "0xFFFFFFF007008000"
32 assert kernel_cache.dictionary()["dylibs"][0]["segments"][1]["name"] == "__DATA"
33 assert kernel_cache.dictionary()["dylibs"][0]["segments"][1]["vmAddr"] == "0xFFFFFFF007014000"
34 assert kernel_cache.dictionary()["dylibs"][0]["segments"][2]["name"] == "__TEXT_EXEC"
35 assert kernel_cache.dictionary()["dylibs"][0]["segments"][2]["vmAddr"] == "0xFFFFFFF00700C000"
36 assert kernel_cache.dictionary()["dylibs"][0]["segments"][3]["name"] == "__LINKEDIT"
37 assert kernel_cache.dictionary()["dylibs"][0]["segments"][3]["vmAddr"] == "0xFFFFFFF00701C000"
38
39 # Check the entry point
40 kernel_cache.analyze("/kernel-base-address/main.kc", ["-entrypoint", "-arch", "arm64"])
41 assert kernel_cache.dictionary()["entrypoint"] == "0xFFFFFFF00700C000"
42
43 # Check the fixups
44 kernel_cache.analyze("/kernel-base-address/main.kc", ["-fixups", "-arch", "arm64"])
45 assert len(kernel_cache.dictionary()["fixups"]) == 4
46 assert kernel_cache.dictionary()["fixups"]["0x10000"] == "kc(0) + 0xFFFFFFF007014028"
47 assert kernel_cache.dictionary()["fixups"]["0x10008"] == "kc(0) + 0xFFFFFFF007014028"
48 assert kernel_cache.dictionary()["fixups"]["0x10018"] == "kc(0) + 0xFFFFFFF00701402C"
49 assert kernel_cache.dictionary()["fixups"]["0x10020"] == "kc(0) + 0xFFFFFFF00701402D"
50 assert len(kernel_cache.dictionary()["dylibs"]) == 1
51 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
52 assert kernel_cache.dictionary()["dylibs"][0]["fixups"] == "none"
53
54 # [~]> xcrun -sdk iphoneos.internal cc -arch arm64 -Wl,-static -mkernel -nostdlib -Wl,-add_split_seg_info -Wl,-e,__start -Wl,-pie main.c -Wl,-pagezero_size,0x0 -Wl,-rename_section,__TEXT,__text,__TEXT_EXEC,__text -o main.kernel -Wl,-install_name,/usr/lib/swift/split.seg.v2.hack -Wl,-image_base,0xfffffff007004000
55