xref: /onnv-gate/usr/src/uts/common/sys/kobj.h (revision 1414:b4126407ac5b)
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 /*
23*1414Scindi  * Copyright 2006 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 typedef	void	module_mach;
540Sstevel@tonic-gate 
550Sstevel@tonic-gate struct module {
560Sstevel@tonic-gate 	int total_allocated;
570Sstevel@tonic-gate 
580Sstevel@tonic-gate 	Ehdr hdr;
590Sstevel@tonic-gate 	char *shdrs;
600Sstevel@tonic-gate 	Shdr *symhdr, *strhdr;
610Sstevel@tonic-gate 
620Sstevel@tonic-gate 	char *depends_on;
630Sstevel@tonic-gate 
640Sstevel@tonic-gate 	size_t symsize;
650Sstevel@tonic-gate 	char *symspace;	/* symbols + strings + hashtbl, or NULL */
660Sstevel@tonic-gate 	int flags;
670Sstevel@tonic-gate 
680Sstevel@tonic-gate 	size_t text_size;
690Sstevel@tonic-gate 	size_t data_size;
700Sstevel@tonic-gate 	char *text;
710Sstevel@tonic-gate 	char *data;
720Sstevel@tonic-gate 
730Sstevel@tonic-gate 	unsigned int symtbl_section;
740Sstevel@tonic-gate 	/* pointers into symspace, or NULL */
750Sstevel@tonic-gate 	char *symtbl;
760Sstevel@tonic-gate 	char *strings;
770Sstevel@tonic-gate 
780Sstevel@tonic-gate 	unsigned int hashsize;
790Sstevel@tonic-gate 	symid_t *buckets;
800Sstevel@tonic-gate 	symid_t *chains;
810Sstevel@tonic-gate 
820Sstevel@tonic-gate 	unsigned int nsyms;
830Sstevel@tonic-gate 
840Sstevel@tonic-gate 	unsigned int bss_align;
850Sstevel@tonic-gate 	size_t bss_size;
860Sstevel@tonic-gate 	uintptr_t bss;
870Sstevel@tonic-gate 
880Sstevel@tonic-gate 	char *filename;
890Sstevel@tonic-gate 
900Sstevel@tonic-gate 	struct module_list *head, *tail;
910Sstevel@tonic-gate 	reloc_dest_t destination;
920Sstevel@tonic-gate 	module_mach * machdata;
930Sstevel@tonic-gate 	char *ctfdata;
940Sstevel@tonic-gate 	size_t ctfsize;
950Sstevel@tonic-gate 
960Sstevel@tonic-gate 	char *fbt_tab;
970Sstevel@tonic-gate 	size_t fbt_size;
980Sstevel@tonic-gate 	size_t fbt_nentries;
990Sstevel@tonic-gate 	caddr_t textwin;
1000Sstevel@tonic-gate 	caddr_t textwin_base;
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate 	sdt_probedesc_t *sdt_probes;
1030Sstevel@tonic-gate 	size_t sdt_nprobes;
1040Sstevel@tonic-gate 	char *sdt_tab;
1050Sstevel@tonic-gate 	size_t sdt_size;
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate 	char *sigdata;
1080Sstevel@tonic-gate 	size_t sigsize;
1090Sstevel@tonic-gate };
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate struct kobj_mem {
1120Sstevel@tonic-gate 	struct kobj_mem	*km_next;
1130Sstevel@tonic-gate 	struct kobj_mem *km_prev;
1140Sstevel@tonic-gate 	uintptr_t	km_addr;
1150Sstevel@tonic-gate 	size_t		km_size;
1160Sstevel@tonic-gate 	uintptr_t	km_alloc_addr;
1170Sstevel@tonic-gate 	size_t		km_alloc_size;
1180Sstevel@tonic-gate };
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate struct _buf {
1210Sstevel@tonic-gate 	intptr_t	 _fd;
1220Sstevel@tonic-gate 	char		*_ptr;
1230Sstevel@tonic-gate 	char		*_base;
1240Sstevel@tonic-gate 	char 		*_name;
1250Sstevel@tonic-gate 	int		 _size;
1260Sstevel@tonic-gate 	int		_cnt;
1270Sstevel@tonic-gate 	int		 _off;
1280Sstevel@tonic-gate 	int		_ln;
1290Sstevel@tonic-gate };
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate /*
1330Sstevel@tonic-gate  * Statistical info.
1340Sstevel@tonic-gate  */
1350Sstevel@tonic-gate typedef struct {
1360Sstevel@tonic-gate 	int nalloc;
1370Sstevel@tonic-gate 	int nfree;
1380Sstevel@tonic-gate 	int nalloc_calls;
1390Sstevel@tonic-gate 	int nfree_calls;
1400Sstevel@tonic-gate } kobj_stat_t;
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate #define	kobj_filename(p) ((p)->_name)
1430Sstevel@tonic-gate #define	kobj_linenum(p)  ((p)->_ln)
1440Sstevel@tonic-gate #define	kobj_newline(p)	 ((p)->_ln++)
1450Sstevel@tonic-gate #define	kobj_getc(p)	(--(p)->_cnt >= 0 ? ((int)*(p)->_ptr++):kobj_filbuf(p))
1460Sstevel@tonic-gate #define	kobj_ungetc(p)	 (++(p)->_cnt > (p)->_size ? -1 : ((int)*(--(p)->_ptr)))
1470Sstevel@tonic-gate 
1480Sstevel@tonic-gate #define	B_OFFSET(f_offset) (f_offset & (MAXBSIZE-1))	/* Offset into buffer */
1490Sstevel@tonic-gate #define	F_PAGE(f_offset)   (f_offset & ~(MAXBSIZE-1))	/* Start of page */
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate #if defined(_KERNEL)
1520Sstevel@tonic-gate 
1530Sstevel@tonic-gate extern int kobj_load_module(struct modctl *, int);
1540Sstevel@tonic-gate extern void kobj_unload_module(struct modctl *);
155*1414Scindi extern uintptr_t kobj_lookup(struct module *, const char *);
1560Sstevel@tonic-gate extern Sym *kobj_lookup_all(struct module *, char *, int);
1570Sstevel@tonic-gate extern int kobj_addrcheck(void *, caddr_t);
1580Sstevel@tonic-gate extern int kobj_module_to_id(void *);
1590Sstevel@tonic-gate extern void kobj_getmodinfo(void *, struct modinfo *);
1600Sstevel@tonic-gate extern int kobj_get_needed(void *, short *, int);
1610Sstevel@tonic-gate extern uintptr_t kobj_getsymvalue(char *, int);
1620Sstevel@tonic-gate extern char *kobj_getsymname(uintptr_t, ulong_t *);
1630Sstevel@tonic-gate extern char *kobj_searchsym(struct module *, uintptr_t, ulong_t *);
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate extern intptr_t kobj_open(char *);
166309Scth extern int kobj_path_exists(char *, int);
1670Sstevel@tonic-gate extern struct _buf *kobj_open_path(char *, int, int);
1680Sstevel@tonic-gate extern int kobj_read(intptr_t, char *, unsigned int, unsigned int);
1690Sstevel@tonic-gate extern void kobj_close(intptr_t);
1700Sstevel@tonic-gate extern void *kobj_alloc(size_t, int);
1710Sstevel@tonic-gate extern void *kobj_zalloc(size_t, int);
1720Sstevel@tonic-gate extern void kobj_free(void *, size_t);
1730Sstevel@tonic-gate extern struct _buf *kobj_open_file(char *);
1740Sstevel@tonic-gate extern void kobj_close_file(struct _buf *);
1750Sstevel@tonic-gate extern int kobj_read_file(struct _buf *, char *, unsigned, unsigned);
1760Sstevel@tonic-gate extern uintptr_t kobj_getelfsym(char *, void *, int *);
1770Sstevel@tonic-gate extern void kobj_set_ctf(struct module *, caddr_t data, size_t size);
1780Sstevel@tonic-gate 
1790Sstevel@tonic-gate extern int kobj_filbuf(struct _buf *);
1800Sstevel@tonic-gate extern void kobj_sync(void);
1810Sstevel@tonic-gate #if defined(__i386) || defined(__sparc) || defined(__amd64)
1820Sstevel@tonic-gate extern void kobj_vmem_init(vmem_t **, vmem_t **);
1830Sstevel@tonic-gate #else
1840Sstevel@tonic-gate #error "ISA not supported"
1850Sstevel@tonic-gate #endif
1860Sstevel@tonic-gate extern caddr_t kobj_text_alloc(vmem_t *, size_t);
1870Sstevel@tonic-gate extern caddr_t kobj_texthole_alloc(caddr_t, size_t);
1880Sstevel@tonic-gate extern void kobj_texthole_free(caddr_t, size_t);
1890Sstevel@tonic-gate extern void kobj_stat_get(kobj_stat_t *);
1900Sstevel@tonic-gate extern void kobj_textwin_alloc(struct module *);
1910Sstevel@tonic-gate extern void kobj_textwin_free(struct module *);
1920Sstevel@tonic-gate 
1930Sstevel@tonic-gate #endif	/* defined(_KERNEL) */
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate #ifdef	__cplusplus
1960Sstevel@tonic-gate }
1970Sstevel@tonic-gate #endif
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate #endif /* !_SYS_KOBJ_H */
200