1 /* 2 * COPYRIGHT: See COPYING in the top level directory 3 * PROJECT: ReactOS Keyboard class driver 4 * FILE: drivers/input/kbdclass/misc.c 5 * PURPOSE: Miscellaneous operations 6 * 7 * PROGRAMMERS: Herv� Poussineau (hpoussin@reactos.org) 8 */ 9 10 #include "kbdclass.h" 11 12 #include <debug.h> 13 14 15 NTSTATUS NTAPI 16 ForwardIrpAndForget( 17 IN PDEVICE_OBJECT DeviceObject, 18 IN PIRP Irp) 19 { 20 PDEVICE_OBJECT LowerDevice; 21 22 ASSERT(!((PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsClassDO); 23 LowerDevice = ((PPORT_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice; 24 25 IoSkipCurrentIrpStackLocation(Irp); 26 return IoCallDriver(LowerDevice, Irp); 27 } 28 29 NTSTATUS 30 DuplicateUnicodeString( 31 IN ULONG Flags, 32 IN PCUNICODE_STRING SourceString, 33 OUT PUNICODE_STRING DestinationString) 34 { 35 if (SourceString == NULL || DestinationString == NULL 36 || SourceString->Length > SourceString->MaximumLength 37 || (SourceString->Length == 0 && SourceString->MaximumLength > 0 && SourceString->Buffer == NULL) 38 || Flags == RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING || Flags >= 4) 39 { 40 return STATUS_INVALID_PARAMETER; 41 } 42 43 44 if ((SourceString->Length == 0) 45 && (Flags != (RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE | 46 RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING))) 47 { 48 DestinationString->Length = 0; 49 DestinationString->MaximumLength = 0; 50 DestinationString->Buffer = NULL; 51 } 52 else 53 { 54 USHORT DestMaxLength = SourceString->Length; 55 56 if (Flags & RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE) 57 DestMaxLength += sizeof(UNICODE_NULL); 58 59 DestinationString->Buffer = ExAllocatePoolWithTag(PagedPool, DestMaxLength, CLASS_TAG); 60 if (DestinationString->Buffer == NULL) 61 return STATUS_NO_MEMORY; 62 63 RtlCopyMemory(DestinationString->Buffer, SourceString->Buffer, SourceString->Length); 64 DestinationString->Length = SourceString->Length; 65 DestinationString->MaximumLength = DestMaxLength; 66 67 if (Flags & RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE) 68 DestinationString->Buffer[DestinationString->Length / sizeof(WCHAR)] = 0; 69 } 70 71 return STATUS_SUCCESS; 72 } 73