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 5986fd29aSsetje * Common Development and Distribution License (the "License"). 6986fd29aSsetje * 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 /* 22986fd29aSsetje * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 24c61137dfSJohn Levon * 25c61137dfSJohn Levon * Copyright 2020 Joyent, Inc. 267c478bd9Sstevel@tonic-gate */ 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate /* 297c478bd9Sstevel@tonic-gate * Kernel Run-Time Linker/Loader private interfaces. 307c478bd9Sstevel@tonic-gate */ 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #ifndef _SYS_KOBJ_IMPL_H 337c478bd9Sstevel@tonic-gate #define _SYS_KOBJ_IMPL_H 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #include <sys/kdi.h> 367c478bd9Sstevel@tonic-gate #include <sys/kobj.h> 37508de9f3SToomas Soome #include <sys/varargs.h> 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #ifdef __cplusplus 407c478bd9Sstevel@tonic-gate extern "C" { 417c478bd9Sstevel@tonic-gate #endif 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate /* 447c478bd9Sstevel@tonic-gate * Boot/aux vector attributes. 457c478bd9Sstevel@tonic-gate */ 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate #define BA_DYNAMIC 0 487c478bd9Sstevel@tonic-gate #define BA_PHDR 1 497c478bd9Sstevel@tonic-gate #define BA_PHNUM 2 507c478bd9Sstevel@tonic-gate #define BA_PHENT 3 517c478bd9Sstevel@tonic-gate #define BA_ENTRY 4 527c478bd9Sstevel@tonic-gate #define BA_PAGESZ 5 537c478bd9Sstevel@tonic-gate #define BA_LPAGESZ 6 547c478bd9Sstevel@tonic-gate #define BA_LDELF 7 557c478bd9Sstevel@tonic-gate #define BA_LDSHDR 8 567c478bd9Sstevel@tonic-gate #define BA_LDNAME 9 577c478bd9Sstevel@tonic-gate #define BA_BSS 10 587c478bd9Sstevel@tonic-gate #define BA_IFLUSH 11 597c478bd9Sstevel@tonic-gate #define BA_CPU 12 607c478bd9Sstevel@tonic-gate #define BA_MMU 13 617c478bd9Sstevel@tonic-gate #define BA_GOTADDR 14 627c478bd9Sstevel@tonic-gate #define BA_NEXTGOT 15 637c478bd9Sstevel@tonic-gate #define BA_NUM 16 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate typedef union { 667c478bd9Sstevel@tonic-gate unsigned long ba_val; 677c478bd9Sstevel@tonic-gate void *ba_ptr; 687c478bd9Sstevel@tonic-gate } val_t; 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate /* 717c478bd9Sstevel@tonic-gate * Segment info. 727c478bd9Sstevel@tonic-gate */ 737c478bd9Sstevel@tonic-gate struct proginfo { 747c478bd9Sstevel@tonic-gate uint_t size; 757c478bd9Sstevel@tonic-gate uint_t align; 767c478bd9Sstevel@tonic-gate }; 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate /* 797c478bd9Sstevel@tonic-gate * Implementation-specific flags. 807c478bd9Sstevel@tonic-gate */ 817c478bd9Sstevel@tonic-gate #define KOBJ_EXEC 0x0004 /* executable (unix module) */ 827c478bd9Sstevel@tonic-gate #define KOBJ_INTERP 0x0008 /* the interpreter module */ 837c478bd9Sstevel@tonic-gate #define KOBJ_PRIM 0x0010 /* a primary kernel module */ 847c478bd9Sstevel@tonic-gate #define KOBJ_RESOLVED 0x0020 /* fully resolved */ 85*2570281cSToomas Soome /* 0x0040 unused. */ 867c478bd9Sstevel@tonic-gate #define KOBJ_RELOCATED 0x0080 /* relocation completed */ 877c478bd9Sstevel@tonic-gate #define KOBJ_NOPARENTS 0x0200 /* nothing can depend on this module */ 887c478bd9Sstevel@tonic-gate #define KOBJ_IGNMULDEF 0x0400 /* ignore dups during sym resolution */ 897c478bd9Sstevel@tonic-gate #define KOBJ_NOKSYMS 0x0800 /* module's symbols don't go into ksyms */ 907c478bd9Sstevel@tonic-gate #define KOBJ_EXPORTED 0x1000 /* ctf, syms copied to vmem */ 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate /* 937c478bd9Sstevel@tonic-gate * kobj_notify_add() data notification structure 947c478bd9Sstevel@tonic-gate */ 957c478bd9Sstevel@tonic-gate typedef void kobj_notify_f(uint_t, struct modctl *); 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate typedef struct kobj_notify_list { 987c478bd9Sstevel@tonic-gate kobj_notify_f *kn_func; /* notification func */ 997c478bd9Sstevel@tonic-gate uint_t kn_type; /* notification type */ 1007c478bd9Sstevel@tonic-gate struct kobj_notify_list *kn_prev; 1017c478bd9Sstevel@tonic-gate struct kobj_notify_list *kn_next; 1027c478bd9Sstevel@tonic-gate } kobj_notify_list_t; 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate /* 1057c478bd9Sstevel@tonic-gate * krtld can provide notification to external clients on the 1067c478bd9Sstevel@tonic-gate * following events. 1077c478bd9Sstevel@tonic-gate */ 1087c478bd9Sstevel@tonic-gate #define KOBJ_NOTIFY_MODLOADING 1 /* very early in module load */ 1097c478bd9Sstevel@tonic-gate #define KOBJ_NOTIFY_MODUNLOADING 2 /* before module unload */ 1107c478bd9Sstevel@tonic-gate #define KOBJ_NOTIFY_MODLOADED 3 /* after module load */ 1117c478bd9Sstevel@tonic-gate #define KOBJ_NOTIFY_MODUNLOADED 4 /* after module unload */ 1127c478bd9Sstevel@tonic-gate #define KOBJ_NOTIFY_MAX 4 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate #define ALIGN(x, a) ((a) == 0 ? (uintptr_t)(x) : \ 1157c478bd9Sstevel@tonic-gate (((uintptr_t)(x) + (uintptr_t)(a) - 1l) & ~((uintptr_t)(a) - 1l))) 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate #ifdef DEBUG 1187c478bd9Sstevel@tonic-gate #define KOBJ_DEBUG 1197c478bd9Sstevel@tonic-gate #endif 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate #ifdef KOBJ_DEBUG 1227c478bd9Sstevel@tonic-gate /* 1237c478bd9Sstevel@tonic-gate * Debugging flags. 1247c478bd9Sstevel@tonic-gate */ 1257c478bd9Sstevel@tonic-gate #define D_DEBUG 0x001 /* general debugging */ 1267c478bd9Sstevel@tonic-gate #define D_SYMBOLS 0x002 /* debug symbols */ 1277c478bd9Sstevel@tonic-gate #define D_RELOCATIONS 0x004 /* debug relocations */ 1287c478bd9Sstevel@tonic-gate #define D_LOADING 0x008 /* section loading */ 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate extern int kobj_debug; /* different than moddebug */ 1317c478bd9Sstevel@tonic-gate #endif 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate /* 1347c478bd9Sstevel@tonic-gate * Flags for kobj memory allocation. 1357c478bd9Sstevel@tonic-gate */ 1367c478bd9Sstevel@tonic-gate #define KM_WAIT 0x0 /* wait for it */ 1377c478bd9Sstevel@tonic-gate #define KM_NOWAIT 0x1 /* return immediately */ 1387c478bd9Sstevel@tonic-gate 139986fd29aSsetje #define KM_TMP 0x1000 /* freed before kobj_init returns */ 140986fd29aSsetje #define KM_SCRATCH 0x2000 /* not freed until kobj_sync */ 141986fd29aSsetje 142986fd29aSsetje #ifdef KOBJ_OVERRIDES 143986fd29aSsetje /* 144986fd29aSsetje * Until the kernel is fully linked, all code running in the 145986fd29aSsetje * context of krtld/kobj using bcopy or bzero must be directed 146986fd29aSsetje * to the kobj equivalents. All (ok, most) references to bcopy 147986fd29aSsetje * or bzero are thus so vectored. 148986fd29aSsetje */ 149986fd29aSsetje #define bcopy(s, d, n) kobj_bcopy((s), (d), (n)) 150986fd29aSsetje #define bzero(p, n) kobj_bzero((p), (n)) 151986fd29aSsetje #define strlcat(s, d, n) kobj_strlcat((s), (d), (n)) 152986fd29aSsetje #endif 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate extern kdi_t kobj_kdi; 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate struct bootops; 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate extern struct modctl_list *kobj_linkmaps[]; 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate extern char *kobj_kmdb_argv[]; 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate extern int kobj_mmu_pagesize; 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate extern void kobj_init(void *romvec, void *dvec, 1657c478bd9Sstevel@tonic-gate struct bootops *bootvec, val_t *bootaux); 1667c478bd9Sstevel@tonic-gate extern int kobj_notify_add(kobj_notify_list_t *); 1677c478bd9Sstevel@tonic-gate extern int kobj_notify_remove(kobj_notify_list_t *); 1687c478bd9Sstevel@tonic-gate extern int do_relocations(struct module *); 169584b574aSToomas Soome extern int do_relocate(struct module *, char *, int, int, Addr); 1707c478bd9Sstevel@tonic-gate extern struct bootops *ops; 1717c478bd9Sstevel@tonic-gate extern void exitto(caddr_t); 1727c478bd9Sstevel@tonic-gate extern void kobj_sync_instruction_memory(caddr_t, size_t); 1737c478bd9Sstevel@tonic-gate extern uint_t kobj_gethashsize(uint_t); 1747c478bd9Sstevel@tonic-gate extern void * kobj_mod_alloc(struct module *, size_t, int, reloc_dest_t *); 1757c478bd9Sstevel@tonic-gate extern void mach_alloc_funcdesc(struct module *); 1767c478bd9Sstevel@tonic-gate extern uint_t kobj_hash_name(const char *); 1777c478bd9Sstevel@tonic-gate extern caddr_t kobj_segbrk(caddr_t *, size_t, size_t, caddr_t); 1787c478bd9Sstevel@tonic-gate extern int get_progbits_size(struct module *, struct proginfo *, 1797c478bd9Sstevel@tonic-gate struct proginfo *, struct proginfo *); 1807c478bd9Sstevel@tonic-gate extern Sym *kobj_lookup_kernel(const char *); 1817c478bd9Sstevel@tonic-gate extern struct modctl *kobj_boot_mod_lookup(const char *); 1827c478bd9Sstevel@tonic-gate extern void kobj_export_module(struct module *); 1837c478bd9Sstevel@tonic-gate extern int kobj_load_primary_module(struct modctl *); 184986fd29aSsetje extern int boot_compinfo(int, struct compinfo *); 185986fd29aSsetje extern void mach_modpath(char *, const char *); 1867c478bd9Sstevel@tonic-gate 187986fd29aSsetje extern void kobj_setup_standalone_vectors(void); 188986fd29aSsetje extern void kobj_restore_vectors(void); 189c61137dfSJohn Levon extern void (*_kobj_printf)(void *, const char *fmt, ...) __KPRINTFLIKE(2); 190c61137dfSJohn Levon extern void (*_vkobj_printf)(void *, const char *fmt, va_list) 191c61137dfSJohn Levon __KVPRINTFLIKE(2); 192986fd29aSsetje extern void (*kobj_bcopy)(const void *, void *, size_t); 193986fd29aSsetje extern void (*kobj_bzero)(void *, size_t); 194986fd29aSsetje extern size_t (*kobj_strlcat)(char *, const char *, size_t); 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate #define KOBJ_LM_PRIMARY 0x0 1977c478bd9Sstevel@tonic-gate #define KOBJ_LM_DEBUGGER 0x1 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate extern void kobj_lm_append(int, struct modctl *modp); 2007c478bd9Sstevel@tonic-gate extern struct modctl_list *kobj_lm_lookup(int); 2017c478bd9Sstevel@tonic-gate extern void kobj_lm_dump(int); 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2047c478bd9Sstevel@tonic-gate } 2057c478bd9Sstevel@tonic-gate #endif 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate #endif /* _SYS_KOBJ_IMPL_H */ 208