13.3  Mac OS X Dynamic Driver Loading

13.3.1  Dynamically Loading Your Driver on Mac OS X

Normally, to load a driver kernel extension dynamically on Mac OS X, you need to use the OS's kextload utility, as super user (root), and point the utility to the location of the kernel extension folder. The entire path to the kernel extension folder must be owned by root:wheel, with permissions non-writable by group and other – rwxr-xr-x (755).
One way to ensure the necessary permissions, is to copy the driver's kernel extension folder, as super user, to the /tmp folder.
To reload the driver automatically on each boot, the kernel extension folder should be copied to the OS's kernel extensions folder: /System/Library/Extensions. (Note: On some Mac OS X platforms, the act of copying the kernel extension folder to the /System/Library/Extensions folder also loads the driver, in which case running kextload will result in a message indicating that the driver is already loaded.)

13.3.1.1  The wdreg Script

WinDriver's wdreg installation script simplifies the dynamic driver loading procedure on Mac OS X.
wdreg receives a path to a kernel extension folder; if it locates the extension folder in the specified search path, it copies the extension to the OS's /tmp folder in order to ensure the proper permissions, and then uses the OS's kextload utility to load the driver; if the extension folder is not found in the search path, wdreg searches for the extension in the OS's kernel extensions folder – /System/Library/Extensions – and if a matching extension is found, it is installed from this location.

[Note]
  • wdreg is provided in the WinDriver/redist directory.
  • Since driver installation requires root privileges, you must run wdreg as super user.
  • When using wdreg, the name of the kernel extension folder may be specified with or without the .kext suffix. For example, WinDriver.kext and WinDriver are equally valid ways of pointing to WinDriver's WinDriver.kext kernel extension folder, using wdreg.

To dynamically load a driver using wdreg, run the following command:
sudo <path to wdreg> <path to the driver's kext folder>

As indicated above, if the kernel extension folder is found in the OS's /System/Library/Extensions folder, you may omit the path to the extension folder. For example, to dynamically load the WinDriver kernel extension, which has been copied to the /System/Library/Extensions folder (as done automatically as part of the WinDriver toolkit installation), run this command:
sudo <path to wdreg> WinDriver

13.3.2  Dynamically Unoading Your Driver on Mac OS X

To unload a driver dynamically on Mac OS X, you need to run the OS's kextunload utility, and provide it with the path to the driver's kernel extension folder:
sudo kextunload <path to the driver's kext folder>

[Note]
  • kextunload must be run with root privileges.
  • You must provide kextunload with the full path to the kernel extension folder, and provide the full extension name – including the .kext suffix.

For example, to unload the WinDriver kernel extension, which has been copied to the /System/Library/Extensions folder, run the following command:
sudo kextunload /System/Library/Extensions/WinDriver.kext