[Compuware Corporation] [Compuware NuMega home page] [NuMega Lab] [teal] [DriverStudio] [Image][Image] · Home [Driver Products] Driver Technical Tips · DriverStudio Using IOCTL METHOD_NEITHER · DriverBundle · Previews If you read our earlier tip on METHOD_IN/OUT_DIRECT, you may have been left · Compatibility wondering about the details of the other IOCTL methods, METHOD_BUFFERED, and [Downloads] · METHOD_NEITHER. This tip explores the latter, lesser known of the two, METHOD_NEITHER. Wizards · Utilities If an IOCTL code passed to DeviceIoControl is defined using METHOD_NEITHER, · NT source the operating system performs no address translation or validation of examples pointers passed in parameters InputBuffer and OutputBuffer. Because there is · VxD source relatively less work for the system to do, it can deliver an IRP that uses examples METHOD_NEITHER to a driver faster than it can IRPs that use the other two · WDM source IOCTL methods. However, the burden is now on the driver to ensure that the examples pointers passed to it are valid. In addition, the driver can use the raw [Resources] · pointers only in the context of the calling process. Technical papers · Useful links As shown in the diagram, the pointer passed as parameter InputBuffer appears · Technical tips in field IoGetCurrentIrpStackLocation(pIrp)-> [Support] · Parameters.DeviceIoControl.Type3InputBuffer. The pointer passed as parameter OutputBuffer appears in pIrp-> UserBuffer. Support · Knowledge base Because the operating system has not validated the pointers passed to a · Problem driver in a METHOD_NEITHER IRP, it is crucial to guard against exceptions submission that could result from accessing these pointers. A driver can easily trap an · Product exception that results from dereferencing a bad pointer by bracketing access registration to the pointer in a _try/_except block. Here is some Driver::Works code that · Release notes illustrates the basic idea: [Shop NuMega] · Buy it! NTSTATUS MyDevice::DeviceControl(KIrp I) · Price list { · How to buy · Sales offices switch (I.IoctlCode()) { case IOCTL_NEITHER_OPERATION: [Y2K Compliance] PINPUT_DATA pInput = PINPUT_DATA(I.IoctlType3InputBuffer()); PULONG pOutput = I.UserBuffer(); [More information] _try { NTSTATUS status=Process(pInput, pOutput); return I.Complete(status); } _except ( EXCEPTION_EXECUTE_HANDLER ) { I.Information()=0; return I.Complete(STATUS_ACCESS_DENIED); } // etc. } } The other important thing to remember about pointers in a METHOD_NEITHER IRP is that they may be used only in the context of the calling process. If your driver serializes requests through StartIo, or ever needs to access the buffers from an arbitrary thread context or at IRQL > PASSIVE_LEVEL, then your driver must lock down the buffers and map them to system space. The system services you'll need are MmCreateMdl, MmProbeAndLockPages, and MmGetSystemAddressForMdl. In summary, METHOD_NEITHER can be useful for certain kinds of requests. The precaution of structured exception handling (_try/_except) is required whenever accessing pointers that have not been validated by the system. If the driver can process the request quickly and without synchronization, then METHOD_NEITHER provides an easy and efficient mechanism. However, most of the time it is better to take advantage of the operating system's facilities for buffer management, using either METHOD_IN/OUT_DIRECT, or METHOD_BUFFERED. Back to technical tip start page. DriverCentral · DriverStudio · Free downloads · Resources · Support and Services · Shop NuMega Compuware NuMega · Tel: +1 603 578-8400 · Updated: 9 August 1999 · Problems? Contact our webmaster.