This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

GPIO driver implementation bug

It looks to me like there might be a bug in the 35XX CE BSP's GPIO driver.

If you look at the gpio.h file in the common directory it clearly look like it was designed for both inprocess and cross process use.

The first call to GPIOOpen tests if it is an inprocess or out of process call (see GPIO.cpp). In process calls will use the returned function table for subsequent calls where as out of process call will use the DeviceIoControl call.

If you look at around 515 in gpio.h you will see DeviceIoControl return does not seem to handle the returned code correctly.

i.e.

// Get function pointers. If not possible (b/c of cross process calls), use IOCTLs instead

if (!DeviceIoControl(

hDevice, IOCTL_DDK_GET_DRIVER_IFC, (VOID*)&DEVICE_IFC_GPIO_GUID,

sizeof(DEVICE_IFC_GPIO_GUID), &pContext->ifc,

sizeof(DEVICE_IFC_GPIO), NULL, NULL))

{

// Need to use IOCTLs instead of direct function ptrs

pContext->ifc.context = 0;

DEBUGMSG(1, (L"GPIOOpen DeviceIoControl failed\r\n"));

CloseHandle(hDevice);

LocalFree(pContext);

pContext = NULL;

goto cleanUp;

}

// Save device handle

pContext->hDevice = hDevice;

cleanUp:

return pContext;

}

I think it should be something like:

// Get function pointers. If not possible (b/c of cross process calls), use IOCTLs instead

if

(!DeviceIoControl(

hDevice, IOCTL_DDK_GET_DRIVER_IFC, (VOID*)&DEVICE_IFC_GPIO_GUID,

sizeof

(DEVICE_IFC_GPIO_GUID), &pContext->ifc,

sizeof

(DEVICE_IFC_GPIO), NULL, NULL))

{

//// Need to use IOCTLs instead of direct function ptrs

//pContext->ifc.context = 0;

//DEBUGMSG(1, (L"GPIOOpen DeviceIoControl failed\r\n"));

//CloseHandle(hDevice);

//LocalFree(pContext);

//pContext = NULL;

//goto cleanUp;

if

(ERROR_ACCESS_DENIED == GetLastError())

{

// Need to use IOCTLs instead of direct function ptrs

pContext->ifc.context = 0;

}

else

{

DEBUGMSG(1, (L

"GPIOOpen DeviceIoControl failed\r\n"

));

CloseHandle(hDevice);

LocalFree(pContext);

pContext = NULL;

goto

cleanUp;

}

}

// Save device handle

pContext->hDevice = hDevice;

cleanUp:

return

pContext;

 

 

 

}

Could someone please give me a second opinion? I have not fully verified but I think its better. 

DV

 

  • Thanks. Looks like  a valid problem. We will open up a bug report and incorporate it into a future release.

  • A better approach would have been to check if the process making the call to the GPIOOpen() is the Kernel Process or a non-Kernel Process.

    WinCE provides the GetCallerVMProcessID() function to check the ID of the calling process, if this is not the same as the current Kernel Process [GetCurrentProcessId()], then it can be modified to use the IOCTL approach rather than the direct function calling approach.

    Regards,

    Ravi