xref: /titanic_51/usr/src/uts/common/sys/kobj.h (revision 355b4669e025ff377602b6fc7caaf30dbc218371)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_KOBJ_H
27 #define	_SYS_KOBJ_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/modctl.h>
32 #include <sys/elf.h>
33 #include <sys/machelf.h>
34 #include <sys/vmem.h>
35 #include <sys/sdt.h>
36 #include <sys/bootstat.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 typedef	void	module_mach;
54 
55 struct module {
56 	int total_allocated;
57 
58 	Ehdr hdr;
59 	char *shdrs;
60 	Shdr *symhdr, *strhdr;
61 
62 	char *depends_on;
63 
64 	size_t symsize;
65 	char *symspace;	/* symbols + strings + hashtbl, or NULL */
66 	int flags;
67 
68 	size_t text_size;
69 	size_t data_size;
70 	char *text;
71 	char *data;
72 
73 	unsigned int symtbl_section;
74 	/* pointers into symspace, or NULL */
75 	char *symtbl;
76 	char *strings;
77 
78 	unsigned int hashsize;
79 	symid_t *buckets;
80 	symid_t *chains;
81 
82 	unsigned int nsyms;
83 
84 	unsigned int bss_align;
85 	size_t bss_size;
86 	uintptr_t bss;
87 
88 	char *filename;
89 
90 	struct module_list *head, *tail;
91 	reloc_dest_t destination;
92 	module_mach * machdata;
93 	char *ctfdata;
94 	size_t ctfsize;
95 
96 	char *fbt_tab;
97 	size_t fbt_size;
98 	size_t fbt_nentries;
99 	caddr_t textwin;
100 	caddr_t textwin_base;
101 
102 	sdt_probedesc_t *sdt_probes;
103 	size_t sdt_nprobes;
104 	char *sdt_tab;
105 	size_t sdt_size;
106 
107 	char *sigdata;
108 	size_t sigsize;
109 };
110 
111 struct kobj_mem {
112 	struct kobj_mem	*km_next;
113 	struct kobj_mem *km_prev;
114 	uintptr_t	km_addr;
115 	size_t		km_size;
116 	uintptr_t	km_alloc_addr;
117 	size_t		km_alloc_size;
118 };
119 
120 struct _buf {
121 	intptr_t	 _fd;
122 	char		*_ptr;
123 	char		*_base;
124 	char 		*_name;
125 	int		 _size;
126 	int		_cnt;
127 	int		 _off;
128 	int		_ln;
129 };
130 
131 
132 /*
133  * Statistical info.
134  */
135 typedef struct {
136 	int nalloc;
137 	int nfree;
138 	int nalloc_calls;
139 	int nfree_calls;
140 } kobj_stat_t;
141 
142 #define	kobj_filename(p) ((p)->_name)
143 #define	kobj_linenum(p)  ((p)->_ln)
144 #define	kobj_newline(p)	 ((p)->_ln++)
145 #define	kobj_getc(p)	(--(p)->_cnt >= 0 ? ((int)*(p)->_ptr++):kobj_filbuf(p))
146 #define	kobj_ungetc(p)	 (++(p)->_cnt > (p)->_size ? -1 : ((int)*(--(p)->_ptr)))
147 
148 #define	B_OFFSET(f_offset) (f_offset & (MAXBSIZE-1))	/* Offset into buffer */
149 #define	F_PAGE(f_offset)   (f_offset & ~(MAXBSIZE-1))	/* Start of page */
150 
151 #if defined(_KERNEL)
152 
153 extern int kobj_load_module(struct modctl *, int);
154 extern void kobj_unload_module(struct modctl *);
155 extern uintptr_t kobj_lookup(struct module *, const char *);
156 extern Sym *kobj_lookup_all(struct module *, char *, int);
157 extern int kobj_addrcheck(void *, caddr_t);
158 extern int kobj_module_to_id(void *);
159 extern void kobj_getmodinfo(void *, struct modinfo *);
160 extern int kobj_get_needed(void *, short *, int);
161 extern uintptr_t kobj_getsymvalue(char *, int);
162 extern char *kobj_getsymname(uintptr_t, ulong_t *);
163 extern char *kobj_searchsym(struct module *, uintptr_t, ulong_t *);
164 
165 extern int kobj_fstat(intptr_t, struct bootstat *);
166 extern intptr_t kobj_open(char *);
167 extern int kobj_path_exists(char *, int);
168 extern struct _buf *kobj_open_path(char *, int, int);
169 extern int kobj_read(intptr_t, char *, unsigned int, unsigned int);
170 extern void kobj_close(intptr_t);
171 extern void *kobj_alloc(size_t, int);
172 extern void *kobj_zalloc(size_t, int);
173 extern void kobj_free(void *, size_t);
174 extern struct _buf *kobj_open_file(char *);
175 extern void kobj_close_file(struct _buf *);
176 extern int kobj_read_file(struct _buf *, char *, unsigned, unsigned);
177 extern uintptr_t kobj_getelfsym(char *, void *, int *);
178 extern void kobj_set_ctf(struct module *, caddr_t data, size_t size);
179 
180 extern int kobj_filbuf(struct _buf *);
181 extern void kobj_sync(void);
182 #if defined(__i386) || defined(__sparc) || defined(__amd64)
183 extern void kobj_vmem_init(vmem_t **, vmem_t **);
184 #else
185 #error "ISA not supported"
186 #endif
187 extern caddr_t kobj_text_alloc(vmem_t *, size_t);
188 extern caddr_t kobj_texthole_alloc(caddr_t, size_t);
189 extern void kobj_texthole_free(caddr_t, size_t);
190 extern void kobj_stat_get(kobj_stat_t *);
191 extern void kobj_textwin_alloc(struct module *);
192 extern void kobj_textwin_free(struct module *);
193 
194 #endif	/* defined(_KERNEL) */
195 
196 #ifdef	__cplusplus
197 }
198 #endif
199 
200 #endif /* !_SYS_KOBJ_H */
201