xref: /titanic_52/usr/src/uts/common/sys/kobj.h (revision 986fd29a0dc13f7608ef7f508f6e700bd7bc2720)
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
5ea8dc4b6Seschrock  * Common Development and Distribution License (the "License").
6ea8dc4b6Seschrock  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22b1b8ab34Slling  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _SYS_KOBJ_H
277c478bd9Sstevel@tonic-gate #define	_SYS_KOBJ_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
327c478bd9Sstevel@tonic-gate #include <sys/elf.h>
337c478bd9Sstevel@tonic-gate #include <sys/machelf.h>
347c478bd9Sstevel@tonic-gate #include <sys/vmem.h>
357c478bd9Sstevel@tonic-gate #include <sys/sdt.h>
36ea8dc4b6Seschrock #include <sys/bootstat.h>
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
397c478bd9Sstevel@tonic-gate extern "C" {
407c478bd9Sstevel@tonic-gate #endif
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate  * List of modules maintained by kobj.c
447c478bd9Sstevel@tonic-gate  */
457c478bd9Sstevel@tonic-gate struct module_list {
467c478bd9Sstevel@tonic-gate 	struct module_list *next;
477c478bd9Sstevel@tonic-gate 	struct module *mp;
487c478bd9Sstevel@tonic-gate };
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate typedef unsigned short	symid_t;		/* symbol table index */
517c478bd9Sstevel@tonic-gate typedef unsigned char	*reloc_dest_t;
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate typedef	void	module_mach;
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate struct module {
567c478bd9Sstevel@tonic-gate 	int total_allocated;
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate 	Ehdr hdr;
597c478bd9Sstevel@tonic-gate 	char *shdrs;
607c478bd9Sstevel@tonic-gate 	Shdr *symhdr, *strhdr;
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate 	char *depends_on;
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate 	size_t symsize;
657c478bd9Sstevel@tonic-gate 	char *symspace;	/* symbols + strings + hashtbl, or NULL */
667c478bd9Sstevel@tonic-gate 	int flags;
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate 	size_t text_size;
697c478bd9Sstevel@tonic-gate 	size_t data_size;
707c478bd9Sstevel@tonic-gate 	char *text;
717c478bd9Sstevel@tonic-gate 	char *data;
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate 	unsigned int symtbl_section;
747c478bd9Sstevel@tonic-gate 	/* pointers into symspace, or NULL */
757c478bd9Sstevel@tonic-gate 	char *symtbl;
767c478bd9Sstevel@tonic-gate 	char *strings;
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate 	unsigned int hashsize;
797c478bd9Sstevel@tonic-gate 	symid_t *buckets;
807c478bd9Sstevel@tonic-gate 	symid_t *chains;
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate 	unsigned int nsyms;
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate 	unsigned int bss_align;
857c478bd9Sstevel@tonic-gate 	size_t bss_size;
867c478bd9Sstevel@tonic-gate 	uintptr_t bss;
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate 	char *filename;
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate 	struct module_list *head, *tail;
917c478bd9Sstevel@tonic-gate 	reloc_dest_t destination;
927c478bd9Sstevel@tonic-gate 	module_mach * machdata;
937c478bd9Sstevel@tonic-gate 	char *ctfdata;
947c478bd9Sstevel@tonic-gate 	size_t ctfsize;
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate 	char *fbt_tab;
977c478bd9Sstevel@tonic-gate 	size_t fbt_size;
987c478bd9Sstevel@tonic-gate 	size_t fbt_nentries;
997c478bd9Sstevel@tonic-gate 	caddr_t textwin;
1007c478bd9Sstevel@tonic-gate 	caddr_t textwin_base;
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 	sdt_probedesc_t *sdt_probes;
1037c478bd9Sstevel@tonic-gate 	size_t sdt_nprobes;
1047c478bd9Sstevel@tonic-gate 	char *sdt_tab;
1057c478bd9Sstevel@tonic-gate 	size_t sdt_size;
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate 	char *sigdata;
1087c478bd9Sstevel@tonic-gate 	size_t sigsize;
1097c478bd9Sstevel@tonic-gate };
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate struct kobj_mem {
1127c478bd9Sstevel@tonic-gate 	struct kobj_mem	*km_next;
1137c478bd9Sstevel@tonic-gate 	struct kobj_mem *km_prev;
1147c478bd9Sstevel@tonic-gate 	uintptr_t	km_addr;
1157c478bd9Sstevel@tonic-gate 	size_t		km_size;
1167c478bd9Sstevel@tonic-gate 	uintptr_t	km_alloc_addr;
1177c478bd9Sstevel@tonic-gate 	size_t		km_alloc_size;
1187c478bd9Sstevel@tonic-gate };
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate struct _buf {
1217c478bd9Sstevel@tonic-gate 	intptr_t	 _fd;
1227c478bd9Sstevel@tonic-gate 	char		*_ptr;
1237c478bd9Sstevel@tonic-gate 	char		*_base;
1247c478bd9Sstevel@tonic-gate 	char 		*_name;
125*986fd29aSsetje 	char		*_dbuf;
1267c478bd9Sstevel@tonic-gate 	int		 _size;
1277c478bd9Sstevel@tonic-gate 	int		_cnt;
1287c478bd9Sstevel@tonic-gate 	int		 _off;
1297c478bd9Sstevel@tonic-gate 	int		_ln;
130*986fd29aSsetje 	int		_bsize;
131*986fd29aSsetje 	int		_iscmp;
132*986fd29aSsetje 	int		_dsize;
1337c478bd9Sstevel@tonic-gate };
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate  * Statistical info.
1387c478bd9Sstevel@tonic-gate  */
1397c478bd9Sstevel@tonic-gate typedef struct {
1407c478bd9Sstevel@tonic-gate 	int nalloc;
1417c478bd9Sstevel@tonic-gate 	int nfree;
1427c478bd9Sstevel@tonic-gate 	int nalloc_calls;
1437c478bd9Sstevel@tonic-gate 	int nfree_calls;
1447c478bd9Sstevel@tonic-gate } kobj_stat_t;
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate #define	kobj_filename(p) ((p)->_name)
1477c478bd9Sstevel@tonic-gate #define	kobj_linenum(p)  ((p)->_ln)
1487c478bd9Sstevel@tonic-gate #define	kobj_newline(p)	 ((p)->_ln++)
1497c478bd9Sstevel@tonic-gate #define	kobj_getc(p)	(--(p)->_cnt >= 0 ? ((int)*(p)->_ptr++):kobj_filbuf(p))
1507c478bd9Sstevel@tonic-gate #define	kobj_ungetc(p)	 (++(p)->_cnt > (p)->_size ? -1 : ((int)*(--(p)->_ptr)))
151*986fd29aSsetje #define	kobj_comphdr(p)	((struct comphdr *)(p)->_dbuf)
1527c478bd9Sstevel@tonic-gate 
153*986fd29aSsetje /* Offset into buffer */
154*986fd29aSsetje #define	B_OFFSET(file, off)	(off % (file)->_bsize)
155*986fd29aSsetje 
156*986fd29aSsetje /* Start of page */
157*986fd29aSsetje #define	F_PAGE(file, off)	(off - B_OFFSET(file, off))
158*986fd29aSsetje 
159*986fd29aSsetje #define	F_BLKS(file, size)	((size / (file)->_bsize) * (file)->_bsize)
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate extern int kobj_load_module(struct modctl *, int);
1647c478bd9Sstevel@tonic-gate extern void kobj_unload_module(struct modctl *);
1657aec1d6eScindi extern uintptr_t kobj_lookup(struct module *, const char *);
1667c478bd9Sstevel@tonic-gate extern Sym *kobj_lookup_all(struct module *, char *, int);
1677c478bd9Sstevel@tonic-gate extern int kobj_addrcheck(void *, caddr_t);
1687c478bd9Sstevel@tonic-gate extern int kobj_module_to_id(void *);
1697c478bd9Sstevel@tonic-gate extern void kobj_getmodinfo(void *, struct modinfo *);
1707c478bd9Sstevel@tonic-gate extern int kobj_get_needed(void *, short *, int);
1717c478bd9Sstevel@tonic-gate extern uintptr_t kobj_getsymvalue(char *, int);
1727c478bd9Sstevel@tonic-gate extern char *kobj_getsymname(uintptr_t, ulong_t *);
1737c478bd9Sstevel@tonic-gate extern char *kobj_searchsym(struct module *, uintptr_t, ulong_t *);
1747c478bd9Sstevel@tonic-gate 
175ea8dc4b6Seschrock extern int kobj_fstat(intptr_t, struct bootstat *);
1767c478bd9Sstevel@tonic-gate extern intptr_t kobj_open(char *);
1775c311300Scth extern int kobj_path_exists(char *, int);
1787c478bd9Sstevel@tonic-gate extern struct _buf *kobj_open_path(char *, int, int);
1797c478bd9Sstevel@tonic-gate extern int kobj_read(intptr_t, char *, unsigned int, unsigned int);
1807c478bd9Sstevel@tonic-gate extern void kobj_close(intptr_t);
1817c478bd9Sstevel@tonic-gate extern void *kobj_alloc(size_t, int);
1827c478bd9Sstevel@tonic-gate extern void *kobj_zalloc(size_t, int);
1837c478bd9Sstevel@tonic-gate extern void kobj_free(void *, size_t);
1847c478bd9Sstevel@tonic-gate extern struct _buf *kobj_open_file(char *);
1857c478bd9Sstevel@tonic-gate extern void kobj_close_file(struct _buf *);
1867c478bd9Sstevel@tonic-gate extern int kobj_read_file(struct _buf *, char *, unsigned, unsigned);
187b1b8ab34Slling extern int kobj_get_filesize(struct _buf *, uint64_t *size);
1887c478bd9Sstevel@tonic-gate extern uintptr_t kobj_getelfsym(char *, void *, int *);
1897c478bd9Sstevel@tonic-gate extern void kobj_set_ctf(struct module *, caddr_t data, size_t size);
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate extern int kobj_filbuf(struct _buf *);
1927c478bd9Sstevel@tonic-gate extern void kobj_sync(void);
1937c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__sparc) || defined(__amd64)
1947c478bd9Sstevel@tonic-gate extern void kobj_vmem_init(vmem_t **, vmem_t **);
1957c478bd9Sstevel@tonic-gate #else
1967c478bd9Sstevel@tonic-gate #error "ISA not supported"
1977c478bd9Sstevel@tonic-gate #endif
1987c478bd9Sstevel@tonic-gate extern caddr_t kobj_text_alloc(vmem_t *, size_t);
1997c478bd9Sstevel@tonic-gate extern caddr_t kobj_texthole_alloc(caddr_t, size_t);
2007c478bd9Sstevel@tonic-gate extern void kobj_texthole_free(caddr_t, size_t);
2017c478bd9Sstevel@tonic-gate extern void kobj_stat_get(kobj_stat_t *);
2027c478bd9Sstevel@tonic-gate extern void kobj_textwin_alloc(struct module *);
2037c478bd9Sstevel@tonic-gate extern void kobj_textwin_free(struct module *);
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate #endif	/* defined(_KERNEL) */
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2087c478bd9Sstevel@tonic-gate }
2097c478bd9Sstevel@tonic-gate #endif
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate #endif /* !_SYS_KOBJ_H */
212