xref: /illumos-gate/usr/src/uts/common/sys/kobj.h (revision 7aec1d6e)
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*7aec1d6eScindi  * 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 _SYS_KOBJ_H
287c478bd9Sstevel@tonic-gate #define	_SYS_KOBJ_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/elf.h>
347c478bd9Sstevel@tonic-gate #include <sys/machelf.h>
357c478bd9Sstevel@tonic-gate #include <sys/vmem.h>
367c478bd9Sstevel@tonic-gate #include <sys/sdt.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;
1257c478bd9Sstevel@tonic-gate 	int		 _size;
1267c478bd9Sstevel@tonic-gate 	int		_cnt;
1277c478bd9Sstevel@tonic-gate 	int		 _off;
1287c478bd9Sstevel@tonic-gate 	int		_ln;
1297c478bd9Sstevel@tonic-gate };
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate /*
1337c478bd9Sstevel@tonic-gate  * Statistical info.
1347c478bd9Sstevel@tonic-gate  */
1357c478bd9Sstevel@tonic-gate typedef struct {
1367c478bd9Sstevel@tonic-gate 	int nalloc;
1377c478bd9Sstevel@tonic-gate 	int nfree;
1387c478bd9Sstevel@tonic-gate 	int nalloc_calls;
1397c478bd9Sstevel@tonic-gate 	int nfree_calls;
1407c478bd9Sstevel@tonic-gate } kobj_stat_t;
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate #define	kobj_filename(p) ((p)->_name)
1437c478bd9Sstevel@tonic-gate #define	kobj_linenum(p)  ((p)->_ln)
1447c478bd9Sstevel@tonic-gate #define	kobj_newline(p)	 ((p)->_ln++)
1457c478bd9Sstevel@tonic-gate #define	kobj_getc(p)	(--(p)->_cnt >= 0 ? ((int)*(p)->_ptr++):kobj_filbuf(p))
1467c478bd9Sstevel@tonic-gate #define	kobj_ungetc(p)	 (++(p)->_cnt > (p)->_size ? -1 : ((int)*(--(p)->_ptr)))
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate #define	B_OFFSET(f_offset) (f_offset & (MAXBSIZE-1))	/* Offset into buffer */
1497c478bd9Sstevel@tonic-gate #define	F_PAGE(f_offset)   (f_offset & ~(MAXBSIZE-1))	/* Start of page */
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate extern int kobj_load_module(struct modctl *, int);
1547c478bd9Sstevel@tonic-gate extern void kobj_unload_module(struct modctl *);
155*7aec1d6eScindi extern uintptr_t kobj_lookup(struct module *, const char *);
1567c478bd9Sstevel@tonic-gate extern Sym *kobj_lookup_all(struct module *, char *, int);
1577c478bd9Sstevel@tonic-gate extern int kobj_addrcheck(void *, caddr_t);
1587c478bd9Sstevel@tonic-gate extern int kobj_module_to_id(void *);
1597c478bd9Sstevel@tonic-gate extern void kobj_getmodinfo(void *, struct modinfo *);
1607c478bd9Sstevel@tonic-gate extern int kobj_get_needed(void *, short *, int);
1617c478bd9Sstevel@tonic-gate extern uintptr_t kobj_getsymvalue(char *, int);
1627c478bd9Sstevel@tonic-gate extern char *kobj_getsymname(uintptr_t, ulong_t *);
1637c478bd9Sstevel@tonic-gate extern char *kobj_searchsym(struct module *, uintptr_t, ulong_t *);
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate extern intptr_t kobj_open(char *);
1665c311300Scth extern int kobj_path_exists(char *, int);
1677c478bd9Sstevel@tonic-gate extern struct _buf *kobj_open_path(char *, int, int);
1687c478bd9Sstevel@tonic-gate extern int kobj_read(intptr_t, char *, unsigned int, unsigned int);
1697c478bd9Sstevel@tonic-gate extern void kobj_close(intptr_t);
1707c478bd9Sstevel@tonic-gate extern void *kobj_alloc(size_t, int);
1717c478bd9Sstevel@tonic-gate extern void *kobj_zalloc(size_t, int);
1727c478bd9Sstevel@tonic-gate extern void kobj_free(void *, size_t);
1737c478bd9Sstevel@tonic-gate extern struct _buf *kobj_open_file(char *);
1747c478bd9Sstevel@tonic-gate extern void kobj_close_file(struct _buf *);
1757c478bd9Sstevel@tonic-gate extern int kobj_read_file(struct _buf *, char *, unsigned, unsigned);
1767c478bd9Sstevel@tonic-gate extern uintptr_t kobj_getelfsym(char *, void *, int *);
1777c478bd9Sstevel@tonic-gate extern void kobj_set_ctf(struct module *, caddr_t data, size_t size);
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate extern int kobj_filbuf(struct _buf *);
1807c478bd9Sstevel@tonic-gate extern void kobj_sync(void);
1817c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__sparc) || defined(__amd64)
1827c478bd9Sstevel@tonic-gate extern void kobj_vmem_init(vmem_t **, vmem_t **);
1837c478bd9Sstevel@tonic-gate #else
1847c478bd9Sstevel@tonic-gate #error "ISA not supported"
1857c478bd9Sstevel@tonic-gate #endif
1867c478bd9Sstevel@tonic-gate extern caddr_t kobj_text_alloc(vmem_t *, size_t);
1877c478bd9Sstevel@tonic-gate extern caddr_t kobj_texthole_alloc(caddr_t, size_t);
1887c478bd9Sstevel@tonic-gate extern void kobj_texthole_free(caddr_t, size_t);
1897c478bd9Sstevel@tonic-gate extern void kobj_stat_get(kobj_stat_t *);
1907c478bd9Sstevel@tonic-gate extern void kobj_textwin_alloc(struct module *);
1917c478bd9Sstevel@tonic-gate extern void kobj_textwin_free(struct module *);
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate #endif	/* defined(_KERNEL) */
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1967c478bd9Sstevel@tonic-gate }
1977c478bd9Sstevel@tonic-gate #endif
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate #endif /* !_SYS_KOBJ_H */
200