Hi
I'm enhancing my PCIe device driver to log information via a linked list: In EvtIoRead
, I allocate ~20 bytes of non-paged memory using ExAllocatePool2
for each list item, store the data, and save the pointer in DEVICE_CONTEXT
. Upon receiving a device response, deviceDPC
logs additional info and links the item. The data is read and freed later. To test this, I created a minimal kernel module (no physical device) mimicking a process explorer, which successfully validated the memory management logic.
However, when I integrated this into my PCIe driver and attempted installation via Device Manager, I encountered error "The driver may be corrupted or missing. (Code 39)".
After troubleshooting, I isolated the issue to the ExAllocatePool2
call in EvtIoRead
. The behavior I'm observing is perplexing and I'm seeking insights on potential causes.
- EvtIoRead implementation 1, and I got The driver may be corrupted or missing. (Code 39) when installing it with Device Manager.
void myEvtIoRead(...)
{
...
MyInfoStruct * info = (MyInfoStruct *)ExAllocatePool2(POOL_FLAG_NON_PAGED, sizeof(MyInfoStruct), DRIVER_TAG);
info->data = 1;
// I should not have freed this memory space here;
// instead, it should be released at a future time when the linked list has accumulated too many entries or when other users have read this data.
// I deliberately released it directly here to eliminate the possibility that improper memory management was the cause.
ExFreePool(info);
...
}
- EvtIoRead implementation 2, Driver installed successfully with Device Manager and appeared to be functioning normally.
void myEvtIoRead(..)
{
MyInfoStruct info;
// MyInfoStruct * info = (MyInfoStruct *)ExAllocatePool2(POOL_FLAG_NON_PAGED, sizeof(MyInfoStruct), DRIVER_TAG);
//info->data = 1;
info.data = 1;
//ExFreePool(info);
...
}
I am certain that this is the only difference between the two versions of the code. Additionally, my operating system is Windows 10, version 1809. I am at a loss to understand why this is happening. Could this be due to some form of restriction?