]> git.saurik.com Git - apple/dyld.git/blob - testing/kernel-cache-tests/kext-bind-to-kext-arm64-chains/test.py
dyld-832.7.1.tar.gz
[apple/dyld.git] / testing / kernel-cache-tests / kext-bind-to-kext-arm64-chains / test.py
1 #!/usr/bin/python2.7
2
3 import os
4 import KernelCollection
5
6 # This tests that kexts can bind to each other using DYLD_CHAINED_PTR_64_OFFSET
7
8 def check(kernel_cache):
9 kernel_cache.buildKernelCollection("arm64", "/kext-bind-to-kext-arm64-chains/main.kc", "/kext-bind-to-kext-arm64-chains/main.kernel", "/kext-bind-to-kext-arm64-chains/extensions", ["com.apple.foo", "com.apple.bar"], [])
10
11 # layout
12 kernel_cache.analyze("/kext-bind-to-kext-arm64-chains/main.kc", ["-layout", "-arch", "arm64"])
13 assert len(kernel_cache.dictionary()["dylibs"]) == 3
14 # main.kernel
15 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
16 assert len(kernel_cache.dictionary()["dylibs"][0]["segments"]) == 4
17 # bar.kext
18 assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.bar"
19 assert kernel_cache.dictionary()["dylibs"][1]["segments"][2]["name"] == "__DATA_CONST"
20 assert kernel_cache.dictionary()["dylibs"][1]["segments"][2]["vmAddr"] == "0xFFFFFFF00701C000"
21 # foo.kext
22 assert kernel_cache.dictionary()["dylibs"][2]["name"] == "com.apple.foo"
23
24 # Symbols
25 kernel_cache.analyze("/kext-bind-to-kext-arm64-chains/main.kc", ["-symbols", "-arch", "arm64"])
26 assert kernel_cache.dictionary()["dylibs"][2]["name"] == "com.apple.foo"
27 assert kernel_cache.dictionary()["dylibs"][2]["global-symbols"][0]["name"] == "_foo"
28 assert kernel_cache.dictionary()["dylibs"][2]["global-symbols"][0]["vmAddr"] == "0xFFFFFFF007018020"
29
30 # Check the fixups
31 kernel_cache.analyze("/kext-bind-to-kext-arm64-chains/main.kc", ["-fixups", "-arch", "arm64"])
32 assert len(kernel_cache.dictionary()["fixups"]) == 2
33 # bar.kext: extern int foo();
34 assert kernel_cache.dictionary()["fixups"]["0x20000"] == "kc(0) + 0xFFFFFFF007014000"
35 # main.kernel: __typeof(&func) funcPtr = &func;
36 assert kernel_cache.dictionary()["fixups"]["0x18000"] == "kc(0) + 0xFFFFFFF007018020"
37 assert len(kernel_cache.dictionary()["dylibs"]) == 3
38 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
39 assert kernel_cache.dictionary()["dylibs"][0]["fixups"] == "none"
40 assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.bar"
41 assert kernel_cache.dictionary()["dylibs"][1]["fixups"] == "none"
42 assert kernel_cache.dictionary()["dylibs"][2]["name"] == "com.apple.foo"
43 assert kernel_cache.dictionary()["dylibs"][2]["fixups"] == "none"
44
45
46 # [~]> xcrun -sdk iphoneos.internal cc -arch arm64 -Wl,-static -mkernel -Wl,-fixup_chains -Wl,-kernel -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,-image_base,0xfffffff007004000 -Wl,-install_name,/usr/lib/swift/split.seg.v2.hack
47 # [~]> xcrun -sdk iphoneos.internal cc -arch arm64 -Wl,-kext -mkernel -nostdlib -Wl,-add_split_seg_info -Wl,-fixup_chains foo.c -o extensions/foo.kext/foo
48 # [~]> xcrun -sdk iphoneos.internal cc -arch arm64 -Wl,-kext -mkernel -nostdlib -Wl,-add_split_seg_info -Wl,-fixup_chains bar.c -o extensions/bar.kext/bar
49 # [~]> rm -r extensions/*.kext/*.ld
50