]> git.saurik.com Git - apple/dyld.git/blob - testing/kernel-cache-tests/text-fixups-x86_64/test.py
dyld-832.7.1.tar.gz
[apple/dyld.git] / testing / kernel-cache-tests / text-fixups-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", "/text-fixups-x86_64/main.kc", "/text-fixups-x86_64/main.kernel", "/text-fixups-x86_64/extensions", ["com.apple.foo", "com.apple.bar"], [])
9 kernel_cache.analyze("/text-fixups-x86_64/main.kc", ["-layout", "-arch", "x86_64"])
10
11 assert len(kernel_cache.dictionary()["cache-segments"]) == 11
12 assert kernel_cache.dictionary()["cache-segments"][0]["name"] == "__TEXT"
13 assert kernel_cache.dictionary()["cache-segments"][0]["vmAddr"] == "0xFFFFFF8000200000"
14 assert kernel_cache.dictionary()["cache-segments"][1]["name"] == "__PRELINK_TEXT"
15 assert kernel_cache.dictionary()["cache-segments"][1]["vmAddr"] == "0xFFFFFF8000204000"
16 assert kernel_cache.dictionary()["cache-segments"][2]["name"] == "__TEXT_EXEC"
17 assert kernel_cache.dictionary()["cache-segments"][2]["vmAddr"] == "0xFFFFFF8000204000"
18 assert kernel_cache.dictionary()["cache-segments"][3]["name"] == "__PRELINK_INFO"
19 assert kernel_cache.dictionary()["cache-segments"][3]["vmAddr"] == "0xFFFFFF8000208000"
20 assert kernel_cache.dictionary()["cache-segments"][4]["name"] == "__DATA"
21 assert kernel_cache.dictionary()["cache-segments"][4]["vmAddr"] == "0xFFFFFF800020C000"
22 assert kernel_cache.dictionary()["cache-segments"][5]["name"] == "__HIB"
23 assert kernel_cache.dictionary()["cache-segments"][5]["vmAddr"] == "0xFFFFFF8000100000"
24 assert kernel_cache.dictionary()["cache-segments"][6]["name"] == "__REGION0"
25 assert kernel_cache.dictionary()["cache-segments"][6]["vmAddr"] == "0xFFFFFF8000218000"
26 assert kernel_cache.dictionary()["cache-segments"][7]["name"] == "__REGION1"
27 assert kernel_cache.dictionary()["cache-segments"][7]["vmAddr"] == "0xFFFFFF8000219000"
28 assert kernel_cache.dictionary()["cache-segments"][8]["name"] == "__REGION2"
29 assert kernel_cache.dictionary()["cache-segments"][8]["vmAddr"] == "0xFFFFFF800021A000"
30 assert kernel_cache.dictionary()["cache-segments"][9]["name"] == "__REGION3"
31 assert kernel_cache.dictionary()["cache-segments"][9]["vmAddr"] == "0xFFFFFF800021B000"
32 assert kernel_cache.dictionary()["cache-segments"][10]["name"] == "__LINKEDIT"
33 assert kernel_cache.dictionary()["cache-segments"][10]["vmAddr"] == "0xFFFFFF800021C000"
34
35 assert len(kernel_cache.dictionary()["dylibs"]) == 3
36 # main.kernel
37 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
38 assert len(kernel_cache.dictionary()["dylibs"][0]["segments"]) == 4
39 assert kernel_cache.dictionary()["dylibs"][0]["segments"][0]["name"] == "__TEXT"
40 assert kernel_cache.dictionary()["dylibs"][0]["segments"][0]["vmAddr"] == "0xFFFFFF8000204000"
41 assert kernel_cache.dictionary()["dylibs"][0]["segments"][1]["name"] == "__DATA"
42 assert kernel_cache.dictionary()["dylibs"][0]["segments"][1]["vmAddr"] == "0xFFFFFF800020C000"
43 assert kernel_cache.dictionary()["dylibs"][0]["segments"][2]["name"] == "__HIB"
44 assert kernel_cache.dictionary()["dylibs"][0]["segments"][2]["vmAddr"] == "0xFFFFFF8000100000"
45 assert kernel_cache.dictionary()["dylibs"][0]["segments"][3]["name"] == "__LINKEDIT"
46 assert kernel_cache.dictionary()["dylibs"][0]["segments"][3]["vmAddr"] == "0xFFFFFF800021C000"
47 # bar.kext
48 assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.bar"
49 assert len(kernel_cache.dictionary()["dylibs"][1]["segments"]) == 3
50 assert kernel_cache.dictionary()["dylibs"][1]["segments"][0]["name"] == "__TEXT"
51 assert kernel_cache.dictionary()["dylibs"][1]["segments"][0]["vmAddr"] == "0xFFFFFF8000218000"
52 assert kernel_cache.dictionary()["dylibs"][1]["segments"][1]["name"] == "__DATA"
53 assert kernel_cache.dictionary()["dylibs"][1]["segments"][1]["vmAddr"] == "0xFFFFFF8000219000"
54 assert kernel_cache.dictionary()["dylibs"][1]["segments"][2]["name"] == "__LINKEDIT"
55 assert kernel_cache.dictionary()["dylibs"][1]["segments"][2]["vmAddr"] == "0xFFFFFF800021C000"
56 # foo.kext
57 assert kernel_cache.dictionary()["dylibs"][2]["name"] == "com.apple.foo"
58 assert len(kernel_cache.dictionary()["dylibs"][2]["segments"]) == 3
59 assert kernel_cache.dictionary()["dylibs"][2]["segments"][0]["name"] == "__TEXT"
60 assert kernel_cache.dictionary()["dylibs"][2]["segments"][0]["vmAddr"] == "0xFFFFFF800021A000"
61 assert kernel_cache.dictionary()["dylibs"][2]["segments"][1]["name"] == "__DATA"
62 assert kernel_cache.dictionary()["dylibs"][2]["segments"][1]["vmAddr"] == "0xFFFFFF800021B000"
63 assert kernel_cache.dictionary()["dylibs"][2]["segments"][2]["name"] == "__LINKEDIT"
64 assert kernel_cache.dictionary()["dylibs"][2]["segments"][2]["vmAddr"] == "0xFFFFFF800021C000"
65
66 # Check the fixups
67 kernel_cache.analyze("/text-fixups-x86_64/main.kc", ["-fixups", "-arch", "x86_64"])
68 assert len(kernel_cache.dictionary()["fixups"]) == 12
69 # main.kernel: S s = { &func, &func, &g, &func, &g };
70 # _s is at 0xFFFFFF8000208000 which is offset 0x108000 from __HIB
71 assert kernel_cache.dictionary()["fixups"]["0x10C000"] == "kc(0) + 0xFFFFFF8000204FF0 : pointer64"
72 assert kernel_cache.dictionary()["fixups"]["0x10C008"] == "kc(0) + 0xFFFFFF8000204FF0 : pointer64"
73 assert kernel_cache.dictionary()["fixups"]["0x10C010"] == "kc(0) + 0xFFFFFF800021402C : pointer64"
74 assert kernel_cache.dictionary()["fixups"]["0x110000"] == "kc(0) + 0xFFFFFF8000204FF0 : pointer64"
75 assert kernel_cache.dictionary()["fixups"]["0x110008"] == "kc(0) + 0xFFFFFF800021402C : pointer64"
76 # main.kernel: PackedS ps = { 0, &func, &func, 0, &g, 0, &g };
77 # _ps is at 0xFFFFFF8000210000 which is offset 0x110000 from __HIB
78 assert kernel_cache.dictionary()["fixups"]["0x114004"] == "kc(0) + 0xFFFFFF8000204FF0 : pointer64"
79 assert kernel_cache.dictionary()["fixups"]["0x11400C"] == "kc(0) + 0xFFFFFF8000204FF0 : pointer64"
80 assert kernel_cache.dictionary()["fixups"]["0x114018"] == "kc(0) + 0xFFFFFF800021402C : pointer64"
81 assert kernel_cache.dictionary()["fixups"]["0x114021"] == "kc(0) + 0xFFFFFF800021402C : pointer64"
82 # bar.kext: __typeof(&bar) barPtr = &bar;
83 # _barPtr is at 0xFFFFFF8000210030 which is offset 0x110030 from __HIB
84 assert kernel_cache.dictionary()["fixups"]["0x118FF0"] == "kc(0) + 0xFFFFFF8000218FD0"
85 # foo.kext: int* gPtr = &g;
86 # _gPtr is at 0xFFFFFF8000210040 which is offset 0x110040 from __HIB
87 assert kernel_cache.dictionary()["fixups"]["0x11AFF0"] == "kc(0) + 0xFFFFFF800021B000"
88 # main.kernel: movl _foo, %esp
89 # The _foo reloc is at 0xFFFFFF8000100002 which is offset 0x2 from __HIB
90 assert kernel_cache.dictionary()["fixups"]["0x2"] == "kc(0) + 0x100000 : pointer32"
91 assert len(kernel_cache.dictionary()["dylibs"]) == 3
92 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
93 assert kernel_cache.dictionary()["dylibs"][0]["fixups"] == "none"
94 assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.bar"
95 assert kernel_cache.dictionary()["dylibs"][1]["fixups"] == "none"
96 assert kernel_cache.dictionary()["dylibs"][2]["name"] == "com.apple.foo"
97 assert kernel_cache.dictionary()["dylibs"][2]["fixups"] == "none"
98
99 # [~]> xcrun -sdk macosx.internal cc -arch x86_64 -Wl,-static -mkernel -nostdlib -Wl,-kernel -Wl,-e,__start -Wl,-pie main.cpp -Wl,-pagezero_size,0x0 -o main.kernel -Wl,-image_base,0xffffff8000200000 -Wl,-segaddr,__HIB,0xffffff8000100000 -Wl,-add_split_seg_info -Wl,-read_only_relocs,suppress -Wl,-install_name,/usr/lib/swift/split.seg.v2.hack
100 # [~]> xcrun -sdk macosx.internal cc -arch x86_64 -Wl,-kext -mkernel -nostdlib foo.c -o extensions/foo.kext/foo
101 # [~]> xcrun -sdk macosx.internal cc -arch x86_64 -Wl,-kext -mkernel -nostdlib bar.c -o extensions/bar.kext/bar
102