modctl.h revision 5206:34f0b41fc3c5
11592Srgrimes/* 250476Speter * CDDL HEADER START 31592Srgrimes * 41592Srgrimes * The contents of this file are subject to the terms of the 545396Sbrian * Common Development and Distribution License (the "License"). 645396Sbrian * You may not use this file except in compliance with the License. 774814Sru * 81592Srgrimes * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 990164Skris * or http://www.opensolaris.org/os/licensing. 1090164Skris * See the License for the specific language governing permissions 111592Srgrimes * 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 2007 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26#ifndef _SYS_MODCTL_H 27#define _SYS_MODCTL_H 28 29#pragma ident "%Z%%M% %I% %E% SMI" 30 31/* 32 * loadable module support. 33 */ 34 35#include <sys/types.h> 36#include <sys/ioccom.h> 37#include <sys/nexusdefs.h> 38#include <sys/thread.h> 39#include <sys/t_lock.h> 40#include <sys/dditypes.h> 41#include <sys/hwconf.h> 42 43#ifdef __cplusplus 44extern "C" { 45#endif 46 47/* 48 * The following structure defines the operations used by modctl 49 * to load and unload modules. Each supported loadable module type 50 * requires a set of mod_ops. 51 */ 52struct mod_ops { 53 int (*modm_install)(); /* install module in kernel */ 54 int (*modm_remove)(); /* remove from kernel */ 55 int (*modm_info)(); /* module info */ 56}; 57 58#ifdef _KERNEL 59 60/* 61 * The defined set of mod_ops structures for each loadable module type 62 * Defined in modctl.c 63 */ 64extern struct mod_ops mod_brandops; 65#if defined(__i386) || defined(__amd64) 66extern struct mod_ops mod_cpuops; 67#endif 68extern struct mod_ops mod_cryptoops; 69extern struct mod_ops mod_driverops; 70extern struct mod_ops mod_execops; 71extern struct mod_ops mod_fsops; 72extern struct mod_ops mod_miscops; 73extern struct mod_ops mod_schedops; 74extern struct mod_ops mod_strmodops; 75extern struct mod_ops mod_syscallops; 76#ifdef _SYSCALL32_IMPL 77extern struct mod_ops mod_syscallops32; 78#endif 79extern struct mod_ops mod_dacfops; 80extern struct mod_ops mod_ippops; 81extern struct mod_ops mod_pcbeops; 82extern struct mod_ops mod_devfsops; 83extern struct mod_ops mod_kiconvops; 84 85#endif /* _KERNEL */ 86 87/* 88 * Definitions for the module specific linkage structures. 89 * The first two fields are the same in all of the structures. 90 * The linkinfo is for informational purposes only and is returned by 91 * modctl with the MODINFO cmd. 92 */ 93 94/* For drivers */ 95struct modldrv { 96 struct mod_ops *drv_modops; 97 char *drv_linkinfo; 98 struct dev_ops *drv_dev_ops; 99}; 100 101/* For system calls */ 102struct modlsys { 103 struct mod_ops *sys_modops; 104 char *sys_linkinfo; 105 struct sysent *sys_sysent; 106}; 107 108/* For filesystems */ 109struct modlfs { 110 struct mod_ops *fs_modops; 111 char *fs_linkinfo; 112 struct vfsdef_v3 *fs_vfsdef; /* version may actually vary */ 113}; 114 115#if defined(__i386) || defined(__amd64) 116struct cmi_ops; 117 118/* For CPU modules */ 119struct modlcpu { 120 struct mod_ops *cpu_modops; 121 char *cpu_linkinfo; 122 struct cmi_ops *cpu_cmiops; 123}; 124#endif 125 126/* For cryptographic providers */ 127struct modlcrypto { 128 struct mod_ops *crypto_modops; 129 char *crypto_linkinfo; 130}; 131 132/* For misc */ 133struct modlmisc { 134 struct mod_ops *misc_modops; 135 char *misc_linkinfo; 136}; 137 138/* For IP Modules */ 139struct modlipp { 140 struct mod_ops *ipp_modops; 141 char *ipp_linkinfo; 142 struct ipp_ops *ipp_ops; 143}; 144 145/* For Streams Modules. */ 146struct modlstrmod { 147 struct mod_ops *strmod_modops; 148 char *strmod_linkinfo; 149 struct fmodsw *strmod_fmodsw; 150}; 151 152/* For Scheduling classes */ 153struct modlsched { 154 struct mod_ops *sched_modops; 155 char *sched_linkinfo; 156 struct sclass *sched_class; 157}; 158 159/* For Exec file type (like ELF, ...) */ 160struct modlexec { 161 struct mod_ops *exec_modops; 162 char *exec_linkinfo; 163 struct execsw *exec_execsw; 164}; 165 166/* For dacf modules */ 167struct modldacf { 168 struct mod_ops *dacf_modops; 169 char *dacf_linkinfo; 170 struct dacfsw *dacf_dacfsw; 171}; 172 173/* For PCBE modules */ 174struct modlpcbe { 175 struct mod_ops *pcbe_modops; 176 char *pcbe_linkinfo; 177 struct __pcbe_ops *pcbe_ops; 178}; 179 180/* For Brand modules */ 181struct modlbrand { 182 struct mod_ops *brand_modops; 183 char *brand_linkinfo; 184 struct brand *brand_branddef; 185}; 186 187/* for devname fs */ 188struct modldev { 189 struct mod_ops *dev_modops; 190 char *dev_linkinfo; 191 struct devname_ops *dev_ops; 192}; 193 194/* For kiconv modules */ 195struct modlkiconv { 196 struct mod_ops *kiconv_modops; 197 char *kiconv_linkinfo; 198 struct kiconv_mod_info *kiconv_moddef; 199}; 200 201/* 202 * Revision number of loadable modules support. This is the value 203 * that must be used in the modlinkage structure. 204 */ 205#define MODREV_1 1 206 207/* 208 * The modlinkage structure is the structure that the module writer 209 * provides to the routines to install, remove, and stat a module. 210 * The ml_linkage element is an array of pointers to linkage structures. 211 * For most modules there is only one linkage structure. We allocate 212 * enough space for 3 linkage structures which happens to be the most 213 * we have in any sun supplied module. For those modules with more 214 * than 3 linkage structures (which is very unlikely), a modlinkage 215 * structure must be kmem_alloc'd in the module wrapper to be big enough 216 * for all of the linkage structures. 217 */ 218struct modlinkage { 219 int ml_rev; /* rev of loadable modules system */ 220#ifdef _LP64 221 void *ml_linkage[7]; /* more space in 64-bit OS */ 222#else 223 void *ml_linkage[4]; /* NULL terminated list of */ 224 /* linkage structures */ 225#endif 226}; 227 228/* 229 * commands. These are the commands supported by the modctl system call. 230 */ 231#define MODLOAD 0 232#define MODUNLOAD 1 233#define MODINFO 2 234#define MODRESERVED 3 235#define MODSETMINIROOT 4 236#define MODADDMAJBIND 5 237#define MODGETPATH 6 238#define MODREADSYSBIND 7 239#define MODGETMAJBIND 8 240#define MODGETNAME 9 241#define MODSIZEOF_DEVID 10 242#define MODGETDEVID 11 243#define MODSIZEOF_MINORNAME 12 244#define MODGETMINORNAME 13 245#define MODGETPATHLEN 14 246#define MODEVENTS 15 247#define MODGETFBNAME 16 248#define MODREREADDACF 17 249#define MODLOADDRVCONF 18 250#define MODUNLOADDRVCONF 19 251#define MODREMMAJBIND 20 252#define MODDEVT2INSTANCE 21 253#define MODGETDEVFSPATH_LEN 22 254#define MODGETDEVFSPATH 23 255#define MODDEVID2PATHS 24 256#define MODSETDEVPOLICY 26 257#define MODGETDEVPOLICY 27 258#define MODALLOCPRIV 28 259#define MODGETDEVPOLICYBYNAME 29 260#define MODLOADMINORPERM 31 261#define MODADDMINORPERM 32 262#define MODREMMINORPERM 33 263#define MODREMDRVCLEANUP 34 264#define MODDEVEXISTS 35 265#define MODDEVREADDIR 36 266#define MODDEVNAME 37 267#define MODGETDEVFSPATH_MI_LEN 38 268#define MODGETDEVFSPATH_MI 39 269#define MODRETIRE 40 270#define MODUNRETIRE 41 271#define MODISRETIRED 42 272 273/* 274 * sub cmds for MODEVENTS 275 */ 276#define MODEVENTS_FLUSH 0 277#define MODEVENTS_FLUSH_DUMP 1 278#define MODEVENTS_SET_DOOR_UPCALL_FILENAME 2 279#define MODEVENTS_GETDATA 3 280#define MODEVENTS_FREEDATA 4 281#define MODEVENTS_POST_EVENT 5 282#define MODEVENTS_REGISTER_EVENT 6 283 284/* 285 * devname subcmds for MODDEVNAME 286 */ 287#define MODDEVNAME_LOOKUPDOOR 0 288#define MODDEVNAME_DEVFSADMNODE 1 289#define MODDEVNAME_NSMAPS 2 290#define MODDEVNAME_PROFILE 3 291#define MODDEVNAME_RECONFIG 4 292#define MODDEVNAME_SYSAVAIL 5 293 294 295/* 296 * Data structure passed to modconfig command in kernel to build devfs tree 297 */ 298 299struct aliases { 300 struct aliases *a_next; 301 char *a_name; 302 int a_len; 303}; 304 305#define MAXMODCONFNAME 256 306 307struct modconfig { 308 char drvname[MAXMODCONFNAME]; 309 char drvclass[MAXMODCONFNAME]; 310 int major; 311 int num_aliases; 312 struct aliases *ap; 313}; 314 315#if defined(_SYSCALL32) 316 317struct aliases32 { 318 caddr32_t a_next; 319 caddr32_t a_name; 320 int32_t a_len; 321}; 322 323struct modconfig32 { 324 char drvname[MAXMODCONFNAME]; 325 char drvclass[MAXMODCONFNAME]; 326 int32_t major; 327 int32_t num_aliases; 328 caddr32_t ap; 329}; 330 331#endif /* _SYSCALL32 */ 332 333/* 334 * Max module path length 335 */ 336#define MOD_MAXPATH 256 337 338/* 339 * Default search path for modules ADDITIONAL to the directory 340 * where the kernel components we booted from are. 341 * 342 * Most often, this will be "/platform/{platform}/kernel /kernel /usr/kernel", 343 * but we don't wire it down here. 344 */ 345#define MOD_DEFPATH "/kernel /usr/kernel" 346 347/* 348 * Default file name extension for autoloading modules. 349 */ 350#define MOD_DEFEXT "" 351 352/* 353 * Parameters for modinfo 354 */ 355#define MODMAXNAMELEN 32 /* max module name length */ 356#define MODMAXLINKINFOLEN 32 /* max link info length */ 357 358/* 359 * Module specific information. 360 */ 361struct modspecific_info { 362 char msi_linkinfo[MODMAXLINKINFOLEN]; /* name in linkage struct */ 363 int msi_p0; /* module specific information */ 364}; 365 366/* 367 * Structure returned by modctl with MODINFO command. 368 */ 369#define MODMAXLINK 10 /* max linkages modinfo can handle */ 370 371struct modinfo { 372 int mi_info; /* Flags for info wanted */ 373 int mi_state; /* Flags for module state */ 374 int mi_id; /* id of this loaded module */ 375 int mi_nextid; /* id of next module or -1 */ 376 caddr_t mi_base; /* virtual addr of text */ 377 size_t mi_size; /* size of module in bytes */ 378 int mi_rev; /* loadable modules rev */ 379 int mi_loadcnt; /* # of times loaded */ 380 char mi_name[MODMAXNAMELEN]; /* name of module */ 381 struct modspecific_info mi_msinfo[MODMAXLINK]; 382 /* mod specific info */ 383}; 384 385 386#if defined(_SYSCALL32) 387 388#define MODMAXNAMELEN32 32 /* max module name length */ 389#define MODMAXLINKINFOLEN32 32 /* max link info length */ 390#define MODMAXLINK32 10 /* max linkages modinfo can handle */ 391 392struct modspecific_info32 { 393 char msi_linkinfo[MODMAXLINKINFOLEN32]; /* name in linkage struct */ 394 int32_t msi_p0; /* module specific information */ 395}; 396 397struct modinfo32 { 398 int32_t mi_info; /* Flags for info wanted */ 399 int32_t mi_state; /* Flags for module state */ 400 int32_t mi_id; /* id of this loaded module */ 401 int32_t mi_nextid; /* id of next module or -1 */ 402 caddr32_t mi_base; /* virtual addr of text */ 403 uint32_t mi_size; /* size of module in bytes */ 404 int32_t mi_rev; /* loadable modules rev */ 405 int32_t mi_loadcnt; /* # of times loaded */ 406 char mi_name[MODMAXNAMELEN32]; /* name of module */ 407 struct modspecific_info32 mi_msinfo[MODMAXLINK32]; 408 /* mod specific info */ 409}; 410 411#endif /* _SYSCALL32 */ 412 413/* Values for mi_info flags */ 414#define MI_INFO_ONE 1 415#define MI_INFO_ALL 2 416#define MI_INFO_CNT 4 417#ifdef _KERNEL 418#define MI_INFO_LINKAGE 8 /* used internally to extract modlinkage */ 419#endif 420/* 421 * MI_INFO_NOBASE indicates caller does not need mi_base. Failure to use this 422 * flag may lead 32-bit apps to receive an EOVERFLOW error from modctl(MODINFO) 423 * when used with a 64-bit kernel. 424 */ 425#define MI_INFO_NOBASE 16 426 427/* Values for mi_state */ 428#define MI_LOADED 1 429#define MI_INSTALLED 2 430 431/* 432 * Macros to vector to the appropriate module specific routine. 433 */ 434#define MODL_INSTALL(MODL, MODLP) \ 435 (*(MODL)->misc_modops->modm_install)(MODL, MODLP) 436#define MODL_REMOVE(MODL, MODLP) \ 437 (*(MODL)->misc_modops->modm_remove)(MODL, MODLP) 438#define MODL_INFO(MODL, MODLP, P0) \ 439 (*(MODL)->misc_modops->modm_info)(MODL, MODLP, P0) 440 441/* 442 * Definitions for stubs 443 */ 444struct mod_stub_info { 445 uintptr_t mods_func_adr; 446 struct mod_modinfo *mods_modinfo; 447 uintptr_t mods_stub_adr; 448 int (*mods_errfcn)(); 449 int mods_flag; /* flags defined below */ 450}; 451 452/* 453 * Definitions for mods_flag. 454 */ 455#define MODS_WEAK 0x01 /* weak stub (not loaded if called) */ 456#define MODS_NOUNLOAD 0x02 /* module not unloadable (no _fini()) */ 457#define MODS_INSTALLED 0x10 /* module installed */ 458 459struct mod_modinfo { 460 char *modm_module_name; 461 struct modctl *mp; 462 struct mod_stub_info modm_stubs[1]; 463}; 464 465struct modctl_list { 466 struct modctl_list *modl_next; 467 struct modctl *modl_modp; 468}; 469 470/* 471 * Structure to manage a loadable module. 472 * Note: the module (mod_mp) structure's "text" and "text_size" information 473 * are replicated in the modctl structure so that mod_containing_pc() 474 * doesn't have to grab any locks (modctls are persistent; modules are not.) 475 */ 476typedef struct modctl { 477 struct modctl *mod_next; /* &modules based list */ 478 struct modctl *mod_prev; 479 int mod_id; 480 void *mod_mp; 481 kthread_t *mod_inprogress_thread; 482 struct mod_modinfo *mod_modinfo; 483 struct modlinkage *mod_linkage; 484 char *mod_filename; 485 char *mod_modname; 486 487 char mod_busy; /* inprogress_thread has locked */ 488 char mod_want; /* someone waiting for unlock */ 489 char mod_prim; /* primary module */ 490 491 int mod_ref; /* ref count - from dependent or stub */ 492 493 char mod_loaded; /* module in memory */ 494 char mod_installed; /* post _init pre _fini */ 495 char mod_loadflags; 496 char mod_delay_unload; /* deferred unload */ 497 498 struct modctl_list *mod_requisites; /* mods this one depends on. */ 499 void *__unused; /* NOTE: reuse (same size) is OK, */ 500 /* deletion causes mdb.vs.core issues */ 501 int mod_loadcnt; /* number of times mod was loaded */ 502 int mod_nenabled; /* # of enabled DTrace probes in mod */ 503 char *mod_text; 504 size_t mod_text_size; 505 506 int mod_gencount; /* # times loaded/unloaded */ 507 struct modctl *mod_requisite_loading; /* mod circular dependency */ 508} modctl_t; 509 510/* 511 * mod_loadflags 512 */ 513 514#define MOD_NOAUTOUNLOAD 0x1 /* Auto mod-unloader skips this mod */ 515#define MOD_NONOTIFY 0x2 /* No krtld notifications on (un)load */ 516#define MOD_NOUNLOAD 0x4 /* Assume EBUSY for all _fini's */ 517 518 519#ifdef _KERNEL 520 521#define MOD_BIND_HASHSIZE 64 522#define MOD_BIND_HASHMASK (MOD_BIND_HASHSIZE-1) 523 524typedef int modid_t; 525 526/* 527 * global function and data declarations 528 */ 529extern kmutex_t mod_lock; 530 531extern char *systemfile; 532extern char **syscallnames; 533extern int moddebug; 534 535/* 536 * this is the head of a doubly linked list. Only the next and prev 537 * pointers are used 538 */ 539extern modctl_t modules; 540 541extern int modload_qualified(const char *, 542 const char *, const char *, const char *, uint_t[], int); 543 544extern void mod_setup(void); 545extern int modload(char *, char *); 546extern int modloadonly(char *, char *); 547extern int modunload(int); 548extern int mod_hold_stub(struct mod_stub_info *); 549extern void modunload_disable(void); 550extern void modunload_enable(void); 551extern void modunload_begin(void); 552extern void modunload_end(void); 553extern int mod_remove_by_name(char *); 554extern int mod_sysvar(const char *, const char *, u_longlong_t *); 555extern int mod_sysctl(int, void *); 556struct sysparam; 557extern int mod_hold_by_modctl(modctl_t *, int); 558#define MOD_WAIT_ONCE 0x01 559#define MOD_WAIT_FOREVER 0x02 560#define MOD_LOCK_HELD 0x04 561#define MOD_LOCK_NOT_HELD 0x08 562extern int mod_sysctl_type(int, int (*)(struct sysparam *, void *), 563 void *); 564extern void mod_read_system_file(int); 565extern void mod_release_stub(struct mod_stub_info *); 566extern void mod_askparams(void); 567extern void mod_uninstall_daemon(void); 568extern void modreap(void); 569extern modctl_t *mod_hold_by_id(modid_t); 570extern modctl_t *mod_hold_by_name(const char *); 571extern void mod_release_mod(modctl_t *); 572extern uintptr_t modlookup(const char *, const char *); 573extern uintptr_t modlookup_by_modctl(modctl_t *, const char *); 574extern char *modgetsymname(uintptr_t, unsigned long *); 575extern void mod_release_requisites(modctl_t *); 576extern modctl_t *mod_load_requisite(modctl_t *, char *); 577extern modctl_t *mod_find_by_filename(char *, char *); 578extern uintptr_t modgetsymvalue(char *, int); 579 580extern void mod_rele_dev_by_major(major_t); 581extern struct dev_ops *mod_hold_dev_by_major(major_t); 582extern struct dev_ops *mod_hold_dev_by_devi(dev_info_t *); 583extern void mod_rele_dev_by_devi(dev_info_t *); 584 585extern int make_devname(char *, major_t); 586extern int gmatch(const char *, const char *); 587 588struct bind; 589extern void make_aliases(struct bind **); 590extern int read_binding_file(char *, struct bind **, 591 int (*line_parser)(char *, int, char *, struct bind **)); 592extern void clear_binding_hash(struct bind **); 593 594extern void read_class_file(void); 595extern void setbootpath(char *); 596extern void setbootfstype(char *); 597 598extern int install_stubs_by_name(modctl_t *, char *); 599extern void install_stubs(modctl_t *); 600extern void uninstall_stubs(modctl_t *); 601extern void reset_stubs(modctl_t *); 602extern modctl_t *mod_getctl(struct modlinkage *); 603extern major_t mod_name_to_major(char *); 604extern modid_t mod_name_to_modid(char *); 605extern char *mod_major_to_name(major_t); 606extern void init_devnamesp(int); 607extern void init_syscallnames(int); 608 609extern char *mod_getsysname(int); 610extern int mod_getsysnum(char *); 611 612extern char *mod_containing_pc(caddr_t); 613extern int mod_in_autounload(void); 614extern char *mod_modname(struct modlinkage *); 615 616extern int dev_minorperm(dev_info_t *, char *, mperm_t *); 617extern void dev_devices_cleanup(void); 618 619/* 620 * Declarations used for dynamic linking support routines. Interfaces 621 * are marked with the pragma "unknown_control_flow" to prevent tail call 622 * optimization, so that implementations can reliably use caller() to 623 * determine initiating module. 624 */ 625#define KRTLD_MODE_FIRST 0x0001 626typedef struct __ddi_modhandle *ddi_modhandle_t; 627extern ddi_modhandle_t ddi_modopen(const char *, 628 int, int *); 629extern void *ddi_modsym(ddi_modhandle_t, 630 const char *, int *); 631extern int ddi_modclose(ddi_modhandle_t); 632#pragma unknown_control_flow(ddi_modopen, ddi_modsym, ddi_modclose) 633 634/* 635 * Only the following are part of the DDI/DKI 636 */ 637extern int _init(void); 638extern int _fini(void); 639extern int _info(struct modinfo *); 640extern int mod_install(struct modlinkage *); 641extern int mod_remove(struct modlinkage *); 642extern int mod_info(struct modlinkage *, struct modinfo *); 643 644#else /* _KERNEL */ 645 646extern int modctl(int, ...); 647 648#endif /* _KERNEL */ 649 650/* 651 * bit definitions for moddebug. 652 */ 653#define MODDEBUG_LOADMSG 0x80000000 /* print "[un]loading..." msg */ 654#define MODDEBUG_ERRMSG 0x40000000 /* print detailed error msgs */ 655#define MODDEBUG_LOADMSG2 0x20000000 /* print 2nd level msgs */ 656#define MODDEBUG_RETIRE 0x10000000 /* print retire msgs */ 657#define MODDEBUG_FINI_EBUSY 0x00020000 /* pretend fini returns EBUSY */ 658#define MODDEBUG_NOAUL_IPP 0x00010000 /* no Autounloading ipp mods */ 659#define MODDEBUG_NOAUL_DACF 0x00008000 /* no Autounloading dacf mods */ 660#define MODDEBUG_KEEPTEXT 0x00004000 /* keep text after unloading */ 661#define MODDEBUG_NOAUL_DRV 0x00001000 /* no Autounloading Drivers */ 662#define MODDEBUG_NOAUL_EXEC 0x00000800 /* no Autounloading Execs */ 663#define MODDEBUG_NOAUL_FS 0x00000400 /* no Autounloading File sys */ 664#define MODDEBUG_NOAUL_MISC 0x00000200 /* no Autounloading misc */ 665#define MODDEBUG_NOAUL_SCHED 0x00000100 /* no Autounloading scheds */ 666#define MODDEBUG_NOAUL_STR 0x00000080 /* no Autounloading streams */ 667#define MODDEBUG_NOAUL_SYS 0x00000040 /* no Autounloading syscalls */ 668#define MODDEBUG_NOCTF 0x00000020 /* do not load CTF debug data */ 669#define MODDEBUG_NOAUTOUNLOAD 0x00000010 /* no autounloading at all */ 670#define MODDEBUG_DDI_MOD 0x00000008 /* ddi_mod{open,sym,close} */ 671#define MODDEBUG_MP_MATCH 0x00000004 /* dev_minorperm */ 672#define MODDEBUG_MINORPERM 0x00000002 /* minor perm modctls */ 673#define MODDEBUG_USERDEBUG 0x00000001 /* bpt after init_module() */ 674 675#ifdef __cplusplus 676} 677#endif 678 679#endif /* _SYS_MODCTL_H */ 680