1 /* 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: Miscellaneous operations 6 * PROGRAMMERS: Copyright 2006-2007 Herv� Poussineau (hpoussin@reactos.org) 7 */ 8 9 /* INCLUDES ******************************************************************/ 10 11 #include "i8042prt.h" 12 13 #include <debug.h> 14 15 /* FUNCTIONS *****************************************************************/ 16 17 NTSTATUS NTAPI 18 ForwardIrpAndForget( 19 IN PDEVICE_OBJECT DeviceObject, 20 IN PIRP Irp) 21 { 22 PDEVICE_OBJECT LowerDevice = ((PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice; 23 24 ASSERT(LowerDevice); 25 26 IoSkipCurrentIrpStackLocation(Irp); 27 return IoCallDriver(LowerDevice, Irp); 28 } 29 30 NTSTATUS 31 DuplicateUnicodeString( 32 IN ULONG Flags, 33 IN PCUNICODE_STRING SourceString, 34 OUT PUNICODE_STRING DestinationString) 35 { 36 if (SourceString == NULL || DestinationString == NULL 37 || SourceString->Length > SourceString->MaximumLength 38 || (SourceString->Length == 0 && SourceString->MaximumLength > 0 && SourceString->Buffer == NULL) 39 || Flags == RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING || Flags >= 4) 40 { 41 return STATUS_INVALID_PARAMETER; 42 } 43 44 45 if ((SourceString->Length == 0) 46 && (Flags != (RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE | 47 RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING))) 48 { 49 DestinationString->Length = 0; 50 DestinationString->MaximumLength = 0; 51 DestinationString->Buffer = NULL; 52 } 53 else 54 { 55 USHORT DestMaxLength = SourceString->Length; 56 57 if (Flags & RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE) 58 DestMaxLength += sizeof(UNICODE_NULL); 59 60 DestinationString->Buffer = ExAllocatePoolWithTag(PagedPool, DestMaxLength, I8042PRT_TAG); 61 if (DestinationString->Buffer == NULL) 62 return STATUS_NO_MEMORY; 63 64 RtlCopyMemory(DestinationString->Buffer, SourceString->Buffer, SourceString->Length); 65 DestinationString->Length = SourceString->Length; 66 DestinationString->MaximumLength = DestMaxLength; 67 68 if (Flags & RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE) 69 DestinationString->Buffer[DestinationString->Length / sizeof(WCHAR)] = 0; 70 } 71 72 return STATUS_SUCCESS; 73 } 74