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