]>
git.saurik.com Git - apple/dyld.git/blob - testing/kernel-cache-tests/kext-bind-to-kext-arm64e-chains/test.py
4 import KernelCollection
6 # This tests that kexts can bind to each other using DYLD_CHAINED_PTR_ARM64E_KERNEL
8 def check(kernel_cache
):
9 kernel_cache
.buildKernelCollection("arm64e", "/kext-bind-to-kext-arm64e-chains/main.kc", "/kext-bind-to-kext-arm64e-chains/main.kernel", "/kext-bind-to-kext-arm64e-chains/extensions", ["com.apple.foo", "com.apple.bar"], [])
10 kernel_cache
.analyze("/kext-bind-to-kext-arm64e-chains/main.kc", ["-layout", "-arch", "arm64e"])
12 assert len(kernel_cache
.dictionary()["dylibs"]) == 3
14 assert kernel_cache
.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
16 assert kernel_cache
.dictionary()["dylibs"][1]["name"] == "com.apple.bar"
17 assert kernel_cache
.dictionary()["dylibs"][1]["segments"][3]["name"] == "__DATA_CONST"
18 assert kernel_cache
.dictionary()["dylibs"][1]["segments"][3]["vmAddr"] == "0xFFFFFFF00701C000"
20 assert kernel_cache
.dictionary()["dylibs"][2]["name"] == "com.apple.foo"
23 kernel_cache
.analyze("/kext-bind-to-kext-arm64e-chains/main.kc", ["-symbols", "-arch", "arm64e"])
25 assert kernel_cache
.dictionary()["dylibs"][1]["name"] == "com.apple.bar"
26 assert kernel_cache
.dictionary()["dylibs"][1]["global-symbols"][1]["name"] == "_fooPtr"
27 assert kernel_cache
.dictionary()["dylibs"][1]["global-symbols"][1]["vmAddr"] == "0xFFFFFFF007028000"
29 assert kernel_cache
.dictionary()["dylibs"][2]["name"] == "com.apple.foo"
30 assert kernel_cache
.dictionary()["dylibs"][2]["global-symbols"][0]["name"] == "_f"
31 assert kernel_cache
.dictionary()["dylibs"][2]["global-symbols"][0]["vmAddr"] == "0xFFFFFFF007028008"
32 assert kernel_cache
.dictionary()["dylibs"][2]["global-symbols"][1]["name"] == "_foo"
33 assert kernel_cache
.dictionary()["dylibs"][2]["global-symbols"][1]["vmAddr"] == "0xFFFFFFF007018070"
36 kernel_cache
.analyze("/kext-bind-to-kext-arm64e-chains/main.kc", ["-fixups", "-arch", "arm64e"])
37 assert len(kernel_cache
.dictionary()["fixups"]) == 4
39 # bar.kext: extern int foo();
40 # bar.kext: extern int f;
41 assert kernel_cache
.dictionary()["fixups"]["0x18000"] == "kc(0) + 0xFFFFFFF007018070 auth(IA addr 0)"
42 assert kernel_cache
.dictionary()["fixups"]["0x18008"] == "kc(0) + 0xFFFFFFF007028008"
44 # main.kernel: __typeof(&func) funcPtr = &func;
45 assert kernel_cache
.dictionary()["fixups"]["0x20000"] == "kc(0) + 0xFFFFFFF007014000 auth(IA !addr 0)"
46 # bar.kext: __typeof(&foo) fooPtr = &foo;
47 assert kernel_cache
.dictionary()["fixups"]["0x24000"] == "kc(0) + 0xFFFFFFF007018070 auth(IA !addr 0)"
48 assert len(kernel_cache
.dictionary()["dylibs"]) == 3
49 assert kernel_cache
.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
50 assert kernel_cache
.dictionary()["dylibs"][0]["fixups"] == "none"
51 assert kernel_cache
.dictionary()["dylibs"][1]["name"] == "com.apple.bar"
52 assert kernel_cache
.dictionary()["dylibs"][1]["fixups"] == "none"
53 assert kernel_cache
.dictionary()["dylibs"][2]["name"] == "com.apple.foo"
54 assert kernel_cache
.dictionary()["dylibs"][2]["fixups"] == "none"
57 # [~]> xcrun -sdk iphoneos.internal cc -arch arm64e -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
58 # [~]> 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
59 # [~]> 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
60 # [~]> rm -r extensions/*.kext/*.ld