10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51544Seschrock * Common Development and Distribution License (the "License"). 61544Seschrock * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 223912Slling * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _SYS_KOBJ_H 270Sstevel@tonic-gate #define _SYS_KOBJ_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 300Sstevel@tonic-gate 310Sstevel@tonic-gate #include <sys/modctl.h> 320Sstevel@tonic-gate #include <sys/elf.h> 330Sstevel@tonic-gate #include <sys/machelf.h> 340Sstevel@tonic-gate #include <sys/vmem.h> 350Sstevel@tonic-gate #include <sys/sdt.h> 361544Seschrock #include <sys/bootstat.h> 370Sstevel@tonic-gate 380Sstevel@tonic-gate #ifdef __cplusplus 390Sstevel@tonic-gate extern "C" { 400Sstevel@tonic-gate #endif 410Sstevel@tonic-gate 420Sstevel@tonic-gate /* 430Sstevel@tonic-gate * List of modules maintained by kobj.c 440Sstevel@tonic-gate */ 450Sstevel@tonic-gate struct module_list { 460Sstevel@tonic-gate struct module_list *next; 470Sstevel@tonic-gate struct module *mp; 480Sstevel@tonic-gate }; 490Sstevel@tonic-gate 500Sstevel@tonic-gate typedef unsigned short symid_t; /* symbol table index */ 510Sstevel@tonic-gate typedef unsigned char *reloc_dest_t; 520Sstevel@tonic-gate 530Sstevel@tonic-gate typedef void module_mach; 540Sstevel@tonic-gate 550Sstevel@tonic-gate struct module { 560Sstevel@tonic-gate int total_allocated; 570Sstevel@tonic-gate 580Sstevel@tonic-gate Ehdr hdr; 590Sstevel@tonic-gate char *shdrs; 600Sstevel@tonic-gate Shdr *symhdr, *strhdr; 610Sstevel@tonic-gate 620Sstevel@tonic-gate char *depends_on; 630Sstevel@tonic-gate 640Sstevel@tonic-gate size_t symsize; 650Sstevel@tonic-gate char *symspace; /* symbols + strings + hashtbl, or NULL */ 660Sstevel@tonic-gate int flags; 670Sstevel@tonic-gate 680Sstevel@tonic-gate size_t text_size; 690Sstevel@tonic-gate size_t data_size; 700Sstevel@tonic-gate char *text; 710Sstevel@tonic-gate char *data; 720Sstevel@tonic-gate 730Sstevel@tonic-gate unsigned int symtbl_section; 740Sstevel@tonic-gate /* pointers into symspace, or NULL */ 750Sstevel@tonic-gate char *symtbl; 760Sstevel@tonic-gate char *strings; 770Sstevel@tonic-gate 780Sstevel@tonic-gate unsigned int hashsize; 790Sstevel@tonic-gate symid_t *buckets; 800Sstevel@tonic-gate symid_t *chains; 810Sstevel@tonic-gate 820Sstevel@tonic-gate unsigned int nsyms; 830Sstevel@tonic-gate 840Sstevel@tonic-gate unsigned int bss_align; 850Sstevel@tonic-gate size_t bss_size; 860Sstevel@tonic-gate uintptr_t bss; 870Sstevel@tonic-gate 880Sstevel@tonic-gate char *filename; 890Sstevel@tonic-gate 900Sstevel@tonic-gate struct module_list *head, *tail; 910Sstevel@tonic-gate reloc_dest_t destination; 920Sstevel@tonic-gate module_mach * machdata; 930Sstevel@tonic-gate char *ctfdata; 940Sstevel@tonic-gate size_t ctfsize; 950Sstevel@tonic-gate 960Sstevel@tonic-gate char *fbt_tab; 970Sstevel@tonic-gate size_t fbt_size; 980Sstevel@tonic-gate size_t fbt_nentries; 990Sstevel@tonic-gate caddr_t textwin; 1000Sstevel@tonic-gate caddr_t textwin_base; 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate sdt_probedesc_t *sdt_probes; 1030Sstevel@tonic-gate size_t sdt_nprobes; 1040Sstevel@tonic-gate char *sdt_tab; 1050Sstevel@tonic-gate size_t sdt_size; 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate char *sigdata; 1080Sstevel@tonic-gate size_t sigsize; 1090Sstevel@tonic-gate }; 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate struct kobj_mem { 1120Sstevel@tonic-gate struct kobj_mem *km_next; 1130Sstevel@tonic-gate struct kobj_mem *km_prev; 1140Sstevel@tonic-gate uintptr_t km_addr; 1150Sstevel@tonic-gate size_t km_size; 1160Sstevel@tonic-gate uintptr_t km_alloc_addr; 1170Sstevel@tonic-gate size_t km_alloc_size; 1180Sstevel@tonic-gate }; 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate struct _buf { 1210Sstevel@tonic-gate intptr_t _fd; 1220Sstevel@tonic-gate char *_ptr; 1230Sstevel@tonic-gate char *_base; 1240Sstevel@tonic-gate char *_name; 125*5648Ssetje char *_dbuf; 1260Sstevel@tonic-gate int _size; 1270Sstevel@tonic-gate int _cnt; 1280Sstevel@tonic-gate int _off; 1290Sstevel@tonic-gate int _ln; 130*5648Ssetje int _bsize; 131*5648Ssetje int _iscmp; 132*5648Ssetje int _dsize; 1330Sstevel@tonic-gate }; 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate /* 1370Sstevel@tonic-gate * Statistical info. 1380Sstevel@tonic-gate */ 1390Sstevel@tonic-gate typedef struct { 1400Sstevel@tonic-gate int nalloc; 1410Sstevel@tonic-gate int nfree; 1420Sstevel@tonic-gate int nalloc_calls; 1430Sstevel@tonic-gate int nfree_calls; 1440Sstevel@tonic-gate } kobj_stat_t; 1450Sstevel@tonic-gate 1460Sstevel@tonic-gate #define kobj_filename(p) ((p)->_name) 1470Sstevel@tonic-gate #define kobj_linenum(p) ((p)->_ln) 1480Sstevel@tonic-gate #define kobj_newline(p) ((p)->_ln++) 1490Sstevel@tonic-gate #define kobj_getc(p) (--(p)->_cnt >= 0 ? ((int)*(p)->_ptr++):kobj_filbuf(p)) 1500Sstevel@tonic-gate #define kobj_ungetc(p) (++(p)->_cnt > (p)->_size ? -1 : ((int)*(--(p)->_ptr))) 151*5648Ssetje #define kobj_comphdr(p) ((struct comphdr *)(p)->_dbuf) 1520Sstevel@tonic-gate 153*5648Ssetje /* Offset into buffer */ 154*5648Ssetje #define B_OFFSET(file, off) (off % (file)->_bsize) 155*5648Ssetje 156*5648Ssetje /* Start of page */ 157*5648Ssetje #define F_PAGE(file, off) (off - B_OFFSET(file, off)) 158*5648Ssetje 159*5648Ssetje #define F_BLKS(file, size) ((size / (file)->_bsize) * (file)->_bsize) 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate #if defined(_KERNEL) 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate extern int kobj_load_module(struct modctl *, int); 1640Sstevel@tonic-gate extern void kobj_unload_module(struct modctl *); 1651414Scindi extern uintptr_t kobj_lookup(struct module *, const char *); 1660Sstevel@tonic-gate extern Sym *kobj_lookup_all(struct module *, char *, int); 1670Sstevel@tonic-gate extern int kobj_addrcheck(void *, caddr_t); 1680Sstevel@tonic-gate extern int kobj_module_to_id(void *); 1690Sstevel@tonic-gate extern void kobj_getmodinfo(void *, struct modinfo *); 1700Sstevel@tonic-gate extern int kobj_get_needed(void *, short *, int); 1710Sstevel@tonic-gate extern uintptr_t kobj_getsymvalue(char *, int); 1720Sstevel@tonic-gate extern char *kobj_getsymname(uintptr_t, ulong_t *); 1730Sstevel@tonic-gate extern char *kobj_searchsym(struct module *, uintptr_t, ulong_t *); 1740Sstevel@tonic-gate 1751544Seschrock extern int kobj_fstat(intptr_t, struct bootstat *); 1760Sstevel@tonic-gate extern intptr_t kobj_open(char *); 177309Scth extern int kobj_path_exists(char *, int); 1780Sstevel@tonic-gate extern struct _buf *kobj_open_path(char *, int, int); 1790Sstevel@tonic-gate extern int kobj_read(intptr_t, char *, unsigned int, unsigned int); 1800Sstevel@tonic-gate extern void kobj_close(intptr_t); 1810Sstevel@tonic-gate extern void *kobj_alloc(size_t, int); 1820Sstevel@tonic-gate extern void *kobj_zalloc(size_t, int); 1830Sstevel@tonic-gate extern void kobj_free(void *, size_t); 1840Sstevel@tonic-gate extern struct _buf *kobj_open_file(char *); 1850Sstevel@tonic-gate extern void kobj_close_file(struct _buf *); 1860Sstevel@tonic-gate extern int kobj_read_file(struct _buf *, char *, unsigned, unsigned); 1873912Slling extern int kobj_get_filesize(struct _buf *, uint64_t *size); 1880Sstevel@tonic-gate extern uintptr_t kobj_getelfsym(char *, void *, int *); 1890Sstevel@tonic-gate extern void kobj_set_ctf(struct module *, caddr_t data, size_t size); 1900Sstevel@tonic-gate 1910Sstevel@tonic-gate extern int kobj_filbuf(struct _buf *); 1920Sstevel@tonic-gate extern void kobj_sync(void); 1930Sstevel@tonic-gate #if defined(__i386) || defined(__sparc) || defined(__amd64) 1940Sstevel@tonic-gate extern void kobj_vmem_init(vmem_t **, vmem_t **); 1950Sstevel@tonic-gate #else 1960Sstevel@tonic-gate #error "ISA not supported" 1970Sstevel@tonic-gate #endif 1980Sstevel@tonic-gate extern caddr_t kobj_text_alloc(vmem_t *, size_t); 1990Sstevel@tonic-gate extern caddr_t kobj_texthole_alloc(caddr_t, size_t); 2000Sstevel@tonic-gate extern void kobj_texthole_free(caddr_t, size_t); 2010Sstevel@tonic-gate extern void kobj_stat_get(kobj_stat_t *); 2020Sstevel@tonic-gate extern void kobj_textwin_alloc(struct module *); 2030Sstevel@tonic-gate extern void kobj_textwin_free(struct module *); 2040Sstevel@tonic-gate 2050Sstevel@tonic-gate #endif /* defined(_KERNEL) */ 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate #ifdef __cplusplus 2080Sstevel@tonic-gate } 2090Sstevel@tonic-gate #endif 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate #endif /* !_SYS_KOBJ_H */ 212