Re: Device Driver that uploads it's own code?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



respect privacy wrote:
I'm a newbie to Device Driver development so this may be an off-the-wall question:

Is it possible to have only the outer skeleton of a device driver, where the inner code logic is uploaded at runtime from the users own application that uses the driver?

Yes, but this is hardly trivial. Worse, such a design would be badly flawed since it would give user mode code full access to the kernel, which is exactly what the separation between user mode and kernel mode is supposed to prevent. If your user-mode components have a vulnerability, this can be exploited by a third party to get kernel-mode access, which is game over. Even a simple bug in your user-mode application can crash the whole system. In short: don't do that.

I'd like to give UserMode applications full control/configuration and runtime alteration of the driver's behavior. For example, if the driver must deal with complicated timing and sequencing issues on real-time in/out data streams, and those issues are not know until runtime or might even change during the application's runtime, how else can that be coped with?

By having the driver do its own timing and adjustment, just like many parts of the Windows kernel do? How would a user-mode application be of any help here? If a kernel-mode component couldn't handle "real-time in/out data streams", a user-mode component certainly couldn't.

You can have a user-mode component tune a driver, but the communication should be indirect: the user-mode component can, for example, set registry values that the kernel-mode component would read and act on. Obviously, the kernel-mode component has to verify any such parameters thoroughly and have sensible defaults to fall back on.

Seem impractical to have a library of 1,000's of slightly different
device drivers and always be unloading reloading different drivers to
accommodate different functionality that changes on-the-fly. Or to have a
mega-driver with millions of different code branches to account for all
possible combinations.

Software is highly nonlinear. A few branches can produce exponentially more reachable state. I highly doubt you've got a problem with flexibility. Even if you do, the separation between kernel-mode and user-mode curtails flexibility in trade for stability. Don't be too eager to trade it away.

Maybe this is what is meant by UserMode driver?

No. A user-mode driver is what the name implies: a driver that runs in user mode, and has no separate kernel component of its own. Instead it uses kernel services just like a user-mode application would.

I'm still not clear on difference between a KernalMode and UserMode
driver, and under which situations I would use either one, and their
respective advantages disadvantages.

Kernel-mode driver: direct access to the hardware, direct access to system structures, more risk of making the system unstable or insecure, crashed driver will bring down the entire system.

User-mode driver: no direct access to the hardware (must rely on already provided services), no access to system structures beyond what services provide and what all user-mode code has, less risk of making the system unstable or insecure, crashed driver cannot bring down the system.

Is there some kind of digital signature that's within all .SYS files, which is tested for validity before it's allowed to load or run?

Not exactly, but something like it. You're probably thinking of WHQL certification. Look it up.

If so, is there a "hack" workaround to get past such limitations?

Yes, but there are good reasons why those limitations are there.

--
J.
http://symbolsprose.blogspot.com
.



Relevant Pages

  • Re: Whats wrong with my driver?
    ... Then the virtual disk approach is simply wrong. ... A block device would have several additional ... built-in Windows driver stack. ... the implementation of the kernel-mode part, ...
    (microsoft.public.win32.programmer.kernel)
  • Re: DispatchDeviceControl vs. DispatchInternalDeviceControl
    ... IRP_MJ_INTERNAL_DEVICE_CONTROL handler. ... Kernel-mode drivers can call other drivers using the IoCallDriver mechanism. ... If a driver can accept calls from both user-mode and kernel-mode clients ...
    (microsoft.public.development.device.drivers)
  • Re: devicephyicalmemory fails in XP 64-bit
    ... > As of Windows Server 2003 SP1, ... > kernel-mode drivers. ... > allocated the memory range through MmAllocatePagesForMdl or another method ... if a driver maps two different virtual address ranges to the ...
    (microsoft.public.win32.programmer.kernel)
  • Re: "the system has recovered from a serious error"...
    ... Background information on Stop Error message ... this error condition means that a kernel-mode ... process or driver tried to access a memory location to which it did not ... Are there any yellow question marks in Device Manager? ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: Originator of an IRP
    ... You can check the RequestorMode flag in the IRP to see the mode of the ... User-mode initiators will have UserMode set in this value. ... Kernel-mode ... documented and passed to the driver. ...
    (microsoft.public.development.device.drivers)