17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*986fd29aSsetje * Common Development and Distribution License (the "License"). 6*986fd29aSsetje * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*986fd29aSsetje * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* 277c478bd9Sstevel@tonic-gate * Kernel Run-Time Linker/Loader private interfaces. 287c478bd9Sstevel@tonic-gate */ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #ifndef _SYS_KOBJ_IMPL_H 317c478bd9Sstevel@tonic-gate #define _SYS_KOBJ_IMPL_H 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #include <sys/kdi.h> 367c478bd9Sstevel@tonic-gate #include <sys/kobj.h> 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate #ifdef __cplusplus 397c478bd9Sstevel@tonic-gate extern "C" { 407c478bd9Sstevel@tonic-gate #endif 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate /* 437c478bd9Sstevel@tonic-gate * Boot/aux vector attributes. 447c478bd9Sstevel@tonic-gate */ 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate #define BA_DYNAMIC 0 477c478bd9Sstevel@tonic-gate #define BA_PHDR 1 487c478bd9Sstevel@tonic-gate #define BA_PHNUM 2 497c478bd9Sstevel@tonic-gate #define BA_PHENT 3 507c478bd9Sstevel@tonic-gate #define BA_ENTRY 4 517c478bd9Sstevel@tonic-gate #define BA_PAGESZ 5 527c478bd9Sstevel@tonic-gate #define BA_LPAGESZ 6 537c478bd9Sstevel@tonic-gate #define BA_LDELF 7 547c478bd9Sstevel@tonic-gate #define BA_LDSHDR 8 557c478bd9Sstevel@tonic-gate #define BA_LDNAME 9 567c478bd9Sstevel@tonic-gate #define BA_BSS 10 577c478bd9Sstevel@tonic-gate #define BA_IFLUSH 11 587c478bd9Sstevel@tonic-gate #define BA_CPU 12 597c478bd9Sstevel@tonic-gate #define BA_MMU 13 607c478bd9Sstevel@tonic-gate #define BA_GOTADDR 14 617c478bd9Sstevel@tonic-gate #define BA_NEXTGOT 15 627c478bd9Sstevel@tonic-gate #define BA_NUM 16 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate typedef union { 657c478bd9Sstevel@tonic-gate unsigned long ba_val; 667c478bd9Sstevel@tonic-gate void *ba_ptr; 677c478bd9Sstevel@tonic-gate } val_t; 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate /* 707c478bd9Sstevel@tonic-gate * Segment info. 717c478bd9Sstevel@tonic-gate */ 727c478bd9Sstevel@tonic-gate struct proginfo { 737c478bd9Sstevel@tonic-gate uint_t size; 747c478bd9Sstevel@tonic-gate uint_t align; 757c478bd9Sstevel@tonic-gate }; 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate /* 787c478bd9Sstevel@tonic-gate * Implementation-specific flags. 797c478bd9Sstevel@tonic-gate */ 807c478bd9Sstevel@tonic-gate #define KOBJ_EXEC 0x0004 /* executable (unix module) */ 817c478bd9Sstevel@tonic-gate #define KOBJ_INTERP 0x0008 /* the interpreter module */ 827c478bd9Sstevel@tonic-gate #define KOBJ_PRIM 0x0010 /* a primary kernel module */ 837c478bd9Sstevel@tonic-gate #define KOBJ_RESOLVED 0x0020 /* fully resolved */ 847c478bd9Sstevel@tonic-gate #define KOBJ_TNF_PROBE 0x0040 /* Contains TNF probe(s) */ 857c478bd9Sstevel@tonic-gate #define KOBJ_RELOCATED 0x0080 /* relocation completed */ 867c478bd9Sstevel@tonic-gate #define KOBJ_NOPARENTS 0x0200 /* nothing can depend on this module */ 877c478bd9Sstevel@tonic-gate #define KOBJ_IGNMULDEF 0x0400 /* ignore dups during sym resolution */ 887c478bd9Sstevel@tonic-gate #define KOBJ_NOKSYMS 0x0800 /* module's symbols don't go into ksyms */ 897c478bd9Sstevel@tonic-gate #define KOBJ_EXPORTED 0x1000 /* ctf, syms copied to vmem */ 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate /* 927c478bd9Sstevel@tonic-gate * kobj_notify_add() data notification structure 937c478bd9Sstevel@tonic-gate */ 947c478bd9Sstevel@tonic-gate typedef void kobj_notify_f(uint_t, struct modctl *); 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate typedef struct kobj_notify_list { 977c478bd9Sstevel@tonic-gate kobj_notify_f *kn_func; /* notification func */ 987c478bd9Sstevel@tonic-gate uint_t kn_type; /* notification type */ 997c478bd9Sstevel@tonic-gate struct kobj_notify_list *kn_prev; 1007c478bd9Sstevel@tonic-gate struct kobj_notify_list *kn_next; 1017c478bd9Sstevel@tonic-gate } kobj_notify_list_t; 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate /* 1047c478bd9Sstevel@tonic-gate * krtld can provide notification to external clients on the 1057c478bd9Sstevel@tonic-gate * following events. 1067c478bd9Sstevel@tonic-gate */ 1077c478bd9Sstevel@tonic-gate #define KOBJ_NOTIFY_MODLOADING 1 /* very early in module load */ 1087c478bd9Sstevel@tonic-gate #define KOBJ_NOTIFY_MODUNLOADING 2 /* before module unload */ 1097c478bd9Sstevel@tonic-gate #define KOBJ_NOTIFY_MODLOADED 3 /* after module load */ 1107c478bd9Sstevel@tonic-gate #define KOBJ_NOTIFY_MODUNLOADED 4 /* after module unload */ 1117c478bd9Sstevel@tonic-gate #define KOBJ_NOTIFY_MAX 4 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate #define ALIGN(x, a) ((a) == 0 ? (uintptr_t)(x) : \ 1147c478bd9Sstevel@tonic-gate (((uintptr_t)(x) + (uintptr_t)(a) - 1l) & ~((uintptr_t)(a) - 1l))) 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate #ifdef DEBUG 1177c478bd9Sstevel@tonic-gate #define KOBJ_DEBUG 1187c478bd9Sstevel@tonic-gate #endif 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate #ifdef KOBJ_DEBUG 1217c478bd9Sstevel@tonic-gate /* 1227c478bd9Sstevel@tonic-gate * Debugging flags. 1237c478bd9Sstevel@tonic-gate */ 1247c478bd9Sstevel@tonic-gate #define D_DEBUG 0x001 /* general debugging */ 1257c478bd9Sstevel@tonic-gate #define D_SYMBOLS 0x002 /* debug symbols */ 1267c478bd9Sstevel@tonic-gate #define D_RELOCATIONS 0x004 /* debug relocations */ 1277c478bd9Sstevel@tonic-gate #define D_LOADING 0x008 /* section loading */ 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate extern int kobj_debug; /* different than moddebug */ 1307c478bd9Sstevel@tonic-gate #endif 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate /* 1337c478bd9Sstevel@tonic-gate * Flags for kobj memory allocation. 1347c478bd9Sstevel@tonic-gate */ 1357c478bd9Sstevel@tonic-gate #define KM_WAIT 0x0 /* wait for it */ 1367c478bd9Sstevel@tonic-gate #define KM_NOWAIT 0x1 /* return immediately */ 1377c478bd9Sstevel@tonic-gate 138*986fd29aSsetje #define KM_TMP 0x1000 /* freed before kobj_init returns */ 139*986fd29aSsetje #define KM_SCRATCH 0x2000 /* not freed until kobj_sync */ 140*986fd29aSsetje 141*986fd29aSsetje #ifdef KOBJ_OVERRIDES 142*986fd29aSsetje /* 143*986fd29aSsetje * Until the kernel is fully linked, all code running in the 144*986fd29aSsetje * context of krtld/kobj using bcopy or bzero must be directed 145*986fd29aSsetje * to the kobj equivalents. All (ok, most) references to bcopy 146*986fd29aSsetje * or bzero are thus so vectored. 147*986fd29aSsetje */ 148*986fd29aSsetje #define bcopy(s, d, n) kobj_bcopy((s), (d), (n)) 149*986fd29aSsetje #define bzero(p, n) kobj_bzero((p), (n)) 150*986fd29aSsetje #define strlcat(s, d, n) kobj_strlcat((s), (d), (n)) 151*986fd29aSsetje #endif 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate extern kdi_t kobj_kdi; 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate struct bootops; 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate extern struct modctl_list *kobj_linkmaps[]; 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate extern char *kobj_kmdb_argv[]; 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate extern int kobj_mmu_pagesize; 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate extern void kobj_init(void *romvec, void *dvec, 1647c478bd9Sstevel@tonic-gate struct bootops *bootvec, val_t *bootaux); 1657c478bd9Sstevel@tonic-gate extern int kobj_notify_add(kobj_notify_list_t *); 1667c478bd9Sstevel@tonic-gate extern int kobj_notify_remove(kobj_notify_list_t *); 1677c478bd9Sstevel@tonic-gate extern int do_relocations(struct module *); 1687c478bd9Sstevel@tonic-gate extern int do_relocate(struct module *, char *, Word, int, int, Addr); 1697c478bd9Sstevel@tonic-gate extern struct bootops *ops; 1707c478bd9Sstevel@tonic-gate extern void exitto(caddr_t); 1717c478bd9Sstevel@tonic-gate extern void kobj_sync_instruction_memory(caddr_t, size_t); 1727c478bd9Sstevel@tonic-gate extern uint_t kobj_gethashsize(uint_t); 1737c478bd9Sstevel@tonic-gate extern void * kobj_mod_alloc(struct module *, size_t, int, reloc_dest_t *); 1747c478bd9Sstevel@tonic-gate extern void mach_alloc_funcdesc(struct module *); 1757c478bd9Sstevel@tonic-gate extern uint_t kobj_hash_name(const char *); 1767c478bd9Sstevel@tonic-gate extern caddr_t kobj_segbrk(caddr_t *, size_t, size_t, caddr_t); 1777c478bd9Sstevel@tonic-gate extern int get_progbits_size(struct module *, struct proginfo *, 1787c478bd9Sstevel@tonic-gate struct proginfo *, struct proginfo *); 1797c478bd9Sstevel@tonic-gate extern Sym *kobj_lookup_kernel(const char *); 1807c478bd9Sstevel@tonic-gate extern struct modctl *kobj_boot_mod_lookup(const char *); 1817c478bd9Sstevel@tonic-gate extern void kobj_export_module(struct module *); 1827c478bd9Sstevel@tonic-gate extern int kobj_load_primary_module(struct modctl *); 183*986fd29aSsetje extern int boot_compinfo(int, struct compinfo *); 184*986fd29aSsetje extern void mach_modpath(char *, const char *); 1857c478bd9Sstevel@tonic-gate 186*986fd29aSsetje extern void kobj_setup_standalone_vectors(void); 187*986fd29aSsetje extern void kobj_restore_vectors(void); 188*986fd29aSsetje extern void (*_kobj_printf)(void *, const char *fmt, ...); 189*986fd29aSsetje extern void (*kobj_bcopy)(const void *, void *, size_t); 190*986fd29aSsetje extern void (*kobj_bzero)(void *, size_t); 191*986fd29aSsetje extern size_t (*kobj_strlcat)(char *, const char *, size_t); 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate #define KOBJ_LM_PRIMARY 0x0 1947c478bd9Sstevel@tonic-gate #define KOBJ_LM_DEBUGGER 0x1 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate extern void kobj_lm_append(int, struct modctl *modp); 1977c478bd9Sstevel@tonic-gate extern struct modctl_list *kobj_lm_lookup(int); 1987c478bd9Sstevel@tonic-gate extern void kobj_lm_dump(int); 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2017c478bd9Sstevel@tonic-gate } 2027c478bd9Sstevel@tonic-gate #endif 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate #endif /* _SYS_KOBJ_IMPL_H */ 205