xref: /titanic_44/usr/src/cmd/mdb/common/kmdb/kmdb_module.h (revision 5ae68c692a4082733aae5ac4a477733bb784819f)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23*5ae68c69Sjohnlev  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef _KMDB_MODULE_H
287c478bd9Sstevel@tonic-gate #define	_KMDB_MODULE_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
337c478bd9Sstevel@tonic-gate #include <sys/kobj.h>
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #include <mdb/mdb_gelf.h>
367c478bd9Sstevel@tonic-gate #include <mdb/mdb_module.h>
377c478bd9Sstevel@tonic-gate #include <kmdb/kmdb_wr_impl.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #ifdef __cplusplus
407c478bd9Sstevel@tonic-gate extern "C" {
417c478bd9Sstevel@tonic-gate #endif
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #define	KMDB_MC_STATE_LOADING	1
447c478bd9Sstevel@tonic-gate #define	KMDB_MC_STATE_LOADED	2
457c478bd9Sstevel@tonic-gate #define	KMDB_MC_STATE_UNLOADING	3
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate #define	KMDB_MC_FL_NOUNLOAD	0x1
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate /*
507c478bd9Sstevel@tonic-gate  * The mdb_module_t describes the runtime attributes of dmods - things that
517c478bd9Sstevel@tonic-gate  * matter after the dmod has been loaded.  kmdb needs to track information about
527c478bd9Sstevel@tonic-gate  * modules before they've been loaded, and while they're in the process of
537c478bd9Sstevel@tonic-gate  * being unloaded.  As such, a kmdb_modctl_t is created for each module when the
547c478bd9Sstevel@tonic-gate  * load is requested, and isn't destroyed until the module has completed
557c478bd9Sstevel@tonic-gate  * unloading.
567c478bd9Sstevel@tonic-gate  *
577c478bd9Sstevel@tonic-gate  * This description reflects the sequence of events that occur during the
587c478bd9Sstevel@tonic-gate  * successful loading and unloading of a dmod.
597c478bd9Sstevel@tonic-gate  *
607c478bd9Sstevel@tonic-gate  * 1. Debugger requests a dmod load.
617c478bd9Sstevel@tonic-gate  *
627c478bd9Sstevel@tonic-gate  *    A kmdb_modctl_t is allocated.  kmc_state is set to KMDB_MC_STATE_LOADING.
637c478bd9Sstevel@tonic-gate  *
647c478bd9Sstevel@tonic-gate  * 2. The driver reports the successful loading of the dmod.
657c478bd9Sstevel@tonic-gate  *
667c478bd9Sstevel@tonic-gate  *    kmc_state is set to KMDB_MC_STATE_LOADED, and an mdb_module_t is created
677c478bd9Sstevel@tonic-gate  *    by mdb_module_create.
687c478bd9Sstevel@tonic-gate  *
697c478bd9Sstevel@tonic-gate  * 3. Debugger requests a dmod unload.
707c478bd9Sstevel@tonic-gate  *
717c478bd9Sstevel@tonic-gate  *    The mdb_module_t is destroyed, and kmc_state is set to
727c478bd9Sstevel@tonic-gate  *    KMDB_MC_STATE_UNLOADING.
737c478bd9Sstevel@tonic-gate  *
747c478bd9Sstevel@tonic-gate  * 4. The driver reports the successful unloading of the dmod.
757c478bd9Sstevel@tonic-gate  *
767c478bd9Sstevel@tonic-gate  *    The kmdb_modctl_t is destroyed.
777c478bd9Sstevel@tonic-gate  */
787c478bd9Sstevel@tonic-gate typedef struct kmdb_modctl {
797c478bd9Sstevel@tonic-gate 	mdb_module_t *kmc_mod;		/* common dmod state */
807c478bd9Sstevel@tonic-gate 	struct modctl *kmc_modctl;	/* kernel's modctl for this dmod */
817c478bd9Sstevel@tonic-gate 	int kmc_exported;		/* KOBJ_EXPORTED set when last seen? */
827c478bd9Sstevel@tonic-gate 	char *kmc_modname;		/* name of this dmod */
837c478bd9Sstevel@tonic-gate 	ushort_t kmc_loadmode;		/* MDB_MOD_* from load request */
847c478bd9Sstevel@tonic-gate 	ushort_t kmc_flags;		/* KMDB_MC_FL_* (above) */
857c478bd9Sstevel@tonic-gate 	int kmc_dlrefcnt;		/* Counts dlopens/dlcloses */
867c478bd9Sstevel@tonic-gate 	int kmc_state;			/* KMDB_MC_STATE_* (above) */
877c478bd9Sstevel@tonic-gate 	mdb_gelf_symtab_t *kmc_symtab;	/* This dmod's symbol table */
887c478bd9Sstevel@tonic-gate 	GElf_Ehdr kmc_ehdr;		/* Copy of ehdr in gelf format */
897c478bd9Sstevel@tonic-gate } kmdb_modctl_t;
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate extern int kmdb_module_loaded(kmdb_wr_load_t *);
927c478bd9Sstevel@tonic-gate extern void kmdb_module_load_ack(kmdb_wr_load_t *);
937c478bd9Sstevel@tonic-gate extern void kmdb_module_load_all_ack(kmdb_wr_t *);
947c478bd9Sstevel@tonic-gate extern int kmdb_module_unloaded(kmdb_wr_unload_t *);
957c478bd9Sstevel@tonic-gate extern void kmdb_module_unload_ack(kmdb_wr_unload_t *);
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate extern void kmdb_module_path_set(const char **, size_t);
987c478bd9Sstevel@tonic-gate extern void kmdb_module_path_ack(kmdb_wr_path_t *);
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate extern int kmdb_module_lookup_by_addr(uintptr_t, uint_t, char *, size_t,
1017c478bd9Sstevel@tonic-gate     GElf_Sym *, mdb_syminfo_t *);
1027c478bd9Sstevel@tonic-gate extern int kmdb_module_lookup_by_name(const char *, const char *, GElf_Sym *,
1037c478bd9Sstevel@tonic-gate     mdb_syminfo_t *);
104*5ae68c69Sjohnlev extern ctf_file_t *kmdb_module_addr_to_ctf(uintptr_t);
105*5ae68c69Sjohnlev extern ctf_file_t *kmdb_module_name_to_ctf(const char *);
1067c478bd9Sstevel@tonic-gate extern int kmdb_module_symbol_iter(const char *, uint_t, mdb_tgt_sym_f *,
1077c478bd9Sstevel@tonic-gate     void *);
1087c478bd9Sstevel@tonic-gate extern void kmdb_module_sync(void);
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1117c478bd9Sstevel@tonic-gate }
1127c478bd9Sstevel@tonic-gate #endif
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate #endif /* _KMDB_MODULE_H */
115