xref: /onnv-gate/usr/src/uts/common/sys/kobj.h (revision 309:ce16da2e9351)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
230Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #ifndef _SYS_KOBJ_H
280Sstevel@tonic-gate #define	_SYS_KOBJ_H
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <sys/modctl.h>
330Sstevel@tonic-gate #include <sys/elf.h>
340Sstevel@tonic-gate #include <sys/machelf.h>
350Sstevel@tonic-gate #include <sys/vmem.h>
360Sstevel@tonic-gate #include <sys/sdt.h>
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #ifdef	__cplusplus
390Sstevel@tonic-gate extern "C" {
400Sstevel@tonic-gate #endif
410Sstevel@tonic-gate 
420Sstevel@tonic-gate /*
430Sstevel@tonic-gate  * List of modules maintained by kobj.c
440Sstevel@tonic-gate  */
450Sstevel@tonic-gate struct module_list {
460Sstevel@tonic-gate 	struct module_list *next;
470Sstevel@tonic-gate 	struct module *mp;
480Sstevel@tonic-gate };
490Sstevel@tonic-gate 
500Sstevel@tonic-gate typedef unsigned short	symid_t;		/* symbol table index */
510Sstevel@tonic-gate typedef unsigned char	*reloc_dest_t;
520Sstevel@tonic-gate 
530Sstevel@tonic-gate #if defined(__ia64)
540Sstevel@tonic-gate typedef	struct kobj_funcdesc {
550Sstevel@tonic-gate 	char			*kf_name;	/* function name */
560Sstevel@tonic-gate 	Elf64_Addr		kf_faddr;	/* function address */
570Sstevel@tonic-gate 	Elf64_Addr		kf_gp;		/* GP for module */
580Sstevel@tonic-gate 	struct kobj_funcdesc	*kf_next;	/* next FD in chain */
590Sstevel@tonic-gate } kobj_funcdesc;
600Sstevel@tonic-gate 
610Sstevel@tonic-gate typedef struct {
620Sstevel@tonic-gate 	char			*m_sdata;	/* address of ia64 small data */
630Sstevel@tonic-gate 	char			*m_gotaddr;	/* starting address of */
640Sstevel@tonic-gate 						/*	GOT table */
650Sstevel@tonic-gate 	char			*m_gotend;	/* tail of filled in */
660Sstevel@tonic-gate 						/*	GOT table */
670Sstevel@tonic-gate 	unsigned long		m_gotcnt;	/* number of GOT entries */
680Sstevel@tonic-gate 	size_t 			m_sdatasize;	/* size of small data + */
690Sstevel@tonic-gate 						/*	got table */
700Sstevel@tonic-gate 	uint_t			m_fdhsize;	/* # of hash buckets for */
710Sstevel@tonic-gate 						/*	FD list */
720Sstevel@tonic-gate 	kobj_funcdesc		**m_fdbuckets;	/* head of FD bucket's */
730Sstevel@tonic-gate 	kobj_funcdesc		*m_fdchains;	/* head of FD hash list */
740Sstevel@tonic-gate 	kobj_funcdesc		*m_fdfree;	/* next free FD bucket */
750Sstevel@tonic-gate 	char			*m_fstrtab;	/* strtab for func descs */
760Sstevel@tonic-gate } module_mach;
770Sstevel@tonic-gate #else
780Sstevel@tonic-gate typedef	void	module_mach;
790Sstevel@tonic-gate #endif
800Sstevel@tonic-gate 
810Sstevel@tonic-gate struct module {
820Sstevel@tonic-gate 	int total_allocated;
830Sstevel@tonic-gate 
840Sstevel@tonic-gate 	Ehdr hdr;
850Sstevel@tonic-gate 	char *shdrs;
860Sstevel@tonic-gate 	Shdr *symhdr, *strhdr;
870Sstevel@tonic-gate 
880Sstevel@tonic-gate 	char *depends_on;
890Sstevel@tonic-gate 
900Sstevel@tonic-gate 	size_t symsize;
910Sstevel@tonic-gate 	char *symspace;	/* symbols + strings + hashtbl, or NULL */
920Sstevel@tonic-gate 	int flags;
930Sstevel@tonic-gate 
940Sstevel@tonic-gate 	size_t text_size;
950Sstevel@tonic-gate 	size_t data_size;
960Sstevel@tonic-gate 	char *text;
970Sstevel@tonic-gate 	char *data;
980Sstevel@tonic-gate 
990Sstevel@tonic-gate 	unsigned int symtbl_section;
1000Sstevel@tonic-gate 	/* pointers into symspace, or NULL */
1010Sstevel@tonic-gate 	char *symtbl;
1020Sstevel@tonic-gate 	char *strings;
1030Sstevel@tonic-gate 
1040Sstevel@tonic-gate 	unsigned int hashsize;
1050Sstevel@tonic-gate 	symid_t *buckets;
1060Sstevel@tonic-gate 	symid_t *chains;
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate 	unsigned int nsyms;
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate 	unsigned int bss_align;
1110Sstevel@tonic-gate 	size_t bss_size;
1120Sstevel@tonic-gate 	uintptr_t bss;
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate 	char *filename;
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate 	struct module_list *head, *tail;
1170Sstevel@tonic-gate 	reloc_dest_t destination;
1180Sstevel@tonic-gate 	module_mach * machdata;
1190Sstevel@tonic-gate 	char *ctfdata;
1200Sstevel@tonic-gate 	size_t ctfsize;
1210Sstevel@tonic-gate 
1220Sstevel@tonic-gate 	char *fbt_tab;
1230Sstevel@tonic-gate 	size_t fbt_size;
1240Sstevel@tonic-gate 	size_t fbt_nentries;
1250Sstevel@tonic-gate 	caddr_t textwin;
1260Sstevel@tonic-gate 	caddr_t textwin_base;
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate 	sdt_probedesc_t *sdt_probes;
1290Sstevel@tonic-gate 	size_t sdt_nprobes;
1300Sstevel@tonic-gate 	char *sdt_tab;
1310Sstevel@tonic-gate 	size_t sdt_size;
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate 	char *sigdata;
1340Sstevel@tonic-gate 	size_t sigsize;
1350Sstevel@tonic-gate };
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate struct kobj_mem {
1380Sstevel@tonic-gate 	struct kobj_mem	*km_next;
1390Sstevel@tonic-gate 	struct kobj_mem *km_prev;
1400Sstevel@tonic-gate 	uintptr_t	km_addr;
1410Sstevel@tonic-gate 	size_t		km_size;
1420Sstevel@tonic-gate 	uintptr_t	km_alloc_addr;
1430Sstevel@tonic-gate 	size_t		km_alloc_size;
1440Sstevel@tonic-gate };
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate struct _buf {
1470Sstevel@tonic-gate 	intptr_t	 _fd;
1480Sstevel@tonic-gate 	char		*_ptr;
1490Sstevel@tonic-gate 	char		*_base;
1500Sstevel@tonic-gate 	char 		*_name;
1510Sstevel@tonic-gate 	int		 _size;
1520Sstevel@tonic-gate 	int		_cnt;
1530Sstevel@tonic-gate 	int		 _off;
1540Sstevel@tonic-gate 	int		_ln;
1550Sstevel@tonic-gate };
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate /*
1590Sstevel@tonic-gate  * Statistical info.
1600Sstevel@tonic-gate  */
1610Sstevel@tonic-gate typedef struct {
1620Sstevel@tonic-gate 	int nalloc;
1630Sstevel@tonic-gate 	int nfree;
1640Sstevel@tonic-gate 	int nalloc_calls;
1650Sstevel@tonic-gate 	int nfree_calls;
1660Sstevel@tonic-gate } kobj_stat_t;
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate #define	kobj_filename(p) ((p)->_name)
1690Sstevel@tonic-gate #define	kobj_linenum(p)  ((p)->_ln)
1700Sstevel@tonic-gate #define	kobj_newline(p)	 ((p)->_ln++)
1710Sstevel@tonic-gate #define	kobj_getc(p)	(--(p)->_cnt >= 0 ? ((int)*(p)->_ptr++):kobj_filbuf(p))
1720Sstevel@tonic-gate #define	kobj_ungetc(p)	 (++(p)->_cnt > (p)->_size ? -1 : ((int)*(--(p)->_ptr)))
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate #define	B_OFFSET(f_offset) (f_offset & (MAXBSIZE-1))	/* Offset into buffer */
1750Sstevel@tonic-gate #define	F_PAGE(f_offset)   (f_offset & ~(MAXBSIZE-1))	/* Start of page */
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate #if defined(_KERNEL)
1780Sstevel@tonic-gate 
1790Sstevel@tonic-gate extern int kobj_load_module(struct modctl *, int);
1800Sstevel@tonic-gate extern void kobj_unload_module(struct modctl *);
1810Sstevel@tonic-gate extern uintptr_t kobj_lookup(void *, char *);
1820Sstevel@tonic-gate extern Sym *kobj_lookup_all(struct module *, char *, int);
1830Sstevel@tonic-gate extern int kobj_addrcheck(void *, caddr_t);
1840Sstevel@tonic-gate extern int kobj_module_to_id(void *);
1850Sstevel@tonic-gate extern void kobj_getmodinfo(void *, struct modinfo *);
1860Sstevel@tonic-gate extern int kobj_get_needed(void *, short *, int);
1870Sstevel@tonic-gate extern uintptr_t kobj_getsymvalue(char *, int);
1880Sstevel@tonic-gate extern char *kobj_getsymname(uintptr_t, ulong_t *);
1890Sstevel@tonic-gate extern char *kobj_searchsym(struct module *, uintptr_t, ulong_t *);
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate extern intptr_t kobj_open(char *);
192*309Scth extern int kobj_path_exists(char *, int);
1930Sstevel@tonic-gate extern struct _buf *kobj_open_path(char *, int, int);
1940Sstevel@tonic-gate extern int kobj_read(intptr_t, char *, unsigned int, unsigned int);
1950Sstevel@tonic-gate extern void kobj_close(intptr_t);
1960Sstevel@tonic-gate extern void *kobj_alloc(size_t, int);
1970Sstevel@tonic-gate extern void *kobj_zalloc(size_t, int);
1980Sstevel@tonic-gate extern void kobj_free(void *, size_t);
1990Sstevel@tonic-gate extern struct _buf *kobj_open_file(char *);
2000Sstevel@tonic-gate extern void kobj_close_file(struct _buf *);
2010Sstevel@tonic-gate extern int kobj_read_file(struct _buf *, char *, unsigned, unsigned);
2020Sstevel@tonic-gate extern uintptr_t kobj_getelfsym(char *, void *, int *);
2030Sstevel@tonic-gate extern void kobj_set_ctf(struct module *, caddr_t data, size_t size);
2040Sstevel@tonic-gate 
2050Sstevel@tonic-gate extern int kobj_filbuf(struct _buf *);
2060Sstevel@tonic-gate extern void kobj_sync(void);
2070Sstevel@tonic-gate #if defined(__i386) || defined(__sparc) || defined(__amd64)
2080Sstevel@tonic-gate extern void kobj_vmem_init(vmem_t **, vmem_t **);
2090Sstevel@tonic-gate #elif defined(__ia64)
2100Sstevel@tonic-gate extern void kobj_vmem_init(vmem_t **, vmem_t **, vmem_t **);
2110Sstevel@tonic-gate #else
2120Sstevel@tonic-gate #error "ISA not supported"
2130Sstevel@tonic-gate #endif
2140Sstevel@tonic-gate extern caddr_t kobj_text_alloc(vmem_t *, size_t);
2150Sstevel@tonic-gate extern caddr_t kobj_texthole_alloc(caddr_t, size_t);
2160Sstevel@tonic-gate extern void kobj_texthole_free(caddr_t, size_t);
2170Sstevel@tonic-gate extern void kobj_stat_get(kobj_stat_t *);
2180Sstevel@tonic-gate extern void kobj_textwin_alloc(struct module *);
2190Sstevel@tonic-gate extern void kobj_textwin_free(struct module *);
2200Sstevel@tonic-gate 
2210Sstevel@tonic-gate #endif	/* defined(_KERNEL) */
2220Sstevel@tonic-gate 
2230Sstevel@tonic-gate #ifdef	__cplusplus
2240Sstevel@tonic-gate }
2250Sstevel@tonic-gate #endif
2260Sstevel@tonic-gate 
2270Sstevel@tonic-gate #endif /* !_SYS_KOBJ_H */
228