The I/O Kit is a collection of system frameworks, libraries, tools, and other resources for creating device drivers in OS X. It is based on an object-oriented programming model implemented in a restricted form of C++ that omits features unsuitable for use within a multithreaded kernel. By modeling the hardware connected to an OS X system and abstracting common functionality for devices in particular categories, the I/O Kit streamlines the process of device-driver development.
- WELCOME TO MAC'S. We provide quality products and great customer service to the Midwest. MAC'S has been proudly serving farm, home, and industry for over 50 years. Today, we have stores throughout MN, ND and SD, and a Corporate Office and Distribution Center in Moorhead, MN.
- May 30, 2018 Your computer consists of both hardware and software and a number of things can go wrong. In this 2-part series, we’ll take a look at how to check your Mac’s hardware and software to verify your system is in good shape or if certain components are failing.
- CUDA Mac Driver Latest Version: CUDA 418.163 driver for MAC Release Date: Previous Releases: CUDA 418.105 driver for MAC Release Date: CUDA 410.130 driver for MAC Release Date: CUDA 396.148 driver for MAC Release Date: CUDA 396.64 driver for MAC Release Date: CUDA 387.178 driver for MAC.
This chapter talks about the inherent capabilities of the I/O Kit (and of the drivers developed with it), about the decisions informing its design, and about the I/O Kit when considered as a product. It also offers some caveats and guidelines for those considering developing kernel software such as device drivers.
Before You Begin
May 22, 2018 We recommend you get your drivers straight from the hardware manufacturer’s official websites. Skip the scammy “driver downloader” apps you may see online. Here’s a list of the official places to get drivers: Acer provides drivers for its Aspire, Predator, TravelMate, and other PCs, as well as various Acer-made accessories.
You might have developed device drivers for other platforms—Mac OS 9, perhaps, or BSD or another flavor of UNIX. One thing you’ll discover reading this document is how different the approach is with the I/O Kit. Although writing drivers for OS X requires new ways of thinking and different ways of programming, you are amply rewarded for shifting to this new approach. The I/O Kit simplifies driver development and supports many categories of devices. Once you get the basics of the I/O Kit down, you’ll find it a relatively easy and efficient matter to create device drivers.
Before you attempt driver development with the I/O Kit, Apple highly recommends certain prerequisites. Because the framework uses an object-oriented programming model, which is implemented in a restricted subset of C++, it helps to know C++ or object-oriented concepts in general. Also, device drivers are not the same thing as applications because, being kernel-resident, they must abide by more restrictive rules. Knowledge of kernel programming is therefore very useful.
Indeed, programming in the kernel is discouraged except when it is absolutely necessary. Many alternatives for communicating with hardware and networks exist at higher levels of the system, including the “device interface” feature of the I/O Kit described in Controlling Devices From Outside the Kernel See Should You Program in the Kernel? for more on alternatives to kernel programming.
I/O Kit Features
From its inception, the fundamental goal for the I/O Kit has been to accommodate and augment native features and capabilities of OS X, particularly those of the kernel environment. As the driver model for OS X, the I/O Kit supports the following features:
Dynamic and automatic device configuration (plug-and-play)
Many new types of devices, including graphics acceleration and multimedia devices
Power management (for example, “sleep” mode)
The kernel’s enforcement of protected memory—separate address spaces for kernel and user programs
Preemptive multitasking
Symmetric multiprocessing
Common abstractions shared between types of devices
Enhanced development experience—new drivers should be easy to write
The I/O Kit supports these kernel features with its new model for device drivers and adds some additional features:
An object-oriented framework implementing common behavior shared among all drivers and types (families) of drivers
Many families for developers to build upon
Threading, communication, and>
Using Static Constructors in an I/O Kit Driver
In OS X v10.4, GCC 4.0 is the default compiler for all new projects, including I/O Kit drivers. This section describes a particular difference between GCC 3.3 and GCC 4.0 that may affect the compatibility of your in-kernel driver between OS X v10.3.x and OS X v10.4.x. For more information on the differences between GCC 3.3 (the default compiler in OS X v10.3) and GCC 4.0, including porting guidance, see GCC Porting Guide.
If you perform static construction within a function in a C++ I/O Kit driver (or other KEXT) compiled with GCC 3.3 or earlier, be aware that the same KEXT compiled with GCC 4.0 will no longer load successfully. This is because GCC 4.0 is more strict about taking and releasing locks in the kernel environment. If you perform in-function static construction in your I/O Kit driver compiled with GCC 4.0, you will probably see the following error when you try to load it:
The solution to this problem is simple: move the static constructor to a global namespace. For example, suppose that your I/O Kit driver includes an in-function static construction, such as in the code shown below:
Hardware Drivers For Mac Windows 7
You can avoid loading errors by changing this code to avoid in-function static construction, as in the code shown below:
Note that you may be able to avoid the load errors associated with in-function static construction without changing your code if you compile your KEXT with GCC 4.0 using the -fno-threadsafe-statics
compiler option, but this may lead to other problems. Specifically, unless you can guarantee thread safety in other ways, compiling your KEXT with this option may break your code.
The Parts of the I/O Kit
Physically and electronically, the I/O Kit is composed of many parts: frameworks and libraries, development and testing tools, and informational resources such as example projects, documentation, and header files. This section catalogs these parts and indicates where they are installed and how they can be accessed.
Frameworks and Libraries
The I/O Kit is based on three C++ libraries. All of them are packaged in frameworks, but only IOKit.framework
is a true framework. The Kernel framework exists primarily to expose kernel header files, including those of libkern and IOKit. The code of these “libraries” is actually built into the kernel; however, drivers (when loaded) do link against the kernel as if it were a library.
Framework or library | Description and location |
---|---|
Kernel/IOKit | The library used for developing kernel-resident device drivers. Headers location: |
Kernel/libkern | The library containing classes useful for all development of kernel software. Headers location: |
IOKit | The framework used for developing device interfaces. Location: |
Applications and Tools
You use a handful of development applications to build, manage, debug, examine, and package device drivers. Table 1-2 lists the applications used in driver development; these applications are installed in /Developer/Applications
.
Mac Hardware Info
Application | Description |
---|---|
Xcode | The primary development application for OS X. Xcode manages projects, provides a full-featured code editor, builds projects according to arbitrarily complex rules, provides a user interface for software configuration, and acts as a front end for debugging and documentation searches. |
I/O Registry Explorer | Enables the graphical exploration of the contents and structure of the I/O Registry. |
Package Maker | Creates an installation package for the Installer application; used for deployment of kernel extensions (including device drivers). |
Table 1-3 describes the command-line tools used in developing device drivers with the I/O Kit; all tools are located in /usr/sbin/
or /sbin
.
Note: You can view on-line documentation of these tools (called man pages in the UNIX world) by entering a command in the shell provided by the Terminal application. The command is man
, and the main argument to the man
command is the name of the tool for which you want to see documentation. For example, to see the man page for the kextload
tool, enter the following line in Terminal:
man kextload
Tool | Description and location |
---|---|
| Prints the contents of the I/O Registry (a command-line version of the I/O Registry Explorer application). |
| Loads a kernel extension (such as device driver) or generates a statically linked symbol file for remote debugging. |
| Unloads a kernel extension (if possible). |
| Prints statistics about currently loaded drivers and other kernel extensions. |
| Displays kernel I/O statistics on terminal, disk, and CPU operations. |
| Displays instance count of a specified class. |
| Displays some accounting of memory allocated by I/O Kit objects in the kernel. |
| Compresses and archives kernel extensions (including drivers) so they can be automatically loaded into the kernel at boot time. |
| Apple’s version of the GNU C++ compiler; Xcode automatically invokes it with the correct set of flags for I/O Kit projects. |
| Apple’s version of the GNU debugger; Xcode automatically invokes it with the correct set of flags for I/O Kit projects. |
Other I/O Kit Resources
Several informational resources are included with the I/O Kit “product,” particularly documentation and header files. Some of these resources are described in the preceding chapter, Introduction to I/O Kit Fundamentals
The I/O Kit is part of the Darwin Open Source project. Apple maintains a website where you can find much information related to the I/O Kit and other Open Source projects managed by Apple. The following two locations are of particular interest:
Open Source Projects—http://developer.apple.com/darwin/projects/
Here you can find links to the Darwin and Darwin Streaming projects, among other projects. Also featured are links to documentation and tools.
Mailing lists—http://developer.apple.com/darwin/mail.html
This page features links that will put you on the Darwin-Development and DarwinOS-Users mailing lists, among others.
Should You Program in the Kernel?
If you are thinking of writing code for the kernel environment, think carefully. Programming in the kernel can be a difficult and dangerous task. And often there is a way to accomplish what you want to do without touching the kernel.
Software that resides in the kernel tends to be expensive. Kernel code is “wired” into physical memory and thus cannot be paged out by the virtual memory system. As more code is put into the kernel, less physical memory is available to user-space processes. Consequently, paging activity will probably intensify, thereby degrading system performance.
Kernel code is also inherently destabilizing, much more so than application code. The kernel environment is a single process, and this means that there is no memory protection between your driver and anything else in the kernel. Access memory in the wrong place and the entire system can grind to a halt, a victim of a kernel panic.
Mac Driver 10
Moreover, because kernel code usually provides services to numerous user-space clients, any inefficiencies in the code can be propagated to those clients, thereby affecting the system globally.
Finally, kernel software is a real pain to write. There are subtleties to grapple with that are unknown in the realm of application development. And bugs in kernel code are harder to find than in user-space software.
With all this in mind, the message is clear. It is in everyone's best interest to put as little code as possible into the kernel. And any code that ends up in the kernel should be honed and rigorously tested.
When Code Should Reside in the Kernel
A handful of situations warrant loading a driver or extension into the kernel environment:
The software is used by the kernel environment itself.
User-space programs will frequently use the software.
The software needs to respond directly to primary interrupts (those delivered by the CPU's interrupt controller).
If the software you are writing does not match any of these criteria, it probably doesn’t belong in the kernel. If your software is a driver for a disk, a network controller, or a keyboard, it should reside in the kernel. If it is an extension to the file system, it should live in the kernel. If, on the other hand, it is used only now and then by a single user-space program, it should be loaded by the program and reside within it. Drivers for printers and scanners fall into this latter category.
Alternatives to Kernel-Resident Code
Apple provides a number of technologies that might let you accomplish what you want to do and stay out of the kernel. First are the higher-level APIs that give you some hardware-level access. For example, Open Transport is a powerful resource for many networking capabilities, and Quartz Compositor enables you to do some fairly low-level things with the graphics subsystem.
Second, and just as important, is the device-interface technology of the I/O Kit framework. Through a plug-in architecture, this technology makes it possible for your application to interact with the kernel to access hardware. In addition, you can—with a little help from the I/O Kit—use POSIX APIs to access serial, storage, or network devices. See Controlling Devices From Outside the Kernel for a summary of device interfaces and see the documentAccessing Hardware From Applications for a full discussion of this technology.
Note: Objective-C does not provide device-level I/O services. However, in your Cocoa application, you can call the C APIs for device-level functionality that the I/O Kit and BSD provide. Note that you can view the man pages that document BSD and POSIX functions and tools at OS X Man Pages.
Copyright © 2001, 2014 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2014-04-09