当操作系统调用已注册的回调函数时,它会将指针传递到 NotificationStructure 参数中的DEVICE_INTERFACE_CHANGE_NOTIFICATION结构。
下面的代码示例演示了一个回调函数的实现,该函数处理处理器的异步驱动程序通知:
// Asynchronous processor notification callback function
NTSTATUS
AsyncProcessorCallback(
IN PVOID NotificationStructure,
IN PVOID Context
)
{
PDEVICE_INTERFACE_CHANGE_NOTIFICATION Notification;
ULONG ProcessorCount;
KAFFINITY ActiveProcessors;
Notification =
(PDEVICE_INTERFACE_CHANGE_NOTIFICATION)
NotificationStructure;
// Verify that this notification is about a processor
// that is being added to the hardware partition.
if (IsEqualGUID(
&Notification->Event,
&GUID_DEVICE_INTERFACE_ARRIVAL
))
{
// Get the current processor count and affinity
ProcessorCount =
KeQueryActiveProcessorCount(
&ActiveProcessors
);
// Adjust any resource allocations that are based
// on the number of processors.
...
// Adjust the assignment of resources that are
// assigned to specific processors.
...
// Begin scheduling any per processor threads
// on the new processor.
...
// Adjust the scheduling of DPCs and other threads
...
// Adjust any load balancing algorithms
...
}
// Always return success status
return STATUS_SUCCESS;
}
下面的代码示例演示回调函数的实现,该函数处理内存的异步驱动程序通知:
// Asynchronous memory notification callback function
NTSTATUS
AsyncMemoryCallback(
IN PVOID NotificationStructure,
IN PVOID Context
)
{
PDEVICE_INTERFACE_CHANGE_NOTIFICATION Notification;
Notification =
(PDEVICE_INTERFACE_CHANGE_NOTIFICATION)
NotificationStructure;
// Verify that this notification is about memory
// that is being added to the hardware partition.
if (IsEqualGUID(
&Notification->Event,
&GUID_DEVICE_INTERFACE_ARRIVAL
))
{
// Increase the size of any memory buffers
// for optimal performance of the driver.
...
}
// Always return success status
return STATUS_SUCCESS;
}