xref: /titanic_52/usr/src/uts/common/sys/kobj.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef _SYS_KOBJ_H
28*7c478bd9Sstevel@tonic-gate #define	_SYS_KOBJ_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
33*7c478bd9Sstevel@tonic-gate #include <sys/elf.h>
34*7c478bd9Sstevel@tonic-gate #include <sys/machelf.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/vmem.h>
36*7c478bd9Sstevel@tonic-gate #include <sys/sdt.h>
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
39*7c478bd9Sstevel@tonic-gate extern "C" {
40*7c478bd9Sstevel@tonic-gate #endif
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate /*
43*7c478bd9Sstevel@tonic-gate  * List of modules maintained by kobj.c
44*7c478bd9Sstevel@tonic-gate  */
45*7c478bd9Sstevel@tonic-gate struct module_list {
46*7c478bd9Sstevel@tonic-gate 	struct module_list *next;
47*7c478bd9Sstevel@tonic-gate 	struct module *mp;
48*7c478bd9Sstevel@tonic-gate };
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate typedef unsigned short	symid_t;		/* symbol table index */
51*7c478bd9Sstevel@tonic-gate typedef unsigned char	*reloc_dest_t;
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate #if defined(__ia64)
54*7c478bd9Sstevel@tonic-gate typedef	struct kobj_funcdesc {
55*7c478bd9Sstevel@tonic-gate 	char			*kf_name;	/* function name */
56*7c478bd9Sstevel@tonic-gate 	Elf64_Addr		kf_faddr;	/* function address */
57*7c478bd9Sstevel@tonic-gate 	Elf64_Addr		kf_gp;		/* GP for module */
58*7c478bd9Sstevel@tonic-gate 	struct kobj_funcdesc	*kf_next;	/* next FD in chain */
59*7c478bd9Sstevel@tonic-gate } kobj_funcdesc;
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate typedef struct {
62*7c478bd9Sstevel@tonic-gate 	char			*m_sdata;	/* address of ia64 small data */
63*7c478bd9Sstevel@tonic-gate 	char			*m_gotaddr;	/* starting address of */
64*7c478bd9Sstevel@tonic-gate 						/*	GOT table */
65*7c478bd9Sstevel@tonic-gate 	char			*m_gotend;	/* tail of filled in */
66*7c478bd9Sstevel@tonic-gate 						/*	GOT table */
67*7c478bd9Sstevel@tonic-gate 	unsigned long		m_gotcnt;	/* number of GOT entries */
68*7c478bd9Sstevel@tonic-gate 	size_t 			m_sdatasize;	/* size of small data + */
69*7c478bd9Sstevel@tonic-gate 						/*	got table */
70*7c478bd9Sstevel@tonic-gate 	uint_t			m_fdhsize;	/* # of hash buckets for */
71*7c478bd9Sstevel@tonic-gate 						/*	FD list */
72*7c478bd9Sstevel@tonic-gate 	kobj_funcdesc		**m_fdbuckets;	/* head of FD bucket's */
73*7c478bd9Sstevel@tonic-gate 	kobj_funcdesc		*m_fdchains;	/* head of FD hash list */
74*7c478bd9Sstevel@tonic-gate 	kobj_funcdesc		*m_fdfree;	/* next free FD bucket */
75*7c478bd9Sstevel@tonic-gate 	char			*m_fstrtab;	/* strtab for func descs */
76*7c478bd9Sstevel@tonic-gate } module_mach;
77*7c478bd9Sstevel@tonic-gate #else
78*7c478bd9Sstevel@tonic-gate typedef	void	module_mach;
79*7c478bd9Sstevel@tonic-gate #endif
80*7c478bd9Sstevel@tonic-gate 
81*7c478bd9Sstevel@tonic-gate struct module {
82*7c478bd9Sstevel@tonic-gate 	int total_allocated;
83*7c478bd9Sstevel@tonic-gate 
84*7c478bd9Sstevel@tonic-gate 	Ehdr hdr;
85*7c478bd9Sstevel@tonic-gate 	char *shdrs;
86*7c478bd9Sstevel@tonic-gate 	Shdr *symhdr, *strhdr;
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate 	char *depends_on;
89*7c478bd9Sstevel@tonic-gate 
90*7c478bd9Sstevel@tonic-gate 	size_t symsize;
91*7c478bd9Sstevel@tonic-gate 	char *symspace;	/* symbols + strings + hashtbl, or NULL */
92*7c478bd9Sstevel@tonic-gate 	int flags;
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate 	size_t text_size;
95*7c478bd9Sstevel@tonic-gate 	size_t data_size;
96*7c478bd9Sstevel@tonic-gate 	char *text;
97*7c478bd9Sstevel@tonic-gate 	char *data;
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate 	unsigned int symtbl_section;
100*7c478bd9Sstevel@tonic-gate 	/* pointers into symspace, or NULL */
101*7c478bd9Sstevel@tonic-gate 	char *symtbl;
102*7c478bd9Sstevel@tonic-gate 	char *strings;
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate 	unsigned int hashsize;
105*7c478bd9Sstevel@tonic-gate 	symid_t *buckets;
106*7c478bd9Sstevel@tonic-gate 	symid_t *chains;
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate 	unsigned int nsyms;
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate 	unsigned int bss_align;
111*7c478bd9Sstevel@tonic-gate 	size_t bss_size;
112*7c478bd9Sstevel@tonic-gate 	uintptr_t bss;
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate 	char *filename;
115*7c478bd9Sstevel@tonic-gate 
116*7c478bd9Sstevel@tonic-gate 	struct module_list *head, *tail;
117*7c478bd9Sstevel@tonic-gate 	reloc_dest_t destination;
118*7c478bd9Sstevel@tonic-gate 	module_mach * machdata;
119*7c478bd9Sstevel@tonic-gate 	char *ctfdata;
120*7c478bd9Sstevel@tonic-gate 	size_t ctfsize;
121*7c478bd9Sstevel@tonic-gate 
122*7c478bd9Sstevel@tonic-gate 	char *fbt_tab;
123*7c478bd9Sstevel@tonic-gate 	size_t fbt_size;
124*7c478bd9Sstevel@tonic-gate 	size_t fbt_nentries;
125*7c478bd9Sstevel@tonic-gate 	caddr_t textwin;
126*7c478bd9Sstevel@tonic-gate 	caddr_t textwin_base;
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate 	sdt_probedesc_t *sdt_probes;
129*7c478bd9Sstevel@tonic-gate 	size_t sdt_nprobes;
130*7c478bd9Sstevel@tonic-gate 	char *sdt_tab;
131*7c478bd9Sstevel@tonic-gate 	size_t sdt_size;
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate 	char *sigdata;
134*7c478bd9Sstevel@tonic-gate 	size_t sigsize;
135*7c478bd9Sstevel@tonic-gate };
136*7c478bd9Sstevel@tonic-gate 
137*7c478bd9Sstevel@tonic-gate struct kobj_mem {
138*7c478bd9Sstevel@tonic-gate 	struct kobj_mem	*km_next;
139*7c478bd9Sstevel@tonic-gate 	struct kobj_mem *km_prev;
140*7c478bd9Sstevel@tonic-gate 	uintptr_t	km_addr;
141*7c478bd9Sstevel@tonic-gate 	size_t		km_size;
142*7c478bd9Sstevel@tonic-gate 	uintptr_t	km_alloc_addr;
143*7c478bd9Sstevel@tonic-gate 	size_t		km_alloc_size;
144*7c478bd9Sstevel@tonic-gate };
145*7c478bd9Sstevel@tonic-gate 
146*7c478bd9Sstevel@tonic-gate struct _buf {
147*7c478bd9Sstevel@tonic-gate 	intptr_t	 _fd;
148*7c478bd9Sstevel@tonic-gate 	char		*_ptr;
149*7c478bd9Sstevel@tonic-gate 	char		*_base;
150*7c478bd9Sstevel@tonic-gate 	char 		*_name;
151*7c478bd9Sstevel@tonic-gate 	int		 _size;
152*7c478bd9Sstevel@tonic-gate 	int		_cnt;
153*7c478bd9Sstevel@tonic-gate 	int		 _off;
154*7c478bd9Sstevel@tonic-gate 	int		_ln;
155*7c478bd9Sstevel@tonic-gate };
156*7c478bd9Sstevel@tonic-gate 
157*7c478bd9Sstevel@tonic-gate 
158*7c478bd9Sstevel@tonic-gate /*
159*7c478bd9Sstevel@tonic-gate  * Statistical info.
160*7c478bd9Sstevel@tonic-gate  */
161*7c478bd9Sstevel@tonic-gate typedef struct {
162*7c478bd9Sstevel@tonic-gate 	int nalloc;
163*7c478bd9Sstevel@tonic-gate 	int nfree;
164*7c478bd9Sstevel@tonic-gate 	int nalloc_calls;
165*7c478bd9Sstevel@tonic-gate 	int nfree_calls;
166*7c478bd9Sstevel@tonic-gate } kobj_stat_t;
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate #define	kobj_filename(p) ((p)->_name)
169*7c478bd9Sstevel@tonic-gate #define	kobj_linenum(p)  ((p)->_ln)
170*7c478bd9Sstevel@tonic-gate #define	kobj_newline(p)	 ((p)->_ln++)
171*7c478bd9Sstevel@tonic-gate #define	kobj_getc(p)	(--(p)->_cnt >= 0 ? ((int)*(p)->_ptr++):kobj_filbuf(p))
172*7c478bd9Sstevel@tonic-gate #define	kobj_ungetc(p)	 (++(p)->_cnt > (p)->_size ? -1 : ((int)*(--(p)->_ptr)))
173*7c478bd9Sstevel@tonic-gate 
174*7c478bd9Sstevel@tonic-gate #define	B_OFFSET(f_offset) (f_offset & (MAXBSIZE-1))	/* Offset into buffer */
175*7c478bd9Sstevel@tonic-gate #define	F_PAGE(f_offset)   (f_offset & ~(MAXBSIZE-1))	/* Start of page */
176*7c478bd9Sstevel@tonic-gate 
177*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
178*7c478bd9Sstevel@tonic-gate 
179*7c478bd9Sstevel@tonic-gate extern int kobj_load_module(struct modctl *, int);
180*7c478bd9Sstevel@tonic-gate extern void kobj_unload_module(struct modctl *);
181*7c478bd9Sstevel@tonic-gate extern uintptr_t kobj_lookup(void *, char *);
182*7c478bd9Sstevel@tonic-gate extern Sym *kobj_lookup_all(struct module *, char *, int);
183*7c478bd9Sstevel@tonic-gate extern int kobj_addrcheck(void *, caddr_t);
184*7c478bd9Sstevel@tonic-gate extern int kobj_module_to_id(void *);
185*7c478bd9Sstevel@tonic-gate extern void kobj_getmodinfo(void *, struct modinfo *);
186*7c478bd9Sstevel@tonic-gate extern int kobj_get_needed(void *, short *, int);
187*7c478bd9Sstevel@tonic-gate extern uintptr_t kobj_getsymvalue(char *, int);
188*7c478bd9Sstevel@tonic-gate extern char *kobj_getsymname(uintptr_t, ulong_t *);
189*7c478bd9Sstevel@tonic-gate extern char *kobj_searchsym(struct module *, uintptr_t, ulong_t *);
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate extern intptr_t kobj_open(char *);
192*7c478bd9Sstevel@tonic-gate extern struct _buf *kobj_open_path(char *, int, int);
193*7c478bd9Sstevel@tonic-gate extern int kobj_read(intptr_t, char *, unsigned int, unsigned int);
194*7c478bd9Sstevel@tonic-gate extern void kobj_close(intptr_t);
195*7c478bd9Sstevel@tonic-gate extern void *kobj_alloc(size_t, int);
196*7c478bd9Sstevel@tonic-gate extern void *kobj_zalloc(size_t, int);
197*7c478bd9Sstevel@tonic-gate extern void kobj_free(void *, size_t);
198*7c478bd9Sstevel@tonic-gate extern struct _buf *kobj_open_file(char *);
199*7c478bd9Sstevel@tonic-gate extern void kobj_close_file(struct _buf *);
200*7c478bd9Sstevel@tonic-gate extern int kobj_read_file(struct _buf *, char *, unsigned, unsigned);
201*7c478bd9Sstevel@tonic-gate extern uintptr_t kobj_getelfsym(char *, void *, int *);
202*7c478bd9Sstevel@tonic-gate extern void kobj_set_ctf(struct module *, caddr_t data, size_t size);
203*7c478bd9Sstevel@tonic-gate 
204*7c478bd9Sstevel@tonic-gate extern int kobj_filbuf(struct _buf *);
205*7c478bd9Sstevel@tonic-gate extern void kobj_sync(void);
206*7c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__sparc) || defined(__amd64)
207*7c478bd9Sstevel@tonic-gate extern void kobj_vmem_init(vmem_t **, vmem_t **);
208*7c478bd9Sstevel@tonic-gate #elif defined(__ia64)
209*7c478bd9Sstevel@tonic-gate extern void kobj_vmem_init(vmem_t **, vmem_t **, vmem_t **);
210*7c478bd9Sstevel@tonic-gate #else
211*7c478bd9Sstevel@tonic-gate #error "ISA not supported"
212*7c478bd9Sstevel@tonic-gate #endif
213*7c478bd9Sstevel@tonic-gate extern caddr_t kobj_text_alloc(vmem_t *, size_t);
214*7c478bd9Sstevel@tonic-gate extern caddr_t kobj_texthole_alloc(caddr_t, size_t);
215*7c478bd9Sstevel@tonic-gate extern void kobj_texthole_free(caddr_t, size_t);
216*7c478bd9Sstevel@tonic-gate extern void kobj_stat_get(kobj_stat_t *);
217*7c478bd9Sstevel@tonic-gate extern void kobj_textwin_alloc(struct module *);
218*7c478bd9Sstevel@tonic-gate extern void kobj_textwin_free(struct module *);
219*7c478bd9Sstevel@tonic-gate 
220*7c478bd9Sstevel@tonic-gate #endif	/* defined(_KERNEL) */
221*7c478bd9Sstevel@tonic-gate 
222*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
223*7c478bd9Sstevel@tonic-gate }
224*7c478bd9Sstevel@tonic-gate #endif
225*7c478bd9Sstevel@tonic-gate 
226*7c478bd9Sstevel@tonic-gate #endif /* !_SYS_KOBJ_H */
227