]>
git.saurik.com Git - apple/dyld.git/blob - testing/kernel-cache-tests/bundle-ids/test.py
4 import KernelCollection
6 # This verifies that we are able to build a kernel collection with a kernel and kext's referenced as bundle id's
8 def check(kernel_cache
):
9 kernel_cache
.buildKernelCollection("arm64", "/bundle-ids/main.kc", "/bundle-ids/main.kernel", "/bundle-ids/extensions", ["com.apple.foo", "com.apple.bar"], [])
10 kernel_cache
.analyze("/bundle-ids/main.kc", ["-layout", "-arch", "arm64"])
12 assert len(kernel_cache
.dictionary()["cache-segments"]) == 6
13 assert kernel_cache
.dictionary()["cache-segments"][0]["name"] == "__TEXT"
14 assert kernel_cache
.dictionary()["cache-segments"][0]["vmAddr"] == "0x0"
15 assert kernel_cache
.dictionary()["cache-segments"][1]["name"] == "__PRELINK_TEXT"
16 assert kernel_cache
.dictionary()["cache-segments"][1]["vmAddr"] == "0x4000"
17 assert kernel_cache
.dictionary()["cache-segments"][2]["name"] == "__TEXT_EXEC"
18 assert kernel_cache
.dictionary()["cache-segments"][2]["vmAddr"] == "0xC000"
19 assert kernel_cache
.dictionary()["cache-segments"][3]["name"] == "__PRELINK_INFO"
20 assert kernel_cache
.dictionary()["cache-segments"][3]["vmAddr"] == "0x18000"
21 assert kernel_cache
.dictionary()["cache-segments"][4]["name"] == "__DATA"
22 assert kernel_cache
.dictionary()["cache-segments"][4]["vmAddr"] == "0x1C000"
23 assert kernel_cache
.dictionary()["cache-segments"][5]["name"] == "__LINKEDIT"
24 assert kernel_cache
.dictionary()["cache-segments"][5]["vmAddr"] == "0x20000"
26 assert len(kernel_cache
.dictionary()["dylibs"]) == 3
28 assert kernel_cache
.dictionary()["dylibs"][0]["name"].endswith("com.apple.kernel")
29 assert len(kernel_cache
.dictionary()["dylibs"][0]["segments"]) == 3
30 assert kernel_cache
.dictionary()["dylibs"][0]["segments"][0]["name"] == "__TEXT"
31 assert kernel_cache
.dictionary()["dylibs"][0]["segments"][0]["vmAddr"] == "0xC000"
32 assert kernel_cache
.dictionary()["dylibs"][0]["segments"][1]["name"] == "__TEXT_EXEC"
33 assert kernel_cache
.dictionary()["dylibs"][0]["segments"][1]["vmAddr"] == "0x10000"
34 assert kernel_cache
.dictionary()["dylibs"][0]["segments"][2]["name"] == "__LINKEDIT"
35 assert kernel_cache
.dictionary()["dylibs"][0]["segments"][2]["vmAddr"] == "0x20000"
37 assert kernel_cache
.dictionary()["dylibs"][1]["name"].endswith("bar")
38 assert len(kernel_cache
.dictionary()["dylibs"][1]["segments"]) == 4
39 assert kernel_cache
.dictionary()["dylibs"][1]["segments"][0]["name"] == "__TEXT"
40 assert kernel_cache
.dictionary()["dylibs"][1]["segments"][0]["vmAddr"] == "0x4000"
41 assert kernel_cache
.dictionary()["dylibs"][1]["segments"][1]["name"] == "__TEXT_EXEC"
42 assert kernel_cache
.dictionary()["dylibs"][1]["segments"][1]["vmAddr"] == "0x14000"
43 assert kernel_cache
.dictionary()["dylibs"][1]["segments"][2]["name"] == "__DATA"
44 assert kernel_cache
.dictionary()["dylibs"][1]["segments"][2]["vmAddr"] == "0x1C000"
45 assert kernel_cache
.dictionary()["dylibs"][1]["segments"][3]["name"] == "__LINKEDIT"
46 assert kernel_cache
.dictionary()["dylibs"][1]["segments"][3]["vmAddr"] == "0x20000"
48 assert kernel_cache
.dictionary()["dylibs"][2]["name"].endswith("foo")
49 assert len(kernel_cache
.dictionary()["dylibs"][2]["segments"]) == 4
50 assert kernel_cache
.dictionary()["dylibs"][2]["segments"][0]["name"] == "__TEXT"
51 assert kernel_cache
.dictionary()["dylibs"][2]["segments"][0]["vmAddr"] == "0x8000"
52 assert kernel_cache
.dictionary()["dylibs"][2]["segments"][1]["name"] == "__TEXT_EXEC"
53 assert kernel_cache
.dictionary()["dylibs"][2]["segments"][1]["vmAddr"] == "0x14030"
54 assert kernel_cache
.dictionary()["dylibs"][2]["segments"][2]["name"] == "__DATA"
55 assert kernel_cache
.dictionary()["dylibs"][2]["segments"][2]["vmAddr"] == "0x1C010"
56 assert kernel_cache
.dictionary()["dylibs"][2]["segments"][3]["name"] == "__LINKEDIT"
57 assert kernel_cache
.dictionary()["dylibs"][2]["segments"][3]["vmAddr"] == "0x20000"
60 kernel_cache
.analyze("/bundle-ids/main.kc", ["-fixups", "-arch", "arm64"])
61 assert len(kernel_cache
.dictionary()["fixups"]) == 2
62 assert kernel_cache
.dictionary()["fixups"]["0x1C000"] == "kc(0) + 0x14000"
63 assert kernel_cache
.dictionary()["fixups"]["0x1C010"] == "kc(0) + 0x1C018"
64 assert len(kernel_cache
.dictionary()["dylibs"]) == 3
65 assert kernel_cache
.dictionary()["dylibs"][0]["name"].endswith("com.apple.kernel")
66 assert kernel_cache
.dictionary()["dylibs"][0]["fixups"] == "none"
67 assert kernel_cache
.dictionary()["dylibs"][1]["name"].endswith("bar")
68 assert kernel_cache
.dictionary()["dylibs"][1]["fixups"] == "none"
69 assert kernel_cache
.dictionary()["dylibs"][2]["name"].endswith("foo")
70 assert kernel_cache
.dictionary()["dylibs"][2]["fixups"] == "none"
73 # [~]> 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
74 # [~]> xcrun -sdk iphoneos.internal cc -arch arm64 -Wl,-kext -mkernel -nostdlib -Wl,-add_split_seg_info foo.c -o extensions/foo.kext/foo
75 # [~]> xcrun -sdk iphoneos.internal cc -arch arm64 -Wl,-kext -mkernel -nostdlib -Wl,-add_split_seg_info bar.c -o extensions/bar.kext/bar
76 # [~]> rm -r extensions/*.kext/*.ld