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