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 *****************************************************************/
17 static IO_COMPLETION_ROUTINE ForwardIrpAndWaitCompletion
;
20 ForwardIrpAndWaitCompletion(
21 IN PDEVICE_OBJECT DeviceObject
,
25 UNREFERENCED_PARAMETER(DeviceObject
);
26 __analysis_assume(Context
!= NULL
);
27 if (Irp
->PendingReturned
)
28 KeSetEvent(Context
, IO_NO_INCREMENT
, FALSE
);
29 return STATUS_MORE_PROCESSING_REQUIRED
;
34 IN PDEVICE_OBJECT DeviceObject
,
39 PDEVICE_OBJECT LowerDevice
= ((PFDO_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
)->LowerDevice
;
42 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
43 IoCopyCurrentIrpStackLocationToNext(Irp
);
45 IoSetCompletionRoutine(Irp
, ForwardIrpAndWaitCompletion
, &Event
, TRUE
, TRUE
, TRUE
);
47 Status
= IoCallDriver(LowerDevice
, Irp
);
48 if (Status
== STATUS_PENDING
)
50 Status
= KeWaitForSingleObject(&Event
, Suspended
, KernelMode
, FALSE
, NULL
);
51 if (NT_SUCCESS(Status
))
52 Status
= Irp
->IoStatus
.Status
;
60 IN PDEVICE_OBJECT DeviceObject
,
63 PDEVICE_OBJECT LowerDevice
= ((PFDO_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
)->LowerDevice
;
67 IoSkipCurrentIrpStackLocation(Irp
);
68 return IoCallDriver(LowerDevice
, Irp
);
72 DuplicateUnicodeString(
74 IN PCUNICODE_STRING SourceString
,
75 OUT PUNICODE_STRING DestinationString
)
77 if (SourceString
== NULL
|| DestinationString
== NULL
78 || SourceString
->Length
> SourceString
->MaximumLength
79 || (SourceString
->Length
== 0 && SourceString
->MaximumLength
> 0 && SourceString
->Buffer
== NULL
)
80 || Flags
== RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING
|| Flags
>= 4)
82 return STATUS_INVALID_PARAMETER
;
86 if ((SourceString
->Length
== 0)
87 && (Flags
!= (RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
|
88 RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING
)))
90 DestinationString
->Length
= 0;
91 DestinationString
->MaximumLength
= 0;
92 DestinationString
->Buffer
= NULL
;
96 USHORT DestMaxLength
= SourceString
->Length
;
98 if (Flags
& RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
)
99 DestMaxLength
+= sizeof(UNICODE_NULL
);
101 DestinationString
->Buffer
= ExAllocatePoolWithTag(PagedPool
, DestMaxLength
, I8042PRT_TAG
);
102 if (DestinationString
->Buffer
== NULL
)
103 return STATUS_NO_MEMORY
;
105 RtlCopyMemory(DestinationString
->Buffer
, SourceString
->Buffer
, SourceString
->Length
);
106 DestinationString
->Length
= SourceString
->Length
;
107 DestinationString
->MaximumLength
= DestMaxLength
;
109 if (Flags
& RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
)
110 DestinationString
->Buffer
[DestinationString
->Length
/ sizeof(WCHAR
)] = 0;
113 return STATUS_SUCCESS
;