12.2. Prepare the User-Mode Source Code

  1. Isolate the functions you need to move into the Kernel PlugIn.
  2. Remove any platform-specific code from the functions. Use only functions that can also be used from the kernel.
  3. Recompile your driver in the user mode.
  4. Debug your driver in user mode again to see that your code still works after changes have been made.
  • Keep in mind that the kernel stack is relatively limited in size. Therefore, code that will be moved into the Kernel PlugIn should not contain static memory allocations. Use the malloc() function to allocate memory dynamically instead. This is especially important for large data structures.
  • If the user-mode code that you are porting to the kernel accesses memory addresses directly using the user-mode mapping of the physical address returned from the low-level WD_CardRegister() function — note that in the kernel you will need to use the kernel mapping of the physical address instead (the kernel mapping is also returned by WD_CardRegister()). For details, refer to the description of WD_CardRegister() in the WinDriver PCI Low-Level API Reference.
    When using the API of the WDC library [B.2] to access memory, you do not need to worry about this, since this API ensures that the correct mapping of the memory is used depending on whether the relevant APIs are used from the user mode or from the kernel mode.