]> git.saurik.com Git - apple/dyld.git/blob - testing/kernel-cache-tests/kext-bind-to-kpi-private-symbol-set/test.py
dyld-832.7.1.tar.gz
[apple/dyld.git] / testing / kernel-cache-tests / kext-bind-to-kpi-private-symbol-set / test.py
1 #!/usr/bin/python2.7
2
3 import os
4 import KernelCollection
5
6 # This verifies that an Apple kext can bind to KPI.private with a symbol set in the kext
7 # com.apple.kpi.private exports foo and bar.kext uses it
8
9 def check(kernel_cache):
10 kernel_cache.buildKernelCollection("arm64", "/kext-bind-to-kpi-private-symbol-set/main.kc", "/kext-bind-to-kpi-private-symbol-set/main.kernel", "/kext-bind-to-kpi-private-symbol-set/extensions", ["com.apple.bar"], [])
11 kernel_cache.analyze("/kext-bind-to-kpi-private-symbol-set/main.kc", ["-layout", "-arch", "arm64"])
12
13 assert len(kernel_cache.dictionary()["dylibs"]) == 2
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"] == "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"] == "0x18000"
21
22 kernel_cache.analyze("/kext-bind-to-kpi-private-symbol-set/main.kc", ["-symbols", "-arch", "arm64"])
23 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
24 assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][2]["name"] == "_foo"
25 assert kernel_cache.dictionary()["dylibs"][0]["global-symbols"][2]["vmAddr"] == "0xC00C"
26
27 # Check the fixups
28 kernel_cache.analyze("/kext-bind-to-kpi-private-symbol-set/main.kc", ["-fixups", "-arch", "arm64"])
29 assert len(kernel_cache.dictionary()["fixups"]) == 1
30 assert kernel_cache.dictionary()["fixups"]["0x18000"] == "kc(0) + 0xC00C"
31 assert len(kernel_cache.dictionary()["dylibs"]) == 2
32 assert kernel_cache.dictionary()["dylibs"][0]["name"] == "com.apple.kernel"
33 assert kernel_cache.dictionary()["dylibs"][0]["fixups"] == "none"
34 assert kernel_cache.dictionary()["dylibs"][1]["name"] == "com.apple.bar"
35 assert kernel_cache.dictionary()["dylibs"][1]["fixups"] == "none"
36
37
38 # [~]> 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 -Wl,-sectcreate,__LINKINFO,__symbolsets,SymbolSets.plist -Wl,-segprot,__LINKINFO,r--,r--
39 # [~]> 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
40 # [~]> rm -r extensions/*.kext/*.ld
41