2 * PROJECT: ReactOS i8042 (ps/2 keyboard-mouse controller) driver
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/input/i8042prt/misc.c
5 * PURPOSE: Misceallenous operations
6 * PROGRAMMERS: Copyright 2006-2007 Hervé Poussineau (hpoussin@reactos.org)
9 /* INCLUDES ******************************************************************/
15 /* FUNCTIONS *****************************************************************/
16 static IO_COMPLETION_ROUTINE ForwardIrpAndWaitCompletion
;
19 ForwardIrpAndWaitCompletion(
20 IN PDEVICE_OBJECT DeviceObject
,
24 UNREFERENCED_PARAMETER(DeviceObject
);
25 if (Irp
->PendingReturned
)
26 KeSetEvent((PKEVENT
)Context
, IO_NO_INCREMENT
, FALSE
);
27 return STATUS_MORE_PROCESSING_REQUIRED
;
32 IN PDEVICE_OBJECT DeviceObject
,
37 PDEVICE_OBJECT LowerDevice
= ((PFDO_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
)->LowerDevice
;
40 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
41 IoCopyCurrentIrpStackLocationToNext(Irp
);
43 IoSetCompletionRoutine(Irp
, ForwardIrpAndWaitCompletion
, &Event
, TRUE
, TRUE
, TRUE
);
45 Status
= IoCallDriver(LowerDevice
, Irp
);
46 if (Status
== STATUS_PENDING
)
48 Status
= KeWaitForSingleObject(&Event
, Suspended
, KernelMode
, FALSE
, NULL
);
49 if (NT_SUCCESS(Status
))
50 Status
= Irp
->IoStatus
.Status
;
58 IN PDEVICE_OBJECT DeviceObject
,
61 PDEVICE_OBJECT LowerDevice
= ((PFDO_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
)->LowerDevice
;
65 IoSkipCurrentIrpStackLocation(Irp
);
66 return IoCallDriver(LowerDevice
, Irp
);
70 DuplicateUnicodeString(
72 IN PCUNICODE_STRING SourceString
,
73 OUT PUNICODE_STRING DestinationString
)
75 if (SourceString
== NULL
|| DestinationString
== NULL
76 || SourceString
->Length
> SourceString
->MaximumLength
77 || (SourceString
->Length
== 0 && SourceString
->MaximumLength
> 0 && SourceString
->Buffer
== NULL
)
78 || Flags
== RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING
|| Flags
>= 4)
80 return STATUS_INVALID_PARAMETER
;
84 if ((SourceString
->Length
== 0)
85 && (Flags
!= (RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
|
86 RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING
)))
88 DestinationString
->Length
= 0;
89 DestinationString
->MaximumLength
= 0;
90 DestinationString
->Buffer
= NULL
;
94 USHORT DestMaxLength
= SourceString
->Length
;
96 if (Flags
& RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
)
97 DestMaxLength
+= sizeof(UNICODE_NULL
);
99 DestinationString
->Buffer
= ExAllocatePoolWithTag(PagedPool
, DestMaxLength
, I8042PRT_TAG
);
100 if (DestinationString
->Buffer
== NULL
)
101 return STATUS_NO_MEMORY
;
103 RtlCopyMemory(DestinationString
->Buffer
, SourceString
->Buffer
, SourceString
->Length
);
104 DestinationString
->Length
= SourceString
->Length
;
105 DestinationString
->MaximumLength
= DestMaxLength
;
107 if (Flags
& RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
)
108 DestinationString
->Buffer
[DestinationString
->Length
/ sizeof(WCHAR
)] = 0;
111 return STATUS_SUCCESS
;