#include <ntoskrnl.h>
#define NDEBUG
-#include <internal/debug.h>
+#include <debug.h>
#if defined (ALLOC_PRAGMA)
#pragma alloc_text(INIT, IopInitPlugPlayEvents)
typedef struct _PNP_EVENT_ENTRY
{
- LIST_ENTRY ListEntry;
- PLUGPLAY_EVENT_BLOCK Event;
+ LIST_ENTRY ListEntry;
+ PLUGPLAY_EVENT_BLOCK Event;
} PNP_EVENT_ENTRY, *PPNP_EVENT_ENTRY;
static NTSTATUS
IopRemovePlugPlayEvent(VOID)
{
- /* Remove a pnp event entry from the tail of the queue */
- if (!IsListEmpty(&IopPnpEventQueueHead))
- {
- ExFreePool(RemoveTailList(&IopPnpEventQueueHead));
- }
-
- /* Signal the next pnp event in the queue */
- if (!IsListEmpty(&IopPnpEventQueueHead))
- {
- KeSetEvent(&IopPnpNotifyEvent,
- 0,
- FALSE);
- }
+ /* Remove a pnp event entry from the tail of the queue */
+ if (!IsListEmpty(&IopPnpEventQueueHead))
+ {
+ ExFreePool(CONTAINING_RECORD(RemoveTailList(&IopPnpEventQueueHead), PNP_EVENT_ENTRY, ListEntry));
+ }
+
+ /* Signal the next pnp event in the queue */
+ if (!IsListEmpty(&IopPnpEventQueueHead))
+ {
+ KeSetEvent(&IopPnpNotifyEvent,
+ 0,
+ FALSE);
+ }
- return STATUS_SUCCESS;
+ return STATUS_SUCCESS;
}
static PDEVICE_OBJECT
return NULL;
if (DeviceInstance == NULL ||
- DeviceInstance->Length == 0
- )
+ DeviceInstance->Length == 0)
{
if (IopRootDeviceNode->PhysicalDeviceObject)
{
UNICODE_STRING Name;
Name.Buffer = NULL;
- _SEH_TRY
- {
- Name.Length = SrcName->Length;
- Name.MaximumLength = SrcName->MaximumLength;
- if (Name.Length > Name.MaximumLength)
- {
- Status = STATUS_INVALID_PARAMETER;
- _SEH_LEAVE;
- }
- if (Name.MaximumLength)
- {
- ProbeForRead(SrcName->Buffer,
- Name.MaximumLength,
- sizeof(WCHAR));
- Name.Buffer = ExAllocatePool(NonPagedPool, Name.MaximumLength);
- if (Name.Buffer == NULL)
- {
- Status = STATUS_INSUFFICIENT_RESOURCES;
- _SEH_LEAVE;
- }
- memcpy(Name.Buffer, SrcName->Buffer, Name.MaximumLength);
- }
- *DstName = Name;
- }
- _SEH_HANDLE
- {
- Status = _SEH_GetExceptionCode();
- }
- _SEH_END;
-
- if (!NT_SUCCESS(Status) && Name.Buffer)
- {
- ExFreePool(Name.Buffer);
+ _SEH2_TRY
+ {
+ Name.Length = SrcName->Length;
+ Name.MaximumLength = SrcName->MaximumLength;
+ if (Name.Length > Name.MaximumLength)
+ {
+ Status = STATUS_INVALID_PARAMETER;
+ _SEH2_LEAVE;
+ }
+
+ if (Name.MaximumLength)
+ {
+ ProbeForRead(SrcName->Buffer,
+ Name.MaximumLength,
+ sizeof(WCHAR));
+ Name.Buffer = ExAllocatePool(NonPagedPool, Name.MaximumLength);
+ if (Name.Buffer == NULL)
+ {
+ Status = STATUS_INSUFFICIENT_RESOURCES;
+ _SEH2_LEAVE;
+ }
+
+ memcpy(Name.Buffer, SrcName->Buffer, Name.MaximumLength);
+ }
+
+ *DstName = Name;
+ }
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+ {
+ if (Name.Buffer)
+ ExFreePool(Name.Buffer);
+ Status = _SEH2_GetExceptionCode();
}
+ _SEH2_END;
+
return Status;
}
IopGetDeviceProperty(PPLUGPLAY_CONTROL_PROPERTY_DATA PropertyData)
{
PDEVICE_OBJECT DeviceObject = NULL;
- NTSTATUS Status = STATUS_SUCCESS;
+ NTSTATUS Status;
UNICODE_STRING DeviceInstance;
ULONG BufferSize;
ULONG Property = 0;
Status = IopCaptureUnicodeString(&DeviceInstance, &PropertyData->DeviceInstance);
if (!NT_SUCCESS(Status))
{
- return Status;
+ return Status;
}
- _SEH_TRY
+ _SEH2_TRY
{
- Property = PropertyData->Property;
+ Property = PropertyData->Property;
BufferSize = PropertyData->BufferSize;
ProbeForWrite(PropertyData->Buffer,
BufferSize,
sizeof(UCHAR));
}
- _SEH_HANDLE
- {
- Status = _SEH_GetExceptionCode();
- }
- _SEH_END;
-
- if (!NT_SUCCESS(Status))
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
- ExFreePool(DeviceInstance.Buffer);
- return Status;
+ ExFreePool(DeviceInstance.Buffer);
+ _SEH2_YIELD(return _SEH2_GetExceptionCode());
}
+ _SEH2_END;
/* Get the device object */
DeviceObject = IopGetDeviceObjectFromDeviceInstance(&DeviceInstance);
Buffer = ExAllocatePool(NonPagedPool, BufferSize);
if (Buffer == NULL)
{
- return STATUS_INSUFFICIENT_RESOURCES;
+ return STATUS_INSUFFICIENT_RESOURCES;
}
-
Status = IoGetDeviceProperty(DeviceObject,
Property,
BufferSize,
if (NT_SUCCESS(Status))
{
- _SEH_TRY
- {
- memcpy(Buffer, PropertyData->Buffer, BufferSize);
- PropertyData->BufferSize = BufferSize;
- }
- _SEH_HANDLE
- {
- Status = _SEH_GetExceptionCode();
- }
- _SEH_END;
+ _SEH2_TRY
+ {
+ memcpy(PropertyData->Buffer, Buffer, BufferSize);
+ PropertyData->BufferSize = BufferSize;
+ }
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+ {
+ Status = _SEH2_GetExceptionCode();
+ }
+ _SEH2_END;
}
+
ExFreePool(Buffer);
return Status;
}
Status = IopCaptureUnicodeString(&TargetDeviceInstance, &RelatedDeviceData->TargetDeviceInstance);
if (!NT_SUCCESS(Status))
{
- return Status;
+ return Status;
}
- _SEH_TRY
+ _SEH2_TRY
{
- Relation = RelatedDeviceData->Relation;
- MaximumLength = RelatedDeviceData->RelatedDeviceInstanceLength;
- ProbeForWrite(RelatedDeviceData->RelatedDeviceInstance,
- MaximumLength,
- sizeof(WCHAR));
+ Relation = RelatedDeviceData->Relation;
+ MaximumLength = RelatedDeviceData->RelatedDeviceInstanceLength;
+ ProbeForWrite(RelatedDeviceData->RelatedDeviceInstance,
+ MaximumLength,
+ sizeof(WCHAR));
}
- _SEH_HANDLE
- {
- Status = _SEH_GetExceptionCode();
- }
- _SEH_END;
-
- if (!NT_SUCCESS(Status))
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
ExFreePool(TargetDeviceInstance.Buffer);
- return Status;
+ _SEH2_YIELD(return _SEH2_GetExceptionCode());
}
+ _SEH2_END;
RtlInitUnicodeString(&RootDeviceName,
L"HTREE\\ROOT\\0");
TRUE))
{
DeviceNode = IopRootDeviceNode;
- ExFreePool(TargetDeviceInstance.Buffer);
+ ExFreePool(TargetDeviceInstance.Buffer);
}
else
{
/* Get the device object */
DeviceObject = IopGetDeviceObjectFromDeviceInstance(&TargetDeviceInstance);
- ExFreePool(TargetDeviceInstance.Buffer);
+ ExFreePool(TargetDeviceInstance.Buffer);
if (DeviceObject == NULL)
return STATUS_NO_SUCH_DEVICE;
}
/* Copy related device instance name */
- _SEH_TRY
+ _SEH2_TRY
{
RtlCopyMemory(RelatedDeviceData->RelatedDeviceInstance,
RelatedDeviceNode->InstancePath.Buffer,
RelatedDeviceNode->InstancePath.Length);
RelatedDeviceData->RelatedDeviceInstanceLength = RelatedDeviceNode->InstancePath.Length;
}
- _SEH_HANDLE
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
- Status = _SEH_GetExceptionCode();
+ Status = _SEH2_GetExceptionCode();
}
- _SEH_END;
+ _SEH2_END;
if (DeviceObject != NULL)
{
ULONG DeviceStatus = 0;
ULONG DeviceProblem = 0;
UNICODE_STRING DeviceInstance;
- NTSTATUS Status = STATUS_SUCCESS;
+ NTSTATUS Status;
DPRINT("IopDeviceStatus() called\n");
return Status;
DPRINT("Device name: '%wZ'\n", &DeviceInstance);
- _SEH_TRY
+ _SEH2_TRY
{
- Operation = StatusData->Operation;
- if (Operation == PNP_SET_DEVICE_STATUS)
- {
- DeviceStatus = StatusData->DeviceStatus;
- DeviceProblem = StatusData->DeviceProblem;
- }
+ Operation = StatusData->Operation;
+ if (Operation == PNP_SET_DEVICE_STATUS)
+ {
+ DeviceStatus = StatusData->DeviceStatus;
+ DeviceProblem = StatusData->DeviceProblem;
+ }
}
- _SEH_HANDLE
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
- Status = _SEH_GetExceptionCode();
- }
- _SEH_END;
-
- if (!NT_SUCCESS(Status))
- {
- if (DeviceInstance.Buffer)
- ExFreePool(DeviceInstance.Buffer);
- return Status;
+ if (DeviceInstance.Buffer) ExFreePool(DeviceInstance.Buffer);
+ _SEH2_YIELD(return _SEH2_GetExceptionCode());
}
+ _SEH2_END;
/* Get the device object */
DeviceObject = IopGetDeviceObjectFromDeviceInstance(&DeviceInstance);
if (Operation == PNP_GET_DEVICE_STATUS)
{
- _SEH_TRY
- {
- StatusData->DeviceStatus = DeviceStatus;
- StatusData->DeviceProblem = DeviceProblem;
- }
- _SEH_HANDLE
- {
- Status = _SEH_GetExceptionCode();
- }
- _SEH_END;
+ _SEH2_TRY
+ {
+ StatusData->DeviceStatus = DeviceStatus;
+ StatusData->DeviceProblem = DeviceProblem;
+ }
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+ {
+ Status = _SEH2_GetExceptionCode();
+ }
+ _SEH2_END;
}
return Status;
Status = IopCaptureUnicodeString(&DeviceInstance, &DepthData->DeviceInstance);
if (!NT_SUCCESS(Status))
{
- return Status;
+ return Status;
}
/* Get the device object */
DeviceNode = IopGetDeviceNode(DeviceObject);
- DepthData->Depth = DeviceNode->Level;
-
- ObDereferenceObject(DeviceObject);
-
- _SEH_TRY
+ _SEH2_TRY
{
- DepthData->Depth = DeviceNode->Level;
+ DepthData->Depth = DeviceNode->Level;
}
- _SEH_HANDLE
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
- Status = _SEH_GetExceptionCode();
+ Status = _SEH2_GetExceptionCode();
}
- _SEH_END;
+ _SEH2_END;
+
+ ObDereferenceObject(DeviceObject);
return Status;
}
OUT PPLUGPLAY_EVENT_BLOCK Buffer,
IN ULONG BufferSize)
{
- PPNP_EVENT_ENTRY Entry;
- NTSTATUS Status;
-
- DPRINT("NtGetPlugPlayEvent() called\n");
-
- /* Function can only be called from user-mode */
- if (KeGetPreviousMode() == KernelMode)
- {
- DPRINT1("NtGetPlugPlayEvent cannot be called from kernel mode!\n");
- return STATUS_ACCESS_DENIED;
- }
-
- /* Check for Tcb privilege */
- if (!SeSinglePrivilegeCheck(SeTcbPrivilege,
- UserMode))
- {
- DPRINT1("NtGetPlugPlayEvent: Caller does not hold the SeTcbPrivilege privilege!\n");
- return STATUS_PRIVILEGE_NOT_HELD;
- }
-
- /* Wait for a PnP event */
- DPRINT("Waiting for pnp notification event\n");
- Status = KeWaitForSingleObject(&IopPnpNotifyEvent,
- UserRequest,
- KernelMode,
- FALSE,
- NULL);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("KeWaitForSingleObject() failed (Status %lx)\n", Status);
- return Status;
- }
+ PPNP_EVENT_ENTRY Entry;
+ NTSTATUS Status;
- /* Get entry from the tail of the queue */
- Entry = CONTAINING_RECORD(IopPnpEventQueueHead.Blink,
- PNP_EVENT_ENTRY,
- ListEntry);
+ DPRINT("NtGetPlugPlayEvent() called\n");
- /* Check the buffer size */
- if (BufferSize < Entry->Event.TotalSize)
- {
- DPRINT1("Buffer is too small for the pnp-event\n");
- return STATUS_BUFFER_TOO_SMALL;
- }
+ /* Function can only be called from user-mode */
+ if (KeGetPreviousMode() == KernelMode)
+ {
+ DPRINT1("NtGetPlugPlayEvent cannot be called from kernel mode!\n");
+ return STATUS_ACCESS_DENIED;
+ }
- /* Copy event data to the user buffer */
- memcpy(Buffer,
- &Entry->Event,
- Entry->Event.TotalSize);
+ /* Check for Tcb privilege */
+ if (!SeSinglePrivilegeCheck(SeTcbPrivilege,
+ UserMode))
+ {
+ DPRINT1("NtGetPlugPlayEvent: Caller does not hold the SeTcbPrivilege privilege!\n");
+ return STATUS_PRIVILEGE_NOT_HELD;
+ }
+
+ /* Wait for a PnP event */
+ DPRINT("Waiting for pnp notification event\n");
+ Status = KeWaitForSingleObject(&IopPnpNotifyEvent,
+ UserRequest,
+ KernelMode,
+ FALSE,
+ NULL);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("KeWaitForSingleObject() failed (Status %lx)\n", Status);
+ return Status;
+ }
- DPRINT("NtGetPlugPlayEvent() done\n");
+ /* Get entry from the tail of the queue */
+ Entry = CONTAINING_RECORD(IopPnpEventQueueHead.Blink,
+ PNP_EVENT_ENTRY,
+ ListEntry);
- return STATUS_SUCCESS;
+ /* Check the buffer size */
+ if (BufferSize < Entry->Event.TotalSize)
+ {
+ DPRINT1("Buffer is too small for the pnp-event\n");
+ return STATUS_BUFFER_TOO_SMALL;
+ }
+
+ /* Copy event data to the user buffer */
+ memcpy(Buffer,
+ &Entry->Event,
+ Entry->Event.TotalSize);
+
+ DPRINT("NtGetPlugPlayEvent() done\n");
+
+ return STATUS_SUCCESS;
}
/*
IN OUT PVOID Buffer,
IN ULONG BufferLength)
{
- NTSTATUS Status = STATUS_SUCCESS;
-
DPRINT("NtPlugPlayControl(%lu %p %lu) called\n",
PlugPlayControlClass, Buffer, BufferLength);
}
/* Probe the buffer */
- _SEH_TRY
+ _SEH2_TRY
{
ProbeForWrite(Buffer,
BufferLength,
sizeof(ULONG));
}
- _SEH_HANDLE
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
- Status = _SEH_GetExceptionCode();
- }
- _SEH_END;
-
- if (!NT_SUCCESS(Status))
- {
- return Status;
+ _SEH2_YIELD(return _SEH2_GetExceptionCode());
}
+ _SEH2_END;
switch (PlugPlayControlClass)
{