]>
Commit | Line | Data |
---|---|---|
1 | #include <string.h> | |
2 | #include <stdlib.h> | |
3 | #include <mach/mach.h> | |
4 | #include <mach_debug/mach_debug.h> | |
5 | #include <darwintest.h> | |
6 | ||
7 | T_GLOBAL_META( | |
8 | T_META_NAMESPACE("xnu.vm"), | |
9 | T_META_CHECK_LEAKS(false) | |
10 | ); | |
11 | ||
12 | static void run_test(void); | |
13 | ||
14 | static void | |
15 | run_test(void) | |
16 | { | |
17 | kern_return_t kr; | |
18 | uint64_t size, i; | |
19 | mach_zone_name_t *name = NULL; | |
20 | unsigned int nameCnt = 0; | |
21 | mach_zone_info_t *info = NULL; | |
22 | unsigned int infoCnt = 0; | |
23 | mach_memory_info_t *wiredInfo = NULL; | |
24 | unsigned int wiredInfoCnt = 0; | |
25 | const char kalloc_str[] = "kalloc."; | |
26 | ||
27 | kr = mach_memory_info(mach_host_self(), | |
28 | &name, &nameCnt, &info, &infoCnt, | |
29 | &wiredInfo, &wiredInfoCnt); | |
30 | T_QUIET; T_ASSERT_MACH_SUCCESS(kr, "mach_memory_info"); | |
31 | T_QUIET; T_ASSERT_EQ(nameCnt, infoCnt, "zone name and info counts don't match"); | |
32 | ||
33 | /* Match the names of the kalloc zones against their element sizes. */ | |
34 | for (i = 0; i < nameCnt; i++) { | |
35 | if (strncmp(name[i].mzn_name, kalloc_str, strlen(kalloc_str)) == 0) { | |
36 | size = strtoul(&(name[i].mzn_name[strlen(kalloc_str)]), NULL, 10); | |
37 | T_LOG("ZONE NAME: %-25s ELEMENT SIZE: %llu", name[i].mzn_name, size); | |
38 | T_QUIET; T_ASSERT_EQ(size, info[i].mzi_elem_size, "kalloc zone name and element size don't match"); | |
39 | } | |
40 | } | |
41 | ||
42 | if ((name != NULL) && (nameCnt != 0)) { | |
43 | kr = vm_deallocate(mach_task_self(), (vm_address_t) name, | |
44 | (vm_size_t) (nameCnt * sizeof *name)); | |
45 | T_QUIET; T_ASSERT_MACH_SUCCESS(kr, "vm_deallocate name"); | |
46 | } | |
47 | ||
48 | if ((info != NULL) && (infoCnt != 0)) { | |
49 | kr = vm_deallocate(mach_task_self(), (vm_address_t) info, | |
50 | (vm_size_t) (infoCnt * sizeof *info)); | |
51 | T_QUIET; T_ASSERT_MACH_SUCCESS(kr, "vm_deallocate info"); | |
52 | } | |
53 | ||
54 | if ((wiredInfo != NULL) && (wiredInfoCnt != 0)) { | |
55 | kr = vm_deallocate(mach_task_self(), (vm_address_t) wiredInfo, | |
56 | (vm_size_t) (wiredInfoCnt * sizeof *wiredInfo)); | |
57 | T_QUIET; T_ASSERT_MACH_SUCCESS(kr, "vm_deallocate wiredInfo"); | |
58 | } | |
59 | ||
60 | T_END; | |
61 | } | |
62 | ||
63 | T_DECL( verify_kalloc_config, | |
64 | "verifies that the kalloc zones are configured correctly", | |
65 | T_META_ASROOT(true)) | |
66 | { | |
67 | run_test(); | |
68 | } |