xref: /illumos-gate/usr/src/cmd/mdb/common/mdb/mdb_kb_kvm.c (revision 581cede61ac9c14d8d4ea452562a567189eead78)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 /*
29  * The default KVM backend, which simply calls directly into libkvm for all
30  * operations.
31  */
32 
33 #include <mdb/mdb_kb.h>
34 #include <mdb/mdb_target_impl.h>
35 
36 #include <fcntl.h>
37 #include <dlfcn.h>
38 #include <kvm.h>
39 
40 /*ARGSUSED*/
41 static mdb_io_t *
42 libkvm_sym_io(void *kvm, const char *symfile)
43 {
44 	mdb_io_t *io;
45 
46 	if ((io = mdb_fdio_create_path(NULL, symfile, O_RDONLY, 0)) == NULL)
47 		mdb_warn("failed to open %s", symfile);
48 
49 	return (io);
50 }
51 
52 mdb_kb_ops_t *
53 libkvm_kb_ops(void)
54 {
55 	static mdb_kb_ops_t ops = {
56 		.kb_open = (void *(*)())kvm_open,
57 		.kb_close = (int (*)())kvm_close,
58 		.kb_sym_io = libkvm_sym_io,
59 		.kb_kread = (ssize_t (*)())kvm_kread,
60 		.kb_kwrite = (ssize_t (*)())kvm_kwrite,
61 		.kb_aread = (ssize_t (*)())kvm_aread,
62 		.kb_awrite = (ssize_t (*)())kvm_awrite,
63 		.kb_pread = (ssize_t (*)())kvm_pread,
64 		.kb_pwrite = (ssize_t (*)())kvm_pwrite,
65 		.kb_getmregs = (int (*)())mdb_tgt_notsup,
66 		.kb_vtop = (uint64_t (*)())kvm_physaddr,
67 	};
68 	return (&ops);
69 }
70