|
|
< Previous PageNext Page > |
One of the most common problems faced when programming in the kernel is use of “standard” functions—things like printf
or bcopy
. Many commonly used standard C library functions are implemented in the kernel. In order to use them, however, you need to include the appropriate prototypes, which may be different from the user space prototypes for those functions, and which generally have different names when included from kernel code.
In general, any non–I/O Kit header that you can safely include in the kernel is located in xnu/bsd/sys
or xnu/osfmk/mach
, although there are a few specialized headers in other places like libkern
and libsa
. Normal headers (those in /usr/include
) cannot be used in the kernel.
Important: If you are writing an I/O Kit KEXT, most of these functions are not what you are looking for. The I/O Kit provides its own APIs for these features, including IOLog
, IOMemoryDescriptor
, and IOLock
. While using the lower-level functionality is not expressly forbidden, it is generally discouraged (though printf
is always fine). For more information about APIs available to I/O Kit KEXTs, see Kernel Framework Reference.
Table 6-1 lists some commonly used C functions, variables, and types, and gives the location of their prototypes.
Function name |
Header path |
---|---|
|
|
Buffer cache functions ( |
|
Directory entries |
|
Error numbers |
|
Kernel special variables |
|
Spinlocks |
|
|
|
Queues |
|
Random number generator |
|
|
|
|
|
Various time functions |
|
Standard type declarations |
|
User credentials |
|
OS and system information |
|
If the standard C function you are trying to use is not in one of these files, chances are the function is not supported for use within the kernel, and you need to implement your code in another way.
The symbols in these header files are divided among multiple symbol sets, depending on the technology area where they were designed to be used. To use these, you may have to declare dependencies on any of the following:
com.apple.kernel
—You should generally avoid this.
com.apple.kernel.bsd
—BSD portions of the kernel.
com.apple.kernel.iokit
—The I/O Kit.
com.apple.kernel.libkern
—General-purpose functions.
com.apple.kernel.mach
—Mach-specific APIs.
com.apple.kpi.bsd
—BSD portions of the kernel (v10.4 and later).
com.apple.kernel.iokit
—The I/O Kit (v10.4 and later).
com.apple.kernel.libkern
—General-purpose functions (v10.4 and later).
com.apple.kernel.mach
—Mach-specific APIs (v10.4 and later).
com.apple.kpi.unsupported
—Unsupported legacy functionality (v10.4 and later).
Where possible, you should specify a dependency on the KPI version of these symbols. However, these symbols are only available in v10.4 and later. For the I/O Kit and libkern, this should make little difference. For other areas, such as network kernel extensions or file system KEXTs, you must use the KPI versions if you want your extension to load in Mac OS X v10.4 and later.
For a complete list of symbols in any of these dependencies, run nm(1)
on the binaries in /System/Library/Extensions/System.kext/PlugIns
.
< Previous PageNext Page > |
Last updated: 2006-11-07
|
Get information on Apple products.
Visit the Apple Store online or at retail locations. 1-800-MY-APPLE Copyright © 2007 Apple Inc. All rights reserved. | Terms of use | Privacy Notice |