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