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 #include <sys/modctl.h>
317c478bd9Sstevel@tonic-gate #include <sys/kobj.h>
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <mdb/mdb_gelf.h>
347c478bd9Sstevel@tonic-gate #include <mdb/mdb_module.h>
357c478bd9Sstevel@tonic-gate #include <kmdb/kmdb_wr_impl.h>
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #ifdef __cplusplus
387c478bd9Sstevel@tonic-gate extern "C" {
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #define	KMDB_MC_STATE_LOADING	1
427c478bd9Sstevel@tonic-gate #define	KMDB_MC_STATE_LOADED	2
437c478bd9Sstevel@tonic-gate #define	KMDB_MC_STATE_UNLOADING	3
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #define	KMDB_MC_FL_NOUNLOAD	0x1
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /*
487c478bd9Sstevel@tonic-gate  * The mdb_module_t describes the runtime attributes of dmods - things that
497c478bd9Sstevel@tonic-gate  * matter after the dmod has been loaded.  kmdb needs to track information about
507c478bd9Sstevel@tonic-gate  * modules before they've been loaded, and while they're in the process of
517c478bd9Sstevel@tonic-gate  * being unloaded.  As such, a kmdb_modctl_t is created for each module when the
527c478bd9Sstevel@tonic-gate  * load is requested, and isn't destroyed until the module has completed
537c478bd9Sstevel@tonic-gate  * unloading.
547c478bd9Sstevel@tonic-gate  *
557c478bd9Sstevel@tonic-gate  * This description reflects the sequence of events that occur during the
567c478bd9Sstevel@tonic-gate  * successful loading and unloading of a dmod.
577c478bd9Sstevel@tonic-gate  *
587c478bd9Sstevel@tonic-gate  * 1. Debugger requests a dmod load.
597c478bd9Sstevel@tonic-gate  *
607c478bd9Sstevel@tonic-gate  *    A kmdb_modctl_t is allocated.  kmc_state is set to KMDB_MC_STATE_LOADING.
617c478bd9Sstevel@tonic-gate  *
627c478bd9Sstevel@tonic-gate  * 2. The driver reports the successful loading of the dmod.
637c478bd9Sstevel@tonic-gate  *
647c478bd9Sstevel@tonic-gate  *    kmc_state is set to KMDB_MC_STATE_LOADED, and an mdb_module_t is created
657c478bd9Sstevel@tonic-gate  *    by mdb_module_create.
667c478bd9Sstevel@tonic-gate  *
677c478bd9Sstevel@tonic-gate  * 3. Debugger requests a dmod unload.
687c478bd9Sstevel@tonic-gate  *
697c478bd9Sstevel@tonic-gate  *    The mdb_module_t is destroyed, and kmc_state is set to
707c478bd9Sstevel@tonic-gate  *    KMDB_MC_STATE_UNLOADING.
717c478bd9Sstevel@tonic-gate  *
727c478bd9Sstevel@tonic-gate  * 4. The driver reports the successful unloading of the dmod.
737c478bd9Sstevel@tonic-gate  *
747c478bd9Sstevel@tonic-gate  *    The kmdb_modctl_t is destroyed.
757c478bd9Sstevel@tonic-gate  */
767c478bd9Sstevel@tonic-gate typedef struct kmdb_modctl {
777c478bd9Sstevel@tonic-gate 	mdb_module_t *kmc_mod;		/* common dmod state */
787c478bd9Sstevel@tonic-gate 	struct modctl *kmc_modctl;	/* kernel's modctl for this dmod */
797c478bd9Sstevel@tonic-gate 	int kmc_exported;		/* KOBJ_EXPORTED set when last seen? */
807c478bd9Sstevel@tonic-gate 	char *kmc_modname;		/* name of this dmod */
817c478bd9Sstevel@tonic-gate 	ushort_t kmc_loadmode;		/* MDB_MOD_* from load request */
827c478bd9Sstevel@tonic-gate 	ushort_t kmc_flags;		/* KMDB_MC_FL_* (above) */
837c478bd9Sstevel@tonic-gate 	int kmc_dlrefcnt;		/* Counts dlopens/dlcloses */
847c478bd9Sstevel@tonic-gate 	int kmc_state;			/* KMDB_MC_STATE_* (above) */
857c478bd9Sstevel@tonic-gate 	mdb_gelf_symtab_t *kmc_symtab;	/* This dmod's symbol table */
867c478bd9Sstevel@tonic-gate 	GElf_Ehdr kmc_ehdr;		/* Copy of ehdr in gelf format */
877c478bd9Sstevel@tonic-gate } kmdb_modctl_t;
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate extern int kmdb_module_loaded(kmdb_wr_load_t *);
907c478bd9Sstevel@tonic-gate extern void kmdb_module_load_ack(kmdb_wr_load_t *);
917c478bd9Sstevel@tonic-gate extern void kmdb_module_load_all_ack(kmdb_wr_t *);
927c478bd9Sstevel@tonic-gate extern int kmdb_module_unloaded(kmdb_wr_unload_t *);
937c478bd9Sstevel@tonic-gate extern void kmdb_module_unload_ack(kmdb_wr_unload_t *);
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate extern void kmdb_module_path_set(const char **, size_t);
967c478bd9Sstevel@tonic-gate extern void kmdb_module_path_ack(kmdb_wr_path_t *);
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate extern int kmdb_module_lookup_by_addr(uintptr_t, uint_t, char *, size_t,
997c478bd9Sstevel@tonic-gate     GElf_Sym *, mdb_syminfo_t *);
1007c478bd9Sstevel@tonic-gate extern int kmdb_module_lookup_by_name(const char *, const char *, GElf_Sym *,
1017c478bd9Sstevel@tonic-gate     mdb_syminfo_t *);
102*5ae68c69Sjohnlev extern ctf_file_t *kmdb_module_addr_to_ctf(uintptr_t);
103*5ae68c69Sjohnlev extern ctf_file_t *kmdb_module_name_to_ctf(const char *);
1047c478bd9Sstevel@tonic-gate extern int kmdb_module_symbol_iter(const char *, uint_t, mdb_tgt_sym_f *,
1057c478bd9Sstevel@tonic-gate     void *);
1067c478bd9Sstevel@tonic-gate extern void kmdb_module_sync(void);
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1097c478bd9Sstevel@tonic-gate }
1107c478bd9Sstevel@tonic-gate #endif
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate #endif /* _KMDB_MODULE_H */
113