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 5*5648Ssetje * Common Development and Distribution License (the "License"). 6*5648Ssetje * 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 /* 22*5648Ssetje * 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 /* 270Sstevel@tonic-gate * Kernel Run-Time Linker/Loader private interfaces. 280Sstevel@tonic-gate */ 290Sstevel@tonic-gate 300Sstevel@tonic-gate #ifndef _SYS_KOBJ_IMPL_H 310Sstevel@tonic-gate #define _SYS_KOBJ_IMPL_H 320Sstevel@tonic-gate 330Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 340Sstevel@tonic-gate 350Sstevel@tonic-gate #include <sys/kdi.h> 360Sstevel@tonic-gate #include <sys/kobj.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 * Boot/aux vector attributes. 440Sstevel@tonic-gate */ 450Sstevel@tonic-gate 460Sstevel@tonic-gate #define BA_DYNAMIC 0 470Sstevel@tonic-gate #define BA_PHDR 1 480Sstevel@tonic-gate #define BA_PHNUM 2 490Sstevel@tonic-gate #define BA_PHENT 3 500Sstevel@tonic-gate #define BA_ENTRY 4 510Sstevel@tonic-gate #define BA_PAGESZ 5 520Sstevel@tonic-gate #define BA_LPAGESZ 6 530Sstevel@tonic-gate #define BA_LDELF 7 540Sstevel@tonic-gate #define BA_LDSHDR 8 550Sstevel@tonic-gate #define BA_LDNAME 9 560Sstevel@tonic-gate #define BA_BSS 10 570Sstevel@tonic-gate #define BA_IFLUSH 11 580Sstevel@tonic-gate #define BA_CPU 12 590Sstevel@tonic-gate #define BA_MMU 13 600Sstevel@tonic-gate #define BA_GOTADDR 14 610Sstevel@tonic-gate #define BA_NEXTGOT 15 620Sstevel@tonic-gate #define BA_NUM 16 630Sstevel@tonic-gate 640Sstevel@tonic-gate typedef union { 650Sstevel@tonic-gate unsigned long ba_val; 660Sstevel@tonic-gate void *ba_ptr; 670Sstevel@tonic-gate } val_t; 680Sstevel@tonic-gate 690Sstevel@tonic-gate /* 700Sstevel@tonic-gate * Segment info. 710Sstevel@tonic-gate */ 720Sstevel@tonic-gate struct proginfo { 730Sstevel@tonic-gate uint_t size; 740Sstevel@tonic-gate uint_t align; 750Sstevel@tonic-gate }; 760Sstevel@tonic-gate 770Sstevel@tonic-gate /* 780Sstevel@tonic-gate * Implementation-specific flags. 790Sstevel@tonic-gate */ 800Sstevel@tonic-gate #define KOBJ_EXEC 0x0004 /* executable (unix module) */ 810Sstevel@tonic-gate #define KOBJ_INTERP 0x0008 /* the interpreter module */ 820Sstevel@tonic-gate #define KOBJ_PRIM 0x0010 /* a primary kernel module */ 830Sstevel@tonic-gate #define KOBJ_RESOLVED 0x0020 /* fully resolved */ 840Sstevel@tonic-gate #define KOBJ_TNF_PROBE 0x0040 /* Contains TNF probe(s) */ 850Sstevel@tonic-gate #define KOBJ_RELOCATED 0x0080 /* relocation completed */ 860Sstevel@tonic-gate #define KOBJ_NOPARENTS 0x0200 /* nothing can depend on this module */ 870Sstevel@tonic-gate #define KOBJ_IGNMULDEF 0x0400 /* ignore dups during sym resolution */ 880Sstevel@tonic-gate #define KOBJ_NOKSYMS 0x0800 /* module's symbols don't go into ksyms */ 890Sstevel@tonic-gate #define KOBJ_EXPORTED 0x1000 /* ctf, syms copied to vmem */ 900Sstevel@tonic-gate 910Sstevel@tonic-gate /* 920Sstevel@tonic-gate * kobj_notify_add() data notification structure 930Sstevel@tonic-gate */ 940Sstevel@tonic-gate typedef void kobj_notify_f(uint_t, struct modctl *); 950Sstevel@tonic-gate 960Sstevel@tonic-gate typedef struct kobj_notify_list { 970Sstevel@tonic-gate kobj_notify_f *kn_func; /* notification func */ 980Sstevel@tonic-gate uint_t kn_type; /* notification type */ 990Sstevel@tonic-gate struct kobj_notify_list *kn_prev; 1000Sstevel@tonic-gate struct kobj_notify_list *kn_next; 1010Sstevel@tonic-gate } kobj_notify_list_t; 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate /* 1040Sstevel@tonic-gate * krtld can provide notification to external clients on the 1050Sstevel@tonic-gate * following events. 1060Sstevel@tonic-gate */ 1070Sstevel@tonic-gate #define KOBJ_NOTIFY_MODLOADING 1 /* very early in module load */ 1080Sstevel@tonic-gate #define KOBJ_NOTIFY_MODUNLOADING 2 /* before module unload */ 1090Sstevel@tonic-gate #define KOBJ_NOTIFY_MODLOADED 3 /* after module load */ 1100Sstevel@tonic-gate #define KOBJ_NOTIFY_MODUNLOADED 4 /* after module unload */ 1110Sstevel@tonic-gate #define KOBJ_NOTIFY_MAX 4 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate #define ALIGN(x, a) ((a) == 0 ? (uintptr_t)(x) : \ 1140Sstevel@tonic-gate (((uintptr_t)(x) + (uintptr_t)(a) - 1l) & ~((uintptr_t)(a) - 1l))) 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate #ifdef DEBUG 1170Sstevel@tonic-gate #define KOBJ_DEBUG 1180Sstevel@tonic-gate #endif 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate #ifdef KOBJ_DEBUG 1210Sstevel@tonic-gate /* 1220Sstevel@tonic-gate * Debugging flags. 1230Sstevel@tonic-gate */ 1240Sstevel@tonic-gate #define D_DEBUG 0x001 /* general debugging */ 1250Sstevel@tonic-gate #define D_SYMBOLS 0x002 /* debug symbols */ 1260Sstevel@tonic-gate #define D_RELOCATIONS 0x004 /* debug relocations */ 1270Sstevel@tonic-gate #define D_LOADING 0x008 /* section loading */ 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate extern int kobj_debug; /* different than moddebug */ 1300Sstevel@tonic-gate #endif 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate /* 1330Sstevel@tonic-gate * Flags for kobj memory allocation. 1340Sstevel@tonic-gate */ 1350Sstevel@tonic-gate #define KM_WAIT 0x0 /* wait for it */ 1360Sstevel@tonic-gate #define KM_NOWAIT 0x1 /* return immediately */ 1370Sstevel@tonic-gate 138*5648Ssetje #define KM_TMP 0x1000 /* freed before kobj_init returns */ 139*5648Ssetje #define KM_SCRATCH 0x2000 /* not freed until kobj_sync */ 140*5648Ssetje 141*5648Ssetje #ifdef KOBJ_OVERRIDES 142*5648Ssetje /* 143*5648Ssetje * Until the kernel is fully linked, all code running in the 144*5648Ssetje * context of krtld/kobj using bcopy or bzero must be directed 145*5648Ssetje * to the kobj equivalents. All (ok, most) references to bcopy 146*5648Ssetje * or bzero are thus so vectored. 147*5648Ssetje */ 148*5648Ssetje #define bcopy(s, d, n) kobj_bcopy((s), (d), (n)) 149*5648Ssetje #define bzero(p, n) kobj_bzero((p), (n)) 150*5648Ssetje #define strlcat(s, d, n) kobj_strlcat((s), (d), (n)) 151*5648Ssetje #endif 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate extern kdi_t kobj_kdi; 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate struct bootops; 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate extern struct modctl_list *kobj_linkmaps[]; 1580Sstevel@tonic-gate 1590Sstevel@tonic-gate extern char *kobj_kmdb_argv[]; 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate extern int kobj_mmu_pagesize; 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate extern void kobj_init(void *romvec, void *dvec, 1640Sstevel@tonic-gate struct bootops *bootvec, val_t *bootaux); 1650Sstevel@tonic-gate extern int kobj_notify_add(kobj_notify_list_t *); 1660Sstevel@tonic-gate extern int kobj_notify_remove(kobj_notify_list_t *); 1670Sstevel@tonic-gate extern int do_relocations(struct module *); 1680Sstevel@tonic-gate extern int do_relocate(struct module *, char *, Word, int, int, Addr); 1690Sstevel@tonic-gate extern struct bootops *ops; 1700Sstevel@tonic-gate extern void exitto(caddr_t); 1710Sstevel@tonic-gate extern void kobj_sync_instruction_memory(caddr_t, size_t); 1720Sstevel@tonic-gate extern uint_t kobj_gethashsize(uint_t); 1730Sstevel@tonic-gate extern void * kobj_mod_alloc(struct module *, size_t, int, reloc_dest_t *); 1740Sstevel@tonic-gate extern void mach_alloc_funcdesc(struct module *); 1750Sstevel@tonic-gate extern uint_t kobj_hash_name(const char *); 1760Sstevel@tonic-gate extern caddr_t kobj_segbrk(caddr_t *, size_t, size_t, caddr_t); 1770Sstevel@tonic-gate extern int get_progbits_size(struct module *, struct proginfo *, 1780Sstevel@tonic-gate struct proginfo *, struct proginfo *); 1790Sstevel@tonic-gate extern Sym *kobj_lookup_kernel(const char *); 1800Sstevel@tonic-gate extern struct modctl *kobj_boot_mod_lookup(const char *); 1810Sstevel@tonic-gate extern void kobj_export_module(struct module *); 1820Sstevel@tonic-gate extern int kobj_load_primary_module(struct modctl *); 183*5648Ssetje extern int boot_compinfo(int, struct compinfo *); 184*5648Ssetje extern void mach_modpath(char *, const char *); 1850Sstevel@tonic-gate 186*5648Ssetje extern void kobj_setup_standalone_vectors(void); 187*5648Ssetje extern void kobj_restore_vectors(void); 188*5648Ssetje extern void (*_kobj_printf)(void *, const char *fmt, ...); 189*5648Ssetje extern void (*kobj_bcopy)(const void *, void *, size_t); 190*5648Ssetje extern void (*kobj_bzero)(void *, size_t); 191*5648Ssetje extern size_t (*kobj_strlcat)(char *, const char *, size_t); 1920Sstevel@tonic-gate 1930Sstevel@tonic-gate #define KOBJ_LM_PRIMARY 0x0 1940Sstevel@tonic-gate #define KOBJ_LM_DEBUGGER 0x1 1950Sstevel@tonic-gate 1960Sstevel@tonic-gate extern void kobj_lm_append(int, struct modctl *modp); 1970Sstevel@tonic-gate extern struct modctl_list *kobj_lm_lookup(int); 1980Sstevel@tonic-gate extern void kobj_lm_dump(int); 1990Sstevel@tonic-gate 2000Sstevel@tonic-gate #ifdef __cplusplus 2010Sstevel@tonic-gate } 2020Sstevel@tonic-gate #endif 2030Sstevel@tonic-gate 2040Sstevel@tonic-gate #endif /* _SYS_KOBJ_IMPL_H */ 205