10786f79cSPoul-Henning Kamp.\" 284f9f2c5SMitchell Horne.\" SPDX-License-Identifier: BSD-2-Clause 30786f79cSPoul-Henning Kamp.\" 484f9f2c5SMitchell Horne.\" Copyright (c) 2023 The FreeBSD Foundation 57fbd6150SJohn-Mark Gurney.\" 684f9f2c5SMitchell Horne.\" This manual page was written by Mitchell Horne <mhorne@FreeBSD.org> under 784f9f2c5SMitchell Horne.\" sponsorship from the FreeBSD Foundation. 87fbd6150SJohn-Mark Gurney.\" 9*712fd5acSGraham Perrin.Dd January 30, 2024 100786f79cSPoul-Henning Kamp.Dt INTRO 9 113d45e180SRuslan Ermilov.Os 120786f79cSPoul-Henning Kamp.Sh NAME 130786f79cSPoul-Henning Kamp.Nm intro 1484f9f2c5SMitchell Horne.Nd "introduction to kernel programming interfaces" 150786f79cSPoul-Henning Kamp.Sh DESCRIPTION 1684f9f2c5SMitchell HorneWelcome to the 1784f9f2c5SMitchell Horne.Fx 1884f9f2c5SMitchell Hornekernel documentation. 19*712fd5acSGraham PerrinOutside the source code itself, this set of 2084f9f2c5SMitchell Horne.Xr man 1 2184f9f2c5SMitchell Hornepages is the primary resource for information on usage of the numerous 2284f9f2c5SMitchell Horneprogramming interfaces available within the kernel. 2384f9f2c5SMitchell HorneIn some cases, it is also a source of truth for the implementation details 2484f9f2c5SMitchell Horneand/or design decisions behind a particular subsystem or piece of code. 25aab5e1b6SMike Pritchard.Pp 2684f9f2c5SMitchell HorneThe intended audience of this documentation is developers, and the primary 2784f9f2c5SMitchell Horneauthors are also developers. 2884f9f2c5SMitchell HorneIt is written assuming a certain familiarity with common programming or 2984f9f2c5SMitchell HorneOS-level concepts and practices. 3084f9f2c5SMitchell HorneHowever, this documentation should also attempt to provide enough background 3184f9f2c5SMitchell Horneinformation that readers approaching a particular subsystem or interface for 3284f9f2c5SMitchell Hornethe first time will be able to understand. 33aab5e1b6SMike Pritchard.Pp 3484f9f2c5SMitchell HorneTo further set expectations, we acknowledge that kernel documentation, like the 3584f9f2c5SMitchell Hornesource code itself, is forever a work-in-progress. 3684f9f2c5SMitchell HorneThere will be large sections of the codebase whose documentation is subtly or 3784f9f2c5SMitchell Horneseverely outdated, or missing altogether. 3884f9f2c5SMitchell HorneThis documentation is a supplement to the source code, and can not always be 3984f9f2c5SMitchell Hornetaken at face value. 40aab5e1b6SMike Pritchard.Pp 4184f9f2c5SMitchell HorneAt its best, section 9 documentation will provide a description of a particular 4284f9f2c5SMitchell Hornepiece of code that, paired with its implementation, fully informs the reader of 4384f9f2c5SMitchell Hornethe intended and realized effects. 44aab5e1b6SMike Pritchard.Pp 4584f9f2c5SMitchell Horne.Xr man 1 4684f9f2c5SMitchell Hornepages in this section most frequently describe functions, but may also 4784f9f2c5SMitchell Hornedescribe types, global variables, macros, or high-level concepts. 4884f9f2c5SMitchell Horne.Sh CODING GUIDELINES 4984f9f2c5SMitchell HorneCode written for the 5084f9f2c5SMitchell Horne.Fx 5184f9f2c5SMitchell Hornekernel is expected to conform to the established style and coding conventions. 5284f9f2c5SMitchell HornePlease see 53b030a305SPoul-Henning Kamp.Xr style 9 5484f9f2c5SMitchell Hornefor a detailed set of rules and guidelines. 5584f9f2c5SMitchell Horne.Sh OVERVIEW 5684f9f2c5SMitchell HorneBelow is presented various subsystems. 5784f9f2c5SMitchell Horne.Ss Data Structures 5884f9f2c5SMitchell HorneThere are implementations for many well-known data structures available in the 5984f9f2c5SMitchell Hornekernel. 6084f9f2c5SMitchell Horne.Bl -tag -width "Xr bitstring 3" 6184f9f2c5SMitchell Horne.It Xr bitstring 3 6284f9f2c5SMitchell HorneSimple bitmap implementation. 6384f9f2c5SMitchell Horne.It Xr counter 9 6484f9f2c5SMitchell HorneAn SMP-safe general-purpose counter implementation. 6584f9f2c5SMitchell Horne.It Xr hash 9 6684f9f2c5SMitchell HorneHash map implementation. 6784f9f2c5SMitchell Horne.It Xr nv 9 6884f9f2c5SMitchell HorneName/value pairs. 6984f9f2c5SMitchell Horne.It Xr queue 3 7084f9f2c5SMitchell HorneSingly-linked and doubly-linked lists, and queues. 7184f9f2c5SMitchell Horne.It Xr refcount 9 7284f9f2c5SMitchell HorneAn SMP-safe implementation of reference counts. 7384f9f2c5SMitchell Horne.It Xr sbuf 9 7484f9f2c5SMitchell HorneDynamic string composition. 7584f9f2c5SMitchell Horne.It Xr sglist 9 7684f9f2c5SMitchell HorneA scatter/gather list implementation. 7784f9f2c5SMitchell Horne.El 7884f9f2c5SMitchell Horne.Ss Utility Functions 7984f9f2c5SMitchell HorneFunctions or facilities of general usefulness or convenience. 8084f9f2c5SMitchell HorneSee also the 8184f9f2c5SMitchell Horne.Sx Testing and Debugging Tools 8284f9f2c5SMitchell Horneor 8384f9f2c5SMitchell Horne.Sx Miscellaneous 8484f9f2c5SMitchell Hornesub-sections below. 8584f9f2c5SMitchell Horne.Pp 8684f9f2c5SMitchell HorneFormatted output and logging functions are described by 8784f9f2c5SMitchell Horne.Xr printf 9 . 8884f9f2c5SMitchell Horne.Pp 8984f9f2c5SMitchell HorneEndian-swapping functions: 9084f9f2c5SMitchell Horne.Xr byteorder 9 . 9184f9f2c5SMitchell Horne.Pp 9284f9f2c5SMitchell HorneData output in hexadecimal format: 9384f9f2c5SMitchell Horne.Xr hexdump 9 . 9484f9f2c5SMitchell Horne.Pp 9584f9f2c5SMitchell HorneA rich set of macros for declaring 9684f9f2c5SMitchell Horne.Xr sysctl 8 9784f9f2c5SMitchell Hornevariables and functions is described by 9884f9f2c5SMitchell Horne.Xr sysctl 9 . 9984f9f2c5SMitchell Horne.Pp 10084f9f2c5SMitchell HorneNon-recoverable errors in the kernel should trigger a 10184f9f2c5SMitchell Horne.Xr panic 9 . 10284f9f2c5SMitchell HorneRun-time assertions can be verified using the 10384f9f2c5SMitchell Horne.Xr KASSERT 9 10484f9f2c5SMitchell Hornemacros. 10584f9f2c5SMitchell HorneCompile-time assertions should use 10684f9f2c5SMitchell Horne.Fn _Static_assert . 10784f9f2c5SMitchell Horne.Pp 10884f9f2c5SMitchell HorneThe SYSINIT framework provides macros for declaring functions that will be 10984f9f2c5SMitchell Horneexecuted during start-up and shutdown; see 11084f9f2c5SMitchell Horne.Xr SYSINIT 9 . 11184f9f2c5SMitchell Horne.Pp 11284f9f2c5SMitchell HorneDeprecation messages may be emitted with 11384f9f2c5SMitchell Horne.Xr gone_in 9 . 11484f9f2c5SMitchell Horne.Pp 11584f9f2c5SMitchell HorneA unit number facility is provided by 11684f9f2c5SMitchell Horne.Xr unr 9 . 11784f9f2c5SMitchell Horne.Ss Synchronization Primitives 11884f9f2c5SMitchell HorneThe 11984f9f2c5SMitchell Horne.Xr locking 9 12084f9f2c5SMitchell Horneman page gives an overview of the various types of locks available in the 12184f9f2c5SMitchell Hornekernel and advice on their usage. 12284f9f2c5SMitchell Horne.Pp 12384f9f2c5SMitchell HorneAtomic primitives are described by 12484f9f2c5SMitchell Horne.Xr atomic 9 . 12584f9f2c5SMitchell Horne.Pp 12684f9f2c5SMitchell HorneThe 12784f9f2c5SMitchell Horne.Xr epoch 9 12884f9f2c5SMitchell Horneand 12984f9f2c5SMitchell Horne.Xr smr 9 13084f9f2c5SMitchell Hornefacilities are used to create lock-free data structures. 13184f9f2c5SMitchell HorneThere is also 13284f9f2c5SMitchell Horne.Xr seqc 9 . 13384f9f2c5SMitchell Horne.Ss Memory Management 13484f9f2c5SMitchell HorneDynamic memory allocations inside the kernel are generally done using 13584f9f2c5SMitchell Horne.Xr malloc 9 . 13684f9f2c5SMitchell HorneFrequently allocated objects may prefer to use 13784f9f2c5SMitchell Horne.Xr uma 9 . 13884f9f2c5SMitchell Horne.Pp 13984f9f2c5SMitchell Horne.\" MHTODO: It would be useful to have a vm_page(9) or similar 14084f9f2c5SMitchell Horne.\" high-level page which points to the following contents instead. 14184f9f2c5SMitchell HorneMuch of the virtual memory system operates on 14284f9f2c5SMitchell Horne.Vt vm_page_t 14384f9f2c5SMitchell Hornestructures. 14484f9f2c5SMitchell HorneThe following functions are documented: 14584f9f2c5SMitchell Horne.Bd -ragged -offset indent 14684f9f2c5SMitchell Horne.Xr vm_page_advise 9 , 14784f9f2c5SMitchell Horne.Xr vm_page_alloc 9 , 14884f9f2c5SMitchell Horne.Xr vm_page_bits 9 , 14984f9f2c5SMitchell Horne.Xr vm_page_aflag 9 , 15084f9f2c5SMitchell Horne.Xr vm_page_alloc 9 , 15184f9f2c5SMitchell Horne.Xr vm_page_bits 9 , 15284f9f2c5SMitchell Horne.Xr vm_page_busy 9 , 15384f9f2c5SMitchell Horne.Xr vm_page_deactivate 9 , 15484f9f2c5SMitchell Horne.Xr vm_page_free 9 , 15584f9f2c5SMitchell Horne.Xr vm_page_grab 9 , 15684f9f2c5SMitchell Horne.Xr vm_page_insert 9 , 15784f9f2c5SMitchell Horne.Xr vm_page_lookup 9 , 15884f9f2c5SMitchell Horne.Xr vm_page_rename 9 , 15984f9f2c5SMitchell Horne.Xr vm_page_sbusy 9 , 16084f9f2c5SMitchell Horne.Xr vm_page_wire 9 1610786f79cSPoul-Henning Kamp.Ed 1623136363fSRuslan Ermilov.Pp 16384f9f2c5SMitchell HorneVirtual address space maps are managed with the 16484f9f2c5SMitchell Horne.Xr vm_map 9 16584f9f2c5SMitchell HorneAPI. 166aab5e1b6SMike Pritchard.Pp 16784f9f2c5SMitchell HorneThe machine-dependent portion of the virtual memory stack is the 16884f9f2c5SMitchell Horne.Xr pmap 9 16984f9f2c5SMitchell Hornemodule. 170aab5e1b6SMike Pritchard.Pp 17184f9f2c5SMitchell HorneAllocation policies for NUMA memory domains are managed with the 17284f9f2c5SMitchell Horne.Xr domainset 9 17384f9f2c5SMitchell HorneAPI. 17484f9f2c5SMitchell Horne.Ss File Systems 17584f9f2c5SMitchell HorneThe kernel interface for file systems is 17684f9f2c5SMitchell Horne.Xr VFS 9 . 17784f9f2c5SMitchell HorneFile system implementations register themselves with 17884f9f2c5SMitchell Horne.Xr vfsconf 9 . 179aab5e1b6SMike Pritchard.Pp 180*712fd5acSGraham PerrinThe 181*712fd5acSGraham Perrin.Xr vnode 9 182*712fd5acSGraham Perrinis the abstract and filesystem-independent representation of a file, 183*712fd5acSGraham Perrindirectory, or other file-like entity within the kernel. 18484f9f2c5SMitchell Horne.Pp 18584f9f2c5SMitchell HorneThe implementation of access control lists for filesystems is described by 18684f9f2c5SMitchell Horne.Xr acl 9 . 18784f9f2c5SMitchell HorneAlso 18884f9f2c5SMitchell Horne.Xr vaccess 9 . 18984f9f2c5SMitchell Horne.Ss I/O and Storage 19084f9f2c5SMitchell Horne.\" TODO: This page needs to be rewritten before it can be included here. 19184f9f2c5SMitchell Horne.\" The buffer cache is described by: 19284f9f2c5SMitchell Horne.\" .Xr buf 9 19384f9f2c5SMitchell Horne.\" .Pp 19484f9f2c5SMitchell HorneThe GEOM framework represents I/O requests using the 19584f9f2c5SMitchell Horne.Xr bio 9 19684f9f2c5SMitchell Hornestructure. 19784f9f2c5SMitchell Horne.Pp 19884f9f2c5SMitchell HorneDisk drivers connect themselves to GEOM using the 19984f9f2c5SMitchell Horne.Xr disk 9 20084f9f2c5SMitchell HorneAPI. 20184f9f2c5SMitchell Horne.Pp 2020786f79cSPoul-Henning KampThe 20384f9f2c5SMitchell Horne.Xr devstat 9 20484f9f2c5SMitchell Hornefacility provides an interface for recording device statistics in disk drivers. 20584f9f2c5SMitchell Horne.Ss Networking 20684f9f2c5SMitchell HorneMuch of the networking stack uses the 20784f9f2c5SMitchell Horne.Xr mbuf 9 , 20884f9f2c5SMitchell Hornea flexible memory management unit commonly used to store network packets. 20984f9f2c5SMitchell Horne.Pp 21084f9f2c5SMitchell HorneNetwork interfaces are implemented using the 21184f9f2c5SMitchell Horne.Xr ifnet 9 21284f9f2c5SMitchell HorneAPI, which has functions for drivers and consumers. 21384f9f2c5SMitchell Horne.Pp 21484f9f2c5SMitchell HorneA framework for managing packet output queues is described by 21584f9f2c5SMitchell Horne.Xr altq 9 . 21684f9f2c5SMitchell Horne.Pp 21784f9f2c5SMitchell HorneTo receive incoming packets, network protocols register themselves with 21884f9f2c5SMitchell Horne.Xr netisr 9 . 21984f9f2c5SMitchell Horne.Pp 22084f9f2c5SMitchell HorneVirtualization of the network stack is provided by 22184f9f2c5SMitchell Horne.Xr VNET 9 . 22284f9f2c5SMitchell Horne.Pp 22384f9f2c5SMitchell HorneThe front-end for interfacing with network sockets from within the kernel is 22484f9f2c5SMitchell Hornedescribed by 22584f9f2c5SMitchell Horne.Xr socket 9 . 22684f9f2c5SMitchell HorneThe back-end interface for socket implementations is 22784f9f2c5SMitchell Horne.Xr domain 9 . 22884f9f2c5SMitchell Horne.Pp 22984f9f2c5SMitchell HorneThe low-level packet filter interface is described by 23084f9f2c5SMitchell Horne.Xr pfil 9 . 23184f9f2c5SMitchell Horne.Pp 23284f9f2c5SMitchell HorneThe 23384f9f2c5SMitchell Horne.Xr bpf 9 23484f9f2c5SMitchell Horneinterface provides a mechanism to redirect packets to userspace. 23584f9f2c5SMitchell Horne.Pp 23684f9f2c5SMitchell HorneThe subsystem for IEEE 802.11 wireless networking is described by 23784f9f2c5SMitchell Horne.Xr ieee80211 9 . 23884f9f2c5SMitchell Horne.Pp 23984f9f2c5SMitchell HorneA framework for modular TCP implementations is described by 24084f9f2c5SMitchell Horne.Xr tcp_functions 9 . 24184f9f2c5SMitchell Horne.Pp 24284f9f2c5SMitchell HorneA framework for modular congestion control algorithms is described by 24384f9f2c5SMitchell Horne.Xr mod_cc 9 . 24484f9f2c5SMitchell Horne.Ss Device Drivers 24584f9f2c5SMitchell Horne.\" TODO: a bus(9) or newbus(9) page, as well as updates to existing pages 24684f9f2c5SMitchell Horne.\" would be helpful in laying out the high-level concepts of FreeBSD's device 24784f9f2c5SMitchell Horne.\" structure, and explaining the organization of existing documentation. 24884f9f2c5SMitchell HorneConsult the 24984f9f2c5SMitchell Horne.Xr device 9 25084f9f2c5SMitchell Horneand 25184f9f2c5SMitchell Horne.Xr driver 9 25284f9f2c5SMitchell Hornepages first. 25384f9f2c5SMitchell Horne.Pp 25484f9f2c5SMitchell HorneMost drivers act as devices, and provide a set of methods implementing the 25584f9f2c5SMitchell Hornedevice interface. 25684f9f2c5SMitchell HorneThis includes methods such as 25784f9f2c5SMitchell Horne.Xr DEVICE_PROBE 9 , 25884f9f2c5SMitchell Horne.Xr DEVICE_ATTACH 9 , 25984f9f2c5SMitchell Horneand 26084f9f2c5SMitchell Horne.Xr DEVICE_DETACH 9 . 26184f9f2c5SMitchell Horne.Pp 26284f9f2c5SMitchell HorneIn addition to devices, there are buses. 26384f9f2c5SMitchell HorneBuses may have children, in the form of devices or other buses. 26484f9f2c5SMitchell HorneBus drivers will implement additional methods, such as 26584f9f2c5SMitchell Horne.Xr BUS_ADD_CHILD 9 , 26684f9f2c5SMitchell Horne.Xr BUS_READ_IVAR 9 , 26784f9f2c5SMitchell Horneor 26884f9f2c5SMitchell Horne.Xr BUS_RESCAN 9 . 26984f9f2c5SMitchell Horne.Pp 27084f9f2c5SMitchell HorneBuses often perform resource accounting on behalf of their children. 27184f9f2c5SMitchell HorneFor this there is the 27284f9f2c5SMitchell Horne.Xr rman 9 27384f9f2c5SMitchell HorneAPI. 27484f9f2c5SMitchell Horne.Pp 27584f9f2c5SMitchell HorneDrivers can request and manage their resources (e.g. memory-space or IRQ 27684f9f2c5SMitchell Hornenumber) from their parent using the following sets of functions: 27784f9f2c5SMitchell Horne.Bd -ragged -offset indent 27884f9f2c5SMitchell Horne.Xr bus_alloc_resource 9 , 27984f9f2c5SMitchell Horne.Xr bus_adjust_resource 9 , 28084f9f2c5SMitchell Horne.Xr bus_get_resource 9 , 28184f9f2c5SMitchell Horne.Xr bus_map_resource 9 , 28284f9f2c5SMitchell Horne.Xr bus_release_resource 9 , 28384f9f2c5SMitchell Horne.Xr bus_set_resource 9 28484f9f2c5SMitchell Horne.Ed 28584f9f2c5SMitchell Horne.Pp 28684f9f2c5SMitchell HorneDirect Memory Access (DMA) is handled using the 28784f9f2c5SMitchell Horne.Xr busdma 9 28884f9f2c5SMitchell Horneframework. 28984f9f2c5SMitchell Horne.Pp 29084f9f2c5SMitchell HorneFunctions for accessing bus space (i.e. read/write) are provided by 29184f9f2c5SMitchell Horne.Xr bus_space 9 . 29284f9f2c5SMitchell Horne.Ss Clocks and Timekeeping 29384f9f2c5SMitchell HorneThe kernel clock frequency and overall system time model is described by 29484f9f2c5SMitchell Horne.Xr hz 9 . 29584f9f2c5SMitchell Horne.Pp 29684f9f2c5SMitchell HorneA few global time variables, such as system up-time, are described by 29784f9f2c5SMitchell Horne.Xr time 9 . 29884f9f2c5SMitchell Horne.Pp 29984f9f2c5SMitchell HorneRaw CPU cycles are provided by 30084f9f2c5SMitchell Horne.Xr get_cyclecount 9 . 30184f9f2c5SMitchell Horne.Ss Userspace Memory Access 30284f9f2c5SMitchell HorneDirect read/write access of userspace memory from the kernel is not permitted, 30384f9f2c5SMitchell Horneand memory transactions that cross the kernel/user boundary must go through one 30484f9f2c5SMitchell Horneof several interfaces built for this task. 30584f9f2c5SMitchell Horne.Pp 30684f9f2c5SMitchell HorneMost device drivers use the 30784f9f2c5SMitchell Horne.Xr uiomove 9 30884f9f2c5SMitchell Horneset of routines. 30984f9f2c5SMitchell Horne.Pp 31084f9f2c5SMitchell HorneSimpler primitives for reading or writing smaller chunks of memory are 31184f9f2c5SMitchell Hornedescribed by 31284f9f2c5SMitchell Horne.Xr casuword 9 , 31384f9f2c5SMitchell Horne.Xr copy 9 , 31484f9f2c5SMitchell Horne.Xr fetch 9 , 31584f9f2c5SMitchell Horneand 31684f9f2c5SMitchell Horne.Xr store 9 . 31784f9f2c5SMitchell Horne.Ss Kernel Threads, Tasks, and Callbacks 31884f9f2c5SMitchell HorneKernel threads and processes are created using the 31984f9f2c5SMitchell Horne.Xr kthread 9 32084f9f2c5SMitchell Horneand 32184f9f2c5SMitchell Horne.Xr kproc 9 32284f9f2c5SMitchell Horneinterfaces, respectively. 32384f9f2c5SMitchell Horne.Pp 32484f9f2c5SMitchell HorneWhere dedicated kernel threads are too heavyweight, there is also the 32584f9f2c5SMitchell Horne.Xr taskqueue 9 32684f9f2c5SMitchell Horneinterface. 32784f9f2c5SMitchell Horne.Pp 32884f9f2c5SMitchell HorneFor low-latency callback handling, the 32984f9f2c5SMitchell Horne.Xr callout 9 33084f9f2c5SMitchell Horneframework should be used. 33184f9f2c5SMitchell Horne.Pp 33284f9f2c5SMitchell HorneDynamic handlers for pre-defined event hooks are registered and invoked using 33384f9f2c5SMitchell Hornethe 33484f9f2c5SMitchell Horne.Xr EVENTHANDLER 9 33584f9f2c5SMitchell HorneAPI. 33684f9f2c5SMitchell Horne.Ss Thread Switching and Scheduling 33784f9f2c5SMitchell HorneThe machine-independent interface to a context switch is 33884f9f2c5SMitchell Horne.Xr mi_switch 9 . 33984f9f2c5SMitchell Horne.Pp 34084f9f2c5SMitchell HorneTo prevent preemption, use a 34184f9f2c5SMitchell Horne.Xr critical 9 34284f9f2c5SMitchell Hornesection. 34384f9f2c5SMitchell Horne.Pp 34484f9f2c5SMitchell HorneTo voluntarily yield the processor, use 34584f9f2c5SMitchell Horne.Xr kern_yield 9 . 34684f9f2c5SMitchell Horne.Pp 34784f9f2c5SMitchell HorneThe various functions which will deliberately put a thread to sleep are 34884f9f2c5SMitchell Hornedescribed by 34984f9f2c5SMitchell Horne.Xr sleep 9 . 35084f9f2c5SMitchell HorneSleeping threads are removed from the scheduler and placed on a 35184f9f2c5SMitchell Horne.Xr sleepqueue 9 . 35284f9f2c5SMitchell Horne.\" TODO: This page is outdated and can't be included here yet. 35384f9f2c5SMitchell Horne.\".Pp 35484f9f2c5SMitchell Horne.\"The thread scheduler interface is described by 35584f9f2c5SMitchell Horne.\".Xr scheduler 9 . 35684f9f2c5SMitchell Horne.Ss Processes and Signals 35784f9f2c5SMitchell HorneTo locate a process or process group by its identifier, use 35884f9f2c5SMitchell Horne.Xr pfind 9 35984f9f2c5SMitchell Horneand 36084f9f2c5SMitchell Horne.Xr pgfind 9 . 36184f9f2c5SMitchell HorneAlternatively, the 36284f9f2c5SMitchell Horne.Xr pget 9 36384f9f2c5SMitchell Hornefunction provides additional search specificity. 36484f9f2c5SMitchell Horne.Pp 36584f9f2c5SMitchell HorneThe "hold count" of a process can be manipulated with 36684f9f2c5SMitchell Horne.Xr PHOLD 9 . 36784f9f2c5SMitchell Horne.Pp 36884f9f2c5SMitchell HorneThe kernel interface for signals is described by 36984f9f2c5SMitchell Horne.Xr signal 9 . 37084f9f2c5SMitchell Horne.Pp 37184f9f2c5SMitchell HorneSignals can be sent to processes or process groups using the functions 37284f9f2c5SMitchell Hornedescribed by 37384f9f2c5SMitchell Horne.Xr psignal 9 . 37484f9f2c5SMitchell Horne.Ss Security 375*712fd5acSGraham PerrinSee the overview in 37684f9f2c5SMitchell Horne.Xr security 7 . 37784f9f2c5SMitchell Horne.Pp 37884f9f2c5SMitchell HorneThe basic structure for user credentials is 37984f9f2c5SMitchell Horne.Vt struct ucred , 38084f9f2c5SMitchell Hornemanaged by the 38184f9f2c5SMitchell Horne.Xr ucred 9 38284f9f2c5SMitchell HorneAPI. 38384f9f2c5SMitchell HorneThread credentials are verified using 38484f9f2c5SMitchell Horne.Xr priv 9 38584f9f2c5SMitchell Horneto allow or deny certain privileged actions. 38684f9f2c5SMitchell Horne.Pp 38784f9f2c5SMitchell HornePolicies influenced by 38884f9f2c5SMitchell Horne.Va kern.securelevel 38984f9f2c5SMitchell Hornemust use the 39084f9f2c5SMitchell Horne.Xr securelevel_gt 9 39184f9f2c5SMitchell Horneor 39284f9f2c5SMitchell Horne.Xr securelevel_ge 9 39384f9f2c5SMitchell Hornefunctions. 39484f9f2c5SMitchell Horne.Pp 39584f9f2c5SMitchell HorneThe Mandatory Access Control (MAC) framework provides a wide set of hooks, 39684f9f2c5SMitchell Hornesupporting dynamically-registered security modules; 39784f9f2c5SMitchell Hornesee 39884f9f2c5SMitchell Horne.Xr mac 9 . 39984f9f2c5SMitchell Horne.Pp 40084f9f2c5SMitchell HorneCryptographic services are provided by the OpenCrypto framework. 401*712fd5acSGraham PerrinThis API provides an interface for both consumers and crypto drivers; 40284f9f2c5SMitchell Hornesee 40384f9f2c5SMitchell Horne.Xr crypto 9 . 40484f9f2c5SMitchell Horne.Pp 40584f9f2c5SMitchell HorneFor information on random number generation, see 40684f9f2c5SMitchell Horne.Xr random 9 40784f9f2c5SMitchell Horneand 40884f9f2c5SMitchell Horne.Xr prng 9 . 40984f9f2c5SMitchell Horne.Ss Kernel Modules 41084f9f2c5SMitchell HorneThe interfaces for declaring loadable kernel modules are described by 41184f9f2c5SMitchell Horne.Xr module 9 . 41284f9f2c5SMitchell Horne.Ss Interrupts 413*712fd5acSGraham Perrin.Xr intr_event 9 414*712fd5acSGraham Perrindescribes the machine-independent portion of the interrupt framework 415*712fd5acSGraham Perrinthat supports registration and execution of interrupt handlers. 41684f9f2c5SMitchell Horne.Pp 41784f9f2c5SMitchell HorneSoftware interrupts are provided by 41884f9f2c5SMitchell Horne.Xr swi 9 . 41984f9f2c5SMitchell Horne.Pp 42084f9f2c5SMitchell HorneDevice drivers register their interrupt handlers using the 42184f9f2c5SMitchell Horne.Xr bus_setup_intr 9 42284f9f2c5SMitchell Hornefunction. 42384f9f2c5SMitchell Horne.Ss Testing and Debugging Tools 42484f9f2c5SMitchell HorneA kernel test framework: 42584f9f2c5SMitchell Horne.Xr kern_testfrwk 9 42684f9f2c5SMitchell Horne.Pp 42784f9f2c5SMitchell HorneA facility for defining configurable fail points is described by 42884f9f2c5SMitchell Horne.Xr fail 9 . 42984f9f2c5SMitchell Horne.Pp 43084f9f2c5SMitchell HorneCommands for the 43184f9f2c5SMitchell Horne.Xr ddb 4 43284f9f2c5SMitchell Hornekernel debugger are defined with the 43384f9f2c5SMitchell Horne.Xr DB_COMMAND 9 43484f9f2c5SMitchell Hornefamily of macros. 43584f9f2c5SMitchell Horne.Pp 43684f9f2c5SMitchell HorneThe 43784f9f2c5SMitchell Horne.Xr ktr 4 43884f9f2c5SMitchell Hornetracing facility adds static tracepoints to many areas of the kernel. 43984f9f2c5SMitchell HorneThese tracepoints are defined using the macros described by 44084f9f2c5SMitchell Horne.Xr ktr 9 . 44184f9f2c5SMitchell Horne.Pp 44284f9f2c5SMitchell HorneStatic probes for DTrace are defined using the 44384f9f2c5SMitchell Horne.Xr SDT 9 44484f9f2c5SMitchell Hornemacros. 44584f9f2c5SMitchell Horne.Pp 44684f9f2c5SMitchell HorneStack traces can be captured and printed with the 44784f9f2c5SMitchell Horne.Xr stack 9 44884f9f2c5SMitchell HorneAPI. 44984f9f2c5SMitchell Horne.Pp 45084f9f2c5SMitchell HorneKernel sanitizers can perform additional compiler-assisted checks against 45184f9f2c5SMitchell Hornememory use/access. 45284f9f2c5SMitchell HorneThese runtimes are capable of detecting difficult-to-identify classes of bugs, 45384f9f2c5SMitchell Horneat the cost of a large overhead. 454*712fd5acSGraham PerrinThe Kernel Address Sanitizer 455*712fd5acSGraham Perrin.Xr KASAN 9 456*712fd5acSGraham Perrinand Kernel Memory Sanitizer 457*712fd5acSGraham Perrin.Xr KMSAN 9 458*712fd5acSGraham Perrinare supported. 45984f9f2c5SMitchell Horne.Pp 46084f9f2c5SMitchell HorneThe 461*712fd5acSGraham Perrin.Xr LOCK_PROFILING 9 46284f9f2c5SMitchell Hornekernel config option enables extra code to assist with profiling and/or 463*712fd5acSGraham Perrindebugging lock performance. 46484f9f2c5SMitchell Horne.Ss Driver Tools 46584f9f2c5SMitchell HorneDefined functions/APIs for specific types of devices. 46684f9f2c5SMitchell Horne.Bl -tag -width "Xr usbdi 9" 46784f9f2c5SMitchell Horne.It Xr iflib 9 46884f9f2c5SMitchell HorneProgramming interface for 46984f9f2c5SMitchell Horne.Xr iflib 4 47084f9f2c5SMitchell Hornebased network drivers. 47184f9f2c5SMitchell Horne.It Xr pci 9 47284f9f2c5SMitchell HornePeripheral Component Interconnect (PCI) and PCI Express (PCIe) programming API. 47384f9f2c5SMitchell Horne.It Xr pwmbus 9 47484f9f2c5SMitchell HornePulse-Width Modulation (PWM) bus interface methods. 47584f9f2c5SMitchell Horne.It Xr usbdi 9 47684f9f2c5SMitchell HorneUniversal Serial Bus programming interface. 47784f9f2c5SMitchell Horne.It Xr superio 9 47884f9f2c5SMitchell HorneFunctions for Super I/O controller devices. 47984f9f2c5SMitchell Horne.El 48084f9f2c5SMitchell Horne.Ss Miscellaneous 48184f9f2c5SMitchell HorneDynamic per-CPU variables: 48284f9f2c5SMitchell Horne.Xr dpcpu 9 . 48384f9f2c5SMitchell Horne.Pp 48484f9f2c5SMitchell HorneCPU bitmap management: 48584f9f2c5SMitchell Horne.Xr cpuset 9 . 48684f9f2c5SMitchell Horne.Pp 48784f9f2c5SMitchell HorneKernel environment management: 48884f9f2c5SMitchell Horne.Xr getenv 9 . 48984f9f2c5SMitchell Horne.Pp 49084f9f2c5SMitchell HorneContexts for CPU floating-point registers are managed by the 49184f9f2c5SMitchell Horne.Xr fpu_kern 9 49284f9f2c5SMitchell Hornefacility. 49384f9f2c5SMitchell Horne.Pp 49484f9f2c5SMitchell HorneFor details on the shutdown/reboot procedure and available shutdown hooks, see 49584f9f2c5SMitchell Horne.Xr reboot 9 . 49684f9f2c5SMitchell Horne.Pp 49784f9f2c5SMitchell HorneA facility for asynchronous logging to files from within the kernel is provided 49884f9f2c5SMitchell Horneby 49984f9f2c5SMitchell Horne.Xr alq 9 . 50084f9f2c5SMitchell Horne.Pp 50184f9f2c5SMitchell HorneThe 50284f9f2c5SMitchell Horne.Xr osd 9 50384f9f2c5SMitchell Horneframework provides a mechanism to dynamically extend core structures in a way 50484f9f2c5SMitchell Hornethat preserves KBI. 50584f9f2c5SMitchell HorneSee the 50684f9f2c5SMitchell Horne.Xr hhook 9 50784f9f2c5SMitchell Horneand 50884f9f2c5SMitchell Horne.Xr khelp 9 50984f9f2c5SMitchell HorneAPIs for information on how this is used. 51084f9f2c5SMitchell Horne.Pp 51184f9f2c5SMitchell HorneThe kernel object implementation is described by 51284f9f2c5SMitchell Horne.Xr kobj 9 . 51384f9f2c5SMitchell Horne.Sh SEE ALSO 51484f9f2c5SMitchell Horne.Xr man 1 , 51584f9f2c5SMitchell Horne.Xr style 9 51684f9f2c5SMitchell Horne.Rs 517*712fd5acSGraham Perrin.%T The FreeBSD Architecture Handbook 518*712fd5acSGraham Perrin.%U https://docs.freebsd.org/en/books/arch-handbook/ 51984f9f2c5SMitchell Horne.Re 520