]> git.saurik.com Git - apple/dyld.git/blob - testing/kernel-cache-tests/kernel-base-address-x86_64/test.py
dyld-851.27.tar.gz
[apple/dyld.git] / testing / kernel-cache-tests / kernel-base-address-x86_64 / 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("x86_64", "/kernel-base-address-x86_64/main.kc", "/kernel-base-address-x86_64/main.kernel", None, [], [])
9
10 # Check the layout
11 kernel_cache.analyze("/kernel-base-address-x86_64/main.kc", ["-layout", "-arch", "x86_64"])
12
13 assert len(kernel_cache.dictionary()["cache-segments"]) == 7
14 assert kernel_cache.dictionary()["cache-segments"][0]["name"] == "__TEXT"
15 assert kernel_cache.dictionary()["cache-segments"][0]["vmAddr"] == "0xFFFFFF8000200000"
16 assert kernel_cache.dictionary()["cache-segments"][1]["name"] == "__PRELINK_TEXT"
17 assert kernel_cache.dictionary()["cache-segments"][1]["vmAddr"] == "0xFFFFFF8000204000"
18 assert kernel_cache.dictionary()["cache-segments"][2]["name"] == "__TEXT_EXEC"
19 assert kernel_cache.dictionary()["cache-segments"][2]["vmAddr"] == "0xFFFFFF8000204000"
20 assert kernel_cache.dictionary()["cache-segments"][3]["name"] == "__PRELINK_INFO"
21 assert kernel_cache.dictionary()["cache-segments"][3]["vmAddr"] == "0xFFFFFF8000208000"
22 assert kernel_cache.dictionary()["cache-segments"][4]["name"] == "__DATA"
23 assert kernel_cache.dictionary()["cache-segments"][4]["vmAddr"] == "0xFFFFFF800020C000"
24 assert kernel_cache.dictionary()["cache-segments"][5]["name"] == "__HIB"
25 assert kernel_cache.dictionary()["cache-segments"][5]["vmAddr"] == "0xFFFFFF8000100000"
26 assert kernel_cache.dictionary()["cache-segments"][6]["name"] == "__LINKEDIT"
27 assert kernel_cache.dictionary()["cache-segments"][6]["vmAddr"] == "0xFFFFFF8000210000"
28
29 assert len(kernel_cache.dictionary()["dylibs"]) == 1
30 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
31 assert len(kernel_cache.dictionary()["dylibs"][0]["segments"]) == 4
32 assert kernel_cache.dictionary()["dylibs"][0]["segments"][0]["name"] == "__TEXT"
33 assert kernel_cache.dictionary()["dylibs"][0]["segments"][0]["vmAddr"] == "0xFFFFFF8000204000"
34 assert kernel_cache.dictionary()["dylibs"][0]["segments"][1]["name"] == "__DATA"
35 assert kernel_cache.dictionary()["dylibs"][0]["segments"][1]["vmAddr"] == "0xFFFFFF800020C000"
36 assert kernel_cache.dictionary()["dylibs"][0]["segments"][2]["name"] == "__HIB"
37 assert kernel_cache.dictionary()["dylibs"][0]["segments"][2]["vmAddr"] == "0xFFFFFF8000100000"
38 assert kernel_cache.dictionary()["dylibs"][0]["segments"][3]["name"] == "__LINKEDIT"
39 assert kernel_cache.dictionary()["dylibs"][0]["segments"][3]["vmAddr"] == "0xFFFFFF8000210000"
40
41 # Check the entry point
42 kernel_cache.analyze("/kernel-base-address-x86_64/main.kc", ["-entrypoint", "-arch", "x86_64"])
43 assert kernel_cache.dictionary()["entrypoint"] == "0xFFFFFF8000100000"
44
45 # Check the fixups
46 kernel_cache.analyze("/kernel-base-address-x86_64/main.kc", ["-fixups", "-arch", "x86_64"])
47 assert len(kernel_cache.dictionary()["fixups"]) == 2
48 assert kernel_cache.dictionary()["fixups"]["0x10C008"] == "kc(0) + 0xFFFFFF8000204FF0 : pointer64"
49 assert kernel_cache.dictionary()["fixups"]["0x30"] == "kc(0) + 0xFFFFFF8000100028 : pointer64"
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 macosx.internal cc -arch x86_64 -Wl,-static -mkernel -nostdlib -Wl,-e,__start -Wl,-pie main.c -Wl,-pagezero_size,0x0 -o main.kernel -Wl,-image_base,0xffffff8000200000 -Wl,-segaddr,__HIB,0xffffff8000100000 -Wl,-add_split_seg_info -Wl,-install_name,/usr/lib/swift/split.seg.v2.hack
55