Listing 1 Reading the device tree from kernel memory
1 /* Compile with gcc -g -o kvm kvm.c -lkvm -lelf */
2 #include <fcntl.h>
3 #include <sys/dditypes.h>
4 #include <sys/ddidmareq.h>
5 #include <sys/ddi_impldefs.h>
6 #include <kvm.h>
7
8 int main(int argc, char *argv[]) {
9 kvm_t *kmem;
10 struct dev_info *pdevnode, devnode;
11 struct nlist sym[] = { { "top_devinfo" }, { 0 } };
12
13 /* Open kernel memory */
14 kmem = kvm_open(NULL, NULL, NULL, O_RDONLY, argv[0]);
15
16 /* Find the top_devinfo symbol, a pointer to the root node */
17 kvm_nlist(kmem, sym);
18
19 /* Read in the pointer */
20 kvm_kread(kmem, sym[0].n_value, (char *) &pdevnode, sizeof(pdevnode));
21
22 /* Now read in the node itself */
23 kvm_kread(kmem, (unsigned long) pdevnode, (char *) &devnode, sizeof(devnode));
24
25 printf("Parent: 0x%08x Child: 0x%08x Sibling: 0x%08x\n",
26 devnode.devi_parent, devnode.devi_child, devnode.devi_sibling);
27
28 /* Close kernel memory */
29 kvm_close(kmem);
30 }
|