The COPY_TO_USER_OR_KERNEL and COPY_FROM_USER_OR_KERNEL macros are used for copying data (when necessary) to/from user-mode memory addresses (respectively), when accessing such addresses from within the Kernel PlugIn. Copying the data ensures that the user-mode address can be used correctly, even if the context of the user-mode process changes in the midst of the I/O operation. This is particularly relevant for long operations, during which the context of the user-mode process might change. The use of macros to perform the copy provides a generic cross-platform solution for all supported operating systems.

Note that if you wish to access the user-mode data from within theKP_IntAtIrql or KP_IntAtDpc functions, you should copy the data into a Kernel PlugIn variable before the execution of these routines.

The COPY_TO_USER_OR_KERNEL and COPY_FROM_USER_OR_KERNEL macros are defined in the WinDriver/include/kpstdlib.h header file.

For an example of using the COPY_TO_USER_OR_KERNEL macro, see the implementation of the KP_Call() function in the generated DriverWizard Kernel PlugIn code (see kp_xxx.c) and in WinDriver’s Kernel PlugIn sample (KP_PCI (v7.0.0+) —WinDriver/samples/pci_diag/kp_pci/kp_pci.c / KP_TEST (v6.2.3-) —WinDriver/kerplug/kermode/kptest.c).

To share a data buffer between the user-mode and Kernel PlugIn routines (e.g., KpIntAtIrql and KpIntAtDpc), consider using the technique outlined in Technical Document #41.