xref: /titanic_52/usr/src/uts/common/sys/kobj.h (revision 5c3113005025c7746cee7871e37f22045f093f96)
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 /*
237c478bd9Sstevel@tonic-gate  * Copyright 2005 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 #if defined(__ia64)
547c478bd9Sstevel@tonic-gate typedef	struct kobj_funcdesc {
557c478bd9Sstevel@tonic-gate 	char			*kf_name;	/* function name */
567c478bd9Sstevel@tonic-gate 	Elf64_Addr		kf_faddr;	/* function address */
577c478bd9Sstevel@tonic-gate 	Elf64_Addr		kf_gp;		/* GP for module */
587c478bd9Sstevel@tonic-gate 	struct kobj_funcdesc	*kf_next;	/* next FD in chain */
597c478bd9Sstevel@tonic-gate } kobj_funcdesc;
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate typedef struct {
627c478bd9Sstevel@tonic-gate 	char			*m_sdata;	/* address of ia64 small data */
637c478bd9Sstevel@tonic-gate 	char			*m_gotaddr;	/* starting address of */
647c478bd9Sstevel@tonic-gate 						/*	GOT table */
657c478bd9Sstevel@tonic-gate 	char			*m_gotend;	/* tail of filled in */
667c478bd9Sstevel@tonic-gate 						/*	GOT table */
677c478bd9Sstevel@tonic-gate 	unsigned long		m_gotcnt;	/* number of GOT entries */
687c478bd9Sstevel@tonic-gate 	size_t 			m_sdatasize;	/* size of small data + */
697c478bd9Sstevel@tonic-gate 						/*	got table */
707c478bd9Sstevel@tonic-gate 	uint_t			m_fdhsize;	/* # of hash buckets for */
717c478bd9Sstevel@tonic-gate 						/*	FD list */
727c478bd9Sstevel@tonic-gate 	kobj_funcdesc		**m_fdbuckets;	/* head of FD bucket's */
737c478bd9Sstevel@tonic-gate 	kobj_funcdesc		*m_fdchains;	/* head of FD hash list */
747c478bd9Sstevel@tonic-gate 	kobj_funcdesc		*m_fdfree;	/* next free FD bucket */
757c478bd9Sstevel@tonic-gate 	char			*m_fstrtab;	/* strtab for func descs */
767c478bd9Sstevel@tonic-gate } module_mach;
777c478bd9Sstevel@tonic-gate #else
787c478bd9Sstevel@tonic-gate typedef	void	module_mach;
797c478bd9Sstevel@tonic-gate #endif
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate struct module {
827c478bd9Sstevel@tonic-gate 	int total_allocated;
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate 	Ehdr hdr;
857c478bd9Sstevel@tonic-gate 	char *shdrs;
867c478bd9Sstevel@tonic-gate 	Shdr *symhdr, *strhdr;
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate 	char *depends_on;
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate 	size_t symsize;
917c478bd9Sstevel@tonic-gate 	char *symspace;	/* symbols + strings + hashtbl, or NULL */
927c478bd9Sstevel@tonic-gate 	int flags;
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate 	size_t text_size;
957c478bd9Sstevel@tonic-gate 	size_t data_size;
967c478bd9Sstevel@tonic-gate 	char *text;
977c478bd9Sstevel@tonic-gate 	char *data;
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate 	unsigned int symtbl_section;
1007c478bd9Sstevel@tonic-gate 	/* pointers into symspace, or NULL */
1017c478bd9Sstevel@tonic-gate 	char *symtbl;
1027c478bd9Sstevel@tonic-gate 	char *strings;
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate 	unsigned int hashsize;
1057c478bd9Sstevel@tonic-gate 	symid_t *buckets;
1067c478bd9Sstevel@tonic-gate 	symid_t *chains;
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate 	unsigned int nsyms;
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate 	unsigned int bss_align;
1117c478bd9Sstevel@tonic-gate 	size_t bss_size;
1127c478bd9Sstevel@tonic-gate 	uintptr_t bss;
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate 	char *filename;
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate 	struct module_list *head, *tail;
1177c478bd9Sstevel@tonic-gate 	reloc_dest_t destination;
1187c478bd9Sstevel@tonic-gate 	module_mach * machdata;
1197c478bd9Sstevel@tonic-gate 	char *ctfdata;
1207c478bd9Sstevel@tonic-gate 	size_t ctfsize;
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate 	char *fbt_tab;
1237c478bd9Sstevel@tonic-gate 	size_t fbt_size;
1247c478bd9Sstevel@tonic-gate 	size_t fbt_nentries;
1257c478bd9Sstevel@tonic-gate 	caddr_t textwin;
1267c478bd9Sstevel@tonic-gate 	caddr_t textwin_base;
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate 	sdt_probedesc_t *sdt_probes;
1297c478bd9Sstevel@tonic-gate 	size_t sdt_nprobes;
1307c478bd9Sstevel@tonic-gate 	char *sdt_tab;
1317c478bd9Sstevel@tonic-gate 	size_t sdt_size;
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate 	char *sigdata;
1347c478bd9Sstevel@tonic-gate 	size_t sigsize;
1357c478bd9Sstevel@tonic-gate };
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate struct kobj_mem {
1387c478bd9Sstevel@tonic-gate 	struct kobj_mem	*km_next;
1397c478bd9Sstevel@tonic-gate 	struct kobj_mem *km_prev;
1407c478bd9Sstevel@tonic-gate 	uintptr_t	km_addr;
1417c478bd9Sstevel@tonic-gate 	size_t		km_size;
1427c478bd9Sstevel@tonic-gate 	uintptr_t	km_alloc_addr;
1437c478bd9Sstevel@tonic-gate 	size_t		km_alloc_size;
1447c478bd9Sstevel@tonic-gate };
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate struct _buf {
1477c478bd9Sstevel@tonic-gate 	intptr_t	 _fd;
1487c478bd9Sstevel@tonic-gate 	char		*_ptr;
1497c478bd9Sstevel@tonic-gate 	char		*_base;
1507c478bd9Sstevel@tonic-gate 	char 		*_name;
1517c478bd9Sstevel@tonic-gate 	int		 _size;
1527c478bd9Sstevel@tonic-gate 	int		_cnt;
1537c478bd9Sstevel@tonic-gate 	int		 _off;
1547c478bd9Sstevel@tonic-gate 	int		_ln;
1557c478bd9Sstevel@tonic-gate };
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate /*
1597c478bd9Sstevel@tonic-gate  * Statistical info.
1607c478bd9Sstevel@tonic-gate  */
1617c478bd9Sstevel@tonic-gate typedef struct {
1627c478bd9Sstevel@tonic-gate 	int nalloc;
1637c478bd9Sstevel@tonic-gate 	int nfree;
1647c478bd9Sstevel@tonic-gate 	int nalloc_calls;
1657c478bd9Sstevel@tonic-gate 	int nfree_calls;
1667c478bd9Sstevel@tonic-gate } kobj_stat_t;
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate #define	kobj_filename(p) ((p)->_name)
1697c478bd9Sstevel@tonic-gate #define	kobj_linenum(p)  ((p)->_ln)
1707c478bd9Sstevel@tonic-gate #define	kobj_newline(p)	 ((p)->_ln++)
1717c478bd9Sstevel@tonic-gate #define	kobj_getc(p)	(--(p)->_cnt >= 0 ? ((int)*(p)->_ptr++):kobj_filbuf(p))
1727c478bd9Sstevel@tonic-gate #define	kobj_ungetc(p)	 (++(p)->_cnt > (p)->_size ? -1 : ((int)*(--(p)->_ptr)))
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate #define	B_OFFSET(f_offset) (f_offset & (MAXBSIZE-1))	/* Offset into buffer */
1757c478bd9Sstevel@tonic-gate #define	F_PAGE(f_offset)   (f_offset & ~(MAXBSIZE-1))	/* Start of page */
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate extern int kobj_load_module(struct modctl *, int);
1807c478bd9Sstevel@tonic-gate extern void kobj_unload_module(struct modctl *);
1817c478bd9Sstevel@tonic-gate extern uintptr_t kobj_lookup(void *, char *);
1827c478bd9Sstevel@tonic-gate extern Sym *kobj_lookup_all(struct module *, char *, int);
1837c478bd9Sstevel@tonic-gate extern int kobj_addrcheck(void *, caddr_t);
1847c478bd9Sstevel@tonic-gate extern int kobj_module_to_id(void *);
1857c478bd9Sstevel@tonic-gate extern void kobj_getmodinfo(void *, struct modinfo *);
1867c478bd9Sstevel@tonic-gate extern int kobj_get_needed(void *, short *, int);
1877c478bd9Sstevel@tonic-gate extern uintptr_t kobj_getsymvalue(char *, int);
1887c478bd9Sstevel@tonic-gate extern char *kobj_getsymname(uintptr_t, ulong_t *);
1897c478bd9Sstevel@tonic-gate extern char *kobj_searchsym(struct module *, uintptr_t, ulong_t *);
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate extern intptr_t kobj_open(char *);
192*5c311300Scth extern int kobj_path_exists(char *, int);
1937c478bd9Sstevel@tonic-gate extern struct _buf *kobj_open_path(char *, int, int);
1947c478bd9Sstevel@tonic-gate extern int kobj_read(intptr_t, char *, unsigned int, unsigned int);
1957c478bd9Sstevel@tonic-gate extern void kobj_close(intptr_t);
1967c478bd9Sstevel@tonic-gate extern void *kobj_alloc(size_t, int);
1977c478bd9Sstevel@tonic-gate extern void *kobj_zalloc(size_t, int);
1987c478bd9Sstevel@tonic-gate extern void kobj_free(void *, size_t);
1997c478bd9Sstevel@tonic-gate extern struct _buf *kobj_open_file(char *);
2007c478bd9Sstevel@tonic-gate extern void kobj_close_file(struct _buf *);
2017c478bd9Sstevel@tonic-gate extern int kobj_read_file(struct _buf *, char *, unsigned, unsigned);
2027c478bd9Sstevel@tonic-gate extern uintptr_t kobj_getelfsym(char *, void *, int *);
2037c478bd9Sstevel@tonic-gate extern void kobj_set_ctf(struct module *, caddr_t data, size_t size);
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate extern int kobj_filbuf(struct _buf *);
2067c478bd9Sstevel@tonic-gate extern void kobj_sync(void);
2077c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__sparc) || defined(__amd64)
2087c478bd9Sstevel@tonic-gate extern void kobj_vmem_init(vmem_t **, vmem_t **);
2097c478bd9Sstevel@tonic-gate #elif defined(__ia64)
2107c478bd9Sstevel@tonic-gate extern void kobj_vmem_init(vmem_t **, vmem_t **, vmem_t **);
2117c478bd9Sstevel@tonic-gate #else
2127c478bd9Sstevel@tonic-gate #error "ISA not supported"
2137c478bd9Sstevel@tonic-gate #endif
2147c478bd9Sstevel@tonic-gate extern caddr_t kobj_text_alloc(vmem_t *, size_t);
2157c478bd9Sstevel@tonic-gate extern caddr_t kobj_texthole_alloc(caddr_t, size_t);
2167c478bd9Sstevel@tonic-gate extern void kobj_texthole_free(caddr_t, size_t);
2177c478bd9Sstevel@tonic-gate extern void kobj_stat_get(kobj_stat_t *);
2187c478bd9Sstevel@tonic-gate extern void kobj_textwin_alloc(struct module *);
2197c478bd9Sstevel@tonic-gate extern void kobj_textwin_free(struct module *);
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate #endif	/* defined(_KERNEL) */
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2247c478bd9Sstevel@tonic-gate }
2257c478bd9Sstevel@tonic-gate #endif
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate #endif /* !_SYS_KOBJ_H */
228