]> git.saurik.com Git - apple/dyld.git/blob - testing/kernel-cache-tests/kext-bind-to-kext-symbol-set/test.py
dyld-832.7.1.tar.gz
[apple/dyld.git] / testing / kernel-cache-tests / kext-bind-to-kext-symbol-set / test.py
1 #!/usr/bin/python2.7
2
3 import os
4 import KernelCollection
5
6 # This verifies that an non-Apple kext can bind to an Apple kext with a symbol set in the kext
7 # foo.kext exports foo and bar.kext uses it
8
9 def check(kernel_cache):
10 kernel_cache.buildKernelCollection("arm64", "/kext-bind-to-kext-symbol-set/main.kc", "/kext-bind-to-kext-symbol-set/main.kernel", "/kext-bind-to-kext-symbol-set/extensions", ["com.apple.foo", "not.com.apple.bar"], [])
11 kernel_cache.analyze("/kext-bind-to-kext-symbol-set/main.kc", ["-layout", "-arch", "arm64"])
12
13 assert len(kernel_cache.dictionary()["dylibs"]) == 3
14 # main.kernel
15 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
16 # bar.kext
17 assert kernel_cache.dictionary()["dylibs"][1]["name"] == "not.com.apple.bar"
18 assert len(kernel_cache.dictionary()["dylibs"][1]["segments"]) == 4
19 assert kernel_cache.dictionary()["dylibs"][1]["segments"][2]["name"] == "__DATA"
20 assert kernel_cache.dictionary()["dylibs"][1]["segments"][2]["vmAddr"] == "0x1C000"
21 # foo.kext
22 assert kernel_cache.dictionary()["dylibs"][2]["name"] == "com.apple.foo"
23
24 kernel_cache.analyze("/kext-bind-to-kext-symbol-set/main.kc", ["-symbols", "-arch", "arm64"])
25 assert kernel_cache.dictionary()["dylibs"][2]["name"] == "com.apple.foo"
26 assert kernel_cache.dictionary()["dylibs"][2]["global-symbols"][0]["name"] == "_foo"
27 assert kernel_cache.dictionary()["dylibs"][2]["global-symbols"][0]["vmAddr"] == "0x14020"
28
29 # Check the fixups
30 kernel_cache.analyze("/kext-bind-to-kext-symbol-set/main.kc", ["-fixups", "-arch", "arm64"])
31 assert len(kernel_cache.dictionary()["fixups"]) == 1
32 assert kernel_cache.dictionary()["fixups"]["0x1C000"] == "kc(0) + 0x14020"
33 assert len(kernel_cache.dictionary()["dylibs"]) == 3
34 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
35 assert kernel_cache.dictionary()["dylibs"][0]["fixups"] == "none"
36 assert kernel_cache.dictionary()["dylibs"][1]["name"] == "not.com.apple.bar"
37 assert kernel_cache.dictionary()["dylibs"][1]["fixups"] == "none"
38 assert kernel_cache.dictionary()["dylibs"][2]["name"] == "com.apple.foo"
39 assert kernel_cache.dictionary()["dylibs"][2]["fixups"] == "none"
40
41
42 # [~]> ../kext-symbols.sh SymbolSets.plist ./extensions/foo.kext/Info.plist exports.txt
43 # [~]> xcrun -sdk iphoneos.internal cc -arch arm64 -Wl,-static -mkernel -nostdlib -Wl,-add_split_seg_info -Wl,-rename_section,__TEXT,__text,__TEXT_EXEC,__text -Wl,-e,__start -Wl,-pagezero_size,0x0 -Wl,-pie main.c -o main.kernel
44 # [~]> xcrun -sdk iphoneos.internal cc -arch arm64 -Wl,-kext -mkernel -nostdlib -Wl,-add_split_seg_info -Wl,-no_data_const foo.c -o extensions/foo.kext/foo -Wl,-sectcreate,__LINKINFO,__symbolsets,SymbolSets.plist -Wl,-segprot,__LINKINFO,r--,r--
45 # [~]> xcrun -sdk iphoneos.internal cc -arch arm64 -Wl,-kext -mkernel -nostdlib -Wl,-add_split_seg_info -Wl,-no_data_const bar.c -o extensions/bar.kext/bar
46 # [~]> rm -r extensions/*.kext/*.ld
47