Kernel Programming Guide
PDF
About This Document
Who Should Read This Document
Road Map
Other Apple Publications
Mach API Reference
Information on the Web
Keep Out
Why You Should Avoid Programming in the Kernel
Kernel Architecture Overview
Darwin
Architecture
Mach
BSD
Networking
File Systems
I/O Kit
Kernel Extensions
Security Considerations
Security Implications of Paging
Buffer Overflows and Invalid Input
User Credentials
Basic User Credentials
Access Control Lists
Remote Authentication
One-Time Pads
Time-based authentication
Temporary Files
/dev/mem and /dev/kmem
Key-based Authentication and Encryption
Public Key Weaknesses
Trust Models
Sensitivity to Patterns and Short Messages
Using Public Keys for Message Exchange
Using Public Keys for Identity Verification
Using Public Keys for Data Integrity Checking
Encryption Summary
Console Debugging
Code Passing
Performance Considerations
Interrupt Latency
Locking Bottlenecks
Working With Highly Contended Locks
Reducing Contention by Decreasing Granularity
Code Profiling
Using Counters for Code Profiling
Lock Profiling
Kernel Programming Style
C++ Naming Conventions
Basic Conventions
Additional Guidelines
Standard C Naming Conventions
Commonly Used Functions
Performance and Stability Tips
Performance and Stability Tips
Stability Tips
Style Summary
Mach Overview
Mach Kernel Abstractions
Tasks and Threads
Ports, Port Rights, Port Sets, and Port Namespaces
Memory Management
Interprocess Communication (IPC)
IPC Transactions and Event Dispatching
Message Queues
Semaphores
Notifications
Locks
Remote Procedure Call (RPC) Objects
Time Management
Memory and Virtual Memory
Mac OS X VM Overview
Memory Maps Explained
Named Entries
Universal Page Lists (UPLs)
Using Mach Memory Maps
Other VM and VM-Related Subsystems
Pagers
Working Set Detection Subsystem
VM Shared Memory Server Subsystem
Address Spaces
Background Info on PCI Address Translation
IOMemoryDescriptor Changes
VM System and pmap Changes:
Kernel Dependency Changes
Summary
Allocating Memory in the Kernel
Allocating Memory Using Mach Routines
Allocating Memory From the I/O Kit
Mach Scheduling and Thread Interfaces
Overview of Scheduling
Why Did My Thread Priority Change?
Using Mach Scheduling From User Applications
Using the pthreads API to Influence Scheduling
Using the Mach Thread API to Influence Scheduling
Using the Mach Task API to Influence Scheduling
Kernel Thread APIs
Creating and Destroying Kernel Threads
SPL and Friends
Wait Queues and Wait Primitives
Bootstrap Contexts
How Contexts Affect Users
How Contexts Affect Developers
I/O Kit Overview
Redesigning the I/O Model
I/O Kit Architecture
Families
Drivers
Nubs
Connection Example
For More Information
BSD Overview
BSD Facilities
Differences between Mac OS X and BSD
For Further Reading
File Systems Overview
Working With the File System
VFS Transition
Network Architecture
Boundary Crossings
Security Considerations
Choosing a Boundary Crossing Method
Kernel Subsystems
Bandwidth and Latency
Mach Messaging and Mach Interprocess Communication (IPC)
Using Well-Defined Ports
Remote Procedure Calls (RPC)
Calling RPC From User Applications
BSD syscall API
BSD ioctl API
BSD sysctl API
General Information on Adding a sysctl
Adding a sysctl Procedure Call
Registering a New Top Level sysctl
Adding a Simple sysctl
Calling a sysctl From User Space
The sysctlbyname System Call
The sysctl System Call
Memory Mapping and Block Copying
Summary
Synchronization Primitives
Semaphores
Condition Variables
Locks
Spinlocks
Mutexes
Read-Write Locks
Spin/Sleep Locks
Using Lock Functions
Miscellaneous Kernel Services
Using Kernel Time Abstractions
Obtaining Time Information
Event and Timer Waits
Using IODelay and IOSleep
Using Mach Absolute Time Functions
Using msleep
Handling Version Dependencies
Boot Option Handling
Queues
Installing Shutdown Hooks
Kernel Extension Overview
Implementation of a Kernel Extension (KEXT)
Kernel Extension Dependencies
Building and Testing Your Extension
Debugging Your KEXT
Installed KEXTs
Building and Debugging Kernels
Adding New Files or Modules
Modifying the Configuration Files
Adding the Files or Modules
Enabling Module Options
Modifying the Source Code Files
Building Your First Kernel
Building an Alternate Kernel Configuration
When Things Go Wrong: Debugging the Kernel
Setting Debug Flags in Open Firmware
Avoiding Watchdog Timer Problems
Choosing a Debugger
Using gdb for Kernel Debugging
Special gdb I/O Addressing Issues
Using ddb for Kernel Debugging
Commands and Syntax of ddb
Revision History
Bibliography
Apple Mac OS X Publications
General UNIX and Open Source Resources
BSD and UNIX Internals
Mach
Networking
Operating Systems
POSIX
Programming
Websites and Online Resources
Security and Cryptography
Glossary
Index