xref: /titanic_50/usr/src/cmd/mdb/common/mdb/mdb_kb_kvm.c (revision 1320caf7cc74a3c5be65ef23516dee229adc288a)
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 /*
27  * Copyright (c) 2013, Joyent, Inc.  All rights reserved.
28  */
29 
30 /*
31  * The default KVM backend, which simply calls directly into libkvm for all
32  * operations.
33  */
34 
35 #include <mdb/mdb_kb.h>
36 #include <mdb/mdb_target_impl.h>
37 
38 #include <fcntl.h>
39 #include <dlfcn.h>
40 #include <kvm.h>
41 
42 /*ARGSUSED*/
43 static mdb_io_t *
libkvm_sym_io(void * kvm,const char * ignored)44 libkvm_sym_io(void *kvm, const char *ignored)
45 {
46 	mdb_io_t *io;
47 	const char *symfile = kvm_namelist(kvm);
48 
49 	if ((io = mdb_fdio_create_path(NULL, symfile, O_RDONLY, 0)) == NULL)
50 		mdb_warn("failed to open %s", symfile);
51 
52 	return (io);
53 }
54 
55 mdb_kb_ops_t *
libkvm_kb_ops(void)56 libkvm_kb_ops(void)
57 {
58 	static mdb_kb_ops_t ops = {
59 		.kb_open = (void *(*)())kvm_open,
60 		.kb_close = (int (*)())kvm_close,
61 		.kb_sym_io = libkvm_sym_io,
62 		.kb_kread = (ssize_t (*)())kvm_kread,
63 		.kb_kwrite = (ssize_t (*)())kvm_kwrite,
64 		.kb_aread = (ssize_t (*)())kvm_aread,
65 		.kb_awrite = (ssize_t (*)())kvm_awrite,
66 		.kb_pread = (ssize_t (*)())kvm_pread,
67 		.kb_pwrite = (ssize_t (*)())kvm_pwrite,
68 		.kb_getmregs = (int (*)())mdb_tgt_notsup,
69 		.kb_vtop = (uint64_t (*)())kvm_physaddr,
70 	};
71 	return (&ops);
72 }
73